The coin class is pretty simple, i’m just using it to test at the moment, code here:
package entities
{
import net.flashpunk.Entity;
import net.flashpunk.graphics.Spritemap;
/**
* ...
* @author Gil
*/
public class Coin extends Entity
{
[Embed(source = "../../assets/gfx/Coin.png")]
public var ART_COIN:Class;
public var coinSprite:Spritemap = new Spritemap(ART_COIN, 16, 16);
public function Coin()
{
coinSprite.add("Spin", [0, 1, 2, 3, 4, 5, 6, 7, 8], 18, true);
graphic = coinSprite;
}
override public function added():void
{
super.added();
coinSprite.play("Spin");
}
override public function update():void
{
super.update();
}
}
}
The coin is actually supposed to be added to the player and it’s destroy function:
package entities
{
import net.flashpunk.Entity;
import net.flashpunk.graphics.Image;
import net.flashpunk.Graphic;
import net.flashpunk.Mask;
import net.flashpunk.FP;
import entities.hudRed;
import Variables;
import entities.redEnemy;
import entities.redEnemyStackable;
import entities.Coin;
/**
* ...Player's red square
* @author Gil
*/
public class RedSquare extends DraggableEntity
{
[Embed(source = "../../assets/gfx/Red.png")]
public var ART_RED:Class;
public var redImage:Image;
public var deathTime:Number = 0;
public function RedSquare(x:Number=0, y:Number=0, mask:Mask = null)
{
redImage = new Image(ART_RED)
super(x, y, redImage);
if (!mask) setHitboxTo(redImage);
redImage.centerOrigin();
centerOrigin();
type = "Obstacle"
}
override public function added():void
{
super.added();
x = hudRed.hudRedDrag.x;
y = hudRed.hudRedDrag.y;
draggable = true;
isDragging = true;
onStartDrag();
FP.world.add(hor);
FP.world.add(ver);
}
override public function update():void
{
super.update();
// force it to remain inside left half of the screen (taking origin into account)
if (isDragging)
{
FP.clampInRect(this, -384 - originX , 0 + originY, FP.width + width, FP.height + height);
FP.clampInRect(this, 224 + originX , 0 + originY, FP.width - width, FP.height - height);
}
}
override public function onStartDrag():void
{
super.onStartDrag();
redEnemyStackable.redSqStackSet = false;
redEnemy.redSqSet = false;
}
override public function onEndDrag():void
{
super.onEndDrag();
redEnemyStackable.redSqStackSet = true;
redEnemy.redSqSet = true;
}
public function destroy():void //Is activated via collision with enemy.
{
var coin1:Entity = new Coin;
if (!isDragging && !draggable) //Entity must be set and placed before deletion occurs.
{
FP.world.add(coin1); //Coin is added before Entity is destroyed but at (0, 0) by default.
FP.world.remove(this); //If Entity is set and placed, deletion successful.
}
}
}
}