This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MovingObject.cs
127 lines (108 loc) · 3.38 KB
/
MovingObject.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Copyright (C) 2009 Tom Postma, Gertjan Buijs
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Frogger
{
using System;
using System.Drawing;
using System.Windows.Forms;
public class MovingObject : UserControl
{
private int velocity = 0;
private int pos = -1;
private Direction direction;
private Bitmap pic;
/// <summary>
/// Creating a new instance of a movingobj.
/// </summary>
public MovingObject(int velocity, Direction direction, int pos)
{
this.velocity = velocity;
this.direction = direction;
this.pos = pos;
//Add transparancy support
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
//Make transparant
this.BackColor = Color.Transparent;
//todo: not good..
this.Anchor = AnchorStyles.Bottom;
this.DoubleBuffered = true;
this.BringToFront();
InitializeComponent();
}
public Direction Dir
{
get
{
return this.direction;
}
}
public int Velocity
{
get
{
return this.velocity;
}
}
public int Pos
{
get
{
return this.pos;
}
}
/// <summary>
/// De texture.
/// </summary>
public Bitmap Pic
{
get
{
return this.pic;
}
set
{
this.pic = value;
}
}
/// <summary>
/// cleanup memory
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// MovingObject
//
this.DoubleBuffered = true;
this.Name = "MovingObject";
this.Size = new System.Drawing.Size(132, 110);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.MovingObject_Paint);
this.ResumeLayout(false);
}
private void MovingObject_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle(new Point(0, 0), new Size(this.Width, this.Height));
//image scaling is cpu costly.
//Prescale the image when it is first draw and then get the scaled image out of memory.
e.Graphics.DrawImage((Image)this.pic, rect);
//using GDI+ is faster than a picturebox.
}
}
}