Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: aeTIos on May 23, 2011, 01:24:38 pm
-
Okay, since I wanted to do something special for my 1000th post, I decided to write a tutorial on doing platformers. What? Oh, you can't wait? Let's start, then!
The first thing we need, is a tilemap. In this tutorial, I'm using a simple, very awful, but useful tilemap.
Put this in prgmPLATFTLM:
.AXTILEMP
.Map:
[000000000000000000000000→Str1TM
[000000000000000000000000
[000000000000000000000000
[000206050000000000000000
[000300040002060500020605
[000300020605000206000004
[000300030004000300000004
[010101010101010101010101
.Tiles:
[FFAAFF55FFAAFF55→Pic1TL
[0F10204080808080
[8080808080808080
[0101010101010101
[F008040201010101
[FF00000000000000
[0000000000000000
.Now, we can draw the tilemap!
Lbl DMP
.Draw MaP
For(A,0,7
For(B,0,11
If {Str1TL+(A*12)+B}→Θ
Θ -1→Θ
Pt-On(B*8,A*8,Pic1TL+(Θ*8)
End
End
End
Return
If you run this code, you’ll see a not-so-very-bad looking tilemap (uhh, actually nothing, there’s no DispGraph xD).
Now comes the hard part: The collisions. There are 2 ways to do this:
1. Pixel-based collision
2. Tile-based collision
The tile-based collision is the hardest. That’s why I’m doing that first.
Put this code in prgmPLATFCOL:
.COLLISSN
Lbl COL
.COLlission
.Inputs: arg1=X ,arg2=Y ,arg3=dX to check,arg4=dY to check (I’ll explain later)
.Since we want it smooth-scrolling, we divide the X and Y value by 8 to get the corresponding tile
{Str1TL+(((Y+r2)/8)*12)+((X+r1)/8)}
Return
Okay, we can get the tile now, but there’s nothing to actually check something for!
We need an character, and we need to let it move right and left (Jumping and falling come later).
Put this in prgmPLATCHAR:
.CHARACTR
[187E243C7E3C5A66]→Pic1CH
Lbl MOV
.MOVe
If getKey(2) and (X≠0)
X-1→X
End
If getKey(3) and(X≠88)
X+1→X
End
Return
Lbl DCH
.Draw CHaracter
Pt-Off(X,Y,Pic1CH)
.You can also use Pt-Mask(), but come on, this is a tutorial!
Return
Now, that’s done, and we want to actually see something, right?
Put this in prgmPLATFRM:
.PLATFORM
0→X
55→Y
Repeat getKey(15)
ClrDraw
Sub(MOV)
Sub(DMP)
Sub(DCH)
DispGraph
End
Return
prgmPLATFTLM
prgmPLATCHAR
See how easy those sub-routines are?
-
Nice. Also congrats on your 1000th post :D
-
Update!
-
You said you were going to do this!
... 8XPs please. :D
-
8XPs coming when this is finished.
-
Nice. Try to not elaborate too much, though, lol, like writing an entire platformer game altogether. Else some people might just take the entire game code and modify maps/sprites to make their contest entry :P
-
I'm not doing that
There won't be any scrolling or enemies. This is just a skeleton for moving and tilemapping (The basics)
-
what I can't do is hit-detection and physics while scrolling. :P
any plans to do those?
-
Uh, hit-detection with enemies?
I even dont know how to do enemies myself... :P
-
what I can't do is hit-detection and physics while scrolling. :P
any plans to do those?
I just use the pxl-test with 2 points that I assigned usually... Like this
..Bottom Collision
If pxl-test(X+2, Y+16) and ( pxl-test(X+15, Y+16) ) //For 16x16 sprites
.Do something if something's underneath it
End