I'm pretty new to programming and this is my first* real game on my TI-82. You're supposed to stop aliens or monsters from reaching a certain limit. I've done fine on this part, but every time I "kill" a unit, the game becomes slower and slower until it eventually is unplayable. I suspect it's a memory leak.
I'll try my best to guide you through the program, I know that there must be a lot of unnecessary lines here but if you could just try help me understand what's gradually slowing down my game (and if there's a fix), I'd be really happy.
ClrHome 8->U 0->B 1->C 1->D 1->E Variables at the start, doesn't slow down the game. 0->F 1->G 8->X Output(8,1,”- - — — — ^ — — — — ^ — — — — / This is supposed to be the ground. Lbl 1 Output(5,1,”• • • • • • • • • • • • • • • • • • • • • • • • • • • • And this is the limit the enemy units have to surpass in order to win. Output(Y,X,”W This is the controllable character. Looks kinda like a spaceship. Lbl 2 Output(1,1,B This is the scoreline. Output(C,D,” ” D+E->D The enemy unit moves from left to right. If D=U Int(12rand+5)->U generates a position to dive down from. Then 1->G DelVar->E End C+G->C Output(C,D,”X This is how the enemy unit looks like. If F=1 If the unit is marked as dead, generate a new one from left or right. Then Output(C,D,” ” 1->E 1->C 0->F 0->G RandInt(1,2)->V If V=1 Then -1->E 16->D Else 1->E D->1 End End If C>=6 If the unit passes this limit the game will end. Then Output(4,4,”GAME OVER! Pause Stop End getKey->K There are 3 buttons, 24, 26 and 73. If K=24 Move left. Then Output(7,X,” ” X-1->X Output 7,X,”W Goto 2 End If K=26 Move right. Then Output(7,X,” ” X+1->X Output(7,X,”W Goto 2 End If K=73 Shoot. Then For(I,1,6,1 Projectile (straight line) Output(I,X,”: End 0.15->A prgmDELAY I've created a delay program that pauses for the amount of sec var A. For(I,1,6,1 Output(I,X,” ” End If D=X If you're on the same X value as the enemy's, you will mark it as "killed". Then 1->F B+100->B Output(1,1,B randInt(3,14)->U Goto 1 Else Goto 1 End Goto 2 Goes back to the start in order to repeat. End
If I can find a method that doesn't involve a memory leak, I could eventually make a difficulty level. …and make the game playable.