|
Post by 10loadgameplay on Aug 14, 2012 12:52:39 GMT
I'm no code genius, I'll tell you that now, but I managed to code up pushable blocks! After much head scratching I worked out this method of allowing the player to push objects.
In the Sprite type code:
IF COLLISION 0 IF KEY 0 IF CANGORIGHT SPRITERIGHT DELAY 3 ENDIF ENDIF ENDIF IF COLLISION 0 IF KEY 1 IF CANGOLEFT SPRITELEFT DELAY 3 ENDIF ENDIF ENDIF IF COLLISION 0 IF KEY 3 IF CANGOUP SPRITEUP DELAY 3 ENDIF ENDIF ENDIF
It works quite well pushing left or right but the player tended to stick to the block if you pressed up or down then left or right. The work around for this was to remove the pushing down functionality, so the player can detach from the block by pressing down.
One thing I'd like to do is make the pushable object 'solid' so enemies don't walk through it and also allow pushable objects to push each other around.
|
|
|
Post by thesentinel on Mar 13, 2013 8:59:02 GMT
Thanks so much for that. It might come in handy, although I think for what I want to do it pick up blocks and have the character hold them over his head and then toss them, and maybe they bounce a bit when hitting the ground before stopping.
I think I might be getting to ambitious!
|
|
leonardo
Abandoned Uranium Working
Posts: 17
|
Post by leonardo on May 23, 2016 11:00:54 GMT
I'll use part of your code tonite, and see what happens.
Leonardo
|
|
|
Post by andrewvanbeck on May 24, 2016 13:58:31 GMT
You could use 2 variables to store the player X and Y position, as well as the holding state - in the player event, at the end, you'd set say, M and N to the players X and Y variables. Then, in the blocks event, you could set it's own X and Y position to M and N, move it up by 16, and even check the state of the fire button to tell if the block should be thrown.
I did this with a Super Crate Box demake, used variables for the player position, then separate sprites for guns, worked out pretty nice. There is a slight 1 frame lag, but that just adds to the illusion of motion - so the player sprite would move before the held item, and it adds a little inertia to the effect as the item tries to keep up with the player.
For actually making the block throwable... well I'd just use Direction for left(1) or right(2), or 0 for no left/right movement. Then you can make it jump, fall, move left or right depending on direction, and if the sprite can't go left or right you can set the direction to 0. The alternative is fairly difficult to get right, making your own physics, and it tends to always need more variables than the 3 you get per sprite.
|
|
leonardo
Abandoned Uranium Working
Posts: 17
|
Post by leonardo on May 24, 2016 16:15:16 GMT
Thanks. I'll try to write a code following your suggestments. I still have to understand several things. Thanks
|
|