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 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 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 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); }