public override void Update(float deltaTime) { if (level.vars.protoEntity != null) { PositionComponent posComp = ( PositionComponent )level.vars.protoEntity.getComponent(GlobalVars.POSITION_COMPONENT_NAME); PointF p; if (level.vars.gridLock) { p = getGridPoint(level.getInputSystem().mouseX, level.getInputSystem().mouseY); } else { p = new PointF(level.getInputSystem().mouseX, level.getInputSystem().mouseY); } level.getMovementSystem().changePosition(posComp, p.X, p.Y, false, false); } }
public void createEntityFromProto() { if (level.vars.protoEntity.myEntType == typeof(Player) && level.getPlayer() != null) { Console.WriteLine("Trying to add a second player. That's a bad idea."); return; } Entity e = ( Entity )Activator.CreateInstance(level.vars.protoEntity.myEntType, level, 0, 0); if (e.getComponent(GlobalVars.POSITION_COMPONENT_NAME) != null) { PositionComponent newPosComp = ( PositionComponent )e.getComponent(GlobalVars.POSITION_COMPONENT_NAME); PositionComponent protoPosComp = ( PositionComponent )level.vars.protoEntity.getComponent(GlobalVars.POSITION_COMPONENT_NAME); e.isStartingEntity = true; level.getMovementSystem().changePosition(newPosComp, protoPosComp.x, protoPosComp.y, false, false); if (e is BasicGround) { BasicGround ground = ( BasicGround )e; //If no ground above it, change to a grass sprite List <Entity> above = level.getCollisionSystem().findObjectAtPoint(newPosComp.x, (newPosComp.y - newPosComp.height / 2 - 1)); if (above.Count <= 0 || !(above[0] is BasicGround)) { ground.changeSprite(false); } //If ground below it, make dirt List <Entity> below = level.getCollisionSystem().findObjectAtPoint(newPosComp.x, (newPosComp.y + newPosComp.height / 2 + 1)); if (below.Count > 0 && (below[0] is BasicGround)) { BasicGround ground2 = ( BasicGround )below[0]; ground2.changeSprite(true); } } } level.addEntity(e.randId, e); removeProtoEntity(); selectEntity(e); }