-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameObject.cs
More file actions
92 lines (73 loc) · 1.85 KB
/
GameObject.cs
File metadata and controls
92 lines (73 loc) · 1.85 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace SpaceInvaders
{
/// <summary>
///
/// </summary>
public class GameObject
{
protected Image TheImage = null;
public Point Position = new Point(50, 50);
protected Rectangle ImageBounds = new Rectangle(0, 0, 10, 10);
protected Rectangle MovingBounds = new Rectangle();
public GameObject(string fileName)
{
TheImage = Image.FromFile(fileName);
this.Initialize();
}
public GameObject(Bitmap image)
{
TheImage = image;
this.Initialize();
}
private void Initialize()
{
if (this.TheImage == null) return;
this.ImageBounds.Width = this.TheImage.Width;
this.ImageBounds.Height = this.TheImage.Height;
}
public GameObject()
{
TheImage = null;
this.Initialize();
}
public int Width
{
get
{
return ImageBounds.Width;
}
}
public int Height
{
get
{
return ImageBounds.Height;
}
}
public virtual int GetWidth()
{
return ImageBounds.Width;
}
public Image GetImage()
{
return TheImage;
}
public virtual Rectangle GetBounds()
{
return MovingBounds;
}
public void UpdateBounds()
{
MovingBounds = ImageBounds;
MovingBounds.Offset(Position);
}
public virtual void Draw(Graphics g)
{
UpdateBounds();
g.DrawImage(TheImage, MovingBounds, 0, 0, ImageBounds.Width, ImageBounds.Height, GraphicsUnit.Pixel);
}
}
}