/// <summary> /// Constructor /// </summary> /// <param name="game">Game object</param> /// <param name="scene">PlayScene where game is playing</param> /// <param name="spriteBatch">SpriteBatch for drawing</param> public Noguri(Game game, PlayScene scene, SpriteBatch spriteBatch) : base(game) { this.game = (GameNoguri)game; this.scene = scene; this.spriteBatch = spriteBatch; this.position = new Vector2(Shared.LimitRightLevelZero - WIDTH, Ground.GetY(0) - HEIGHT); tex = game.Content.Load <Texture2D>("Images/noguri"); speed = new Vector2(SPEED_X, 0); rectangle = new Rectangle((int)position.X + ALLOWANCE_SIDE, (int)position.Y, WIDTH - (ALLOWANCE_SIDE * 2), HEIGHT); // Load sounds jumpSound = game.Content.Load <SoundEffect>("Sounds/jump"); dieSound = game.Content.Load <SoundEffect>("Sounds/die"); itemSound = game.Content.Load <SoundEffect>("Sounds/item"); fallSound = game.Content.Load <Song>("Sounds/fall"); // Create image frames CreateFrames(); }
/// <summary> /// Update data /// </summary> /// <param name="gameTime">GameTime object</param> public override void Update(GameTime gameTime) { KeyboardState ks = Keyboard.GetState(); if (isFalling) { Fall(); } else if (!isOnLadder) { if (isJumping) { Jump(direction == 0 ? FRAMEROW_LJUMP : FRAMEROW_RJUMP); } else if (isStabbed) { frameRow = 5; frameIndex = 2; } else { Move(); } } // Set the limit if (position.X < Shared.LimitLeft) { // End of Left position.X = Shared.LimitLeft; } else { // End of Right if (position.Y > Ground.GetY(1)) { // Level 0 Exception if (position.X + WIDTH > Shared.LimitRightLevelZero) { position.X = Shared.LimitRightLevelZero - WIDTH; } } else if (position.X + WIDTH > Shared.LimitRight) { position.X = Shared.LimitRight - WIDTH; } } // Sync rectangle with position rectangle.X = (int)position.X + ALLOWANCE_SIDE; rectangle.Y = (int)position.Y; // Tacks foreach (Tack tack in scene.tacks) { if (rectangle.Intersects(tack.Rectangle) && !isJumping) { HitTack(); } } // Ladders isLadderBehind = false; foreach (Ladder ladder in scene.ladders) { if (rectangle.Intersects(ladder.Rectangle) && !isFalling) { this.ladder = ladder; isLadderBehind = true; Climb(); } } // Centipedes foreach (Centipede centipede in scene.centipedes) { if (rectangle.Intersects(centipede.Rectangle)) { isFalling = true; } } // Grounds int intersectsCount = 0; foreach (Ground ground in scene.grounds) { if (rectangle.Intersects(ground.Rectangle)) { intersectsCount++; } } if (intersectsCount == 0 && !isJumping) { isFalling = true; } // Items int itemCount = 0; foreach (Item item in scene.items) { if (rectangle.Intersects(item.Rectangle) && !isJumping && !isFalling && !isOnLadder) { if (item.Visible) { itemSound.Play(); game.Score += item.Point; item.Enabled = false; item.Visible = false; } } if (item.Visible) { itemCount++; } } if (itemCount == 0) { if (scene.Stage < Shared.FinalStage) { // Go to next stage game.NewPlayScene(scene.Stage + 1, true); } else { // Show clear scene scene.Hide(); game.ClearScene.Show(); } } base.Update(gameTime); }