public void Update(GameTime gameTime, RunNJumpMap game_map, string GameState) { if (GameState == "Playing") { //Update the player's ninja based on input if (Keyboard.GetState().IsKeyDown(Keys.Space) && PrevKeyboardState.IsKeyUp(Keys.Space) || GamePad.GetState(Player_Index).IsButtonDown(Buttons.A) && PrevGamepadState.IsButtonUp(Buttons.A)) _ninja.Jump(); if (PrevKeyboardState.IsKeyDown(Keys.Space) && Keyboard.GetState().IsKeyUp(Keys.Space) || GamePad.GetState(Player_Index).IsButtonUp(Buttons.A) && PrevGamepadState.IsButtonDown(Buttons.A)) _ninja.ReleaseJump(); if (Keyboard.GetState().IsKeyDown(Keys.C)) _ninja.Sliding = true; if (Keyboard.GetState().IsKeyUp(Keys.C)) _ninja.Sliding = false; if (Keyboard.GetState().IsKeyDown(Keys.Left) && _ninja.Sliding == false) _ninja.Position += new Vector2(-1, 0) * speed; if (Keyboard.GetState().IsKeyDown(Keys.Right) && _ninja.Sliding == false) _ninja.Position += new Vector2(1, 0) * speed; _ninja.Position += new Vector2(GamePad.GetState(Player_Index).ThumbSticks.Left.X * speed, 0); //gamepad checks if (GamePad.GetState(Player_Index).IsButtonDown(Buttons.B)) _ninja.Sliding = true; if (GamePad.GetState(Player_Index).IsButtonUp(Buttons.B) && GamePad.GetState(Player_Index).IsButtonDown(Buttons.B)) _ninja.Sliding = false; lock (game_map.ObstacleLock) { foreach (RunNJumpObstacle obstacle in game_map.Obstacles) { // The per-pixel check is expensive, so check the bounding rectangles // first to prevent testing pixels when collisions are impossible. if (_ninja.Collides(obstacle)) { /* Do somemthing with this collision */ Collided = true; } } } } _ninja.Update(gameTime, game_map); base.Update(gameTime); }
public override void LoadContent() { if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); int ninja_slide_effect_name = ArenaParticleEngine.ParticleEngine.Instance.LoadFromFile("SlidingDirt", content); spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice); test = content.Load<Texture2D>(@"blackbox"); rect = new RectangleOverlay(new Rectangle(10, 10, 100, 100), Color.Green, ScreenManager.GraphicsDevice); //List<Texture2D> dirt_textures = new List<Texture2D>(); //dirt_textures.Add(ScreenManager.Game.Content.Load<Texture2D>(@"ParticleTextures\Dirt2")); //particleEngine = new ParticleEngine.ParticleEngine(dirt_textures, new Vector2(400, 240)); test_alpha = content.Load<Texture2D>(@"obstacle_alpha"); //test_obstacle = new RunNJumpObstacle(content.Load<Texture2D>(@"obstacle_alpha"), null, new Vector2(300, 300), 2.0f); _game_map = new RunNJumpMap(content.Load<Texture2D>(@"MapTiles\DirtTile"), content.Load<Texture2D>(@"MapTiles\GrassTile"), content.Load<Texture2D>(@"obstacle_alpha"), ScreenManager.GraphicsDevice); _game_background = content.Load<Texture2D>(@"sky1"); font = content.Load<SpriteFont>(@"SpriteFont1"); gameFont = content.Load<SpriteFont>(@"GameStateFont"); //player = new Players.RunNJumpPlayer(PlayerIndex.One, ScreenManager.Game.Content.Load<Texture2D>(@"blue_ninja_new"), // _game_map.GroundY - (int)(64 * 2.0f), ScreenManager.Game.Content.Load<Texture2D>(@"ParticleTextures\Dirt3"), ScreenManager.GraphicsDevice); //test_sprite = new RunNJumpNinja(content.Load<Texture2D>(@"blue_ninja_new"), new Rectangle(0, 0, 64, 64), new Vector2(100, _game_map.GroundY - (64 * 2.0f)), 2.0f, 0, 4, .08f, new Point(64, 64), ScreenManager.Game.Content.Load<Texture2D>(@"ParticleTextures\Dirt3"), ScreenManager.GraphicsDevice); foreach (PlayerIndex PI in PlayerIndexes) { _players.Add(new RunNJumpPlayer(PI, content.Load<Texture2D>(@"blue_ninja_new"), _game_map.GroundY - (int)(64 * 2.0f), ninja_slide_effect_name, ScreenManager.GraphicsDevice)); } ScreenManager.Game.ResetElapsedTime(); }