Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Munchor on December 22, 2010, 07:26:03 am

Title: [Project] Ahead
Post 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.

Code: [Select]
.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 :)
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 11:58:12 am
Code: [Select]
.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 :)
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 01:17:16 pm
First, I highly recommend that you add ending parenthesis.
Doing
Code: (Bad Example) [Select]
For(A,0,100
  If A=(rand^100
    Pt-On(10,10,Pic1
  End
End
is no different (and is equally optimized) compared to
Code: (Good Example) [Select]
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.
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 01:19:30 pm
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
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 01:53:52 pm
Also, because I needed a break from what I was doing, I simplified parts of your code:
Code: [Select]
.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.
Title: Re: [Project] Ahead
Post by: DJ Omnimaga on December 22, 2010, 01:56:47 pm
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!
Title: Re: [Project] Ahead
Post by: Ashbad on December 22, 2010, 02:09:59 pm
I can help with physics too, I'm pretty decent at it, though builderboy might be better ;)
Title: Re: [Project] Ahead
Post by: DJ Omnimaga on December 22, 2010, 02:13:09 pm
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.
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 02:18:42 pm
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.
Title: Re: [Project] Ahead
Post by: shmibs on December 22, 2010, 02:40:29 pm
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.
Title: Re: [Project] Ahead
Post by: DJ Omnimaga on December 22, 2010, 02:52:26 pm
Yeah what Shmibs said. That's what JustCause did actually. I heard that if you do it wrong, it can run very slow, though.
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 03:45:24 pm
I just tried Michael Lee's code without making any changes xD

I had a new idea for gravity, though :)
Title: Re: [Project] Ahead
Post by: yunhua98 on December 22, 2010, 04:31:32 pm
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)
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 04:33:59 pm
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 :)
Title: Re: [Project] Ahead
Post by: yunhua98 on December 22, 2010, 04:35:26 pm
for side scrolling you could just use "Horizontal -"  ;)
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 04:42:17 pm
for side scrolling you could just use "Horizontal -"  ;)

I don't know how to use it :( I will learn it later. Not now.

Code: [Select]
If pxl-Test(X,Y+9)=0
Y-1->Y
End

What do you think of this?
Title: Re: [Project] Ahead
Post by: yunhua98 on December 22, 2010, 04:44:47 pm
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)
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 04:53:36 pm
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)

Code: [Select]
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?

Title: Re: [Project] Ahead
Post by: yunhua98 on December 22, 2010, 05:05:10 pm
the x-1->x part will make the sprite float up if there is ground underneath.  ???
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 05:07:37 pm
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)
Title: Re: [Project] Ahead
Post by: yunhua98 on December 22, 2010, 05:12:04 pm
the x+7 checks for the pixel below the sprite on the bottom right corner.  ;)
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 05:12:45 pm
Code: [Select]
.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
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 05:14:06 pm
@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.
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 05:17:41 pm
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?
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 05:26:45 pm
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

Code: [Select]
#       #
 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.
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 05:29:48 pm
Code: [Select]
    #    #
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
    #    #

Actually this since I can't go back.
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 05:35:20 pm
No, not really, what if you were inching forward very slowly on a platform...

Code: [Select]
    #    #
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
 XXXXXXXX
    #    #
@@@
@@@
@@@
@@@
@@@
Then you would fall off, and through the platform.
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 05:37:51 pm
No, not really, what if you were inching forward very slowly on a platform...

Code: [Select]
    #    #
 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.
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 05:41:37 pm
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)
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 05:45:15 pm
Code: [Select]
.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
Title: Re: [Project] Ahead
Post by: Michael_Lee on December 22, 2010, 05:51:03 pm
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)
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 06:10:37 pm
New gif, looks better, but still buggy.

You can go back but that is for testing purposes :)
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 06:10:52 pm
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
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 06:18:13 pm
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
Title: Re: [Project] Ahead
Post by: jnesselr on December 22, 2010, 06:20:26 pm
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.
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 06:20:40 pm
timer?

i suggest.

If getkey=1
code code code....
if getkey(1)
up just a bit higher)
end
end
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 06:21:50 pm
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!

Code: [Select]
.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
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 06:38:14 pm
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)
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 06:41:03 pm
Code: [Select]
.Jumping
  If getKey(4)
    If Y>0
      If pxl-Test(X,Y+8)
        Y-3->Y
      End
    End
  End

Didn't work too...
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 06:42:19 pm
ummm....

it should work.  change
Y-3->Y
to
Y-10->Y
and see if it is just a lack of visual responce
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 06:45:24 pm
I see, trying to find where the bug is.

But it's not lack of visual response. Tried 50, doesn't work :(
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 06:46:54 pm
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.
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 06:50:01 pm
It worked... but WOAH!
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 06:53:06 pm
what worked?
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 06:53:43 pm
what worked?

I can't fly anymore...

I can't double press up in the air, I mean.
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 06:57:51 pm
no, i mean what change in the code fixed it?
Title: Re: [Project] Ahead
Post by: jnesselr on December 22, 2010, 06:58:32 pm
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.
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 07:01:37 pm
Code: [Select]
Y+1->Y
Gravity is as slow as it can be... Can it be <1?
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 07:02:41 pm
yes. that would be 65024
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 07:04:34 pm
yes. that would be 65024

I found a different way (1/4), in the screenshot.

Now my concern are the X collisions:

Code: [Select]
.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
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 07:36:37 pm
ummm.  1/4 shouldn't work.  That would be 0.
0.25 is truncated to 0
Title: Re: [Project] Ahead
Post by: Munchor on December 22, 2010, 07:56:43 pm
ummm.  1/4 shouldn't work.  That would be 0.
0.25 is truncated to 0


But it worked :)
Title: Re: [Project] Ahead
Post by: Happybobjr on December 22, 2010, 08:02:48 pm
you can double all you y values and then display y/2
i am trying to say to use proportions.
Title: Re: [Project] Ahead
Post by: Ashbad on December 22, 2010, 08:06:25 pm
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))





;)

Title: Re: [Project] Ahead
Post by: yunhua98 on December 22, 2010, 09:43:39 pm
Axe is an Integer system, I think it has something to do with your guy appearing there instantly.  ;)
as for the wall, use
Code: [Select]
: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
Code: [Select]
:If J and (getkey(1))
:Y-1->Y
:End

with a timer, that is.  ;)
Title: Re: [Project] Ahead
Post by: DJ Omnimaga on December 23, 2010, 12:17:59 am
ANother thing: It might be nice if movement wasn't too fast either. Maybe add A Pause command to slow things down?
Title: Re: [Project] Ahead
Post by: Munchor on December 23, 2010, 05:28:32 am
Code: [Select]
:If pxl-test(X+8,Y)
:X-1->X
:End

That will only work if I change the sprite to this:

Code: [Select]
0E040E15040A0A0A
Which I've already done.

Code: [Select]
: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:

Code: [Select]
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.