protected void movesToward(VGDLSprite target) { double distance = physics.distance(rect, target.rect); if (maxDistance >= 0 && distance > maxDistance) { //We have a maximum distance set up, and the target is further than that. // -> We don't react to this target. return; } foreach (var act in VGDLUtils.BASEDIRS) { //Calculate the distance if I'd apply this move. var r = new Rect(rect); r = r.translate(act.x, act.y); var newDist = physics.distance(r, target.rect); //depending on getting me closer/farther, if I'm fleeing/chasing, add move: if (fleeing && distance < newDist) { actions.Add(act); } if (!fleeing && distance > newDist) { actions.Add(act); } } }
public override VGDLMovementTypes passiveMovement(VGDLSprite sprite) { if (sprite.isFirstTick) { sprite.isFirstTick = false; return(VGDLMovementTypes.STILL); } //This needs to be thoroughly tested when continuous physics are added //Specially the returned type. if (sprite.speed != 0) { sprite.updatePos(sprite.orientation, (int)sprite.speed); if (sprite.gravity > 0 && sprite.mass > 0 && !sprite.on_ground) { Vector2 gravityAction = new Vector2(0, sprite.gravity * sprite.mass); activeMovement(sprite, gravityAction, 0); } sprite.speed *= (1 - sprite.friction); return(VGDLMovementTypes.MOVE); } return(VGDLMovementTypes.STILL); }
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); }
/** * Updates the persistent observation of this sprite, or creates it if the * observation is new. * @param sprite sprite to take the observation from. */ private void updateObservation(VGDLSprite sprite) { var spriteId = sprite.spriteID; bool moved = false, newObs = false; var oldPosition = Vector2.negativeInfinity; Observation obs = null; var success = observations.TryGetValue(spriteId, out obs); if (success && obs != null) { oldPosition = obs.position; var position = sprite.getPosition(); moved = !obs.position.Equals(position); obs.position = position; } else { obs = createSpriteObservation(sprite); newObs = true; } updateGrid(obs, newObs, moved, oldPosition); }
/** * Determines if the collision is horizontal and/or vertical * @param sprite1 Sprite colliding * @param s2rect Collision colliding against. * @param g game * @return An array indicating if the collision is []{horizontal, vertical}. */ protected bool[] determineCollision(VGDLSprite sprite1, Rect s2rect, VGDLGame g) { var intersec = sprite1.rect.intersection(s2rect); var horizontalBounce = (sprite1.rect.height == intersec.height); var verticalBounce = (sprite1.rect.width == intersec.width); if (!horizontalBounce && !verticalBounce) { Vector2 vel = sprite1.getVelocity(); //Distance on X, according to the direction of travel var distX = (vel.x == 0.0f) ? Mathf.Abs(sprite1.lastrect.x - s2rect.x) : //Travelling vertically ((vel.x > 0.0f) ? Mathf.Abs((sprite1.lastrect.x + sprite1.rect.width) - s2rect.x) : //Going right Mathf.Abs((s2rect.x + s2rect.width) - sprite1.lastrect.x)); //Going left //Distance on Y, according to the direction of travel var distY = (vel.y == 0.0f) ? Mathf.Abs(sprite1.lastrect.y - s2rect.y) : //Travelling laterally ((vel.y > 0.0f) ? Mathf.Abs((sprite1.lastrect.y + sprite1.rect.height) - s2rect.y) : //Going downwards Mathf.Abs(sprite1.lastrect.y - (s2rect.y + s2rect.height))); //Going upwards var tX = Mathf.Abs(distX / vel.x); var tY = Mathf.Abs(distY / vel.y); horizontalBounce = (tX < tY); verticalBounce = (tY < tX); } return(new[] { horizontalBounce, verticalBounce }); }
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 TransformToSingleton interaction."); } //First, transform all sprites in the game to the stype_other type. // (in theory, there should be only 1 or none). var sprites = game.getSprites(stype); foreach (var sprite in sprites) { var otherSprite = game.addSprite(stype_other, sprite.getPosition()); if (otherSprite != null) { setSpriteFields(game, otherSprite, sprite); } } //Now, make the transformTo normal operation. var newSprite = game.addSprite(stype, sprite1.getPosition()); if (newSprite != null) { setSpriteFields(game, newSprite, sprite1); if (takeOrientation) { var orientation = new Vector2(-sprite2.orientation.x, -sprite2.orientation.y); newSprite.is_oriented = true; newSprite.orientation = orientation; } } }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null) { throw new ArgumentException("1st sprite can't be EOS with AddHealthPoints interaction."); } applyScore = false; if (sprite1.healthPoints + value < sprite1.limitHealthPoints) { sprite1.healthPoints += value; if (sprite1.healthPoints > sprite1.maxHealthPoints) { sprite1.maxHealthPoints = sprite1.healthPoints; } applyScore = true; if (killSecond && sprite2 != null) { //boolean variable set to false to indicate the sprite was not transformed game.killSprite(sprite2, false); } } }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite2 == null) { throw new ArgumentException("1st sprite can't be EOS with SpawnBehind interaction."); } if (Random.value >= prob) { return; } var currentPos = Vector2.negativeInfinity; if (stepBack) { currentPos = sprite2.getLastPosition(); } else { currentPos = sprite2.getPosition(); } var dir = new Vector2(-1, 0) * game.block_size; if (currentPos != Vector2.negativeInfinity) { Vector2 nextPos = currentPos + dir; game.addSprite(stype, nextPos); } }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { var timeEffect = new VGDLTimeEffect(this); timeEffect.planExecution(game); game.addTimeEffect(timeEffect); }
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 TransformIfCount interaction."); } var numSpritesCheck = game.getNumberOfSprites(stypeCount); applyScore = false; count = false; countElse = false; if (numSpritesCheck <= leq && numSpritesCheck >= geq) { var newSprite = game.addSprite(stype, sprite1.getPosition(), true); doTransformTo(newSprite, sprite1, sprite2, game); applyScore = true; count = true; } else if (!string.IsNullOrEmpty(estype)) { var newSprite = game.addSprite(estype, sprite1.getPosition(), true); doTransformTo(newSprite, sprite1, sprite2, game); countElse = true; } }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null || sprite2 == null) { throw new ArgumentException("Neither 1st not 2nd sprite can be EOS with AttractGaze interaction."); } if (sprite1.is_oriented && sprite2.is_oriented) { if (Random.value < prob) { sprite1.orientation = sprite2.orientation; if (align) { if (sprite1.orientation.Equals(VGDLUtils.VGDLDirections.LEFT.getDirection()) || sprite1.orientation.Equals(VGDLUtils.VGDLDirections.RIGHT.getDirection())) { //Need to align on the Y coordinate. sprite1.rect = new Rect(sprite1.rect.x, sprite2.rect.y, sprite1.rect.width, sprite1.rect.height); } else { //Need to align on the X coordinate. sprite1.rect = new Rect(sprite2.rect.x, sprite1.rect.y, sprite1.rect.width, sprite1.rect.height); } } } } }
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 CollectResourceIfHeld interaction."); } if (sprite1.is_resource) { var r = (Resource)sprite1; applyScore = false; //Check if we have the secondary resource first var numResourcesHeld = sprite2.getAmountResource(heldResource); if (numResourcesHeld < value) { return; } var numResources = sprite2.getAmountResource(r.resource_name); if (numResources + r.value <= game.getResourceLimit(r.resource_name)) { applyScore = true; sprite2.modifyResource(r.resource_name, r.value); } if (killResource) { //boolean variable set to false to indicate the sprite was not transformed game.killSprite(sprite1, false); } } }
public override VGDLMovementTypes activeMovement(VGDLSprite sprite, Vector2 action, float speed = -1) { if (!sprite.stationary) { if (speed == 0) { if (sprite.speed <= 0) { speed = 1; } else { speed = sprite.speed; } } if (speed != 0 && !action.Equals(Vector2.negativeInfinity) && !(action.Equals(Vector2.zero))) { if (sprite.rotateInPlace) { bool change = sprite.updateOrientation(action); if (change) { return(VGDLMovementTypes.ROTATE); } } if (sprite.updatePos(action, (int)(speed * gridSize.x))) { return(VGDLMovementTypes.MOVE); } } } return(VGDLMovementTypes.STILL); }
protected Rect calculatePixelPerfect(VGDLSprite sprite1, VGDLSprite sprite2) { var spriteVector = new Vector2(sprite1.rect.center.x - sprite1.lastrect.center.x, sprite1.rect.center.y - sprite1.lastrect.center.y); spriteVector.Normalize(); if (spriteVector.Equals(VGDLUtils.VGDLDirections.DOWN.getDirection())) { return(adjustDown(sprite1, sprite2)); } else if (spriteVector.Equals(VGDLUtils.VGDLDirections.RIGHT.getDirection())) { return(adjustRight(sprite1, sprite2)); } else if (spriteVector.Equals(VGDLUtils.VGDLDirections.UP.getDirection())) { return(adjustUp(sprite1, sprite2)); } else if (spriteVector.Equals(VGDLUtils.VGDLDirections.LEFT.getDirection())) { return(adjustLeft(sprite1, sprite2)); } return(sprite1.lastrect); }
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 1st not 2nd sprite can be EOS with KillIfSlow interaction."); } var relspeed = 0.0f; if (sprite1.is_static) { relspeed = sprite2.speed; } else if (sprite2.is_static) { relspeed = sprite1.speed; } else { var vvx = sprite1.orientation.x - sprite2.orientation.x; var vvy = sprite1.orientation.y - sprite2.orientation.y; var vv = new Vector2(vvx, vvy); relspeed = vv.magnitude; } if (relspeed < limspeed) { game.killSprite(sprite1, false); } }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null) { throw new ArgumentException("1st sprite can't be EOS with WrapAround interaction."); } if (sprite1.orientation.x > 0) { sprite1.rect.x = (int)(offset * sprite1.rect.width); } else if (sprite1.orientation.x < 0) { sprite1.rect.x = (int)(game.screenSize.x - sprite1.rect.width * (1 + offset)); } else if (sprite1.orientation.y > 0) { sprite1.rect.y = (int)(offset * sprite1.rect.height); } else if (sprite1.orientation.y < 0) { sprite1.rect.y = (int)(game.screenSize.y - sprite1.rect.height * (1 + offset)); } sprite1.lastmove = 0; }
private void doReverse(VGDLSprite sprite1, Rect s2rect, VGDLGame g) { var collisions = determineCollision(sprite1, s2rect, g); var horizontalBounce = collisions[0]; var verticalBounce = collisions[1]; Vector2 v; if (verticalBounce) { v = new Vector2(sprite1.orientation.x, 0); } else if (horizontalBounce) { v = new Vector2(-sprite1.orientation.x, 0); } else { //By default: v = new Vector2(-sprite1.orientation.x, 0); } var mag = v.magnitude; v.Normalize(); sprite1.orientation = new Vector2(v.x, v.y); sprite1.speed = sprite1.speed * mag; if (sprite1.speed < sprite1.gravity) { sprite1.speed = sprite1.gravity; } }
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 CollectResource interaction."); } if (!sprite1.is_resource) { return; } var r = (Resource)sprite1; applyScore = false; var numResources = sprite2.getAmountResource(r.resource_name); if (numResources >= game.getResourceLimit(r.resource_name)) { return; } var topup = Mathf.Min(r.value, game.getResourceLimit(r.resource_name) - numResources); applyScore = true; sprite2.modifyResource(r.resource_name, topup); if (killResource) { //boolean variable set to false to indicate the sprite was not transformed game.killSprite(sprite1, true); } }
public override VGDLMovementTypes passiveMovement(VGDLSprite sprite) { if (sprite.isFirstTick) { sprite.isFirstTick = false; return(VGDLMovementTypes.STILL); } var speed = 1f; if (sprite.speed != -1) { speed = sprite.speed; } if (speed != 0 && sprite.is_oriented) { if (sprite.updatePos(sprite.orientation, (int)(speed * gridSize.x))) { return(VGDLMovementTypes.MOVE); } } return(VGDLMovementTypes.STILL); }
/** * Creates the sprite observation of a given sprite. * @param sprite sprite to create the observation from. * @return the observation object. */ private Observation createSpriteObservation(VGDLSprite sprite) { var category = getSpriteCategory(sprite); Observation obs = new Observation(sprite.getType(), sprite.spriteID, sprite.getPosition(), VGDLUtils.VGDLDirections.NIL.getDirection(), category); observations.Add(sprite.spriteID, obs); return(obs); }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { effectDelegate.execute(sprite1, sprite2, game); if (repeating) { planExecution(game); } }
private Rect adjustDown(VGDLSprite sprite1, VGDLSprite sprite2) { //Sprite DOWN adjusts for overlap. var overlay = (sprite1.rect.y + sprite1.rect.height) - sprite2.rect.y; return(new Rect(sprite1.rect.x, sprite1.rect.y - overlay, sprite1.rect.width, sprite1.rect.height)); }
private Rect adjustRight(VGDLSprite sprite1, VGDLSprite sprite2) { //Sprite RIGHT adjusts for overlap. var overlay = (sprite1.rect.x + sprite1.rect.width) - sprite2.rect.x; return(new Rect(sprite1.rect.x - overlay, sprite1.rect.y, sprite1.rect.width, sprite1.rect.height)); }
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); } }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { var current_rotation = ((sprite1.rotation + 2f * Math.PI) % (2f * Mathf.PI)); if (!(current_rotation < 5.0f && current_rotation > 4.4f)) { game.killSprite(sprite1, false); } }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null) { throw new ArgumentException("1st sprite can't be EOS with flipDirection interaction"); } sprite1.orientation = VGDLUtils.RandomCardinalDirection(); }
public PathAltChaser(PathAltChaser from) : base(from) { //Insert fields to be copied by copy constructor. randomTarget = from.randomTarget; lastKnownTargetPosition = from.lastKnownTargetPosition; //NOTE: shouldn't this reference be updated from spriteID instead? lastTarget = from.lastTarget; }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null) { throw new ArgumentException("1st sprite can't be EOS with HalfSpeed interaction."); } sprite1.speed *= 0.5f; }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null) { throw new ArgumentException("1st sprite can't be EOS with shieldFrom interaction."); } game.addShield(sprite1.getType(), stype, ftype.GetHashCode()); }