This is my first project, a Tank Game. Thanks to all you guys on the forum for answering all my questions
.
Code Below:
Rem Project: Tank Game
Rem Created: 4/8/2008 12:59:38 PM
Center Text Screen Width()/2,Screen Height()/2,"Ready To Start?"
Suspend For Key
GoSub Set_Up
Repeat
GoSub Handle_Tanks
Gosub Handle_Bullets
Until P1TankDead=1 or P2TankDead=1
GoSub End_Game
Wait Key
End
Set_Up:
Rem Init The Tank Types
Type TankType
Number As Integer
SpriteString As String
PosX As Integer
PosY As Integer
Angle As Float
Speed As Float
EndType
P1Tank As TankType
P1Tank.Number=1
P1Tank.SpriteString="BlueTank.bmp"
P1Tank.PosX=32
P1Tank.PosY=32
P1Tank.Angle=135
P1Tank.Speed=.15
P2Tank As TankType
P2Tank.Number=2
P2Tank.SpriteString="RedTank.bmp"
P2Tank.PosX=608
P2Tank.PosY=448
P2Tank.Angle=315
P2Tank.Speed=.35
Rem Init the Bullet Types
Type BulletType
Number As Integer
SpriteString As String
PosX As Integer
PosY As Integer
Angle As Float
Speed As Float
Fired As Integer
EndType
P1Bullet As BulletType
P1Bullet.Number=21
P1Bullet.SpriteString="BlueBullet.bmp"
P1Bullet.PosX=0
P1Bullet.PosY=0
P1Bullet.Angle=P1Tank.Angle
P1Bullet.Speed=3
P1Bullet.Fired=0
P2Bullet As BulletType
P2Bullet.Number=22
P2Bullet.SpriteString="RedBullet.bmp"
P2Bullet.PosX=0
P2Bullet.PosY=0
P2Bullet.Angle=P2Tank.Angle
P2Bullet.Speed=2
P2Bullet.Fired=0
Rem Loading The Images
Load Image P1Tank.SpriteString,P1Tank.Number
Load Image P1Bullet.SpriteString,P1Bullet.Number
Load Image P2Tank.SpriteString,P2Tank.Number
Load Image P2Bullet.SpriteString,P2Bullet.Number
Rem Loading The Sounds
Load Sound "StartSound.wav",1
Load Sound "Shot.wav",2
Rem Displaying the Tanks
Sprite P1Tank.Number,P1Tank.PosX,P1Tank.PosY,P1Tank.Number
Offset Sprite P1Tank.Number,(Sprite Width(P1Tank.Number)/2),(Sprite Height(P1Tank.Number)/2)
Rotate Sprite P1Tank.Number,P1Tank.Angle
Sprite P2Tank.Number,P2Tank.PosX,P2Tank.PosY,P2Tank.Number
Offset Sprite P2Tank.Number,(Sprite Width(P2Tank.Number)/2),(Sprite Height(P2Tank.Number)/2)
Rotate Sprite P2Tank.Number,P2Tank.Angle
Rem Starting Up...
Randomize Timer()
Backdrop On
Color Backdrop RGB(0,0,45)
Play Sound 1
Return
Handle_Tanks:
Rem Code Controlling Player 1's Input and Tank Movement
If Keystate(17)=1 : Move Sprite P1Tank.Number,P1Tank.Speed : Endif
If Keystate(31)=1 : Move Sprite P1Tank.Number,-P1Tank.Speed : Endif
If Keystate(30)=1 : Dec P1Tank.Angle,.2 : Endif
If Keystate(32)=1 : Inc P1Tank.Angle,.2 : Endif
If Keystate(57)=1 and (P1Bullet.Fired=0 or Timer()>FireTimer1)
Sprite P1Bullet.Number,Sprite X(P1Tank.Number),Sprite Y(P1Tank.Number),P1Bullet.Number
Rotate Sprite P1Bullet.Number,P1Tank.Angle
Play Sound 2
P1Bullet.Fired=1
FireTimer1=Timer()+1000
Endif
Rotate Sprite P1Tank.Number,P1Tank.Angle
Rem Code Controlling Player 2's Input and Tank Movement
If Keystate(72)=1 : Move Sprite P2Tank.Number,P2Tank.Speed : Endif
If Keystate(80)=1 : Move Sprite P2Tank.Number,-P2Tank.Speed : Endif
If Keystate(75)=1 : Dec P2Tank.Angle,.2 : Endif
If Keystate(77)=1 : Inc P2Tank.Angle,.2 : Endif
If Keystate(82)=1 and (P2Bullet.Fired=0 or Timer()>FireTimer2)
Sprite P2Bullet.Number,Sprite X(P2Tank.Number),Sprite Y(P2Tank.Number),P2Bullet.Number
Rotate Sprite P2Bullet.Number,P2Tank.Angle
Play Sound 2
P2Bullet.Fired=1
FireTimer2=Timer()+1000
Endif
Rotate Sprite P2Tank.Number,P2Tank.Angle
Return
Handle_Bullets:
Rem Code Controlling Player 1's Bullet Movement and Collision
If P1Bullet.Fired=1
Move Sprite P1Bullet.Number,P1Bullet.Speed
If Sprite Hit(P1Bullet.Number,P2Tank.Number)
P2TankDead=1
Endif
If Timer()=FireTimer1
P1Bullet.Fired=0
Endif
Endif
Rem Code Controlling Player 2's Bullet Movement and Collision
If P2Bullet.Fired=1
Move Sprite P2Bullet.Number,P2Bullet.Speed
If Sprite Hit(P2Bullet.Number,P1Tank.Number)
P1TankDead=1
Endif
If Timer()=FireTimer2
P2Bullet.Fired=0
Endif
Endif
Return
End_Game:
Rem Deleting the Sprites
If Sprite Exist(P1Tank.Number): Delete Sprite P1Tank.Number : Endif
If Sprite Exist(P2Tank.Number): Delete Sprite P2Tank.Number : Endif
If Sprite Exist(P1Bullet.Number
Delete Sprite P1Bullet.Number : Endif
If Sprite Exist(P2Bullet.Number)
Delete Sprite P2Bullet.Number : Endif
Backdrop Off
Rem Print the Winners
If P2TankDead=1
Center Text Screen Width()/2,Screen Height()/2,"Player 1 Wins!" Endif
If P1TankDead=1
Center Text Screen Width()/2,Screen Height()/2,"Player 2 Wins!" Endif
Return
Here's a screenshot...