Author Topic: Path prediction  (Read 11240 times)

0 Members and 1 Guest are viewing this topic.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Path prediction
« on: November 03, 2012, 06:09:32 pm »
Here's my code:
Code: [Select]
:[00003C3C3C3C0000]?Pic1
:37?X
:53?Y
:5?D?C?F
:0?E?S?I?J?G?N
:Repeat (Y?56) or getKey(15) or (G=1)
:Pt-On(X,Y,Pic1)
:X+E?X
:Y-D?Y
:D--
:If (D>64) and pxl-Test(X+4,Y+7)
:C?D
:5?F
:4+X-B/2+E?E
:End
:If X<3
:4?X
:End
:If (X>64) and (X<99)
:63?X
:End
:If pxl-Test(X,Y+4) or pxl-Test(X+7,Y+4)
:?E?E
:End
:DispGraph
:End
I took off the stuff with the paddle movement and some more 'cause it doesn't affect the ball movement. But you can see all the code as attachment BOUNCSRC.8xp on the first post on this thread:
http://ourl.ca/17002
Anyways, the ball bounces around on a paddle 16 pxls long and the very left of it is B-8. I want to have a trail of dots like in the original game:
http://www.madebypixelate.com/games/mr-bounce
It'll describe how the ball will move until it gets to the bottom of the screen, and if the paddle is where the ball will end up, it'll describe how it'll move until it gets to the bottom again. It will also change dynamically with the paddle's movement.
Anyone have any idea how to do this?
I could make ball movement into its own loop and disp a pxl rather than the ball sprite and run it until the Y>56. But that would probably be pretty slow and take up lots of bytes.
« Last Edit: November 03, 2012, 06:19:29 pm by dinosteven »

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Path prediction
« Reply #1 on: November 03, 2012, 08:04:44 pm »
I think that last thing is what you're going to have to do. Run a loop every frame drawing a pxl for where the ball would be assuming the paddle doesn't move. If you do it efficiently and at a low-ish sample speed, it shouldn't be too hard on performance.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Path prediction
« Reply #2 on: November 03, 2012, 10:18:52 pm »
Ugh... Is there a way to make subprograms like methods in Java? I'm running out of variables, so I want to have the subprogram use private variables and only output stuff on the screen and an x value it'll be at when it touches the ground. Something like:
public int max(int X, int Y, D, int E, int F) { that code except it's 'Repeat Y>56'; return X; }

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Path prediction
« Reply #3 on: November 03, 2012, 10:51:15 pm »
Because Axe isn't object-oriented, you can't use private variables like that. What you can do is call #Realloc(, which moves your "variables" to a temporary space of free RAM. This allows you to still use A-Z for ease, but doesn't affect the "original copy" of those variables.

What you would want to do is something like:

<codecodecode>
#Realloc(L4)   //moves your variable locations to L4
run subroutine, return values (maybe store to another free RAM location)
#Realloc()    //resets to original location

« Last Edit: November 03, 2012, 10:51:34 pm by leafy »
In-progress: Graviter (...)

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Path prediction
« Reply #4 on: November 04, 2012, 12:02:39 am »
Does it move the variables or copy them? I want them to stay there.

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Path prediction
« Reply #5 on: November 04, 2012, 08:37:35 am »
I was curious if it'd slow it down much or not, but really i don't see much difference. When there were 256 dots (there was a bug in my code :P) it slowed down a bit, but still not too bad. I just spend pretty much all day on this, getting the ball to jump to the height of the bar took forever (thanks Tari!) :P


Source code and demo .8XP attached :) What i've got here is it showing every other dot (ie, every other coordinate where the ball/block will go). Showing every coordinate looked really ugly (half of it was a solid line), i think you could even go for showing every third coordinate.

What i did for this is just build an array of coordinates everytime the ball bounces which then get drawn every frame. For the next part calculating where the next bounce will go that might cause a bit of slowdown, especially in my engine since the part that calculates the initial velocity of the ball is a little slow. I can try adding that in too if you want to get an idea of what it might look like...

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Path prediction
« Reply #6 on: November 04, 2012, 08:50:18 am »
Holy ****! That's nice. To calculate the height the ball will jump, just do ([initial velocity]+1)*[initial velocity]/2+base height.
It's just a sum of all that it'll move up, assuming the velocity decreases by 1 each time.
But if you want to calculate the initial velocity based on the height so the height levels are uniform, that's a lot more trouble.
Anyways, thanks!

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Path prediction
« Reply #7 on: November 04, 2012, 01:46:20 pm »
Is there a command in Axe that lets me copy data rather than move it? My subprogram's gotta have the variables concerning the ball's location and velocities so it can predict...
EDIT: Sorry about the double posting...
« Last Edit: November 04, 2012, 01:46:59 pm by dinosteven »

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Path prediction
« Reply #8 on: November 04, 2012, 01:47:10 pm »
Try Copy() (in the math menu)

Copy(source, destination,size)
« Last Edit: November 04, 2012, 01:47:27 pm by squidgetx »

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Path prediction
« Reply #9 on: November 04, 2012, 01:47:53 pm »
What about for every variable?

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Path prediction
« Reply #10 on: November 04, 2012, 01:52:36 pm »
Variables are data too, you can copy them just like any other data.

Copy(oA,wherever,56)
#ReAlloc(wherever)

would move the variable pointers to wherever but also copy their values there as well
« Last Edit: November 04, 2012, 01:52:46 pm by squidgetx »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Path prediction
« Reply #11 on: November 04, 2012, 01:56:01 pm »
What about for every variable?
The variable A is located at L1+714, and the 26 other letters (including theta) are after, until L1+768 :)

edit ninja'd :P
Also, I didn't think about °A -.-
« Last Edit: November 04, 2012, 01:56:47 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Path prediction
« Reply #12 on: November 04, 2012, 02:15:18 pm »
How do you define 'whatever'?

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Path prediction
« Reply #13 on: November 04, 2012, 02:55:00 pm »
Literally whatever. Wherever you want to back up those variables to. Could be L1, L2, L1+444, any area of free ram that's availabel.

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Path prediction
« Reply #14 on: November 04, 2012, 02:58:45 pm »
This is going to sound stupid: I used Copy(oA,GDB1,56) and it had a compile error undefined. What do I have to do in the beginning to allocate 56 bytes of memory at pointer GDB1 so I can Copy there?