Omnimaga
Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Munchor on December 22, 2010, 07:26:03 am
-
Ahead is the title of my next Axe calculator game: a platformer where you cannot go back. That's right, you can't go back.
Here's an initial screenshot, with a very concerning bug:
(http://img.removedfromgame.com/imgs/Screenshot1.gif)
No, I will not be using someone else's code as a base. It's all mine this time.
I actually started this program with the help of Ashbad but I deleted the whole code (on purpose) because it was very messy and started it all over again.
.PLATFORM
[3810385410282828->Pic0
[FFFFFFFFFFFFFFFF->Pic1
0->X
40->Y
While 1
ClrDraw
Pt-On(X,Y,Pic0
For(A,0,96
Pt-On(A,48,Pic1
A+7->A
End
DispGraph
.pxl-Test(X,Y)r Returns 1 if pixel is black and 0 if pixel is white on the back buffer at (X,Y).
If pxl-Test(X,Y+8)r=0
Y+1->Y
Else
End
If getKey(3)
X+2->X
End
If getKey(4)
Y-2->Y
End
End
This is my code, I made a pxl-Test collision check to avoid the character to drop below the floor, but it doesn't seem to work very well.
That's the only help I need at the moment, thanks :)
-
.PLATFORM
[3810385410282828]->Pic0
[FFFFFFFFFFFFFFFF]->Pic1
0->X
40->Y
.Game Loop
While 1
StorePic
.Display Sprite in given coordinates
Pt-On(X,Y,Pic0
For(A,0,96
Pt-On(A,48,Pic1
A+7->A
End
DispGraph
Pt-Change(X,Y,Pic0
RecallPic
.Key Events
If getKey(3)
X+2->X
End
If pxl-Test(X,Y-8) = 0
Y+1->Y
End
If getKey(4) and (Y>0)
Y-5->Y
End
.Close Game
If getKey(15)
Fix 4
Return
End
.End of Game Loop
End
Recycled some of the old code and added a CLEAR button function. I am starting to figure out how to make gravity work :)
-
First, I highly recommend that you add ending parenthesis.
Doing
For(A,0,100
If A=(rand^100
Pt-On(10,10,Pic1
End
End
is no different (and is equally optimized) compared to
For(A,0,100)
If A=(rand^100)
Pt-On(10,10,Pic1)
End
End
Also, not adding parenthesis can do very odd things to your code, and because they don't give you a speed increase like it does in Basic, you should probably just add them.
-
Yes, since it is converted to Assembly, it doesn't mater. Thanks, it's just that I learnt that in Basic :P
I just made another file, but it doesn't have gravity :S
-
Also, because I needed a break from what I was doing, I simplified parts of your code:
.PLATFORM
Fix 5
[3810385410282828]->Pic0
[FFFFFFFFFFFFFFFF]->Pic1
0->X
40->Y
ClrDraw
.Main game loop
While 1
.Moving right
If getKey(3)
X+2->X
End
.Jumping
If Y>0 and getKey(4)
Y-5->Y
End
.Create floor
For(A,0,12)
Pt-On(A*8,48,Pic1)
End
.Collision test (ground) and Gravity
!If pxl-Test(X,Y+8)
!If pxl-Test(X+7,Y+8)
Y+1->Y
End
End
.Display sprite
Pt-On(X,Y,Pic0)
.Display the screen
DispGraph
ClrDraw
.Close Game
If getKey(15)
Fix 4
Return
End
End
Not sure why you were using StorePic and RecallPic, but I think those were the cause of your problems.
-
I would like to see some more platformer games for calcs. I hope you can solve the collision detection issue. I personally had troubles with it before. if you need help with physics, you might want to ask Builderboy, since he's pretty good at it. I believe someone else here did too. He helped me with the physics in Supersonic Ball. Good luck!
-
I can help with physics too, I'm pretty decent at it, though builderboy might be better ;)
-
Ah ok I wasn't sure, because physics is not something a lot of people know. They can be very hard to deal with sometimes. In my case, my gripe is how to detect when you reach a solid tile when your character moves at more than 1 pixel per frame.
-
Yeah, collision detection can be a major PITA at times.
In the project I'm working on right now, I'm trying a method where each time I make an object move (they're sort of like bullets), I see if their x and y coordinates are within a certain range of my character. I'm not too sure if that might work for tiles, though.
-
that works well for bullets and such, as it doesn't matter if the two objects pass through one another(bullets disappear when colliding with the player), but with platform detection the programmer has to use a for( loop or something similar to check every pixel in between the character's current position and the desired one to ensure that the two don't pass through one another. it's not all that difficult, and i would be willing to help if asked.
-
Yeah what Shmibs said. That's what JustCause did actually. I heard that if you do it wrong, it can run very slow, though.
-
I just tried Michael Lee's code without making any changes xD
I had a new idea for gravity, though :)
-
I've made a similar platformer that only moves in one direction, but its not done because of collision detection with incoming obstacles. What I did for jumping was have a variable called J for whether he's jumping or not, a var F for whether he's falling or not, and T as a timer, and V as the vertex, where he stays put in the air for 2-3 frames. (bad physics. :P)
-
I've made a similar platformer that only moves in one direction, but its not done because of collision detection with incoming obstacles. What I did for jumping was have a variable called J for whether he's jumping or not, a var F for whether he's falling or not, and T as a timer, and V as the vertex, where he stays put in the air for 2-3 frames. (bad physics. :P)
That might have worked better than mine, but seems confusing :S
After physics, I'll start sidescrolling :)
-
for side scrolling you could just use "Horizontal -" ;)
-
for side scrolling you could just use "Horizontal -" ;)
I don't know how to use it :( I will learn it later. Not now.
If pxl-Test(X,Y+9)=0
Y-1->Y
End
What do you think of this?
-
just use "Horizontal -" All it does is shift the screen to the left on pixel, put that inside the main loop, and it scrolls everything. This also means you'll have to constantly update the "floor"
also, your problem may be that your using Y+9, it should be Y+8. ;) PLus you should also pxl-Test(X+7,Y+8) as well as pxl-test(X,Y+8)
-
just use "Horizontal -" All it does is shift the screen to the left on pixel, put that inside the main loop, and it scrolls everything. This also means you'll have to constantly update the "floor"
also, your problem may be that your using Y+9, it should be Y+8. ;) PLus you should also pxl-Test(X+7,Y+8) as well as pxl-test(X,Y+8)
If pxl-Test(X,Y+8)
Y-1->Y
End
If pxl-Test(X+7)
X-1->X
End
The 7 will depend on which sprite I use. Code okay?
-
the x-1->x part will make the sprite float up if there is ground underneath. ???
-
Ah, wait. For the code I posted, I forgot to add a 'ClrDraw'.
Immediately after the 'DispGraph', add a 'ClrDraw', and it should work better.
I've edited the code I posted to match. (I also changed the collision detection part slightly to match yunhua98's advice)
-
the x+7 checks for the pixel below the sprite on the bottom right corner. ;)
-
.PLATFORM
Fix 5
[3810385410282828]->Pic0
[FFFFFFFFFFFFFFFF]->Pic1
0->X
40->Y
ClrDraw
.Main game loop
While 1
.Moving right
If getKey(3)
X+2->X
End
.Jumping
If getKey(4) and (Y>0)
Y-5->Y
End
.Create floor
For(A,0,12
Pt-On(A*8,48,Pic1)
End
.Collision test (ground) and Gravity
!If pxl-Test(X,Y-8)
!If pxl-Test(X+7,Y-8)
Y+1->Y
End
End
.Display sprite
Pt-On(X,Y,Pic0)
.Display the screen
DispGraph
ClrDraw
.Close Game
If getKey(15)
Fix 4
Return
End
End
Thanks, I made a similar one, using yunhua's advices, though, I'll be using mine, though :) Thanks much anyways
-
@Yunhua98: Yeah, I forgot about that, although in the current setup, it doesn't actually matter much because the floor is just completely flat. But you would need that for any uneven floors.
-
So, I need three pxl-Tests? I'm also thinking about the top right corner and below right corner. Would that make it 4 pxl-tests?
-
That depends.
Assuming that the floor won't be flat 100% of the time, and assuming that you can run into things unless you jump, you'd probably need 3 pxl-Tests.
If it's possible to jump up and hit a ceiling (which could also be uneven), then 4 pxl-Tests
# #
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
# #
If the X's are your sprite, then the # would be where the pxl-Tests should probably be given your current setup.
-
# #
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
# #
Actually this since I can't go back.
-
No, not really, what if you were inching forward very slowly on a platform...
# #
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
# #
@@@
@@@
@@@
@@@
@@@
Then you would fall off, and through the platform.
-
No, not really, what if you were inching forward very slowly on a platform...
# #
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
# #
@@@
@@@
@@@
@@@
@@@
Then you would fall off, and through the platform.
You are very clever, I understood that, adding more pxl-Tests nows.
-
Wait, adding more?
I don't think you need to add more, just shift the locations a bit.
As long as any surface you encounter is 8 pixels wide (or more), the locations of the pxl-Tests I gave earlier should be enough to cover everything.
(Of course, if you plan on adding surface areas less then 8 pixels wide, then more would be needed)
-
.Collision test (ground) and Gravity
!If pxl-Test(X,Y+8)
!If pxl-Test(X+7,Y+8)
Y+1->Y
End
End
If pxl-Test(X+7,Y)
X-1->X
End
I have these at the moment :S
-
That should work, as long as you put that code after you create the floor/obstacles, but before you create your sprite.
(By create, I mean use Pt-On)
-
New gif, looks better, but still buggy.
You can go back but that is for testing purposes :)
-
might i suggest for showing your character you use this code.
Pt-change(X,Y,Pic1)
DisplayGraph
Pt-change(X,Y,Pic1)
EDIT: ninja'd
-
Now, you can't fly so much.
I wonder how to disable pressing the UP key too long or many times to avoid flying :S
-
Now, you can't fly so much.
I wonder how to disable pressing the UP key too long or many times to avoid flying :S
well, you could always just wait til you hit the ground again.
-
timer?
i suggest.
If getkey=1
code code code....
if getkey(1)
up just a bit higher)
end
end
-
Now, you can't fly so much.
I wonder how to disable pressing the UP key too long or many times to avoid flying :S
well, you could always just wait til you hit the ground again.
THaNkS! I know how to do that!
.Jumping
If getKey(4)
If pxl-Test(X,Y+8)=1
If Y>0
Y-3->Y
End
End
End
This didn't work... Any idea why? Thanks
-
it should work. change
Y-3->Y
to
Y-10->Y
and see if it is just a lack of visual responce
also optimization... V
change
If pxl-Test(X,Y+8)=1
to
If pxl-Test(X,Y+8)
-
.Jumping
If getKey(4)
If Y>0
If pxl-Test(X,Y+8)
Y-3->Y
End
End
End
Didn't work too...
-
ummm....
it should work. change
Y-3->Y
to
Y-10->Y
and see if it is just a lack of visual responce
-
I see, trying to find where the bug is.
But it's not lack of visual response. Tried 50, doesn't work :(
-
look at your last screeny.
I think that the gravity is just so strong.
might take some work but move this code between the gravity and the displaying of the character.
-
It worked... but WOAH!
-
what worked?
-
what worked?
I can't fly anymore...
I can't double press up in the air, I mean.
-
no, i mean what change in the code fixed it?
-
what worked?
I can't fly anymore...
I can't double press up in the air, I mean.
If you need to double-press, decrease gravity, or have it start out lower, right after the initial jump and slowly increase. Also have it only allow two or three jumps in all by having some counter.
-
Y+1->Y
Gravity is as slow as it can be... Can it be <1?
-
yes. that would be 65024
-
yes. that would be 65024
I found a different way (1/4), in the screenshot.
Now my concern are the X collisions:
.Collision test (ground) and Gravity
!If pxl-Test(X,Y+8)
Y+(1/4)->Y
End
!If pxl-Test(X+7,Y+8)
Y+1->Y
End
If pxl-Test(X+5,Y)
X-1->X
End
If pxl-Test(X-1,Y)
X-1->X
End
There are a few bugs when hitting the wall :S
-
ummm. 1/4 shouldn't work. That would be 0.
0.25 is truncated to 0
-
ummm. 1/4 shouldn't work. That would be 0.
0.25 is truncated to 0
But it worked :)
-
you can double all you y values and then display y/2
i am trying to say to use proportions.
-
And, he's right, that would return 0 there scout. It shouldn't be working. Wonder what's happening. Unless Y is being incremented later on in the program...
Either way nice work so far scout! Later on I can teach you how to use a Matrix appvar like in pyyrix (Technically a 2D array, but I'm used to calling them matrices and my friends think I'm crazy :)) And how to add smoothscroll using state of the art position-modulated routines (fancy name I gave them due to the fact they rely heavily on moduli (plural of modulus))
;)
-
Axe is an Integer system, I think it has something to do with your guy appearing there instantly. ;)
as for the wall, use
:If pxl-test(X+8,Y)
:X-1->X
:End
that should work unless your incrementing the X by more than 1.
otherwise you could include it in your getkey codes. as for double jumping, if you did what I suggested and have a J var for whether you're jmping or not, do this:
where J is 0 for on ground or falling, J is 1 for jumping
:If J and (getkey(1))
:Y-1->Y
:End
with a timer, that is. ;)
-
ANother thing: It might be nice if movement wasn't too fast either. Maybe add A Pause command to slow things down?
-
:If pxl-test(X+8,Y)
:X-1->X
:End
That will only work if I change the sprite to this:
0E040E15040A0A0A
Which I've already done.
:If J and (getkey(1))
:Y-1->Y
:End
I tried something similar to do this, maybe it didn't work because I don't have the correct code for J:
If pxl-Test(X,Y+8)=0
1->J
Else
0->J
End
However, I do believe that is OK, and will try it once again and then post a new screenshot.