Advertisement
Spectrewiz

Obj

Aug 27th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Audio;
  7. using Microsoft.Xna.Framework.Content;
  8. using Microsoft.Xna.Framework.GamerServices;
  9. using Microsoft.Xna.Framework.Graphics;
  10. using Microsoft.Xna.Framework.Input;
  11. using Microsoft.Xna.Framework.Media;
  12.  
  13. namespace Horror
  14. {
  15.     public class Obj
  16.     {
  17.         public int health, ammo,
  18.             maxHealth, maxAmmo;
  19.  
  20.         public KeyboardState key,
  21.             prevKey;
  22.         public MouseState mouse,
  23.             prevMouse;
  24.  
  25.         public Vector2 velocity = Vector2.Zero,
  26.             position;
  27.         public float rotation = 0.0f,
  28.             scale = 1.0f;
  29.  
  30.         public string name;
  31.  
  32.         public Texture2D sprite;
  33.  
  34.         public bool alive = false,
  35.             draw = false,
  36.             solid;
  37.  
  38.         public Rectangle area,
  39.             imageArea;
  40.         public Point frame;
  41.         protected int imageNumber = 1;
  42.         protected float imageSpeed = 1f;
  43.         public float imageIndex = 0f;
  44.  
  45.         public Obj()
  46.         {
  47.  
  48.         }
  49.  
  50.         public Obj(Vector2 position)
  51.         {
  52.             this.position = position;
  53.         }
  54.  
  55.         public virtual void Update()
  56.         {
  57.             if (!alive) return;
  58.             UpdateArea();
  59.             PushTo(velocity, rotation);
  60.         }
  61.  
  62.         public virtual void LoadContent(ContentManager content)
  63.         {
  64.             sprite = content.Load<Texture2D>("Sprites/" + name);
  65.             area = new Rectangle(0, 0, sprite.Width / imageNumber, sprite.Height);
  66.             frame = new Point(sprite.Width / imageNumber, sprite.Height);
  67.         }
  68.  
  69.         public virtual void Draw(SpriteBatch spriteBatch)
  70.         {
  71.             if (!draw) return;
  72.         }
  73.  
  74.         public void UpdateArea()
  75.         {
  76.             area.X = (int)position.X - (sprite.Width / 2);
  77.             area.Y = (int)position.Y - (sprite.Height / 2);
  78.         }
  79.  
  80.         public virtual void PushTo(Vector2 velocity, float direction)
  81.         {
  82.             if (velocity == Vector2.Zero) return;
  83.             float newX = (float)Math.Cos(MathHelper.ToRadians(direction));
  84.             float newY = (float)Math.Sin(MathHelper.ToRadians(direction));
  85.             position.X += velocity.X * newX;
  86.             position.Y += velocity.Y * newY;
  87.         }
  88.  
  89.         public virtual void Damage(int damage)
  90.         {
  91.             health -= damage;
  92.         }
  93.  
  94.         public Obj Clone()
  95.         {
  96.             return (Obj)this.MemberwiseClone();
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement