Im a little new to blitzplus and a I am trying to program a basic game where you move a ship and there is a another that the computer controls. If the two collide then the player lose health. (This program is text based.) So I need help with this:
1. Stop the computer just frezzing up and when it hits the wall to speed up.
2. When the two ships meet the player loses help and level restarts.
3. The ships dont have to be right on top of each other to collide.
4. More ships can apperar after a set time limit.
Here is the code. It is still a work in progress.
Graphics 640, 480
SeedRnd MilliSecs()
Const Ship$ = "<|>"
Const Esc = 1, Space = 57, Up = 200, LeftK = 203, RightK = 205, Down = 208, Shift = 54
Const Startx = 320, Starty = 240
Global EStartx = Rand(1,640)
Global EStarty = Rand(1,480)
Type Ship
Field x, y
Field Ship$
Field directionx
Field directiony
Field hitpoints
End Type
Global cont = 1
Global Player.Ship = New Ship
Player\x = Startx
Player\y = Starty
Player\Ship$ = Ship$
player\hitpoints = 3
Global enemy.ship = New ship
enemy\ship$ = ship$
enemy\x = EStartx
enemy\y = EStarty
enemy\directionx = Rand(1,-1)
enemy\directiony = Rand(1,-1)
enemy\hitpoints = 3
While Not KeyHit(1)
Cls
DrawLevel()
TestInput()
TestEnemy()
TestCollision()
DrawHUD()
Flip
Wend
Function DrawLevel()
Text Player\x, Player\y, Player\Ship$
Text enemy\x, enemy\y, enemy\ship$
End Function
Function TestInput()
If KeyDown(LeftK)
Player\x = Player\x - 1
If Player\x <= 0
Player\x = 10
End If
End If
If KeyDown(RightK)
Player\x = Player\x + 1
If Player\x >= 635
Player\x = 610
End If
End If
If KeyDown(Up)
Player\y = Player\y - 1
If Player\y <= 0
Player\y = 10
End If
End If
If KeyDown(Down)
Player\y = Player\y + 1
If Player\y >= 475
Player\y = 450
End If
End If
End Function
Function TestEnemy()
enemy\x = enemy\x + enemy\directionx
If enemy\x <= 0
enemy\x = 10
enemy\directionx = enemy\directionx * -1
enemy\directionx = enemy\directionx + Rand(1,-1)
End If
If enemy\x >= 635
enemy\x = 610
enemy\directionx = enemy\directionx * -1
enemy\directionx = enemy\directionx + Rand(1,-1)
End If
enemy\y = enemy\y + enemy\directiony
If enemy\y <= 0
enemy\y = 10
enemy\directiony = enemy\directiony * -1
enemy\directiony = enemy\directiony + Rand(1,-1)
End If
If enemy\y >= 475
enemy\y = 450
enemy\directiony = enemy\directiony * -1
enemy\directiony = enemy\directiony + Rand(1,-1)
End If
End Function
Function TestCollision()
If enemy\x = player\x And enemy\y = player\y Then
DrawLevel()
Player\Hitpoints = Player\Hitpoints - 1
If player\hitpoints <= 0 Then
Delete player
End If
End If
End Function
Function DrawHUD()
Text 0, 435, "HitPoints: " + player\hitpoints + ""
Text 0, 450, "X Position: " + Player\x + ""
Text 0, 465, "Y Position: " + Player\y + ""
Text 0, 420, "X Position: " + enemy\x + ""
Text 0, 405, "Y Position: " + enemy\y + ""
End Function
1. Stop the computer just frezzing up and when it hits the wall to speed up.
2. When the two ships meet the player loses help and level restarts.
3. The ships dont have to be right on top of each other to collide.
4. More ships can apperar after a set time limit.
Here is the code. It is still a work in progress.
Graphics 640, 480
SeedRnd MilliSecs()
Const Ship$ = "<|>"
Const Esc = 1, Space = 57, Up = 200, LeftK = 203, RightK = 205, Down = 208, Shift = 54
Const Startx = 320, Starty = 240
Global EStartx = Rand(1,640)
Global EStarty = Rand(1,480)
Type Ship
Field x, y
Field Ship$
Field directionx
Field directiony
Field hitpoints
End Type
Global cont = 1
Global Player.Ship = New Ship
Player\x = Startx
Player\y = Starty
Player\Ship$ = Ship$
player\hitpoints = 3
Global enemy.ship = New ship
enemy\ship$ = ship$
enemy\x = EStartx
enemy\y = EStarty
enemy\directionx = Rand(1,-1)
enemy\directiony = Rand(1,-1)
enemy\hitpoints = 3
While Not KeyHit(1)
Cls
DrawLevel()
TestInput()
TestEnemy()
TestCollision()
DrawHUD()
Flip
Wend
Function DrawLevel()
Text Player\x, Player\y, Player\Ship$
Text enemy\x, enemy\y, enemy\ship$
End Function
Function TestInput()
If KeyDown(LeftK)
Player\x = Player\x - 1
If Player\x <= 0
Player\x = 10
End If
End If
If KeyDown(RightK)
Player\x = Player\x + 1
If Player\x >= 635
Player\x = 610
End If
End If
If KeyDown(Up)
Player\y = Player\y - 1
If Player\y <= 0
Player\y = 10
End If
End If
If KeyDown(Down)
Player\y = Player\y + 1
If Player\y >= 475
Player\y = 450
End If
End If
End Function
Function TestEnemy()
enemy\x = enemy\x + enemy\directionx
If enemy\x <= 0
enemy\x = 10
enemy\directionx = enemy\directionx * -1
enemy\directionx = enemy\directionx + Rand(1,-1)
End If
If enemy\x >= 635
enemy\x = 610
enemy\directionx = enemy\directionx * -1
enemy\directionx = enemy\directionx + Rand(1,-1)
End If
enemy\y = enemy\y + enemy\directiony
If enemy\y <= 0
enemy\y = 10
enemy\directiony = enemy\directiony * -1
enemy\directiony = enemy\directiony + Rand(1,-1)
End If
If enemy\y >= 475
enemy\y = 450
enemy\directiony = enemy\directiony * -1
enemy\directiony = enemy\directiony + Rand(1,-1)
End If
End Function
Function TestCollision()
If enemy\x = player\x And enemy\y = player\y Then
DrawLevel()
Player\Hitpoints = Player\Hitpoints - 1
If player\hitpoints <= 0 Then
Delete player
End If
End If
End Function
Function DrawHUD()
Text 0, 435, "HitPoints: " + player\hitpoints + ""
Text 0, 450, "X Position: " + Player\x + ""
Text 0, 465, "Y Position: " + Player\y + ""
Text 0, 420, "X Position: " + enemy\x + ""
Text 0, 405, "Y Position: " + enemy\y + ""
End Function