View Full Version : Ant Game
ryanflair
May 24th, 2004, 02:45 PM
Along with the fighting game I am working on a tile based top down game where your character has to squash and use items to kill a certain number of ants, and you can lose by the ants reaching your counter where the food is ( there would be a food meter) I have the world created ( code as well) also i have the code for my character and his movement, I have hit a road block though for the code for my ants I want them to be motivated to move towards the food ( a certain tile) and there only to be a certain number of ants to be on the stage at a given time. so ants would be removed from the stage when they were killed or when they reach the food. any help would be appreciated.
Blackspirit
May 25th, 2004, 08:38 AM
heya,
I'm doing a warfare type engine with stickmen, so kind of behave like ants, I've got some behaviors where they flee and where they go to a point, they've got a range of vision etc.
My starting point would be the beetle examples in flash, it calculates how many degrees they're are between it an the mouse pointer and the moves towards it. This could be used for your food thing. Goes something like this:
delta_x = _x-gotoSpotX;
delta_y = _y-gotoSpotY;
targetRotation = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>speed) {
_y -= speed*Math.cos(_rotation*(Math.PI/180));
_x += speed*Math.sin(_rotation*(Math.PI/180));
}
Youd need a variable to count the ants use you create them like this:
if (stickmanNum<5){
newStickMan = stickman_mc.duplicateMovieClip("stickman"+i, i);
stickmanNum++
}
And then maybe a variable in each instance of the ant that says weather its dead or has found food:
if (stickmanNum<5){
newStickMan = stickman_mc.duplicateMovieClip("stickman"+i, i);
stickmanDead=false <--this line
stickmanNum++
}
then youd just test for this var whenever you want, and if its dead, or found food, remove the movieclip.
Hope it helps
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.