Recent posts by the_taken on Kongregate

Subscribe to Recent posts by the_taken on Kongregate

avatar for the_taken the_taken 3 posts
Flag Post

Topic: Tyrant / Post Active Raid Links Here

Started up the Siege on Kor. http://www.kongregate.com/games/synapticon/tyrant?kv_joinraid=195428

Bring your Catapults! Tell all your friends!

 
avatar for the_taken the_taken 3 posts
Flag Post

Topic: Tyrant / Mission 66 made easy

Rally Flags are uncommon, which means you have to buy Silver Packs to get them. Still not terribly expensive…

 
avatar for the_taken the_taken 3 posts
Flag Post

Topic: Game Programming / Shootutorial Z -> seeking missiles and enemies

Some people performing the shooturials and playing some of the scion entries may be wondering how to get missiles (and enemies) to try a little harder to get at the player. I present for the curious my solution. It’s not perfect, as you may have noticed by playing my game: http://www.kongregate.com/games/the_taken/eternal-earth

The first step is setting up targeting information. The seeker needs to know it’s destination coordinates. For the enemies, that’s easy – there’s only one valid target. But if it’s a seeking missile, you have to be able to have the missile pick a target for the enemies array.

Make sure that the seeker points to the right in the .FLA

Create a function in the seeker’s class. I called it setRotation(). When called, this will point the seeker towards it’s target. Add the following code:
{
var desiredY:Number = root.ship.y-this.y;
var desiredX:Number = _root.ship.
x-this._x;
var desRot:Number = 180/Math.PI * Math.atan2(desiredY, desiredX);
if( _rotation > desRot) {
_rotation -= agility;
} esle if( _ rotation < desRot) {
_rotation += agility;
}
}
Agility is a variable that I have defined individually for each enemy type. The higher the number, the faster seeker points towards it’s target.
In the onEnterFrame() function, replace whatever movement code you were using with this:

x += Math.cos(rotation * Math.PI/180) * speed;
y += Math.sin(rotation * Math.PI/180) * speed;
setRotation();

Now the enemy will move a little, then point more towards the player.
Be warned that there is a tiny cone behind the seeker. If the target is within this cone, the seeker will zig-zag away form the target. If you’re making a side scroller, the enemy may (likely) spawn with the player in this cone and run away. To compensate, in the enemy’s onLoad function add “_rotation = 180;” to spin ‘em around. For vertical scrollers “_rotation = 90;” to point ’em strait down.
To make bullets aim at the player, you simply recycle the movement code the enemy uses sans “setRotaion();” When the enemy fire the bullets, simply assign the new bullet’s rotation to equal the firer’s (missile.rotation = this._rotation;)

For the player’s missiles, it gets really complicated.
First, we need to have the the enemies:Array have a set length. In the ship class, replace in the onLoad function “enemies = [];” to “enemies = new Array(20);” This will make the enemies:Array a set length an allow us to keep better track of the things in it. Replace the whole enemy spawning code with the following if statement within for…loop:
for (var i = enemies.length-1; i > 0; i—) {
if (enemies[i] == undefined) {
enemies[i] = root.attachMovie("enemy"+enemyData0, "enemy"+i, _root.getNextHighestDepth());
enemies[i].
x = 650;
enemies[i]._y = Math.random() * 250 + 25;
enemies[i].moi = i;
break;
}
}

Add a moi variable to the enemy class, then in explode() function add “delete _root.ship.enemies[moi];” just before “this.removeMovieClip();”
This will set the pointer in the enemies:Array to “undefined” instead of nothing (which isn’t the same), which is what would have happened if removeMovieClip() was called. You can have you code look for “undefined” or “null”, but not nothing.

In the missile class define a variable called “targetLock”, and add the following code to the beginning of the setRotation() function:
{
if( _root.ship.enemies[targetLock] = undefined)
for (var i in _root.ship.enemies) {
targetLock = i;
break;
}
}

and replace the “ship” in the rest of the function with “ship.enemies[targetLock]” to look like this:

var desiredY:Number = root.ship.enemies[targetLock].y – this.y;
var desiredX:Number = _root.ship.enemies[targetLock].
x – this._x;
var desRot:Number = 180/Math.PI * Math.atan2(desiredY, desiredX);
if( _rotation > desRot) {
_rotation -= agility;
} esle if( _ rotation < desRot) {
_rotation += agility;
}
}

Congratulations! You now have seeker missiles and/or enemies. If you’re making a vertical scroller, be sure to set the missiles _rotation to -90 or they’ll be pointing to the right when they spawn.