Hi everyone!, I'm new on this forum, and, of course, in blitz programming.
I've been trying to create a little game in blitzplus, but I have found a problem that I can't solve. Could you help me?
The case is that when I try to kill the "enemy navs" they don't disappear, and if they do, the program crashes. I'm sure that this is a very simple problem, but how I'm new in this word, I don't see it. Anyway, thanks a lot.
Does anybody know how to kill the enemies?
Oh, yes, this program structure is the worst in the world, I know it. :-)
If you want to see the code in an editor: http://rapidshare.com/files/77814890/movement_test2.bb
----------
;Variables
Global player.nav = New nav
Global bullet.ball = New ball
Global enemy.nav = New nav
Global leftkeyr = 1
Global randomnumber
Global randomgrade = 1000
Global maximumx,maximumy,minimx,minimy
Const rightkey = 205
Const leftkey = 203
Const upkey = 200
Const downkey = 208
Const spacekey = 31
Const esckey = 1
Const ball1$ = ""
Const nav1$ = "<-*->"
Const startx% = 400
Const starty% = 300
Const startvel = 5
;-------------------------------------------------------------------------
;Types
Type nav
Field x,y
Field vel
Field navimage$
End Type
player\x = startx
player\y = starty
player\vel = startvel
player\navimage = nav1$
Type ball
Field x,y
Field vel
Field ballimage
End Type
;-------------------------------------------------------------------------
;#########################################################################
;Main loop
Graphics 800,600,16,2
SeedRnd MilliSecs
SetBuffer BackBuffer ()
While Not KeyHit (esckey)
Cls
userinput ()
drawplayer ()
drawbullets ()
drawenemies ()
deletenemies ()
Flip
Delay 20
Wend
End
;#########################################################################
;=========================================================================
;Functions ;
;=========================================================================
;draw player
Function drawplayer ()
Text player\x,player\y,player\navimage,True,True
End Function
;-------------------------------------------------------------------------
;draw bullets
Function drawbullets ()
For bullet.ball = Each ball
If (bullet\y > -10) Then
Text bullet\x,bullet\y,"*",True,True
bullet\y = bullet\y - bullet\vel
End If
Next
End Function
;draw enemies
Function drawenemies ()
randomnumber = Rnd(0,randomgrade)
If randomnumber < 5 Then
enemy.nav = New nav
enemy\navimage = "(OO)"
enemy\x = Rnd (20,790)
enemy\y = Rnd (20,590)
End If
For enemy.nav = Each nav
Text enemy\x,enemy\y,enemy\navimage,True,True
Next
randomgrade = randomgrade - 1
End Function
;eliminate enemies
Function deletenemies ()
For bullet.ball = Each ball
For enemy.nav = Each nav
If (enemy\x < (bullet\x + 10)) And (bullet\x > (bullet\x - 10)) Then
Delete enemy
End If
Next
Next
End Function
;-------------------------------------------------------------------------
;User input
Function userinput ()
If KeyDown (leftkey) Then
player\x = player\x - player\vel
End If
If player\x <=23 Then
player\x = 23
End If
If KeyDown (rightkey) Then
player\x = player\x + player\vel
End If
If player\x >= 777 Then
player\x = 777
End If
If KeyDown (upkey) Then
player\y = player\y - player\vel
End If
If player\y <=5 Then
player\y = 5
End If
If KeyDown (downkey) Then
player\y = player\y + player\vel
End If
If player\y >= 595 Then
player\y = 595
End If
If KeyDown (31) Then
bullet.ball = New ball
bullet\x = player\x
bullet\y = player\y
bullet\vel = 10
bullet\ballimage = "*"
End If
End Function
;=========================================================================
Again, thanks!
I've been trying to create a little game in blitzplus, but I have found a problem that I can't solve. Could you help me?
The case is that when I try to kill the "enemy navs" they don't disappear, and if they do, the program crashes. I'm sure that this is a very simple problem, but how I'm new in this word, I don't see it. Anyway, thanks a lot.
Does anybody know how to kill the enemies?
Oh, yes, this program structure is the worst in the world, I know it. :-)
If you want to see the code in an editor: http://rapidshare.com/files/77814890/movement_test2.bb
----------
;Variables
Global player.nav = New nav
Global bullet.ball = New ball
Global enemy.nav = New nav
Global leftkeyr = 1
Global randomnumber
Global randomgrade = 1000
Global maximumx,maximumy,minimx,minimy
Const rightkey = 205
Const leftkey = 203
Const upkey = 200
Const downkey = 208
Const spacekey = 31
Const esckey = 1
Const ball1$ = ""
Const nav1$ = "<-*->"
Const startx% = 400
Const starty% = 300
Const startvel = 5
;-------------------------------------------------------------------------
;Types
Type nav
Field x,y
Field vel
Field navimage$
End Type
player\x = startx
player\y = starty
player\vel = startvel
player\navimage = nav1$
Type ball
Field x,y
Field vel
Field ballimage
End Type
;-------------------------------------------------------------------------
;#########################################################################
;Main loop
Graphics 800,600,16,2
SeedRnd MilliSecs
SetBuffer BackBuffer ()
While Not KeyHit (esckey)
Cls
userinput ()
drawplayer ()
drawbullets ()
drawenemies ()
deletenemies ()
Flip
Delay 20
Wend
End
;#########################################################################
;=========================================================================
;Functions ;
;=========================================================================
;draw player
Function drawplayer ()
Text player\x,player\y,player\navimage,True,True
End Function
;-------------------------------------------------------------------------
;draw bullets
Function drawbullets ()
For bullet.ball = Each ball
If (bullet\y > -10) Then
Text bullet\x,bullet\y,"*",True,True
bullet\y = bullet\y - bullet\vel
End If
Next
End Function
;draw enemies
Function drawenemies ()
randomnumber = Rnd(0,randomgrade)
If randomnumber < 5 Then
enemy.nav = New nav
enemy\navimage = "(OO)"
enemy\x = Rnd (20,790)
enemy\y = Rnd (20,590)
End If
For enemy.nav = Each nav
Text enemy\x,enemy\y,enemy\navimage,True,True
Next
randomgrade = randomgrade - 1
End Function
;eliminate enemies
Function deletenemies ()
For bullet.ball = Each ball
For enemy.nav = Each nav
If (enemy\x < (bullet\x + 10)) And (bullet\x > (bullet\x - 10)) Then
Delete enemy
End If
Next
Next
End Function
;-------------------------------------------------------------------------
;User input
Function userinput ()
If KeyDown (leftkey) Then
player\x = player\x - player\vel
End If
If player\x <=23 Then
player\x = 23
End If
If KeyDown (rightkey) Then
player\x = player\x + player\vel
End If
If player\x >= 777 Then
player\x = 777
End If
If KeyDown (upkey) Then
player\y = player\y - player\vel
End If
If player\y <=5 Then
player\y = 5
End If
If KeyDown (downkey) Then
player\y = player\y + player\vel
End If
If player\y >= 595 Then
player\y = 595
End If
If KeyDown (31) Then
bullet.ball = New ball
bullet\x = player\x
bullet\y = player\y
bullet\vel = 10
bullet\ballimage = "*"
End If
End Function
;=========================================================================
Again, thanks!