public DuckPopulation(ContentManager content, CollisionData[] boundary) { m_content = content; m_boundary = boundary; LoadContent(); Reset(); }
public DuckHuntBall(int x, int y, CollisionData []boundary) { m_init_x = x; m_init_y = y; m_scrn_boundary = boundary; m_animList = new List<Drawable>(); if(HelperUtils.GetRandomNumber(0.0, 10.0) < 5.01) { ResetBall(30.0f, 50.0f); } else { ResetBall(140.0f, 160.0f); } }
public PongBall(CollisionData[] boundary, SoundEffect paddlehit, SoundEffect wallhit) { m_hitwall = wallhit; m_paddlehit = paddlehit; m_scrn_boundary = boundary; m_animList = new List<Drawable>(); if (HelperUtils.GetRandomNumber(0.0, 10.0) < 5.01) { ResetBall(50.0f, -50.0f); } else { ResetBall(140.0f, 210.0f); } }
public override void Update(CollisionData p1paddle, CollisionData p2paddle) { if (Ball_State != BallState.DeadBall && Ball_State != BallState.Limbo) { /* Update Position */ X_Pos += (int)X_Vel; Y_Pos += (int)Y_Vel; /* Update current Animation */ m_currAnim.Update(); m_currAnim.X_Pos = X_Pos; m_currAnim.Y_Pos = Y_Pos; m_currAnim.Scale = Ball_Scale; m_currAnimBData = new CollisionData((int)m_currAnim.X_Pos, (int)m_currAnim.Y_Pos, m_currAnim.Texture, m_currAnim.Sprite_Src_Rect, m_currAnim.Origin, m_currAnim.Scale, m_currAnim.Rotation, SpriteEffects.None); PongBall_Rect = m_currAnimBData.m_rect; m_pongBallTransform = m_currAnimBData.m_transformation; /* Detect Collisions */ if (Ball_State == BallState.Active) // No need to detect for collision if we are outofbounds { // Top of boundary if (m_hit != Direction.Top && PongBall_Rect.Intersects(m_scrn_boundary[0].m_rect)) { // Check collision with person if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[0].m_transformation, m_scrn_boundary[0].m_rect.Width, m_scrn_boundary[0].m_rect.Height, m_scrn_boundary[0].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Top; } } // Bottom of boundary else if (m_hit != Direction.Bottom && PongBall_Rect.Intersects(m_scrn_boundary[1].m_rect)) // Cant hit bottom twice in row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[1].m_transformation, m_scrn_boundary[1].m_rect.Width, m_scrn_boundary[1].m_rect.Height, m_scrn_boundary[1].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Bottom; } } // Paddle (DuckHuntPlayer 1) else if (m_hit != Direction.Right && PongBall_Rect.Intersects(p1paddle.m_rect)) // Cant hit p1 paddle twice in a row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, p1paddle.m_transformation, p1paddle.m_rect.Width, p1paddle.m_rect.Height, p1paddle.m_color_data)) { X_Vel = -X_Vel; Ball_Dir = Direction.Right; m_hit = Direction.Right; } } // Paddle (DuckHuntPlayer 2) else if (m_hit != Direction.Left && PongBall_Rect.Intersects(p2paddle.m_rect)) // Cant hit p2 paddle twice in a row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, p2paddle.m_transformation, p2paddle.m_rect.Width, p2paddle.m_rect.Height, p2paddle.m_color_data)) { X_Vel = -X_Vel; Ball_Dir = Direction.Left; m_hit = Direction.Left; } } /* Out of bounds */ // Got past DuckHuntPlayer 1 else if (m_hit != Direction.Right && PongBall_Rect.Intersects(m_scrn_boundary[2].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[2].m_transformation, m_scrn_boundary[2].m_rect.Width, m_scrn_boundary[2].m_rect.Height, m_scrn_boundary[2].m_color_data)) { m_currAnim.Effects = SpriteEffects.None; Ball_State = BallState.OutofBounds; } } // Got past DuckHuntPlayer 2 else if (m_hit != Direction.Left && PongBall_Rect.Intersects(m_scrn_boundary[3].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[3].m_transformation, m_scrn_boundary[3].m_rect.Width, m_scrn_boundary[3].m_rect.Height, m_scrn_boundary[3].m_color_data)) { m_currAnim.Effects = SpriteEffects.FlipHorizontally; Ball_State = BallState.OutofBounds; } } /* for (int i = 0; i < clouds.Length; i++) { if (clouds[i].m_used != true && PongBall_Rect.Intersects(clouds[i].m_collision_rect)) { Y_Vel = -Y_Vel; //clouds[i].m_duck_used = true; m_hit = Direction.None; } } */ if ((X_Vel > 0 && Y_Vel < 0) || (X_Vel < 0 && Y_Vel < 0)) { m_currAnim = m_animList[1]; } else { m_currAnim = m_animList[0]; } if (Ball_Dir == Direction.Right) { m_currAnim.Effects = SpriteEffects.None; } else { m_currAnim.Effects = SpriteEffects.FlipHorizontally; } } else if(Ball_State == BallState.OutofBounds) { if(PongBall_Rect.Intersects(m_scrn_boundary[4].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[4].m_transformation, m_scrn_boundary[4].m_rect.Width, m_scrn_boundary[4].m_rect.Height, m_scrn_boundary[4].m_color_data)) { Ball_State = BallState.DeadBall; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[5].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[5].m_transformation, m_scrn_boundary[5].m_rect.Width, m_scrn_boundary[5].m_rect.Height, m_scrn_boundary[5].m_color_data)) { Ball_State = BallState.DeadBall; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[6].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[6].m_transformation, m_scrn_boundary[6].m_rect.Width, m_scrn_boundary[6].m_rect.Height, m_scrn_boundary[6].m_color_data)) { Ball_State = BallState.DeadBall; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[7].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[7].m_transformation, m_scrn_boundary[7].m_rect.Width, m_scrn_boundary[7].m_rect.Height, m_scrn_boundary[7].m_color_data)) { Ball_State = BallState.DeadBall; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[8].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[8].m_transformation, m_scrn_boundary[8].m_rect.Width, m_scrn_boundary[8].m_rect.Height, m_scrn_boundary[8].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Bottom; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[9].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[9].m_transformation, m_scrn_boundary[9].m_rect.Width, m_scrn_boundary[9].m_rect.Height, m_scrn_boundary[9].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Bottom; } } } m_currAnim.X_Pos = X_Pos; m_currAnim.Y_Pos = Y_Pos; m_currAnim.Scale = Ball_Scale; } }
private DuckHuntBall BuildDuck(CollisionData[] boundary) { DuckHuntBall duckball; AnimatedSprite dscduck = new AnimatedSprite(); AnimatedSprite ascduck = new AnimatedSprite(); int flapspeed = 4; dscduck.BuildAnimation(m_duck_txt, 1, 9, true, new int[20] { 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4 }); dscduck.SetFrame(0, flapspeed, null); dscduck.SetFrame(1, flapspeed, m_flapwing_snd); dscduck.SetFrame(2, flapspeed, null); dscduck.SetFrame(3, flapspeed, m_flapwing_snd); dscduck.SetFrame(4, flapspeed, null); dscduck.SetFrame(5, flapspeed, m_flapwing_snd); dscduck.SetFrame(6, flapspeed, null); dscduck.SetFrame(7, flapspeed, m_flapwing_snd); dscduck.SetFrame(8, flapspeed, m_duckquack_snd); dscduck.SetFrame(9, flapspeed, m_flapwing_snd); dscduck.SetFrame(10, flapspeed, null); dscduck.SetFrame(11, flapspeed, m_flapwing_snd); dscduck.SetFrame(12, flapspeed, null); dscduck.SetFrame(13, flapspeed, m_flapwing_snd); dscduck.SetFrame(14, flapspeed, null); dscduck.SetFrame(15, flapspeed, m_flapwing_snd); dscduck.SetFrame(16, flapspeed, null); dscduck.SetFrame(17, flapspeed, m_flapwing_snd); dscduck.SetFrame(18, flapspeed, null); dscduck.SetFrame(19, flapspeed, m_flapwing_snd); ascduck.BuildAnimation(m_duck_txt, 1, 9, true, new int[20] { 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1 }); ascduck.SetFrame(0, flapspeed, null); ascduck.SetFrame(1, flapspeed, m_flapwing_snd); ascduck.SetFrame(2, flapspeed, null); ascduck.SetFrame(3, flapspeed, m_flapwing_snd); ascduck.SetFrame(4, flapspeed, null); ascduck.SetFrame(5, flapspeed, m_flapwing_snd); ascduck.SetFrame(6, flapspeed, null); ascduck.SetFrame(7, flapspeed, m_flapwing_snd); ascduck.SetFrame(8, flapspeed, m_duckquack_snd); ascduck.SetFrame(9, flapspeed, m_flapwing_snd); ascduck.SetFrame(10, flapspeed, null); ascduck.SetFrame(11, flapspeed, m_flapwing_snd); ascduck.SetFrame(12, flapspeed, null); ascduck.SetFrame(13, flapspeed, m_flapwing_snd); ascduck.SetFrame(14, flapspeed, null); ascduck.SetFrame(15, flapspeed, m_flapwing_snd); ascduck.SetFrame(16, flapspeed, null); ascduck.SetFrame(17, flapspeed, m_flapwing_snd); ascduck.SetFrame(18, flapspeed, null); ascduck.SetFrame(19, flapspeed, m_flapwing_snd); duckball = new DuckHuntBall(HelperUtils.SafeBoundary.X + 512, HelperUtils.SafeBoundary.Y + 476, boundary); duckball.AddAnimation(dscduck); duckball.AddAnimation(ascduck); duckball.Ball_State = BallState.Limbo; return duckball; }
public void UpdateBalls(CollisionData p1paddle, CollisionData p2paddle, Cloud[] clouds) { m_pongballs[0].Update(p1paddle, p2paddle); m_pongballs[0].Update(clouds); m_pongballs[1].Update(p1paddle, p2paddle); m_pongballs[1].Update(clouds); }
public void InitPaddle() { m_colordata = new Color[m_texture.Width * m_texture.Height]; m_texture.GetData(m_colordata); // take boundary and set position according to texture size and the boundary. if(m_player == 0) { m_xpos = m_scrn_boundary.Left - m_texture.Width; } else if (m_player == 1) { m_xpos = m_scrn_boundary.Right; } // Center the paddle in the middle of the boundary m_ypos = ((m_scrn_boundary.Bottom - m_scrn_boundary.Top) / 2) - (m_texture.Height / 2) + m_scrn_boundary.Top; m_rect = new Rectangle(m_xpos, m_ypos, m_texture.Width, m_texture.Height); m_texture_data = new CollisionData(m_rect, m_colordata, Vector2.Zero, 1.0f, 0.0f, SpriteEffects.None); }
public virtual void Update(KeyboardState keyboardState, GamePadState gamePadState) { if (m_player == 1) { if (keyboardState.IsKeyDown(Keys.Up) || gamePadState.IsButtonDown(Buttons.DPadUp)) { m_ypos -= (int)(m_curr_velocity); } else if (keyboardState.IsKeyDown(Keys.Down) || gamePadState.IsButtonDown(Buttons.DPadDown)) { m_ypos += (int)(m_curr_velocity); } else { Vector2 thumbstick = gamePadState.ThumbSticks.Left; m_ypos -= (int)(thumbstick.Y * m_curr_velocity); } } else if (m_player == 0) { if (keyboardState.IsKeyDown(Keys.A) || gamePadState.IsButtonDown(Buttons.DPadUp)) { m_ypos -= (int)(m_curr_velocity); } else if (keyboardState.IsKeyDown(Keys.Z) || gamePadState.IsButtonDown(Buttons.DPadDown)) { m_ypos += (int)(m_curr_velocity); } else { Vector2 thumbstick = gamePadState.ThumbSticks.Left; m_ypos -= (int)(thumbstick.Y * m_curr_velocity); } } // Handle boundaries if (m_ypos < m_scrn_boundary.Top) { m_ypos = m_scrn_boundary.Top; } if((m_ypos + m_texture.Height) > m_scrn_boundary.Bottom) { m_ypos = m_scrn_boundary.Bottom - m_texture.Height; } m_rect = new Rectangle(m_xpos, m_ypos, m_texture.Width, m_texture.Height); m_texture_data = new CollisionData(m_rect, m_colordata, Vector2.Zero, 1.0f, 0.0f, SpriteEffects.None); }
public virtual void Update(CollisionData player1, CollisionData player2) { }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); /* LOAD TEXTURES, SOUNDS AND FONTS */ ScreenTexture = new Texture2D(ScreenManager.GraphicsDevice, 1, 1); ScreenTexture.SetData(new Color[] { Color.White }); paddle = content.Load<Texture2D>("Pong\\Textures\\pongpaddle"); ball = content.Load<Texture2D>("Pong\\Textures\\pongball"); pause = content.Load<SoundEffect>("DuckHunt\\Sounds\\pause"); paddlehit = content.Load<SoundEffect>("Pong\\Sounds\\paddlehit"); wallhit = content.Load<SoundEffect>("Pong\\Sounds\\wallbounce"); balldie = content.Load<SoundEffect>("Pong\\Sounds\\deadball"); m_score_fnt = content.Load<SpriteFont>("Fonts\\hugenesfont"); /* Create Players */ m_player1 = new Paddle(0, paddle, boxrec); m_player2 = new Paddle(1, paddle, boxrec); CollisionData[] temp = new CollisionData[4]; temp[0] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y + -81, 1024, 80)); temp[1] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y + 613, 1024, 80)); temp[2] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X + -81, HelperUtils.SafeBoundary.Y, 80, 612)); temp[3] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X + 1024, HelperUtils.SafeBoundary.Y, 80, 612)); /* Create Ball */ m_ball = new PongBall(temp , paddlehit, wallhit); m_ball.AddAnimation(new Sprite(ball)); m_ball.SetCurrentAnimation(0); m_ball.X_Pos = ScreenManager.GraphicsDevice.Viewport.Width / 2; m_ball.Y_Pos = (int)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Height - ball.Height); // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); }
public override void Update(CollisionData player1, CollisionData player2) { if (Ball_State != BallState.DeadBall) { /* Update Position */ X_Pos += (int)X_Vel; Y_Pos += (int)Y_Vel; /* Update current Animation */ //m_currAnim.Update(); m_currAnim.X_Pos = X_Pos; m_currAnim.Y_Pos = Y_Pos; m_currAnim.Scale = Ball_Scale; m_currAnimBData = new CollisionData((int)m_currAnim.X_Pos, (int)m_currAnim.Y_Pos, m_currAnim.Texture, m_currAnim.Sprite_Src_Rect, m_currAnim.Origin, m_currAnim.Scale, m_currAnim.Rotation, SpriteEffects.None); PongBall_Rect = m_currAnimBData.m_rect; m_pongBallTransform = m_currAnimBData.m_transformation; /* Detect Collisions */ if (Ball_State == BallState.Active) { // Top of boundary if (m_hit != Direction.Top && PongBall_Rect.Intersects(m_scrn_boundary[0].m_rect)) { // Check collision with person if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[0].m_transformation, m_scrn_boundary[0].m_rect.Width, m_scrn_boundary[0].m_rect.Height, m_scrn_boundary[0].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Top; m_hitwall.Play(); } } // Bottom of boundary else if (m_hit != Direction.Bottom && PongBall_Rect.Intersects(m_scrn_boundary[1].m_rect)) // Cant hit bottom twice in row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[1].m_transformation, m_scrn_boundary[1].m_rect.Width, m_scrn_boundary[1].m_rect.Height, m_scrn_boundary[1].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Bottom; m_hitwall.Play(); } } // Paddle (Player 1) else if (m_hit != Direction.Right && PongBall_Rect.Intersects(player1.m_rect)) // Cant hit p1 paddle twice in a row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, player1.m_transformation, player1.m_rect.Width, player1.m_rect.Height, player1.m_color_data)) { X_Vel = -X_Vel; Ball_Dir = Direction.Right; m_hit = Direction.Right; m_paddlehit.Play(); } } // Paddle (Player 2) else if (m_hit != Direction.Left && PongBall_Rect.Intersects(player2.m_rect)) // Cant hit p2 paddle twice in a row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, player2.m_transformation, player2.m_rect.Width, player2.m_rect.Height, player2.m_color_data)) { X_Vel = -X_Vel; Ball_Dir = Direction.Left; m_hit = Direction.Left; m_paddlehit.Play(); } } // Left of boundary else if (PongBall_Rect.Intersects(m_scrn_boundary[2].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[2].m_transformation, m_scrn_boundary[2].m_rect.Width, m_scrn_boundary[2].m_rect.Height, m_scrn_boundary[2].m_color_data)) { Ball_State = BallState.DeadBall; } } // Right of boundary else if (PongBall_Rect.Intersects(m_scrn_boundary[3].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[3].m_transformation, m_scrn_boundary[3].m_rect.Width, m_scrn_boundary[3].m_rect.Height, m_scrn_boundary[3].m_color_data)) { Ball_State = BallState.DeadBall; } } } } }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); /* LOAD TEXTURES, SOUNDS AND FONTS */ tree = content.Load<Texture2D>("DuckHunt\\Textures\\tree"); ground = content.Load<Texture2D>("DuckHunt\\Textures\\ground"); bush = content.Load<Texture2D>("DuckHunt\\Textures\\bush"); m_player_textures[0] = content.Load<Texture2D>("DuckHunt\\Textures\\panel"); walkingdog = content.Load<Texture2D>("DuckHunt\\Textures\\walkdog"); flyawaysign = content.Load<Texture2D>("DuckHunt\\Textures\\flyawaysign"); m_player_textures[1] = content.Load<Texture2D>("DuckHunt\\Textures\\score"); m_player_textures[2] = content.Load<Texture2D>("DuckHunt\\Textures\\clouds"); m_player_textures[3] = content.Load<Texture2D>("DuckHunt\\Textures\\duckcall"); m_player_textures[4] = content.Load<Texture2D>("DuckHunt\\Textures\\shot"); clouds[0] = content.Load<Texture2D>("DuckHunt\\Textures\\smallcloud"); clouds[1] = content.Load<Texture2D>("DuckHunt\\Textures\\medcloud"); clouds[2] = content.Load<Texture2D>("DuckHunt\\Textures\\bigcloud"); dogbark = content.Load<SoundEffect>("DuckHunt\\Sounds\\dogbark"); m_shot = content.Load<SoundEffect>("DuckHunt\\Sounds\\shot"); startround = content.Load<SoundEffect>("DuckHunt\\Sounds\\startround"); endround = content.Load<SoundEffect>("DuckHunt\\Sounds\\roundend"); pause = content.Load<SoundEffect>("DuckHunt\\Sounds\\pause"); m_num = content.Load<SpriteFont>("Fonts\\bignesfont"); m_score_fnt = content.Load<SpriteFont>("Fonts\\hugenesfont"); debug = new Texture2D(ScreenManager.GraphicsDevice, 1, 1); debug.SetData(new Color[] { new Color(255, 255, 255) }); m_clouds_p1 = new Clouds(0, clouds);//, debug); m_clouds_p2 = new Clouds(1, clouds);//, debug); m_clouds = new Cloud[m_clouds_p1.CloudsA.Length*2]; m_clouds[0] = m_clouds_p1.CloudsA[0]; m_clouds[1] = m_clouds_p1.CloudsA[1]; m_clouds[2] = m_clouds_p1.CloudsA[2]; m_clouds[3] = m_clouds_p1.CloudsA[0]; m_clouds[4] = m_clouds_p1.CloudsA[1]; m_clouds[5] = m_clouds_p1.CloudsA[2]; m_clouds[6] = m_clouds_p2.CloudsA[0]; m_clouds[7] = m_clouds_p2.CloudsA[1]; m_clouds[8] = m_clouds_p2.CloudsA[2]; m_clouds[9] = m_clouds_p2.CloudsA[0]; m_clouds[10] = m_clouds_p2.CloudsA[1]; m_clouds[11] = m_clouds_p2.CloudsA[2]; /* SETUP ALL ANIMATIONSPRITES */ wdog.BuildAnimation(walkingdog, 1, 8, true, new int[4] { 1, 2, 3, 4 }); wdog.SetFrame(0, 8, null); wdog.SetFrame(1, 8, null); wdog.SetFrame(2, 8, null); wdog.SetFrame(3, 8, null); wdog.X_Pos = HelperUtils.SafeBoundary.X + 22; wdog.Y_Pos = HelperUtils.SafeBoundary.Y + 471; sdog.BuildAnimation(walkingdog, 1, 8, true, new int[6] { 1, 0, 1, 0, 1, 0 }); sdog.SetFrame(0, 8, null); sdog.SetFrame(1, 8, null); sdog.SetFrame(2, 8, null); sdog.SetFrame(3, 8, null); sdog.SetFrame(4, 8, null); sdog.SetFrame(5, 8, null); sprdog.BuildAnimation(walkingdog, 1, 8, true, new int[1] { 5 }); sprdog.SetFrame(0, 100, null); jdog1.BuildAnimation(walkingdog, 1, 8, true, new int[1] { 6 }); jdog1.SetFrame(0, 1000, dogbark); jdog2.BuildAnimation(walkingdog, 1, 8, true, new int[1] { 6 }); jdog2.SetFrame(0, 50, dogbark); jdog3.BuildAnimation(walkingdog, 1, 8, true, new int[1] { 7 }); jdog3.SetFrame(0, 50, dogbark); /* MAKE INTRO ANIMATION */ m_intro.AddAnimation(new DirXYMover(wdog, 180, 0, 1.7f)); m_intro.AddAnimation(new TimeOutDrawable(sdog, 49, true)); m_intro.AddAnimation(new DirXYMover(wdog, 180, 0, 1.7f)); m_intro.AddAnimation(new TimeOutDrawable(sdog, 49, true)); m_intro.AddAnimation(new DirXYMover(wdog, 10, 0, 1.7f)); m_intro.AddAnimation(new TimeOutDrawable(sprdog, 49, true)); m_intro.AddAnimation(new DirXYMover(jdog1, 5, -50, 3.5f)); m_intro.AddAnimation(new DirXYMover(jdog1, 15, -25, 3.0f)); m_intro.AddAnimation(new DirXYMover(jdog2, 15, -25, 3.0f)); m_intro.AddAnimation(new DirXYMover(jdog3, 40, 40, 3.0f)); m_intro.BuildScene(new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); m_intro.Scene_State = DrawableState.Active; /* Make a texture for bg. NOT gonna be needed when I change the dimension of screen */ ScreenTexture = new Texture2D(ScreenManager.GraphicsDevice, 1, 1); ScreenTexture.SetData(new Color[] { Color.White }); /* Build the SHOT animations */ flash = new Texture2D(ScreenManager.GraphicsDevice, 1, 1); flash.SetData(new Color[] { new Color(255, 255, 255, 128) }); m_flash = new TimeOutDrawable(new Image(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y, 1024, 612, flash), 3, false); m_flash.Draw_State = DrawableState.Finished; /* Create Players */ m_player1 = new DuckHuntPlayer(0); m_player1.LoadContent(m_player_textures, m_num, m_score_fnt, boxrec); m_player2 = new DuckHuntPlayer(1); m_player2.LoadContent(m_player_textures, m_num, m_score_fnt, boxrec); newbound = Boundary.CreateBoundRects(boxrec); bounddata = new CollisionData[newbound.Length]; bounddata[0] = new CollisionData(newbound[0]); bounddata[1] = new CollisionData(newbound[1]); bounddata[2] = new CollisionData(newbound[2]); bounddata[3] = new CollisionData(newbound[3]); bounddata[4] = new CollisionData(newbound[4]); bounddata[5] = new CollisionData(newbound[5]); bounddata[6] = new CollisionData(newbound[6]); bounddata[7] = new CollisionData(newbound[7]); bounddata[8] = new CollisionData(newbound[8]); bounddata[9] = new CollisionData(newbound[9]); m_ducks = new DuckPopulation(content, bounddata); // FLY AWAY SIGN m_fly_sign.Texture = flyawaysign; m_fly_sign.X_Pos = ScreenManager.GraphicsDevice.Viewport.Width / 2 - m_fly_sign.Texture.Width / 2; m_fly_sign.Y_Pos = HelperUtils.SafeBoundary.Y + 256; // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); }
public override void Update(CollisionData p1paddle, CollisionData p2paddle) { if (Ball_State != BallState.DeadBall && Ball_State != BallState.Limbo) { /* Update Position */ X_Pos += (int)X_Vel; Y_Pos += (int)Y_Vel; /* Update current Animation */ m_currAnim.Update(); m_currAnim.X_Pos = X_Pos; m_currAnim.Y_Pos = Y_Pos; m_currAnim.Scale = Ball_Scale; m_currAnimBData = new CollisionData((int)m_currAnim.X_Pos, (int)m_currAnim.Y_Pos, m_currAnim.Texture, m_currAnim.Sprite_Src_Rect, m_currAnim.Origin, m_currAnim.Scale, m_currAnim.Rotation, SpriteEffects.None); PongBall_Rect = m_currAnimBData.m_rect; m_pongBallTransform = m_currAnimBData.m_transformation; /* Detect Collisions */ if (Ball_State == BallState.Active) // No need to detect for collision if we are outofbounds { // Top of boundary if (m_hit != Direction.Top && PongBall_Rect.Intersects(m_scrn_boundary[0].m_rect)) { // Check collision with person if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[0].m_transformation, m_scrn_boundary[0].m_rect.Width, m_scrn_boundary[0].m_rect.Height, m_scrn_boundary[0].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Top; } } // Bottom of boundary else if (m_hit != Direction.Bottom && PongBall_Rect.Intersects(m_scrn_boundary[1].m_rect)) // Cant hit bottom twice in row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[1].m_transformation, m_scrn_boundary[1].m_rect.Width, m_scrn_boundary[1].m_rect.Height, m_scrn_boundary[1].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Bottom; } } // Paddle (DuckHuntPlayer 1) else if (m_hit != Direction.Right && PongBall_Rect.Intersects(p1paddle.m_rect)) // Cant hit p1 paddle twice in a row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, p1paddle.m_transformation, p1paddle.m_rect.Width, p1paddle.m_rect.Height, p1paddle.m_color_data)) { X_Vel = -X_Vel; Ball_Dir = Direction.Right; m_hit = Direction.Right; } } // Paddle (DuckHuntPlayer 2) else if (m_hit != Direction.Left && PongBall_Rect.Intersects(p2paddle.m_rect)) // Cant hit p2 paddle twice in a row { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, p2paddle.m_transformation, p2paddle.m_rect.Width, p2paddle.m_rect.Height, p2paddle.m_color_data)) { X_Vel = -X_Vel; Ball_Dir = Direction.Left; m_hit = Direction.Left; } } /* Out of bounds */ // Got past DuckHuntPlayer 1 else if (m_hit != Direction.Right && PongBall_Rect.Intersects(m_scrn_boundary[2].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[2].m_transformation, m_scrn_boundary[2].m_rect.Width, m_scrn_boundary[2].m_rect.Height, m_scrn_boundary[2].m_color_data)) { m_currAnim.Effects = SpriteEffects.None; Ball_State = BallState.OutofBounds; } } // Got past DuckHuntPlayer 2 else if (m_hit != Direction.Left && PongBall_Rect.Intersects(m_scrn_boundary[3].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[3].m_transformation, m_scrn_boundary[3].m_rect.Width, m_scrn_boundary[3].m_rect.Height, m_scrn_boundary[3].m_color_data)) { m_currAnim.Effects = SpriteEffects.FlipHorizontally; Ball_State = BallState.OutofBounds; } } /* * for (int i = 0; i < clouds.Length; i++) * { * if (clouds[i].m_used != true && PongBall_Rect.Intersects(clouds[i].m_collision_rect)) * { * Y_Vel = -Y_Vel; * //clouds[i].m_duck_used = true; * m_hit = Direction.None; * } * } */ if ((X_Vel > 0 && Y_Vel < 0) || (X_Vel < 0 && Y_Vel < 0)) { m_currAnim = m_animList[1]; } else { m_currAnim = m_animList[0]; } if (Ball_Dir == Direction.Right) { m_currAnim.Effects = SpriteEffects.None; } else { m_currAnim.Effects = SpriteEffects.FlipHorizontally; } } else if (Ball_State == BallState.OutofBounds) { if (PongBall_Rect.Intersects(m_scrn_boundary[4].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[4].m_transformation, m_scrn_boundary[4].m_rect.Width, m_scrn_boundary[4].m_rect.Height, m_scrn_boundary[4].m_color_data)) { Ball_State = BallState.DeadBall; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[5].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[5].m_transformation, m_scrn_boundary[5].m_rect.Width, m_scrn_boundary[5].m_rect.Height, m_scrn_boundary[5].m_color_data)) { Ball_State = BallState.DeadBall; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[6].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[6].m_transformation, m_scrn_boundary[6].m_rect.Width, m_scrn_boundary[6].m_rect.Height, m_scrn_boundary[6].m_color_data)) { Ball_State = BallState.DeadBall; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[7].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[7].m_transformation, m_scrn_boundary[7].m_rect.Width, m_scrn_boundary[7].m_rect.Height, m_scrn_boundary[7].m_color_data)) { Ball_State = BallState.DeadBall; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[8].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[8].m_transformation, m_scrn_boundary[8].m_rect.Width, m_scrn_boundary[8].m_rect.Height, m_scrn_boundary[8].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Bottom; } } else if (PongBall_Rect.Intersects(m_scrn_boundary[9].m_rect)) { if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width, PongBall_Rect.Height, m_currAnimBData.m_color_data, m_scrn_boundary[9].m_transformation, m_scrn_boundary[9].m_rect.Width, m_scrn_boundary[9].m_rect.Height, m_scrn_boundary[9].m_color_data)) { Y_Vel = -Y_Vel; m_hit = Direction.Bottom; } } } m_currAnim.X_Pos = X_Pos; m_currAnim.Y_Pos = Y_Pos; m_currAnim.Scale = Ball_Scale; } }