Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Artificial Intelligience

Author
Message
Mokraton
14
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 23rd Dec 2011 02:33
I am creating a game that is very similar to geometry wars and currently working on simple enemy artificial intelligience.

It's not even really intelligience, but I am trying to create it so that my enemies (which are just circles so far) will follow the user and try to collide into him in order to make him lose a life.

So far I have tried to create a function that will gather the User's current location and then rotate the enemy toward, then it will move the enemy foward based on its rotation, but my enemy still does not move.

In addition to that I am trying to create a loop so that it will randomly generate these enemies into random locations on the map, but not on top of the User. So neither of my codes are working. I am working quite diligiently on this project, but I am always willing to get outside input.

Please have a look at my code snippet and see if you can find the problem with it. I will post what the solution is if I have found it by the time you have read this.

I have compiled my project into a .rar file so you can have a look at it.



Beginning Programmer
Professional Nerd
ZestyPro
14
Years of Service
User Offline
Joined: 27th Aug 2011
Location: The Grid
Posted: 23rd Dec 2011 06:05
try an if then statement that makes sure that the enemies generate away from the user for example



i like cheese pizza. do you like cheese pizza?
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 23rd Dec 2011 07:10
i'm sure there's a better way but what I had a project that generated a random square level with randomised rooms inside it, random spawn location for the player and random spawn locations for enemies. You probably won't need to worry about the variables assosciated with the level creation, but what I did to prevent the enemies spawning too close to the player was define

BlockOccupant(x,y) // you may not need this, but I used it to check if there was already someone/something on this 'block', so as to not spawn multiple items/enemies in the same location

Once you define all of these it gives you enough data to ensure that enemies will spawn in random locations, but will NOT spawn outside of the map, will NOT spawn on the outer edges and allow you specify the minimum boundary margin, and will NOT spawn too close to the player
I then ran through 2 for next loops to check for valid 'blocks' (or units of space) and then make an array of all valid spaces


i=0 // we'll use i to find out how many total blocks are available
dim Temp(LevelWidth,LevelHeight) as boolean // temporarily store valid locations



I'm a bit tired so i'm going to stop writing here and perhaps come back to it later (or someone else can finish it off)
But now you have a boolean array with every valid block marked as 1. What I did was then compress it down into a single array from 0-i (i=how many valid blocks, so if it's 7800 the array will be 7800 values in size)
This array held the X and Y coordinates in a single value, rather than seperate X and Y values. The reason for this is it's easier to find a random location, if I use seperated X and Y values then I need to do 2 rnd calls, X might be valid, but Y might not be. and therefore I have to redo the check and it's very inefficient. When the values are combined you only need to do 1 rnd call and it will always find a valid spot because it's combining X and Y into 1. If that makes sense?

So when I mean by a combined value is if my level is 10x10 then 5,3 becomes 25. Because 1-10 means a Y value of 0, 11-20 Y value of 1, 21-30 Y value of 2 and so on.

So if i'm checking for valid locations then my array might look something like

Valid(1)=2
Valid(2)=3
Valid(3)=7
Valid(4)=8
valid(5)=9
valid(6)=12
Valid(7)=13
valid(8)=17

and so on. so if I call Valid(rnd(8)) it'll find a valid spot. I can then convert the combined value, back in to X and Y coordinates by dividing by the Y height and dropping the remainder
Y = 17/LevelWidth = 1.7 = 1 (drop the remainder)
to find the X coordinate
X = 17-(Y*LevelHeight)=7
so ultimately 17 = 7,1 x,y. That's where I place my unit

Not sure how much sense this has made but hopefully it helps
sovr
16
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 23rd Dec 2011 08:06
I had the same idea in having shape wars a couple years ago, but with 3d shapes... never got to it.

sov the game creator!

Login to post a reply

Server time is: 2026-07-10 00:43:17
Your offset time is: 2026-07-10 00:43:17