private void newGame() { level = 1; money = 0; player = null; newLevelShared(); state = States.Intro; }
public override void die() { state = States.Dead; if (lives >= 0) { // schedule respawning with a copy of this entity if (Game.Instance.Schedule != null) { Game.Instance.Schedule.add(delegate() { PlayerEntity player = new PlayerEntity(this); respawn(player); Game.Instance.Player = player; }, timeToRespawn); int timeToVanish = Config.Instance.getInt("PlayerEntity.timeToVanishDead"); Game.Instance.Schedule.add(delegate() { vanish(); }, timeToVanish); } } else { Game.Instance.endGame(); // end of the game } }
// ----- methods -------------------- // loads map from Config and set player reference public void loadMap() { map = MapPersistence.FromString(Config.Instance[getMapName()]); // set player reference foreach (Entity ent in map) { if ((ent != null) && (ent is PlayerEntity)) { if (player == null) { player = (PlayerEntity)ent; } else { // Set player's coordinates according to map // but retain player object from previous level. // Reset state to Normal. // TODO: think how to do this in a nicer way PlayerEntity p = new PlayerEntity(player); p.Coords = ent.Coords; // can't set ent directly (because of foreach cycle) map.getPlace(ent.Coords).NonWalkable = p; player = p; } break; } } if (onLoadMap != null) { onLoadMap(Game.Instance, new EventArgs()); } }
public PlayerEntity(PlayerEntity p) { state = States.Normal; coords = p.coords; direction = p.direction; health = p.health; maxHealth = p.maxHealth; lives = p.lives; defaultLives = p.defaultLives; timeToRespawn = p.timeToRespawn; attackHitcount = p.attackHitcount; requestedDirection = direction; requestedMovement = false; requestedAttack = false; }
// ----- methods -------------------- public override void giveBonus(PlayerEntity player) { int bonusMoney = Config.Instance.getInt("MoneyBonus.bonusMoney"); Game.Instance.receiveMoney(bonusMoney); vanish(); }
/// <summary> /// Player detects stepping on the bonus himself in his turn and uses /// this function to take it. /// </summary> /// <param name="player"></param> public abstract void giveBonus(PlayerEntity player);
// ----- methods -------------------- public override void giveBonus(PlayerEntity player) { player.Lives += 1; // add 1 life vanish(); }
// ----- methods -------------------- public override void giveBonus(PlayerEntity player) { int changeHealthPercent = Config.Instance.getInt("HealthBonus.changeHealthPercent"); // increase health by given percent player.changeHealth((int)(player.MaxHealth * ((float)changeHealthPercent / 100))); vanish(); }