Hey,
This is the first proper game I have made in DarkBasic so please be nice
It is a 2D space game that has 1 and 2 player modes where you just shoot each other until the other person dies.
There is Screen Wrapping and Bouncing, And there is crash support if you are playing on a big enough screen.
It works with eyefinity, but you have to manually set the width and height (Resolution) at the top of the script.
The AI is pretty basic, it just faces you constantly and shoots every so often, so if anyone can help me make that better it would be much appriciated
Sometimes, it takes a while for the sounds to play first time, so if it seems to be frozen, it isn't
If anyone goes off-screen somehow, press return to return them.
Please post any suggestions, bugs, or nice comments below. (The do help
)
I will attach the Code and a download link.
Controls:
P1:
W - Increase throttle
A - Left
S - Decrease Throttle
D - Right
Shift - Shoot
P2:
Up - Increase throttle
Left - Left
Down - Decrease Throttle
Right - Right
Space - Shoot
Thanks,
Matt
`Display
sync on : sync rate 60
width = desktop width()
height = desktop height()
set window off
set display mode width, height, 32
cls
`Menu Variables
t1$ = "Play"
t2$ = "Exit"
x1 = width / 3 - text width(t1$) / 2
x2 = width / 3 * 2 - text width(t2$) / 2
y = height / 3 * 2
`Game Variables
spritecount = 0
sx1 = width / 4
sx2 = width / 4 * 3
sy1 = height / 2
sy2 = height / 2
sspeed1 = 3
sspeed2 = 3
shealth1 = 100
shealth2 = 100
slives1 = 3
slives2 = 3
wrapping = 0
bouncing = 0
`Images
load image "images\ship1.bmp", 1
load image "images\ship2.bmp", 2
load image "images\bullet1.bmp", 3
load image "images\bullet2.bmp", 4
`Sounds
load sound "sounds\shoot.wav", 1
load sound "sounds\explosion.wav", 2
`Menu
do
set text font "Calibri"
set text size 48
ink rgb(255,0,0),0
x1 = width / 3 - text width(t1$) / 2
x2 = width / 3 * 2 - text width(t2$) / 2
if button(x1, y, t1$) = 1 then goto play
if button(x2, y, t2$) = 1 then end
sync
loop
play:
cls
repeat
input "1 For Screen Wrapping, 2 for Ship Bouncing -> ",wrapping
if wrapping = 2 then bouncing = 1
cls
until wrapping = 1 or wrapping = 2
repeat
input "1 For Singleplayer, 2 for Multiplayer -> ",singleplayer
if singleplayer = 2 then multiplayer = 1
cls
until singleplayer = 1 or singleplayer = 2
repeat
input "1 For No Crashing, 2 for Crashing -> ",crashing
cls
until crashing = 1 or crashing = 2
`Backdrop
backdrop on
color backdrop 0
`Sprites
sprite 1, sx1, sy1, 1
sprite 2, sx2, sy2, 2
offset sprite 1, sprite width(1)/2, sprite height(1)/2
offset sprite 2, sprite width(2)/2, sprite height(2)/2
spritecount = spritecount + 2
do
`Reset ships
if returnkey() = 1
sprite 1, sx1, sy1, 1
sprite 2, sx2, sy2, 2
offset sprite 1, sprite width(1)/2, sprite height(1)/2
offset sprite 2, sprite width(2)/2, sprite height(2)/2
rotate sprite 1, 0
rotate sprite 2, 0
endif
`Crash Handler
if crashing = 2
if sprite hit(1, 2)
play sound 2
slives1 = slives1 - 1
slives2 = slives2 - 1
sprite 1, sx1, sy1, 1
sprite 2, sx2, sy2, 2
offset sprite 1, sprite width(1)/2, sprite height(1)/2
offset sprite 2, sprite width(2)/2, sprite height(2)/2
rotate sprite 1, 0
rotate sprite 2, 0
endif
endif
`Variable Management
if shealth1 =< 0
play sound 2
sprite 1, sx1, sy1, 1
offset sprite 1, sprite width(1)/2, sprite height(1)/2
rotate sprite 1, 0
slives1 = slives1 - 1
shealth1 = 100
sspeed1 = 3
endif
if shealth2 =< 0
play sound 2
sprite 2, sx2, sy2, 2
offset sprite 2, sprite width(2)/2, sprite height(2)/2
rotate sprite 2, 0
slives2 = slives2 - 1
shealth2 = 100
sspeed2 = 3
endif
if slives1 =< 0
delete sprite 1
delete sprite 2
if sprite exist(3)
delete sprite 3
endif
play sound 2
wait key
exit
endif
if slives2 =< 0
delete sprite 1
delete sprite 2
if sprite exist(4)
delete sprite 4
endif
play sound 2
wait key
exit
endif
`HUD
set text size 24
`Ship 1
text 100, 100, "Player 1:"
text 100, 200, "Lives: " + str$(slives1)
text 100, 300, "Health: " + str$(shealth1)
text width - 100 - text width("Player 2:"), 100, "Player 2:"
text width - 100 - text width("Lives: ") - text width(str$(slives2)), 200, "Lives: " + str$(slives2)
text width - 100 - text width("Health: ") - text width(str$(shealth2)), 300, "Health: " + str$(shealth2)
`Screen Wrapping
if wrapping = 1
`Ship 1
if sprite x(1) < 0
sprite 1, width, sprite y(1), 1
offset sprite 1, sprite width(1)/2, sprite height(1)/2
endif
if sprite y(1) < 0
sprite 1, sprite x(1), height, 1
offset sprite 1, sprite width(1)/2, sprite height(1)/2
endif
if sprite x(1) > width
sprite 1, 0, sprite y(1), 1
offset sprite 1, sprite width(1)/2, sprite height(1)/2
endif
if sprite y(1) > height
sprite 1, sprite x(1), 0, 1
offset sprite 1, sprite width(1)/2, sprite height(1)/2
endif
`Ship 2
if sprite x(2) < 0
sprite 2, width, sprite y(2), 2
offset sprite 2, sprite width(2)/2, sprite height(2)/2
endif
if sprite y(2) < 0
sprite 2, sprite x(2), height, 2
offset sprite 2, sprite width(2)/2, sprite height(2)/2
endif
if sprite x(2) > width
sprite 2, 0, sprite y(2), 2
offset sprite 2, sprite width(2)/2, sprite height(2)/2
endif
if sprite y(2) > height
sprite 2, sprite x(2), 0, 2
offset sprite 2, sprite width(2)/2, sprite height(2)/2
endif
endif
`Ship Bouncing
if bouncing = 1
`Ship 1
if sprite x(1) < 1
rotate sprite 1, 360 - sprite angle(1)
endif
if sprite x(1) > width
rotate sprite 1, 360 - sprite angle(1)
endif
if sprite y(1) < 1
rotate sprite 1, 180 - sprite angle(1)
endif
if sprite y(1) > height
rotate sprite 1, 180 - sprite angle(1)
endif
`Ship 2
if sprite x(2) < 1
rotate sprite 2, 360 - sprite angle(2)
endif
if sprite x(2) > width
rotate sprite 2, 360 - sprite angle(2)
endif
if sprite y(2) < 1
rotate sprite 2, 180 - sprite angle(2)
endif
if sprite y(2) > height
rotate sprite 2, 180 - sprite angle(2)
endif
endif
`Bullet Handling
if sprite exist(4)
if sprite hit(4, 1)
shealth1 = shealth1 - 20
endif
endif
if sprite exist(3)
if sprite hit(3, 2)
shealth2 = shealth2 - 20
endif
endif
if sprite exist(3)
move sprite 3, 40
endif
if sprite exist(4)
move sprite 4, 40
endif
if sprite exist(3)
if sprite x(3) > width
delete sprite 3
endif
endif
if sprite exist(3)
if sprite x(3) < 1
delete sprite 3
endif
endif
if sprite exist(3)
if sprite y(3) > height
delete sprite 3
endif
endif
if sprite exist(3)
if sprite y(3) < 1
delete sprite 3
endif
endif
if sprite exist(4)
if sprite x(4) > width
delete sprite 4
endif
endif
if sprite exist(4)
if sprite x(4) < 1
delete sprite 4
endif
endif
if sprite exist(4)
if sprite y(4) > height
delete sprite 4
endif
endif
if sprite exist(4)
if sprite y(4) < 1
delete sprite 4
endif
endif
`Ship Control
`Throttle
move sprite 1, sspeed1
move sprite 2, sspeed2
`Speed Limits
`Ship 1
if sspeed1 > 20
sspeed1 = 20
endif
if sspeed1 < 3
sspeed1 = 3
endif
`Ship 2
if sspeed2 > 20
sspeed2 = 20
endif
if sspeed2 < 3
sspeed2 = 3
endif
`Ship 1 Input
if spacekey() = 1
shoot(1)
endif
if upkey() = 1
sspeed1 = sspeed1 + 1
endif
if downkey() = 1
sspeed1 = sspeed1 - 1
endif
if rightkey() = 1
rotate sprite 1, sprite angle(1) + 5
endif
if leftkey() = 1
rotate sprite 1, sprite angle(1) - 5
endif
`Ship 2 Input
if keystate(42) = 1
shoot(2)
endif
if keystate(17) = 1
sspeed2 = sspeed2 + 1
endif
if keystate(31) = 1
sspeed2 = sspeed2 - 1
endif
if keystate(32) = 1
rotate sprite 2, sprite angle(2) + 5
endif
if keystate(30) = 1
rotate sprite 2, sprite angle(2) - 5
endif
`AI
if singleplayer = 1
pointsprite(2, 1)
if sprite exist(4) = 0
shootnow = rnd(100)
if shootnow = 50
shoot(2)
endif
endif
endif
sync
loop
function shoot(shipno)
if shipno = 1
`Ship 1 Shoots
if sprite exist(3) = 0
sprite 3, sprite x(1), sprite y(1), 3
rotate sprite 3, sprite angle(1)
offset sprite 3, sprite width(3) / 2, sprite height(3) / 2
play sound 1
endif
endif
if shipno = 2
`Ship 2 Shoots
if sprite exist(4) = 0
sprite 4, sprite x(2), sprite y(2), 4
rotate sprite 4, sprite angle(2)
offset sprite 4, sprite width(4) / 2, sprite height(4) / 2
play sound 1
endif
endif
endfunction
function Button(x1,y1,words$)
Pressed=0
x2=Text Width(words$)
y2=Text Height(words$)
if mousex()>x1 and mousex()<x1+x2
if mousey()>y1-y2 and mousey()<y1+y2
pressed=1
endif
endif
if pressed=1 then ink rgb(255,255,255),0 else ink rgb(255,0,0),0
if pressed=1
pressed=mouseclick()
else
pressed = 0
endif
text x1,y1,words$
endfunction pressed
function pointsprite(spriteno,target)
xdist = sprite x(spriteno) - sprite x(target)
ydist = sprite y(spriteno) - sprite y(target)
angle# = -atanfull(xdist, ydist)
rotate sprite spriteno, angle#
endfunction
Uploaded with
ImageShack.us
Umm...