Rem Project Spacerace
`Set Sync rate
Sync on : sync rate 60
`Prepare Display
set display mode 1024,768,32
`hide mouse
hide mouse
`Load External Sound Media
load sound "godluckwarrior.wav", 1
load sound "moonbase power up.wav", 2
load sound "moonbase power cut.wav", 3
load sound "button 1.wav", 4
load music "green wild beast.mp3", 1
`prepare strings used in splash screen and ingame
start$ = "Press S to start the game"
spacerace$ = "Space Race!"
creator$ = "Developed by Aaron Donaghey for CREAM course."
gameover$ = "Game Over!!"
loading$ = "LOADING"
congrats$ = "Congratulations you have won, your time was"
REM Splash screen 1:
`Set start value of fade
fade = 0
`Begin Loop
repeat
`Display Text
set text size 80
set text to bold
ink rgb(255,255,255),0
center text 512,200,spacerace$
set text size 15
set text size 15
set text to normal
`Create Fade Effect on the text
if fade = 0 then fadedir = 1
if fade = 255 then fadedir = 0
if fadedir = 1 then fade = fade + 5
if fadedir = 0 then fade = fade - 5
`More text
ink rgb(fade,fade,fade),0
center text 512,350,start$
center text 512,500,creator$
sync
cls
`Loop continues until the letter S is pressed
until scancode() = 31
`Play a new sound and begin to fade out the enetire screen entirely
play sound 1
play music 1
loop music 1
fade = 255
repeat
ink rgb(fade,fade,fade),0
set text size 80
set text to bold
center text 512,200,pong$
set text size 15
set text to normal
center text 512,350,start$
center text 512,500,creator$
fade = fade - 5
sync
cls
`Once the text is totally faded, begin to load the main play area.
until fade = 0
Ink rgb(255,255,255), 0
`Show that the game is Loading, so as the user will not think something has gone wrong with the program
Center Text 512, 400, LOADING$
`Refresh the screen
Sync
Remstart Obsolete code that may prove useful when expanding the program
Generate Random Image
Image_Size = 64
for x = 0 to Image_Size
for y = 0 to Image_Size
dot x,y,RGB(0,rnd(156),0)
next x
Next y
get image 1,0,0,image_size, image_size
cls
Remend
`Define Varibles
World = 1
Size = 12800
Size2 = 400
Segments = 40
speed# as float
soundpress = 0
`Load External Image Media
load image "rock.bmp",1
load bitmap "land.bmp",1
load image "fire.bmp", 10
`Make 25 Matrixes stacked on top of each other
for m=0 to 25
make matrix 1+m,512,512,32,32 : position matrix 1+m,0,-2,512*m
prepare matrix texture 1+m,1,33,33 : set matrix texture 1+m,2,1
next m
set current bitmap 1
lock pixels
tc=1
for z=0 to 31
for x=0 to 31
col=point(x,z)
h#=rgbr(col)/4.0
for m=0 to 25
set matrix height 1+m,x,z,h#
set matrix tile 1+m,31-x,z,tc
next m
inc tc
next x
inc tc
next z
unlock pixels
delete bitmap 1
for m=0 to 25 : update matrix 1+m : next m
set current bitmap 0
`Color the background of the game
Backdrop On
Color Backdrop 0
rem Load External Media
load image "road.jpg",11
`Make A long flat road, with higher quality texture
for r=0 to 25
make object plain 110+r,128,512
position object 110+r,256+10,0.025,512*r
texture object 110+r,11
xrotate object 110+r,90
set object texture 110+r,1,1
scale object texture 110+r,1,5
set sphere mapping on 110+r, 2
next r
`Load resources and intial positioning/ varibles for player
Hero = 100
load object "scout2.x", hero
scale object hero, 5, 5,5
`Load External Media
load image "space.jpg",2
set sphere mapping on hero,2
position object hero, 256, 1, rnd(20)
xrotate object hero,90
yrotate object hero, 180
fix object pivot hero
`Enemie states to be used for "Mine" revision"
`Enemies
`Enemy States
`1- Idle
`2- Wander
`3- Chase
`Defining Variables relating to enemies.
Number_of_enemies = 50
dim EnemyState(Number_of_enemies)
`Enemy Vision
EnemyAwareness# = 40
`Speed
EnemySpeed#=.5
`Creating the asteroids of random shapes and sizes.
for x = 1 to Number_of_enemies
load object "ast_03.x", x
scale object x, rnd(20) + 5,rnd(20) + 5,rnd(20) + 5
Enemystate(x) = rnd(2)
`Position Asteroids
position object x,(200 + rnd(128)), 3 +rnd(5), rnd(size)
`Allow asteroids to collide
set object collision on x
set object collision to spheres x
next x
`Prepare particles for ingame engine effect
Make Particles 8,10, 40,7
`Set Ambient Light to full for ingame.
set ambient light 100
`Set Ambient Light to white
color ambient light RGB(255,255,255)
`Allow the players ship to give off a lighting effect
make light 1
color light 1, (RGB(0,0,255))
Set point light 1, x1#, y1#, z1#
Set light range 1, 200
`Main Game loop
do
`Move the ship forward relative to its speed value for each cycle
move object Hero, speed#
`Define varibles related to players ship.
x1#= object position x(Hero)
z1#= object position z(Hero)
y1#= get ground height(World,x1#,z1#)
ay1# = object angle y(hero)
`Reposition the light according to player
Position light 1, x1#, y1# + 2, z1#
`Keep player within boundaries
if x1# > 328 then x1# = 328
if x1# < 200 then x1# = 200
if z1# > size then z1# = z1# - 4
if z1# < 0 then z1# = 0
`Rotate the camera
xrotate camera + 20
`Set camera to follow after the players ship
Set camera to follow x1#,y1# + 10,z1#,ay1#,20,17,1,1
`Set playership in correct position
position object hero, x1#,y1#+2,z1#
`Increase speed if upkey is pressed, tilt the ship downwards
if upkey() = 1
`Increase speed variable
speed# = speed# + 0.01
If soundpress = 0
play sound 2
soundpress = 1
endif
xlift = 1
endif
`Decrase Speed if downkey is pressed, tilt the ship upwards
if downkey() = 1
xlift = 2
If soundpress = 0
play sound 3
soundpress = 1
endif
`Stop the ship from going into a quick reverse
if speed# < 0.1
speed = 0.1
else
speed# = speed# - 0.2
endif
endif
`Move the ship left and tilt it to the left
if leftkey() = 1
lift = 1
If soundpress = 0
play sound 4
soundpress = 1
endif
move object left Hero, 1
endif
`Move the ship right and tilt it to the right
if rightkey() = 1
lift = 2
If soundpress = 0
play sound 4
soundpress = 1
endif
move object right Hero, 1
endif
`Code to balance out the ship instead of it remaining in the tilt position. Took a long time to come up with.
If rightkey() = 0
If leftkey() = 0
If lift = 1
srz# = srz# -1
endif
If lift = 2
srz# = srz# + 1
endif
endif
endif
`Reset sound if no keys are pressed.
If rightkey() = 0
if leftkey() = 0
if downkey() = 0
if upkey() = 0
soundpress =0
endif
endif
endif
endif
`Development Only code, this is used to rotate the hero around to give a 360 degree of the level, not in player version.
`rotate object hero, 0, ay1# + mousemovex(), 0
`Code to handle the player tilting left and right, the code limits the amount of tilt and makes it gradual
if lift=1 then srz#=srz#+1
if lift=2 then srz#=srz#-1
zrotate object hero,srz#
srz#=srz#/1.05
`Code to handle the player tilting left and right, the code limits the amount of tilt and makes it gradual
if xlift=1 then srx#=srx#+0.4
if xlift=2 then srx#=srx#-0.2
xrotate object hero,srx#
srx#=srx#/1.05
`Stops the players speedometer as a integer rather than a decimal value.
Speednew = speed# * 1000
rem Show speed
`Code to show the player its speedometer
set text size 10
set cursor 0,13 : print "SPEED"
box 32,15,38+((screen width()-16)/15)*speed#,15+8,rgb(0,100,0),rgb(0,100,0),rgb(0,255,0),rgb(0,255,0)
set cursor (38+((screen width()-16)/15)*speed#)+4,13 : print str$(speednew)
`Asteroid Movement
for x = 1 to number_of_enemies
x2#= object position x(x)
z2#= object position z(x)
y2#= object position y(x)
ay2#= object angle y(x)
`Distance Formula
Distance# = sqrt( ((x2#-X1#)^2)+((y2#-y1#)^2)+((z2#-z1#)^2) )
`If were not as far as the enemies awareness hell chase
If distance# <= enemyawareness#
enemystate(x) = 2
Endif
`If were further than hell wander again
if distance#<= EnemyAwareness#
Enemystate(x) = 3
endif
`color green for safe and idlecode <--- DEVELOPMENT CODE
If enemystate(x)=2
`color object x,rgb(0,128,0) <--- DEVELOPMENT CODE
endif
`Enemyblue and circle if on wander
If enemystate(x)=2
`color object x, rgb(0,0,128) <--- DEVELOPMENT CODE
`varible for wander dir
If Upright = 0
x2#=x2# + enemyspeed#
z2#=z2# + enemyspeed#
if x2#>=512 or z2#>=12800 then upright=1
endif
if upright = 1
x2#=x2# - enemyspeed#
z2#=z2# - enemyspeed#
if x2#<=0 or z2#<=0 then upright = 0
endif
endif
`*****************************Code for later Expansion************************
`if Enemystate(x)=3
`color object x,rgb(128,0,0)
`if x2#<x1# then x2#=x2# + enemyspeed#
`if x2#>x1# then x2#=x2# - enemyspeed#
`if z2#<z1# then z2#=z2# + enemyspeed#
`if z2#>z1# then z2#=z2# - enemyspeed#
`endif#
`*****************************************************************************
` *****************************Code for later Expansion***********************
`Position Particle Emissions 1, OBJECT POSITION X(hero), OBJECT POSITION y(hero), (OBJECT POSITION z(hero) - 2.8)
`Position Particle Emissions 8, 256, 10, 2
`Position Particles 8, 256,10,2
` ****************************************************************************
`Refresh enemies position on the screen
position object x, x2#, y2#, z2#
rotate object x, object angle x(X), ay2#, object angle z(x)
next x
`Show the engine particle effect
Position Particles 8, OBJECT POSITION X(hero), OBJECT POSITION y(hero), (OBJECT POSITION z(hero) - 2.8)
Set particle Emissions 8, 30
Set Particle Life 8, 2000
Set Particle Velocity 8, .5
`Stop the asteroids from collding into each other <---- Code for expanding
`Colliding_objects = 0
` for x = 1 to number_of_enemies
` for y = 1 to number_of_enemies
` if x <> y
` if object collision(x,y) = 1
` x2# = object position x(x)
` z2# = object position z (x)
` y2# = get ground height(world,x2,z2#)
` ay2# = object angle y(x)
` inc colliding_objects, 1
` position object x,x1#,y2#,z1#+(object size(x)*colliding_objects)
` move object left x,(enemyspeed#*.5)
` endif
` endif
`next y
`next x
`Check to see if the players ship has collided with an asteroid
For xx = 1 TO NUMBER_of_enemies
if object collision(hero,xx)
Cls
Sync
Set Text Size 30
`End the game if it has showing the sign gameover.
Center Text 512, 300, Gameover$
Stop music 1
Sync
Wait key
end
endif
next xx
`Check to see if the player has completed the level
If object position z(hero) > 12800
Cls
Sync
Set Text Size 30
`If the player has completed the game, show him the time he completed it in, wait for the players input before ending game.
Center Text 512, 300, congrats$
Center Text 512, 400, str$(timer() / 1000000 ) + " seconds"
stop music 1
Sync
Wait key
end
endif
`print object position x(hero) <--- DEVELOPMENT CODE
`print object position y(hero) <--- DEVELOPMENT CODE
`print object position z(hero) <--- DEVELOPMENT CODE
`print particles position x(8) <--- DEVELOPMENT CODE
`print particles position y(8) <--- DEVELOPMENT CODE
`print particles position z(8) <--- DEVELOPMENT CODE
`Refresh the screen
sync
`Continue the program endlessly
loop