Sign in to follow this  

blitz basic ai bullets

This topic is 4751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've just started working with blitz basic, and I've read through a book on game programming using Blitz Basic. I've started my own 2d side scrolling game. I've gotten all the sprites up and junk, and I've gotten the player sprite up and shooting. I've also got moving enemy AI's. But I can't get the ai bullets to work right. At first I couldn't get them ot move they would just hang out in front of the enemy's. I finally got them moving but now only one shoots it. And its shooting a bullet every dang frame. I've tried getting a millisecs() timer going but it won't work. Is there anyone who knows blitz basic who could help me fix this issue?

Share this post


Link to post
Share on other sites
ok, the game is simple side scroller. You have a plane that sits in the middle of the screen, I have a background of stars that scrolls giving the illusion of moving forward. The user can move the plane up and down with the arrow keys, and shoot bullets with the spacebar. I also have about 5 ai who sits at varying x and y coords on the right side of the screen. Since this is my first game I decided not to give them much of an ai, so they just move up and down bouncing off the screen edges at varying speeds. I've been trying to give them weapons since it isn't much fun shooting them out of the sky, like ducks. But I can't seem to get them to work. The problem is that only one enemy is shooting bullets. I can't get the others to shoot them. And second I can't get a
millisec() timer to work. So every frame one eggbot shoots a bullet. Creating a giant zigzagging line. I think my source code could just have alot of defiencys. Should I post my source code so ppl can pick through it and point out problems that I should fix, and organize more?

Share this post


Link to post
Share on other sites
Quote:
Original post by KeybladeHitokiri
ok, the game is simple side scroller. You have a plane that sits in the middle of the screen, I have a background of stars that scrolls giving the illusion of moving forward. The user can move the plane up and down with the arrow keys, and shoot bullets with the spacebar. I also have about 5 ai who sits at varying x and y coords on the right side of the screen. Since this is my first game I decided not to give them much of an ai, so they just move up and down bouncing off the screen edges at varying speeds. I've been trying to give them weapons since it isn't much fun shooting them out of the sky, like ducks. But I can't seem to get them to work. The problem is that only one enemy is shooting bullets. I can't get the others to shoot them. And second I can't get a
millisec() timer to work. So every frame one eggbot shoots a bullet. Creating a giant zigzagging line. I think my source code could just have alot of defiencys. Should I post my source code so ppl can pick through it and point out problems that I should fix, and organize more?

Yeah, you should probably post your source. Now with the bullets. I think that yuo should use for enemy.enemy= each enemy. This will cause the program to cycle through each enemy, and you can just add a shoot function after the command.
If you want them to shoot at random time just add a andom function that will determine when they shoot. Heres the layout:
for enemy.enemy= each enemy
shoot
do other stuff

This will cycle through each enemy and make them do what you put.

Share this post


Link to post
Share on other sites
Ok source is here.

Graphics 1024,768

SetBuffer BackBuffer()
SeedRnd MilliSecs()

;MY KEYBOARD CONSTANTS
Global LEFTKEY=203
Global RIGHTKEY=205
Global UPKEY=200
Global DOWNKEY=208
Global SPACEBAR=57
Const ESC=1


Const replaysound=3000
Const timebetweenbullets=1200

PlayMusic("morning_glow.mp3")

;Images: player, background
Global playerimage=LoadImage("pics\tailsplanesprite.bmp")
Global bg = LoadImage("pics\starscape.bmp")
Global enemyimage = LoadImage("pics\moveggbot.bmp")
Global roundimage = LoadImage("pics\bullets.bmp")
Global enemybullet = LoadImage("pics\bullets2.bmp")

;position is for bullets to come out at front of airplane
HandleImage playerimage,120,50

;player's character variables
Type player
Field x,y ;x and y coords of player
End Type


;enemy's variables
Type enemy
Field x,y
Field yv
Field hits
End Type

;bullet variables
Type bullet
Field x,y
End Type

Type enemybullet
Field x,y
End Type

;player starting position
Global player.player = New player
player\x=400
player\y=300



;airplane moving sound
airplane=LoadSound("bm-sfx\airplane.wav")
SoundVolume airplane, .4

;Create starting timer for plane noise
timerbeginPLANE = MilliSecs()

;Create a variable that says the timer does not need to be reset
timeractivePLANE = 0

Global scrollx=0

Global level=1

;----------------------------------
;| Start Game |
;__________________________________

shotsfiredtime = MilliSecs()

CreateLevel()

;start main loop
While Not KeyDown(ESC)
Cls
;background tiles
TileImage bg,scrollx

;If the counter has run through, update airplane music
If MilliSecs() >= timerbeginPLANE + replaysound

;replay airplane.wav
PlaySound airplane
;make sure timer is reset
timeractivePLANE = 0
EndIf

;If the timer is inactive, reset the timer
If timeractivePLANE = 0
timerbeginPLANE = MilliSecs()
timeractivePLANE = 1
EndIf

Text 0,0, enemyhits
;Movement systems
;Scrolls background
scrollx=scrollx-10
If scrollx=ImageWidth(bg)
scrollx=0
EndIf

If KeyDown(UPKEY)
player\y=player\y-5
EndIf
If KeyDown(DOWNKEY)
player\y=player\y+5
EndIf

DrawImage playerimage, player\x, player\y
If KeyHit(SPACEBAR)
round.bullet = New bullet
round\x = player\x
round\y = player\y
EndIf
If KeyHit(54)
Createlevel()
EndIf


DrawEnemy()
UpdateBullets()
WallCollision()
EnemyAI()
Flip
Delay 25
Wend
End
;____________________________________;
;| End of Game here |;
;------------------------------------;



Function CreateLevel()

enemynumber=level * Rand(4, 6)

For eggbots=1 To enemynumber
CreateEnemy()
Next
End Function


Function CreateEnemy()
bot.enemy=New enemy
bot\x=Rand(500,950)
bot\y=Rand(50,680)
bot\yv=Rand(-15,15)
bot\hits=3
If bot\yv=0
bot\yv=6
EndIf
End Function


Function DrawEnemy()
For bot.enemy = Each enemy
DrawImage enemyimage, bot\x, bot\y
Next
End Function



Function WallCollision()
If player\y <= 42
player\y = 42
EndIf
If player\y >= 685
player\y = 685
EndIf
End Function



Function UpdateBullets()
For round.bullet = Each bullet
round\x= round\x + 10
DrawImage roundimage, round\x, round\y

For bot.enemy = Each enemy
If ImagesCollide(roundimage, round\x, round\y, 0, enemyimage, bot\x, bot\y,0)
bot\hits=bot\hits-1
If bot\hits =< 0
Delete bot
EndIf
End If
Next
Next
For ammo.enemybullet = Each enemybullet
ammo\x=ammo\x - 10
DrawImage enemybullet,ammo\x,ammo\y
Next
End Function



Function EnemyAI()
For enemy.enemy = Each enemy
enemy\y=enemy\y+enemy\yv
If enemy\y <= 42
enemy\yv = -enemy\yv
EndIf
If enemy\y >= 685
enemy\yv=-enemy\yv
EndIf
If MilliSecs() >= shotsfiredtime + timebetweenbullets
ammo.enemybullet=New enemybullet
ammo\x=enemy\x
ammo\y=enemy\y
resetshotstime = 1
EndIf

;If the shotstime counter should be reset, reset it
If resetshotstime = 1
shotsfiredtime = MilliSecs()
resetshotstime = 0
EndIf
Next
End Function



I believe I do have the shoot function in a FOR EACH NEXT loop under EnemyAI()

Share this post


Link to post
Share on other sites
First, with seedrnd, the millisecs should be in paranthesese. Also, i think you should put the update bullets function afetr the ai function because you are checking for bullets before they are even created. I think that will do it.

Share this post


Link to post
Share on other sites
No that didn't work.... And with SeedRnd it doesn't matter my random velocity functions are working fine. I just need to fix the bullet and the millisec timer. I have one timer working. and that would be the airplane sound timer. It plays the airplane wav file every 3 seconds making it a continuous noise. But thanks for your help.

Share this post


Link to post
Share on other sites
You should go to blitzcoder.com, registering is just like gamedev and they will probably be able to answer your question. because i doubt there is many people here who will be able to answer your question.

Share this post


Link to post
Share on other sites

This topic is 4751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this