Author Topic: Need help with horribly coded platform engine  (Read 3623 times)

0 Members and 1 Guest are viewing this topic.

Offline BrownyTCat

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 420
  • Rating: +37/-8
    • View Profile
Need help with horribly coded platform engine
« on: March 13, 2012, 10:45:21 pm »
I need to get this to stop closing when it starts. Not sure what change I made that did it, but it worked perfectly before. Also if possible I want to ask for a simple way to draw a static tilemap (no scrolling) that I can fit in here; I'd rather be able to understand it than have it be barely faster. Tried fixing this for days with no luck but thanks to the Mac version of TI-Connect being fantastic and including an actual BASIC editor and a logical transfer method I can get this up here for examination and help. If you have a Mac I recommend
that port, I just dusted off my old PPC.

Code: [Select]
.TEST
.GFX
ClrDraw
ClrDraw
[FFFFC3DBDBC3FFFF]→Pic0
[FF9999FFFF9999FF]→Pic2
[00FF00FF00FFFF00]
.MOV1
[10107CBCBA282834]→Pic1
.MOV2
[10107CBCBA284466]
.MOV3
[08083E3D5D14142C]→Pic9
.MOV4
[08083E3D5D142266]

.VARS
0→J→Q→D→F→L
20→X→Y

.MAINLOOP
While Q=0

.GREY
ClrDraw
Pt-On(16,48,Pic2)
Pt-On(32,48,Pic2)
Pt-On(32,40,Pic2)
DispGraph
ClrDraw

.LVDRAW
Pt-On(16,40,Pic0
Pt-On(32,32,Pic0
Pt-On(0,56,Pic0
Pt-On(8,56,Pic0
Pt-On(16,56,Pic0
Pt-On(24,56,Pic0
Pt-On(32,56,Pic0
Pt-On(40,56,Pic0
Pt-On(48,56,Pic0
Pt-On(56,56,Pic0
Pt-On(64,56,Pic0
Pt-On(72,56,Pic0
Pt-On(80,56,Pic0
Pt-On(88,56,Pic0

.ANIM
If F>16
0→F
End
If F>8
If D=1
Pt-On(X,Y,Pic1+8
Else
Pt-On(X,Y,Pic9+8
End
Else
If D=1
Pt-On(X,Y,Pic1
Else
Pt-On(X,Y,Pic9
End
End

.KEY-QUIT
If getKey(15)
1→Q
End

.KEY-LEFT
If (getKey(2)) and (pxl-Test(X-1,Y)=0) and (pxl-Test(X-1,Y+7)=0)
X-1→X
0→D
F+1→F
End

.KEY-RIGHT
If (getKey(3)) and (pxl-Test(X+8,Y)=0) and (pxl-Test(X+8,Y+7)=0)
X+1→X
1→D
F+1→F
End

.GRAVITY
If (J=0) and (pxl-Test(X,Y+8)=0) and (pxl-Test(X+7,Y+8)=0)
Y+1→Y
End
If J>0
If (pxl-Test(X,Y-1)=0) and (pxl-Test(X+7,Y-1)=0)
Y-1→Y
End
J-1→J
End

.KEY-JUMP
If getKey(54)
If (pxl-Test(X,Y+9)=1) or (pxl-Test(X+7,Y+9)=1)
16→J
End
End

DispGraph
End

Pause 1000

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Need help with horribly coded platform engine
« Reply #1 on: March 13, 2012, 11:02:09 pm »
First off, a few simple optimizations ;)
Code: [Select]
.TEST
.GFX
ClrDraw
ClrDraw
[FFFFC3DBDBC3FFFF]→Pic0
[FF9999FFFF9999FF]→Pic2
[00FF00FF00FFFF00]
.MOV1
[10107CBCBA282834]→Pic1
.MOV2
[10107CBCBA284466]
.MOV3
[08083E3D5D14142C]→Pic9
.MOV4
[08083E3D5D142266]

.VARS
0→J→Q→D→F→L
20→X→Y

.MAINLOOP
Repeat getKey(15)

.GREY
ClrDraw
Pt-On(16,48,Pic2)
Pt-On(32,48,Pic2)
Pt-On(32,40,Pic2)
DispGraph
ClrDraw

.LVDRAW
Pt-On(16,40,Pic0
Pt-On(32,32,Pic0
For(A,0,88)
Pt-On(A,56,Pic0
A+7->A
End

.ANIM
If F>16
0→F
End
If F>8
If D=1
Pt-On(X,Y,Pic1+8
Else
Pt-On(X,Y,Pic9+8
End
Else
If D=1
Pt-On(X,Y,Pic1
Else
Pt-On(X,Y,Pic9
End
End

.KEY-LEFT
If (getKey(2)) and (pxl-Test(X-1,Y)=0) and (pxl-Test(X-1,Y+7)=0)
X--
0→D
F++
End

.KEY-RIGHT
If (getKey(3)) and (pxl-Test(X+8,Y)=0) and (pxl-Test(X+8,Y+7)=0)
X++
1→D
F++
End

.GRAVITY
If (J=0) and (pxl-Test(X,Y+8)=0) and (pxl-Test(X+7,Y+8)=0)
Y++
End
If J>0
If (pxl-Test(X,Y-1)=0) and (pxl-Test(X+7,Y-1)=0)
Y--
End
J--
End

.KEY-JUMP
If getKey(54)
If pxl-Test(X,Y+9) or (pxl-Test(X+7,Y+9)=1)
16→J
End
End

DispGraph
End

Pause 1000

Also, with a tilemap, you have a set spot in memory to store it. such as: (assuming we are using 8*8 tiles with no scrolling)
GetCalc("appvTempTilE",96)->W  <---- the tilemap is 96 bytes because the screen can hold 12*8 tiles.

You also want to have all your tilemap pics in one place, so that the tilemap can draw them.
For this, I will use Pic2. (this is assuming a 0 in the tilemap is empty and 1 and so on is various tiles)

[0000000000000000]->Pic2
[sprite_when_tilemap_number_is_1]
[more_hex_for_more_tilemap]
[.........................]

and so on and so forth until you have all the data you need for your tilemap.

Secondly, you want to draw it. If you have a static tilemap, I would suggest drawing it to the back buffer and recalling it every frame.

ClrDrawr
For(A,0,11)
A*8->C
For(B,0,7)
Pt-On(C,B*8,{B*12+A+W}+Pic2)r
End
End

sorry, that was a little badly explained.



EDIT: here's a small example:

Code: [Select]
.TILE
GetCalc("appvTileTemP",96)->W

For(A,0,95)
rand^2+0->{W+A}
End

[0000000000000000]->Pic2
[FFFFFFFFFFFFFFFF]

ClrDraw

For(A,0,12)
A*8->C
For(B,0,7)
Pt-On(C,B*8,{B*12+A+W}+Pic2)
End
End

DispGraph
getKey[sup]r[/sup]
« Last Edit: March 13, 2012, 11:11:02 pm by parser padwan »