|
Post by slenkar on Mar 28, 2013 17:22:10 GMT
Im using version 3.0 Im trying to make a platform game where the player has right and left momentum, like a wrestler bouncing off the ropes to run faster in the opposite direction The problem is that my player doesnt bounce off the left and right walls unless I am pressing a key so when the player presses RIGHT his right momentum (variable A) increases, only when the players momentum goes above 120 does he move right and then he goes faster depending on how much momentum he has here is the snapshot www.mediafire.com/?hu8gbqqlcsi24s7a is the players momentum here is some pseudocode of what i did if key 0 add 2 to a endif if a>120 moveright endif if collision 2 (bouncy block on the right of the screen) if a>120 let b=a subtract 120 from b subtract b from a (players momentum is opposite because he bounces off the block) endif endif if a>180 (if momentum is bigger than 180 move right again to simulate speed) moveright endif (check for collision again) if collision 2 (bouncy block on the right of the screen) if a>120 let b=a subtract 120 from b subtract b from a (players momentum is opposite because he bounces off the block) endif endif if a>220 (if momentum is maxed out move the player right again topspeed) moveright endif (check for collision yet again) if collision 2 (bouncy block on the right of the screen) if a>120 let b=a subtract 120 from b subtract b from a (players momentum is opposite because he bounces off the block) endif endif
|
|
|
Post by thesentinel on Mar 30, 2013 5:50:56 GMT
What format is that file? It has no extension and won't open in Spectaculator or Spin.
|
|
|
Post by slenkar on Mar 30, 2013 19:05:47 GMT
sorry, its a snapshot file, created by Fuse spectrum emulator
|
|
|
Post by nra on Mar 31, 2013 17:08:35 GMT
The traditional 90'-solution is using offsets, e.g in Basic pseudocode would be something like10 let x=100: let y=100 //init coords 20 let xx=-1: let yy=1 //offsets for x'/y' . . . 100 let x = x + xx: let y=y + yy //main updating loop 110 if x is not ok then xx=-xx //if needed, reverse xx direction 120 if y is not ok then yy=-yy //if needed, reverse yy direction . . . In the AGD I would use one (direction) or two vars to mimic the idea.
|
|
|
Post by slenkar on Mar 31, 2013 18:27:07 GMT
so you would totally take control of the characters movement , this integrates with collision? as in you dont lose collision with manual adjustment of character co-ords do ya?
|
|
|
Post by nra on Mar 31, 2013 19:50:31 GMT
Check a quick'n'dirty attachment to make it clear. I used A and B variables, although it's possible to replace by proper paramA and paramB per individual sprite. Never mind the K variable in keyboard checking for I'm fighting with 'one button at a time' issue, which works different in different emulators and semi-rows... Hmm, some LastKey variable required... Attachments:
|
|
|
Post by nra on Mar 31, 2013 21:08:08 GMT
By the way, sometimes it's possible to use random direction bouncing--not very realistic but makes the things go funnier)
|
|
|
Post by slenkar on Apr 11, 2013 0:54:08 GMT
good example thanks
|
|
|
Post by nra on Apr 11, 2013 22:39:52 GMT
Now I'm TommyGunning a little, yet it's quite possible to simulate almost 'free-ratio' angle bouncing using A, B (0 or 1) as direction and M, N (0..10?) as magnitude, say, in pseudo-code . . . REPEAT M if A=0 if cangodown spritegodown else bounce endif endif if A=1 if cangoup spritegoup else bounce endif endif ENDREPEAT
REPEAT N if B=0 if cangoleft spritegodleft else bounce endif endif if B=1 if cangoright spritegoright else bounce endif endif ENDREPEAT . . . But as far as it involves rather much typing of similar extracts for bouncing it is better for TommyGun.AGD. Also it's possible to simulate randomness using such an approach if bounce change_direction if rnd(5)=rnd(5) //when double out of 5 delta=1+rnd(4) if rnd(10)>5 offset = offset + delta else offset = offset - delta endif //offset=+-5 endif //rnd(10) endif //bouncing which makes it more logical especially for such games like Krakout and others where limited bouncing may loop rather often. Hope, you grasped the idea)
Cheers
|
|