Simple A.I

BlitzPlus Forums/BlitzPlus Beginners Area/Simple A.I

Siopses(Posted 2006) [#1]
How would I make simple A.I such as making a enemy fight
back, chase after you, etc.


H&K(Posted 2006) [#2]
This is not ment to be glib ok?

Do a search on the Internet for "Game AI"

If you are talking about AI the level of say, the ghosts in packman, then the community can help you. Other than that Im afaid you are on your own

Generaly you check to see how far the player is away, then you generaly make the enemy choose whether to attack or flee.

TAke a look at this
http://www.blitzbasic.com/codearcs/codearcs.php?code=1832#comments
its in B3d and its only AI to path find


Siopses(Posted 2006) [#3]
I didn't search that or anything else, I just want to make an
enemy be able to attack, without actually being attacked.
D'you know what I mean?
For example, in a side-scroller if you ended up in the same area as an enemy have it attack. However, I think I'll be able to work with that for what I'm programming, thanks.


bryan970(Posted 2006) [#4]
copied from the Game Programming for Teens 2nd edition


;demo12-03.bb - Demonstrates chasing algorithms
Graphics 800,600

;Set up backbuffer and automidhandle
SetBuffer BackBuffer()
AutoMidHandle True

;IMAGES
;player and enemies ships
playership = LoadImage ("spaceship.bmp")
enemyship = LoadImage ("enemyship.bmp")

;Load background
backgroundimage = LoadImage ("stars.bmp")


;CONSTANTS
;The following constants are used for testing key presses
Const ESCKEY = 1, UPKEY = 200, LEFTKEY = 203, RIGHTKEY = 205, DOWNKEY = 208

;the following constants define how fast the player and the enemy move
Const PLAYERSPEED = 10
Const ENEMYSPEED = 5

;position player on bottom center of screen
playerx = 400
playery = 400

;positionenemy on upper center of screen
enemyx = 400
enemyy = 200

;set up scrolling variable
scrolly = 0

;MAIN LOOP
While Not KeyDown(ESCKEY)

;tile the background image
TileBlock backgroundimage, 0, scrolly

;move the background up a little
scrolly = scrolly + 1

;If scrolly gets too big, reset it
If scrolly > ImageHeight(backgroundimage)
scrolly = 0
EndIf



;Test the keypresses of the player
;If the player hits up, we move him up
If KeyDown(UPKEY)
playery = playery - PLAYERSPEED
EndIf

;If the player hits left, we move him left
If KeyDown(LEFTKEY)
playerx = playerx - PLAYERSPEED
EndIf

;If player hits right, we move him right
If KeyDown(RIGHTKEY)
playerx = playerx + PLAYERSPEED
EndIf

;If player hits down, we move him down
If KeyDown(DOWNKEY)
playery = playery + PLAYERSPEED
EndIf



;Now, we move the enemy depending on where the player is
;If the player is above the enemy, move the enemy up
If playery > enemyy
enemyy = enemyy + ENEMYSPEED
EndIf

;If the player is to the left of the enemy, move the enemy left
If playerx < enemyx
enemyx = enemyx - ENEMYSPEED
EndIf

;If the player is to the right of the enemy, move the enemy right
If playerx > enemyx
enemyx = enemyx + ENEMYSPEED
EndIf

;if the player is below the enemy, move the enemy down
If playery < enemyy

enemyy = enemyy - ENEMYSPEED
EndIf

;draw the player and enemy on the screen
DrawImage playership, playerx, playery
DrawImage enemyship, enemyx, enemyy


;delay for a bit
Delay 25

;Flip the front and back buffer
Flip

Wend
;END OF MAIN LOOP


Siopses(Posted 2006) [#5]
I'm such an idiot I got that book too! That answers my second question but I still wanna know how to make the enemy fight back. I'm making a side-scrolling fighting game
and I'm not really sure how to make the enemy's fight back.


bryan970(Posted 2006) [#6]
could you define some sort of square or area around your player and when the enemy is within that zone run your attack sequence?

type attack zone
field LeftUpperCorner , RightUpperCorner, ....

or maybe you could make an entirely transparent bitmap that sorrounds your player and use the
imagesoverlap function and when your attackzoneimage collides with your enemyimage go into your attack sequence

just some thoughts


Siopses(Posted 2006) [#7]
Thanks, I think that'll be just fine for what I had in mind. Also
do you know why Blitz Plus saves as blitz basic? I just got Blitz Plus for Chirstmas and (obviously) the cd hasen't arrived
yet but I got the online $60 full version (not the demo). Is this because I haven't got the cd mumbo jumbo in my pc?


Qube(Posted 2006) [#8]

do you know why Blitz Plus saves as blitz basic?



Both BlitzPlus and Blitz3D save with the file extension .bb


Siopses(Posted 2006) [#9]
I know that, but when I access the file the code turns up in
blitz basic. I don't even own blitz basic, I just got rid of the demo that I was using before I got the blitz plus file saved.
Even after I did that the code still came up with Blitz Basic.


b32(Posted 2006) [#10]
It might be that BlitzBasic is still installed. To change the file associations, in the Windows Explorer, go to Tools->Folder Options and choose the "file types" tab.
Or shift+right-click a .bb file, choose "open with", then choose "select program", select b+ and check the box that says "allways open this type of file with this program".
support.microsoft.com/kb/307859


H&K(Posted 2006) [#11]
Download this (Its a better IDE for BPlus)
http://proteanide.whispertablet.co.uk/final/ProteanFinal.exe

could you define some sort of square or area around your player and when the enemy is within that zone run your attack sequence?
lol. Thats just another way of saying
see how far the player is away, then you generaly make the enemy choose whether to attack


The general rule for side scrollers, is "If you have to draw it on the screen, its attacking the player. Or it never attacks the player"


Siopses(Posted 2006) [#12]
I solved the Blitz Basic problem. Thanks, well that just about
solves everything I wanted to know. By the way b32, send
me more of the code for your 'skittish mouse controller question' and I'll take a look at it for you sometime next week. If i'm lucky I might even solve your problem. :)
Siopses out


b32(Posted 2006) [#13]
Thanks Siopses, but that is Bryan970. My problems involve a deadline and a lack of inspiration. Working with deadlines doesn't work around the holidays I guess. He, thanks for the offer and happy newyear!


Siopses(Posted 2006) [#14]
Yeah you to, sorry for the misconception. Happy Holidays


bryan970(Posted 2007) [#15]
I think I got my mouse cursor problem worked out, thanks though