public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null || sprite2 == null) { throw new ArgumentException("Neither the 1st nor 2nd sprite can be EOS with BounceForward interaction."); } Vector2 dir = sprite2.lastDirection(); dir.Normalize(); if (sprite2.lastDirection().x *sprite2.orientation.x < 0) { dir.x *= -1; } if (sprite2.lastDirection().y *sprite2.orientation.y < 0) { dir.y *= -1; } sprite1.physics.activeMovement(sprite1, new Vector2(dir.x, dir.y), sprite2.speed); sprite1.orientation = new Vector2(dir.x, dir.y); }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null || sprite2 == null) { throw new ArgumentException("Neither the 1st nor 2nd sprite can be EOS with KillIfFrontal interaction."); } //Kills the sprite, only if they are going in opposite directions or sprite1 is static. var firstV = sprite1.lastDirection(); var otherV = sprite2.lastDirection(); firstV.Normalize(); otherV.Normalize(); //If the sum of the two vectors (normalized) is (0.0), directions are opposite. var sumDir = new Vector2(firstV.x + otherV.x, firstV.y + otherV.y); var firstDir = new Vector2(firstV.x, firstV.y); applyScore = false; if (firstDir.Equals(VGDLUtils.VGDLDirections.NONE.getDirection()) || (sumDir.Equals(VGDLUtils.VGDLDirections.NONE.getDirection()))) { applyScore = true; //boolean variable set to false to indicate the sprite was not transformed game.killSprite(sprite1, false); } }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null || sprite2 == null) { throw new ArgumentException("Neither the 1st nor 2nd sprite can be EOS with PullWithIt interaction."); } //Keep in the list, for the current cycle, the sprites that have triggered this event. var currentGameTime = game.getGameTick(); if (currentGameTime > lastGameTime) { spritesThisCycle.Clear(); lastGameTime = currentGameTime; } //the event gets triggered only once per time-step on each sprite. if (spritesThisCycle.Contains(sprite1)) { return; } spritesThisCycle.Add(sprite1); //And go on. var r = sprite1.lastrect; var v = sprite2.lastDirection(); v.Normalize(); var gridsize = 1f; if (sprite1.physicstype.CompareAndIgnoreCase(VGDLPhysics.GRID)) { GridPhysics gp = (GridPhysics)(sprite1.physics); gridsize = gp.gridSize.x; } else { ContinuousPhysics gp = (ContinuousPhysics)(sprite1.physics); gridsize = gp.gridSize.x; } sprite1.updatePos(new Vector2(v.x, v.y), (int)(sprite2.speed * gridsize)); if (sprite1.physicstype.CompareAndIgnoreCase(VGDLPhysics.GRID)) { sprite1.rect.y = sprite2.rect.y - sprite2.rect.height; sprite1.orientation = new Vector2(sprite1.orientation.x, 0.0f); } sprite1.lastrect = new Rect(r); if (pixelPerfect) { sprite1.rect = new Rect(sprite2.rect); } }