-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameObject.cs
53 lines (47 loc) · 1.37 KB
/
GameObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace ExtremePong
{
public class GameObject
{
public Vector2 Position { get; set; }
public Vector2 Direction { get; set; }
public float Speed { get; set; }
public Texture2D Texture { get; set; }
public Color Tint { get; set; }
public Rectangle BoundingBox
{
get
{
return new Rectangle(
(int)Position.X,
(int)Position.Y,
Texture.Width,
Texture.Height);
}
}
public GameObject(Texture2D texture)
{
Position = Vector2.Zero;
Direction = Vector2.Zero;
Speed = 0f;
Texture = texture;
Tint = Color.White;
}
public virtual void Update(GameTime gameTime)
{
if (Direction != Vector2.Zero)
Direction.Normalize();
Position += Direction * Speed *
(float)gameTime.ElapsedGameTime.TotalSeconds;
}
public virtual void Draw(GameTime gameTime, SpriteBatch batch)
{
batch.Draw(Texture, Position, Tint);
}
}
}