A couple of months ago, I worked on a DarkBASIC Project for my Science Fair Project about Artifical Intellgience and once the project was finished I abandoned it temporarily, but have recently begun work on it again.
Its a simple game. The Objective is to kill the opponent by shooting bullets at him. The AI of my game is that the Oppenent will Dodge the Bullets, Shoot back at the player, and over the Wall in the middle of the map.
_______________
| * | This is how my Map is designed (quite simple)
| | | The astericks in there are my nodes, points
| * | * | the map that my AI will travel to if he canno
|_____*________| t see the player. I currently have identified these node points as follows:
#CONSTANT NODEONEX 511.0
#CONSTANT NODEONEY 88.0
#CONSTANT NODETWOX 242.0
#CONSTANT NODETWOY 359.0
#CONSTANT NODETHREEX 805.0
#CONSTANT NODETHREEY 360.0
#CONSTANT NODEFOURX 512.0
#CONSTANT NODEFOURY 689.0
What I am trying to do before I go any further with this project, is clean up my code a little
The way my code works:
#CONSTANT NODEONEX 511.0
#CONSTANT NODEONEY 88.0
#CONSTANT NODETWOX 242.0
#CONSTANT NODETWOY 359.0
#CONSTANT NODETHREEX 805.0
#CONSTANT NODETHREEY 360.0
#CONSTANT NODEFOURX 512.0
#CONSTANT NODEFOURY 689.0
GLOBAL NODEHIT AS INTEGER
GLOBAL Node1 AS INTEGER
GLOBAL Node2 AS INTEGER
GLOBAL Node3 AS INTEGER
GLOBAL Node4 AS INTEGER
GLOBAL Enode1 AS INTEGER
GLOBAL Enode2 AS INTEGER
GLOBAL ENode3 AS INTEGER
GLOBAL ENode4 AS INTEGER
FUNCTION CreateNode(Node1,Node2,Node3,Node4) as INTEGER
Closest as INTEGER
CloseNode as STRING
Node1 = CalcDistance(NODEONEX,NODEONEY, gPlayer(SPR_HERO).X, gPlayer(SPR_HERO).Y)
Node2 = CalcDistance(NODETWOX,NODETWOY, gPlayer(SPR_HERO).X, gPlayer(SPR_HERO).Y)
Node3 = CalcDistance(NODETHREEX,NODETHREEY, gPlayer(SPR_HERO).X, gPlayer(SPR_HERO).Y)
Node4 = CalcDistance(NODEFOURX,NODEFOURY, gPlayer(SPR_HERO).X, gPlayer(SPR_HERO).Y)
Enode1 = CalcDistance(NODEONEX,NODEONEY, gPlayer(SPR_ENEMY).X, gPlayer(SPR_ENEMY).Y)
Enode2 = CalcDistance(NODETWOX,NODETWOY, gPlayer(SPR_ENEMY).X, gPlayer(SPR_ENEMY).Y)
Enode3 = CalcDistance(NODETHREEX,NODETHREEY, gPlayer(SPR_ENEMY).X, gPlayer(SPR_ENEMY).Y)
Enode4 = CalcDistance(NODEFOURX,NODEFOURY, gPlayer(SPR_ENEMY).X, gPlayer(SPR_ENEMY).Y)
`Checking for the Clostest Node to Player
IF Node1 <= Node2 AND Node1 <= Node3 AND Node1 <= Node4 THEN Closest = Node1
IF Node2 <= Node3 AND Node2 <= Node4 AND Node2 <= Node1 THEN Closest = Node2
IF Node3 <= Node4 AND Node3 <= Node1 AND Node3 <= Node2 THEN Closest = Node3
IF Node4 <= Node1 AND Node4 <= Node2 AND Node4 <= Node3 THEN Closest = Node4
IF Node1 <= Node2 AND Node1 <= Node3 AND Node1 <= Node4 THEN CloseNode = "Node1"
IF Node2 <= Node3 AND Node2 <= Node4 AND Node2 <= Node1 THEN CloseNode = "Node2"
IF Node3 <= Node4 AND Node3 <= Node1 AND Node3 <= Node2 THEN CloseNode = "Node3"
IF Node4 <= Node1 AND Node4 <= Node2 AND Node4 <= Node3 THEN CloseNode = "Node4"
LoadMsg("Closest Node Is: " + CloseNode ,-999, -1927)
ENDFUNCTION CloseNode
Is that the AI determines first whether he can see the player or not, then if he cannot, he runs through a check to see which node the player is closest to and if that node is in his Line Of Sight(which is a straight line). He will travel to these nodes until he can see the player again and begin shooting.
I have attached my entire Project to this Post (.rar file) for the entire code is quite long. If anyone can look at my game, I would like to make must more complex maps and need a finer way of adjusting the node positions, and running through the distance calculations. If I find a solution to this problem then I will post it for others to see. Thank You!
Beginning Programmer
Professional Nerd