Advertisement
DaveVoyles

Untitled

Apr 11th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.81 KB | None | 0 0
  1. namespace Pong
  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.         public Vector2 position;
  11.         public float moveSpeed;
  12.         public Rectangle size;
  13.         private int points;
  14.         private int yHeight;
  15.         private Texture2D leftBat;
  16.         public float turbo;
  17.         public float recharge;
  18.         public float interval;
  19.         public bool isTurbo;
  20.         TimeSpan turboDelay;
  21.         GameTime turboCooldown;
  22.        
  23.  
  24.         public Bat(ContentManager content, Vector2 screenSize, bool side)
  25.         {
  26.             moveSpeed = 7f;
  27.             turbo = 15f;
  28.             recharge = 100f;
  29.             points = 0;
  30.             interval = 5f;
  31.             leftBat = content.Load<Texture2D>(@"gfx/batGrey");
  32.             size = new Rectangle(0, 0, leftBat.Width, leftBat.Height);
  33.             if (side) position = new Vector2(30, screenSize.Y / 2 - size.Height / 2);
  34.             else position = new Vector2(screenSize.X - 30, screenSize.Y / 2 - size.Height / 2);
  35.             yHeight = (int)screenSize.Y;
  36.         }
  37.  
  38.         public void IncreaseSpeed()
  39.         {
  40.             moveSpeed += .5f;
  41.            
  42.         }
  43.  
  44.        
  45.         public void Turbo()
  46.         {
  47.             moveSpeed += 7.0f;
  48.  //  commented out until I can get it to work         interval = 5;  
  49.         }
  50.          
  51.  
  52.         public Rectangle GetSize()
  53.         {
  54.             return size;
  55.         }
  56.  
  57.         public void IncrementPoints()
  58.         {
  59.             points++;
  60.         }
  61.  
  62.         public int GetPoints()
  63.         {
  64.             return points;
  65.         }
  66.  
  67.         public void SetPosition(Vector2 position)
  68.         {
  69.             if (position.Y < 0)
  70.             {
  71.                 position.Y = 0;
  72.             }
  73.             if (position.Y > yHeight - size.Height)
  74.             {
  75.                 position.Y = yHeight - size.Height;
  76.             }
  77.             this.position = position;
  78.         }
  79.  
  80.         public Vector2 GetPosition()
  81.         {
  82.             return position;
  83.         }
  84.  
  85.         public void MoveUp()
  86.         {
  87.             SetPosition(position + new Vector2(0, -moveSpeed));
  88.         }
  89.  
  90.         public void MoveDown()
  91.         {
  92.             SetPosition(position + new Vector2(0, moveSpeed));
  93.         }
  94.  
  95.  
  96.         public virtual void UpdatePosition(Ball ball)
  97.         {
  98.             size.X = (int)position.X;
  99.             size.Y = (int)position.Y;
  100.         }
  101.  
  102.         public void ResetPosition()
  103.         {
  104.             SetPosition(new Vector2(GetPosition().X, yHeight / 2 - size.Height));
  105.         }
  106.  
  107.  
  108.  
  109.         public virtual void Draw(SpriteBatch batch)
  110.         {
  111.             batch.Draw(leftBat, position, Color.White);
  112.         }
  113.  
  114.    
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement