Skip to content

Instantly share code, notes, and snippets.

@Aaeeschylus
Created November 3, 2015 00:40
Show Gist options
  • Save Aaeeschylus/ae84ae75ffe432b41e03 to your computer and use it in GitHub Desktop.
Save Aaeeschylus/ae84ae75ffe432b41e03 to your computer and use it in GitHub Desktop.
//In the enemy class:
var totalTime = 0;
NormEnemy.prototype.update = function(deltaTime)
{
totalTime = totalTime + deltaTime;
var mathsSin = (100*(Math.sin(totalTime*3)));
if (this.ZigZagMovement == true)
{
this.position.x = this.zigZagMean + mathsSin;
this.position.y += 1;
}
}
//The spawning of the enemy:
function NenemySpawnZigZag(zigZagPosition)
{
var NZZenemy = new NormEnemy ();
NZZenemy.zigZagMean = zigZagPosition;
NZZenemy.position.set(zigZagPosition, 10);
NZZenemy.ZigZagMovement = true;
enemies.push(NZZenemy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment