2

I am trying to make a simple arcade shooter like Galaga in TIBasic. I have successfully created some code that lets you move your character (an "X") horizontally across the screen while shooting a bullet that clears everything along the vertical path it takes. However, I'm having a problem with the "rocks" that are supposed to fall from the screen and disappear when hit. When I shoot the rock, it is cleared by the bullet, but then continues going down the screen until it hits the bottom of the screen. Here's the code for the rocks:

//outside the game loop:
1->R

//inside game loop:
If not(R=8)
Then
R+1->R
If R>1
Then
Output(E-1, 1, " "  //removes last rock
End
Output(R, 1, "R"  //replaces last rock with one below it (traveling towards the ground)
End

This code obviously doesn't stop the "R" from continuing to go down the screen when it is cleared (by the way, I just use Output(...," ") on wherever the bullet was to clear away anything the bullet hits). So, how would I check if the rock was cleared away on the last iteration of the game loop? Is there a way to check if something (the "R") is at a certain place on the screen in order to check if it was cleared away by a bullet on the last iteration? Or is there a better way? Thanks for the help!

lirtosiast
  • 592
  • 4
  • 15
Blake Allen
  • 347
  • 1
  • 10
  • 1
    I don't think that TI-BASIC allows you to check what's on the screen. However, you could always learn how to write programs in z80 ASM and access the screen buffer that way. Once you write a program to do it, you can call it in your main program. However, that will have to be specific to the exact calculator and OS version on it. – fuzzything44 Feb 22 '16 at 21:38
  • Easiest thing for you to do would to just keep it's place in a variable (lists are great for holding more variables than your 28 that you normally get) and check that. – fuzzything44 Feb 24 '16 at 20:20

2 Answers2

3

It appears that the code you have doesn't test if the bullet is in the same place as the rock. To have this collision, you'd need to compare the "R" y-value of the rock with the y-value of your bullet you displayed, and compare the x-value of the rock (however you store that) with the x-value of the bullet. If both are equal to each other, then they have collided, and you can "delete" the rock by setting it to whatever value signifies it doesn't exist anymore. Assuming R is the y-value of the rock, S is the x-value of the rock, Y is the y-value of the bullet, and X is the x-value of the bullet, In the code to move the rock, I'd put this somewhere:

:If R=Y and S=X
:DelVar R
//You could also delete the bullet here because it's "stopped" by the rock

This code will test if the two are collided and set R to 0 (meaning it doesn't exist). If you wanted, you could also add a text-version of an explosion to give it some more flair. Good luck with your project, and I hoped this helped!

Stephen P
  • 195
  • 11
2

When making a game in Ti-Basic, there are 2 options for which "screen" to put it on: The text screen of the calculator, using functions like Disp and Output, and the graph screen, using Text, as well as the drawing functions, stored pictures, and pxl and pt functions. I'm not sure about how to check the text out put screen for the presence of an object on the screen, but the graph function has the Pxl-Test function:

:Pxl-Test(y,x)

Someone else may have know how to check for something on the text screen, but I suggest switching to the graph screen to make use of this function.

If you are going to switch to using the graph output here are some things to note:

  • The text function is

    :Text(row,col,output)
    
  • Row and col are switched from the Output function

  • Rows and cols are measured in pixels on the screen, as opposed to the space it takes to type a letter

  • Most letters are 3 pixels wide, spaces are 1 pixel wide, so it will take multiple spaces to clear out an unwanted character

  • You may need to disable the graph axis (FORMAT menu), the y-functions (VARS menu, then right to Y-VARS), and the stat-plots (STAT PLOT menu) in the begging of the program then restore them at the end.

One last not on using the Pxl-Test function is that it tests a group of pixels, while a letter. For now let's pretend you only use Rs and an X in your program (I don't know if you do or don't), so you should test a spot on that character that is relatively unique to that character.

Good luck!

Scott Mikutsky
  • 746
  • 7
  • 21