Advertisement
rohits134

Bat.cs

Jul 5th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. namespace Pong_Clone
  2. {
  3.     using Microsoft.Xna.Framework;
  4.     using Microsoft.Xna.Framework.Content;
  5.     using Microsoft.Xna.Framework.Graphics;
  6.     using System;
  7.  
  8.     public class Bat
  9.     {
  10.         private Vector2 position;
  11.         private float moveSpeed;
  12.         private Rectangle size;
  13.         private int points;
  14.         private int yHeight;
  15.         private Texture2D texture;
  16.  
  17.         public Bat(ContentManager content, Vector2 screenSize, bool side)
  18.         {
  19.             moveSpeed = 6f;
  20.             points = 0;
  21.             texture = content.Load<Texture2D>("bat_thumb");
  22.             size = new Rectangle(0, 0, texture.Width, texture.Height);
  23.             if (side) position = new Vector2(30, screenSize.Y / 2 - size.Height / 2);
  24.             else position = new Vector2(screenSize.X - 30, screenSize.Y / 2 - size.Height / 2);
  25.             yHeight = (int)screenSize.Y;
  26.         }
  27.  
  28.         public void IncreaseSpeed()
  29.         {
  30.             moveSpeed += 0.6f;
  31.         }
  32.  
  33.         public Rectangle GetSize()
  34.         {
  35.             return size;
  36.         }
  37.  
  38.         public void IncrementPoints()
  39.         {
  40.             points++;
  41.         }
  42.  
  43.         public int GetPoints()
  44.         {
  45.             return points;
  46.         }
  47.  
  48.         private void SetPosition(Vector2 position)
  49.         {
  50.             if (position.Y < 0)
  51.             {
  52.                 position.Y = 0;
  53.             }
  54.             if (position.Y > yHeight - size.Height)
  55.             {
  56.                 position.Y = yHeight - size.Height;
  57.             }
  58.             this.position = position;
  59.         }
  60.  
  61.         public Vector2 GetPosition()
  62.         {
  63.             return position;
  64.         }
  65.  
  66.         public void MoveUp()
  67.         {
  68.             SetPosition(position + new Vector2(0, -moveSpeed));
  69.         }
  70.  
  71.         public void MoveDown()
  72.         {
  73.             SetPosition(position + new Vector2(0, moveSpeed));
  74.         }
  75.  
  76.         public virtual void UpdatePosition(Ball ball)
  77.         {
  78.             size.X = (int)position.X;
  79.             size.Y = (int)position.Y;
  80.         }
  81.  
  82.         public void ResetPosition()
  83.         {
  84.             SetPosition(new Vector2(GetPosition().X, yHeight / 2 - size.Height));
  85.         }
  86.  
  87.         public void Draw(SpriteBatch batch)
  88.         {
  89.             batch.Draw(texture, position, Color.White);
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement