I made this tutorial to teach my friend some 2D and array stuff. I decided to share it on here. It goes over creating a crude version of Avalanche with sprites. Includes splash screen stuff as well
REM Project: Avalanche
REM Created: 12/25/2005 9:16:48 PM
REM
REM ***** Main Source File *****
REM
remstart
The TI-83 game with rocks instead of ice shards of death
By Ted Dobyns
12/25/2005
Runs in a 640x480 window
Tutorial designed to teach newcomers basic variable manipulation, basic array handling, and simple 2D sprite commands
remend
`Basic Setup
sync on : sync rate 60 `Activate Sync On and set the refresh rate
hide mouse `Hide the mouse since it isn't necessary for the game and is distracting
`We also need to make sure that any random numbers we generate are truly random
`We need to set a seed for this and the best way to do that is with timer() which
`is constantly changing
randomize timer()
`anothing thing to note is that when the sprites are loaded there will be a blue background
`Images can be placed there, but for this tutorial we will just make it black
`That is easy enough with this command
color backdrop 0
`Splash Screen
set text size 48
`Create a color for the text that will always stay in greyscale
textcolor as dword
textcolor = rgb(0, 0, 0)
`set the color incrementation value
inkstage = 1
do
`Write AVALANCHE to the screen in size 48 text colored by the value of textcolor
ink textcolor, 0
center text screen width() / 2, screen height() / 2, "AVALANCHE"
`Check to see if the ink is up to pure white and if so set a value to the current timer and set incrementation to 0
if color = 255 and inkstage = 1
starttime = timer()
inkstage = 0
endif
`If the incrementation is 0 then check to see if it has been 2 seconds since the ink was pure white
`If so then set the incremenation to -1 to make the color go back to black
if inkstage = 0
if timer() >= starttime + 2000 then inkstage = -1
endif
`Set the textcolor value every loop
textcolor = rgb(color, color, color)
`If the incrementation is -1 and the color is back to black then set the ink to white and exit the loop
if inkstage = -1 and color = 0
ink rgb(255, 255, 255), 0
exit
endif
`Increases color by the incrementation every loop
inc color, inkstage
`Refresh and go back to the last Do statement
sync
loop
`Load the staggering amount of media
`The media was created in photoshop very quickly
`Each image is a transparent background .png image,
`which is 32x32 pixels
load image "player.png", 1
load image "rock.png", 2
`Make a player sprite and place it in the middle of X axis and at the bottom of the Y axis
sprite 1, 320 - 16, 480 - 32, 1
`We should also create a variable to hold the x position of our sprite for later use
xpos = sprite x(1)
`Make the rocks and put them into position
for rock = 2 to 21
`Since the screen is 640 pixels wide and the rock image is 32 pixels wide
`we can figure out that there should be twenty rocks across the top of the screen
`Rock goes from 2 to 21
sprite rock, (rock - 2) * 32, 0, 2
next rock
`An array is a series of data of the same data structure
`In other words it could be a long list of numbers, names, letters, street adresses, whatever
`The purpose of an array is to eliminate the need for a bunch of variable names
`In this program, we will need to keep track of each rocks Y position (up and down) and be able to
`set the speed of each rock to a new random value each time it comes to the bottom
`To define an array in DB we use the 'dim' command
`The dim command is then followed by the name we want to call the array which could be anything
`In this case we will call it RockY since this will hold the values of the Y positions for all the rocks
`We need to allocate 20 slots of memory for the array so we need to put the number 19 in parenthesis after
`we define the name of the array.
`we put the number 19 because DB starts at 0 and works its way to the number you put in
dim RockY(19)
`There all the words in the world mean nothing unless you see it put to practicale use.
`Next we need to create an array that will hold the speed or the number of pixels per frame that every
`rock moves. We will call this array RockSPD
dim RockSPD(19)
`RockSPD will only be useful if there are values in it.
`We need to put values into it so the program can actually start with something
`We want the spd to be a random integer above 0, but not too high or the rock will fly off the screen
`The best thing to do would probably be to set a constant
`A constant is a like a variable except exactly the opposite
`Confused? Let me explain. You know that you can set a value to a variable
`With a constant you set a value also, but then you can never change it again
`Since we know that we will probably want to change the speed of the rocks again
`in the game we want to have a maximum random variable that requires just a small change in the program
`as opposed to going through the whole program and changing a bunch of threes to fours
`3 sounds like a good starting point so lets do that
`However, to make a random count between 1 and 3 we will need to make the value 2
`the reason for this is that DB goes from the number 0 the the number you declare in the RND() command
`We will have to say RND(value) + 1
#constant maxspd = 2
`Now lets set the initial values
`This can be done with a simple for/next statement
for rock = 0 to 19
RockSPD(rock) = rnd(maxspd) + 1
next rock
`So now we can actually begin a simple game loop!
do `Exciting!
`Joking aside it's time to get down to controlling some mechanics of the game
`The first thing we should probably do is update the rocks
`We will run a loop from 2 to 21 since that is the range of our rock sprite numbers
`We then will refer to any arrays in the loop as rock - 2 to get to the 0 to 19 range
for rock = 2 to 21
`Update the RockY array
RockY(rock - 2) = sprite y(rock)
`Increase the position of the sprite y
sprite rock, sprite x(rock), sprite y(rock) + RockSPD(rock - 2), 2
`Now we will check to see if the rock goes off the bottom of the screen
`We can do this with a simple If/Then statement
if RockY(rock - 2) > screen height()
`First we need to reposition it at the top, but past the starting point to make a more convincing effect
`of a new rock coming down
RockY(rock - 2) = -32
`And update the newly positioned sprite
sprite rock, sprite x(rock), -32, 2
`Then we can set the spd to a new random value
RockSPD(rock - 2) = rnd(maxspd) + 1
endif
next rock
`Next we need to set up some code for the little man to be able to actually avoid the rocks
`This can be done very simply with our xpos variable we created earlier
`We can use the inc command to increase our xpos variable by rightkey() - leftkey()
`Since leftkey() and rightkey() return either 1 or 0 we can get the amount to move through the
`difference of the two values
`However, moving at speeds of -1, 0, and 1 are not fast enough, we need to move faster
`This can be achieved by simply multiplying rightkey() and leftkey() by the same value
inc xpos, (rightkey() * 2) - (leftkey() * 2)
`Then of course we need to update the player
sprite 1, xpos, 480 - 32, 1
`Finally we need to do some collision to check if the player gets hit
`The sprite collision command can do this.
for rock = 2 to 21
`This will end the program if the player get hit
`It is crude for an ending, but can be changed later
if sprite collision(rock, 1) = 1 then end
next rock
`Just update with the sync command and call the loop command and your done with a rough avalanche game
sync
loop
Media is attached. An absolutly staggering 10 kb.