public override void Update(GameTime gameTime, TeeEngine engine) { Hero player = (Hero) engine.GetEntity("Player"); KeyboardState keyboardState = Keyboard.GetState(); if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.S, this, true) && Entity.IntersectsWith(this, null, player, "Shadow", gameTime)) { if (CurrentDrawableState != "Open") { Random random = new Random(); CurrentDrawableState = "Open"; Drawables.ResetState("Open", gameTime); for (int i = 0; i < 10; i++) { Coin coin = new Coin(this.Pos.X, this.Pos.Y, 100, (CoinType)random.Next(3)); coin.Pos.X += (float) ((random.NextDouble() - 0.5) * 100); coin.Pos.Y += (float) ((random.NextDouble() - 0.5) * 100); engine.AddEntity(coin); } } } }
public override void Update(GameTime gameTime, TeeEngine engine) { Hero player = (Hero) engine.GetEntity("Player"); KeyboardState keyboardState = Keyboard.GetState(); if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.S, this, true) && Entity.IntersectsWith(this, "interaction", player, "Shadow", gameTime)) { if (CurrentDrawableState != "Open") { Random random = new Random(); _openSfx[random.Next(1)].Play(); CurrentDrawableState = "Open"; Drawables.ResetState("Open", gameTime); for (int i = 0; i < 10; i++) { Coin coin = new Coin(this.Pos.X, this.Pos.Y, 100, (CoinType)random.Next(3)); coin.Pos.X += (float) ((random.NextDouble() - 0.5) * 100); coin.Pos.Y += (float) ((random.NextDouble() - 0.5) * 100); coin.TerrainCollisionEnabled = false; // Prevent from getting stuck in sorrounding walls. engine.AddEntity(coin); } } } base.Update(gameTime, engine); }
public virtual void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs) { if (mapEventArgs.HasProperty("Target")) { Hero player = new Hero(); MapEntrance targetEntrance = (MapEntrance)engine.GetEntity(mapEventArgs.GetProperty("Target")); player.Pos = targetEntrance.Pos + new Vector2(targetEntrance.Width, targetEntrance.Height) / 2; engine.AddEntity("Player", player); } }
public override void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs) { LightShader lightShader = (LightShader)engine.GetPostGameShader("LightShader"); lightShader.Enabled = false; Random random = new Random(); for (int i = 0; i < 50; i++) { int px = (int)Math.Ceiling(random.NextDouble() * engine.Map.pxWidth); int py = (int)Math.Ceiling(random.NextDouble() * engine.Map.pxHeight); Bat bat = new Bat(px, py); Coin coin = new Coin(px, py, 100, (CoinType)random.Next(3)); // Switch between adding bats and coins to the map. if (i % 2 == 0) engine.AddEntity(bat); else engine.AddEntity(coin); } base.MapLoaded(engine, map, mapEventArgs); }
public override bool PreCreate(GameTime gameTime, TeeEngine engine) { int coinx = (Width / CoinPadding); int coiny = (Height / CoinPadding); for (int i = 0; i < coinx; i++) { for (int j = 0; j < coiny; j++) { Coin coin = new Coin(); coin.CoinType = CoinType; coin.CoinValue = CoinValue; coin.Pos = new Vector2(Pos.X + i * CoinPadding, Pos.Y + j * CoinPadding); engine.AddEntity(coin); } } return false; // Destory self when ready. }
public override void PostCreate(GameTime gameTime, TeeEngine engine) { engine.AddEntity(LightSource); }
private void NPC_Interact(RPGEntity sender, Entity invoker, GameTime gameTime, TeeEngine engine) { SpeechBubble speech = new SpeechBubble(this, "Hello there Adventurer! Whats you're name?"); engine.AddEntity(speech); Vector2 distance = this.Pos - invoker.Pos; if (distance.X > distance.Y) Direction = (distance.X > 0) ? Direction.Left : Direction.Right; else Direction = (distance.Y > 0) ? Direction.Up : Direction.Down; }
/// <summary> /// Rewards the NPC with XP based on the level of the Mob killed. /// </summary> /// <param name="mobLevel">The level of the mob that is awarding XP.</param> public void RewardXP(Entity sender, int mobLevel, GameTime gameTime, TeeEngine engine) { int xpGiven; if (mobLevel == Level) { xpGiven = (Level * 5) + 45; } else if (mobLevel < Level) { xpGiven = ((Level * 5) + 45) * (1 - (Level - mobLevel) / 5); } else // mobLevel > Level { xpGiven = ((Level * 5) + 45) * (int)(1 + 0.05 * (mobLevel - Level)); } XP += xpGiven; // Check for lvl up condition if (XP >= XPToNextLevel) { LevelUp(); } StatusText text = new StatusText(String.Format("+{0} XP", xpGiven), Color.Yellow, new Vector2(Pos.X, Pos.Y - CurrentBoundingBox.Height), Direction.Up); engine.AddEntity(text); }
/// <summary> /// Method called when the NPC has been hit by some Entity residing within the /// game engine. Override this method in order to perform custom functionality /// during a Hit event. /// </summary> public virtual void OnHit(Entity sender, int damage, GameTime gameTime, TeeEngine engine) { if (HP <= 0) return; HP -= damage; StatusText text; if(sender is Hero) text = new StatusText(String.Format("-{0}", damage), Color.OrangeRed, new Vector2(Pos.X, Pos.Y - CurrentBoundingBox.Height), Direction.Up); else text = new StatusText(String.Format("-{0}", damage), Color.Maroon, new Vector2(Pos.X, Pos.Y + 15), Direction.Down); engine.AddEntity(text); }