Screenshots:
[img]
Hi,
This is my first game, so any comments or help appriciated.
It is a two player space shooter with a targeting system and 3dness.
To do list: (
= Working on,
= finished,
= finished but bugged and
= unstarted.)
Controls:
Firing:
Collision:
HUD:
Main Loop:
Problems / Questions
How do I save a variable to a file?
How do I set up collision so that the two spaceships don't hit each other?
How do I see if an object is roughly in front of one of the ships?
Controls:
P1 Controls:
WASD = Move = 17, 30, 31, 32
QE = Up / Down = 16, 18
Left Shift = Boost = 42
Space = Shoot = 57
P2 Controls:
5123 = Move = 76, 79, 80, 81
46 = Up / Down = 75, 77
Right arrow key = Boost = 205
Enter = Shoot = 156
Latest Version Attached.
Current Code:
cls
remstart
if file exist ("Files\settings") then default()
input "Please enter your screen width> ",width
print "Screen Width: 1280" `Only supports 1280 for now.
width = 1280
input "Please enter your screen height> ",height
input "Do you want to use 32 or 16 bit?> ",bit
settings()
remend
goto setup
setup:
`Display
`set display mode width, height, bit
set display mode 1280, 1024, 32
hide mouse
autocam off
sync on
sync rate 60
backdrop off
`Cameras
position camera 0, 0, 30
point camera 0, 0, 0
`Lights
make light 1
position light 1, 0, 0, 30
`Images
load image "Files\Textures\shuttle.bmp", 1
load image "Files\Images\Backdrop.jpg", 2
`Objects
`Ships
load object "Files\Meshes\shuttle.x", 1
load object "Files\Meshes\shuttle.x", 2
texture object 1, 1
texture object 2, 1
position object 1, 0, 10, 0
position object 2, 0, -10, 0
`Planets
make object sphere 10, 20
make object sphere 11, 20
`make object sphere 12, 20
`make object sphere 13, 20
`make object sphere 14, 20
`make object sphere 15, 20
color object 10, rgb(205,127,50)
color object 11, rgb(205,127,50)
position object 10, 170, 90, -290
position object 11, -90, -30, -160
`Declaring Variables
global playagain$ = ""
global wins1 = 0
global wins2 = 0
global score1 = 0
global score2 = 0
global lives1 = 3
global lives2 = 3
global health1 = 50
global health2 = 50
global speed1 = -1
global speed2 = -1
global boost1# = 100.0
global boost2# = 100.0
global enableboost1 = 1
global enableboost2 = 1
`Loop
do
mainloop()
loop
function mainloop()
set cursor 100, 100
print object position x (1)
set cursor 100, 120
print object position y (1)
set cursor 100, 140
print object position z (1)
handlesprites()
handlecontrols()
handlecollision()
handlecalculations()
handlehud()
sync
endfunction
function handlesprites()
draw sprites first
sprite 1, 0, 0, 2
set sprite 1, 0, 0
endfunction
function handlecontrols()
`Player 1
if keystate(42) = 1 and speed1 => -3 and enableboost1 = 1 then boost1()
if keystate(17) = 1 then move object 1, speed1
if keystate(30) = 1 then turn object left 1, 4
if keystate(31) = 1 then move object 1, 1
if keystate(32) = 1 then turn object right 1, 4
if keystate(16) = 1 then move object up 1, 1
if keystate(18) = 1 then move object down 1, 1
if keystate(57) = 1 then shoot1()
`Player 2
if keystate(205) = 1 and speed2 => -3 and enableboost2 = 1 then boost2()
if keystate(76) = 1 then move object 2, speed2
if keystate(79) = 1 then turn object left 2, 4
if keystate(80) = 1 then move object 2, 1
if keystate(81) = 1 then turn object right 2, 4
if keystate(75) = 1 then move object up 2, 1
if keystate(77) = 1 then move object down 2, 1
if keystate(156) = 1 then shoot2()
endfunction
function handlecollision()
set global collision on
if object hit (1, 2)
endif
endfunction
function handlecalculations()
if score1 = 100 then lives1 = lives1 + 1 and score1 = 0
if health1 = 0 then lives1 = lives1 - 1 and health1 = 50
if score2 = 100 then lives2 = lives2 + 1 and score2 = 0
if health2 = 0 then lives2 = lives2 - 1 and health2 = 50
if lives1 = 0 then win2()
if lives2 = 0 then win1()
if keystate(42) = 0 then enableboost1 = 0
if keystate(205) = 0 then enableboost2 = 0
if boost1# > 99 then boost1# = 100
if boost1# =< 1 then enableboost1 = 0
if boost1# => 99 then enableboost1 = 1
if boost2# > 99 then boost2# = 100
if boost2# =< 1 then enableboost2 = 0
if boost2# => 99 then enableboost2 = 1
if enableboost1 = 0 then boost1off()
if enableboost2 = 0 then boost2off()
endfunction
function handlehud()
center text 615, 20, "Wins:"
set cursor 600, 40
print wins1
set cursor 620, 40
print wins2
center text 170, 10, "Player 1:"
center text 50, 30, "Score:"
set cursor 80, 30
print score1
center text 125, 30, "Lives:"
set cursor 155, 30
print lives1
center text 200, 30, "Health:"
set cursor 230, 30
print health1
center text 290, 30, "Energy:"
set cursor 320, 30
print boost1#
center text 1130, 10, "Player 2:"
center text 975, 30, "Score:"
set cursor 1005, 30
print score2
center text 1050, 30, "Lives:"
set cursor 1080, 30
print lives2
center text 1125, 30, "Health:"
set cursor 1155, 30
print health2
center text 1215, 30, "Energy:"
set cursor 1245, 30
print boost2#
endfunction
function shoot1()
cls
print "Player 1 Shot!"
`score1 = score1 + 10
`health2 = health2 - 10
endfunction
function shoot2()
cls
print "Player 2 Shot!"
`score2 = score2 + 10
`health1 = health1 - 10
endfunction
function win1()
wins1 = wins1 + 1
cls
set cursor 1, 1
input "Player 1 wins! Play again? (Y/N)> ",playagain$
if playagain$ = "y" then goto setup
if playagain$ = "n" then exit
endfunction
function win2()
wins2 = wins2 + 1
repeat
cls
set cursor 1, 1
input "Player 2 wins! Play again? (Y/N)> ",playagain$
until playagain$ = "y" or playagain$ = "n"
if playagain$ = "y" then goto setup
if playagain$ = "n" then exit
endfunction
function settings()
if file exist ("Files\settings") then delete file "Files\settings"
open to write 1, "Files\settings"
write file 1, width `How do i put a variable into a file?
write file 1, height `Same here
write file 1, bit `Same Here
close file 1
endfunction
function default()
open to read 1, ("Files\settings")
read file 1, width `I need to load the variable here.
read file 1, height`Same here
read file 1, bit`Same Here
close file 1
goto setup
endfunction
function boost1
speed1 = -3
boost1# = boost1# - 1
endfunction
function boost1off
speed1 = -1
boost1# = boost1# + 0.2
endfunction
function boost2
speed2 = -3
boost2# = boost2# - 1
endfunction
function boost2off
speed2 = -1
boost2# = boost2# + 0.2
endfunction
Any help appriciated!
Matt
Umm...