Okay, go easy... (How do you do the black window thing to denote code)?
This is after a day or so, and I'm kind of proud of it. :)
It's just a simple player ship moves left and right (with 'Z' and 'X', fires a single bullet once every key-press of 'M' and plays a sound when it fires.
Feel free to criticise. I want to know if it can be made more efficient. I'm *very* pleased with sussing out how to use a flag variable to control the bullet's appearance, etc.
But there's a weird bug... Once the player has fired once, the bullet sound just keeps playing over and over at about one second pause interval. I can't see, from the code, why that would happen. Could this be another B+ bug? :)
All help appreciated. :D
Flynn.
-----
gfxplayer=LoadImage("graphics\player.bmp")
gfxlaser=LoadImage("graphics\laser.bmp")
;load and define sounds
soundlaser=LoadSound("sounds\soundlaser.wav")
;define player ship x coordinates and bullet coordinates
playerpos=320
las1=320
las2=390
;scale image up a bit
ScaleImage gfxplayer,1,1.5
;set bullet flag
bulletflag=0
;control loop
While Not KeyHit(1)
Cls
DrawImage gfxplayer, playerpos,420
;move ship left
If KeyDown(44) And playerpos>16 Then playerpos=playerpos-4
;move ship right
If KeyDown(45) And playerpos<590 Then playerpos=playerpos+4
;shoot condition
If KeyHit (50) And bulletflag=0 Then
PlaySound soundlaser
bulletflag=1
las1=playerpos+14
EndIf
;move laser
If bulletflag=1 Then
DrawImage gfxlaser,las1,las2
If las2>16 Then las2=las2-8
If las2<25 Then
las2=390
bulletflag=0
EndIf
EndIf
Flip
Wend
-----
This is after a day or so, and I'm kind of proud of it. :)
It's just a simple player ship moves left and right (with 'Z' and 'X', fires a single bullet once every key-press of 'M' and plays a sound when it fires.
Feel free to criticise. I want to know if it can be made more efficient. I'm *very* pleased with sussing out how to use a flag variable to control the bullet's appearance, etc.
But there's a weird bug... Once the player has fired once, the bullet sound just keeps playing over and over at about one second pause interval. I can't see, from the code, why that would happen. Could this be another B+ bug? :)
All help appreciated. :D
Flynn.
-----
gfxplayer=LoadImage("graphics\player.bmp")
gfxlaser=LoadImage("graphics\laser.bmp")
;load and define sounds
soundlaser=LoadSound("sounds\soundlaser.wav")
;define player ship x coordinates and bullet coordinates
playerpos=320
las1=320
las2=390
;scale image up a bit
ScaleImage gfxplayer,1,1.5
;set bullet flag
bulletflag=0
;control loop
While Not KeyHit(1)
Cls
DrawImage gfxplayer, playerpos,420
;move ship left
If KeyDown(44) And playerpos>16 Then playerpos=playerpos-4
;move ship right
If KeyDown(45) And playerpos<590 Then playerpos=playerpos+4
;shoot condition
If KeyHit (50) And bulletflag=0 Then
PlaySound soundlaser
bulletflag=1
las1=playerpos+14
EndIf
;move laser
If bulletflag=1 Then
DrawImage gfxlaser,las1,las2
If las2>16 Then las2=las2-8
If las2<25 Then
las2=390
bulletflag=0
EndIf
EndIf
Flip
Wend
-----