Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: mrmprog on July 20, 2011, 11:45:09 pm
-
I am working on my first axe program, and I have a problem. If you are falling, and you move into one of the outer walls, you can go through the wall. I know the code is badly written, and the collision testing only test 1 pixel. If someone could explain to me why my code is dying, that would be very helpful.
:.GAME
:DiagnosticOff
:ClrDraw
:[1824187E5A182442]→Pic1
:40→A
:1→B
:0→X
:1→C
:Full
:Line(0,63,95,63)
:Line(0,63,0,0)
:Line(95,63,95,0)
:
:For(15)
:rand^(95-0+1)+0→D
:rand^(95-0+1)+0→E
:rand^(63-0+1)+0→F
:Line(D,F,E,F)
:End
:
:
:Repeat getKey=15
:StorePic
:Pt-On(A,B,Pic1)
:DispGraph
:
Problem may be here
A+pxl-Test(A+1,B+5)→A
:A-pxl-Test(A+6,B+5)→A
:A-getKey(2)→A
:A+getKey(3)→A
:If pxl-Test(A+4,B+8)=1
:B-(12*getKey(54))→B
:Else
:B+1→B
:End
:
:ClrDraw
:RecallPic
:End
Explanation:
A and B are X and Y cords of the sprite
C is useless
X is useless
-
Is the code zero based? I think the first row and column of the screen is 0 so it could be bypassing it entirely.
-
The code works if you run to a wall, but if you fall and move in a wall, you go through.
-
At any point do you move more than one pixel per frame? Which walls does it go through? Is collision handled differently when the character is not on solid ground?
-
I put walls on the outer edge of the graphscreen, just to test the collision testing. You never move more than 1 pixel in a certain direction, but if you move when you are falling, you can move 1 down and 1 to the side. Collision is handled the same way no matter what.
-
Ok, I tried that, but I can still fall through the walls. I will try to make a GIF of the bug in a few minutes.
-
are you sure that didn't fix it? anyways, that will still stop future problems, as you were doing collision checking after the sprite is drawn.
I reread it and now understand your problem. It isn't hard to fix, if i think i am right.
change...
:A+pxl-Test(A+1,B+5)→A
:A-pxl-Test(A+6,B+5)→A
to
:A+pxl-Test(A+1,B+5)-pxl-Test(A+6,B+5)→A
:A+pxl-Test(A+2,B+5)-pxl-Test(A+5,B+5)→A
it is a rather rude way to code it, but it should work. (if i understand the problem)
-
It seems to only happen when there's a platform close to the wall, but not next to it (as in not wide enough for the sprite to fall through)
The way you handle platforms and walls is why. The char is moved both right, from the left pixel text; and left, from the right pixel test. These done at the same time will cancel each other out.
After that you have the key detection, and because the collision detection cancels itself out if the player happens to be holding the arrow key toward the wall, the char goes right through.
I might be completely wrong, but try something like this (and make some use of C and another coordinate)
It's a long way from optimized and such but you should get the idea =P
:pxl-Test(A+1,B+5)→C
:.if pixel test is false, it stores zero. if true, it stores 1
:pxl-Test(A+6,B+5)→D
:.C checks the left side, D checks the right
:A-(getKey(2)*(C=0))→A
:.only if C is zero, meaning the pixel test is false, will the char move left
:A-(getKey(3)*(D=0))→A
What you could do, for a somewhat-inefficient yet nearly foolproof solution, check the coordinates to see if the char is going into a wall.
This could be as simple as adding another check:
:A-(getKey(2)*(C=0)*(A>>0))→A
And (A<<56) for the right wall.
Hope this helps :)
-
I think you actually will want an A+ in stead of an A- on the second long expression that stores to A. Also, somewhat optimized \o/
A-(getKey(2) and (A>>0) and not(pxl-Test(A+1,B+5→r1))?1,0)+(getKey(3) and (A<<56) and not(pxl-Test(A+6,r1))?1,0)→A
-
I think you can actually get rid of the ?1,0 stuff since you're already working with booleans.
-
Thanks to all who helped! I am coding in changes now, but I may wait to compile until the Axe messing with flash problem is fixed.
Btw, Ashbad, your code is way beyond my puny Axe knowledge. ???
-
Just a question, why would you do:
A-getKey(A)→A
getKey(A) returns 1 or 0 (if A is pressed or not)...
-
Is that in my code?
-
:A-getKey(2)→A
:A+getKey(3)→A
That is.
-
That decrements A if the left arrow is being pressed and increments it if the right arrow is. Though, if it's exactly as ephan quotes it, you shouldn't have it in two lines.
A-getKey(2)+getKey(3)→A
This works just as well.
Edit: Woah, look at Ashbad's code :crazy:
-
Lol, Ashbad's code is pretty awesome. Anyway, I have a new problem. I used some jumping/gravity code from Eeem's platform tutorial, and jumping does nothing. I understand the code, but I can't figure out why the code doesn't work. It is probably something very simple that I am missing, but I cant figure it out.
:.GAME
:DiagnosticOff
:ClrDraw
:[1824187E5A182442]→Pic1
:40→A
:1→B
:0→X
:1→C
:Full
:Line(0,63,95,63)
:Line(0,63,0,0)
:Line(95,63,95,0)
:
:For(G,1,15)
:rand^(95-0+1)+0→D
:rand^(95-0+1)+0→E
:rand^(63-0+1)+0→F
:Line(D,F,E,F)
:End
:
:1→C
:Repeat getKey=15
:Pt-Change(A,B,Pic1)
:DispGraph
:Pt-Change(A,B,Pic1
:A-(getKey(2)*(pxl-Test(A+0,B+5)=0))→A
:A+(getKey(3)*(pxl-Test(A+7,B+5)=0))→A
:pxl-Test(A+4,B+8)→C
:B+(C=0)→B
:
:!If D
:10*(getKey(54) and (C))→D
:Else
:D-1→D
:End
:
Here?
B+(2*((C=0) and (D)))→B
:End
Problem was solved