-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScreenObject.cs
More file actions
119 lines (105 loc) · 3.54 KB
/
Copy pathScreenObject.cs
File metadata and controls
119 lines (105 loc) · 3.54 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
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
using System;
using System.Collections;
using System.Drawing;
using Raylib_cs;
using RlColor = Raylib_cs.Color;
namespace Asteroids
{
/// <summary>
/// ScreenObject - defines an object to be displayed on screen
/// This object is based on a cartesian coordinate system
/// centered at 0, 0
/// </summary>
abstract class ScreenObject : CommonOps
{
// points is used for the internal cartesian system
protected ArrayList points;
public ArrayList pointsTransformed; // exposed to simplify explosions
protected Point currLoc;
protected double velocityX;
protected double velocityY;
protected double radians;
public Point GetCurrLoc() {return currLoc;}
public double GetVelocityX() {return velocityX;}
public double GetVelocityY() {return velocityY;}
public double GetRadians() {return radians;}
public ScreenObject(Point location)
{
radians = 180 * Math.PI / 180;
points = new ArrayList();
points.Capacity = 20;
pointsTransformed = new ArrayList();
pointsTransformed.Capacity = 20;
velocityX = 0;
velocityY = 0;
currLoc = location;
InitPoints();
}
public abstract void InitPoints();
// Used to add points to a polygon
public int AddPoint(Point pt)
{
points.Add(pt);
return pointsTransformed.Add(pt);
}
protected void Rotate(double degrees)
{
double radiansAdjust = degrees * 0.0174532925;
radians += radiansAdjust/FPS;
double SinVal = Math.Sin(radians);
double CosVal = Math.Cos(radians);
pointsTransformed.Clear();
Point ptTransformed = new Point(0,0);
for (int i=0; i<points.Count; i++)
{
Point pt = ((Point)points[i]);
ptTransformed.X = (int)(pt.X * CosVal + pt.Y * SinVal);
ptTransformed.Y = (int)(pt.X * SinVal - pt.Y * CosVal);
pointsTransformed.Add(ptTransformed);
}
}
protected void DrawPolyToSC(ArrayList alPoly, ScreenCanvas sc, int iPictX, int iPictY,
RlColor penColor)
{
Point[] ptsPoly = new Point[alPoly.Count];
for (int i = 0; i<alPoly.Count; i++)
{
ptsPoly[i].X = (int)((currLoc.X + ((Point)alPoly[i]).X) / (double)iMaxX * iPictX);
ptsPoly[i].Y = (int)((currLoc.Y + ((Point)alPoly[i]).Y) / (double)iMaxY * iPictY);
}
sc.AddPolygon(ptsPoly, penColor);
}
public virtual bool Move()
{
currLoc.X += (int)velocityX;
currLoc.Y += (int)velocityY;
if (currLoc.X < 0)
currLoc.X = iMaxX-1;
if (currLoc.X >= iMaxX)
currLoc.X = 0;
if (currLoc.Y < 0)
currLoc.Y = iMaxY-1;
if (currLoc.Y >= iMaxY)
currLoc.Y = 0;
return true;
}
protected RlColor GetRandomFireColor()
{
return rndGen.Next(3) switch
{
0 => RlColor.Red,
1 => RlColor.Yellow,
2 => RlColor.Orange,
_ => RlColor.White,
};
}
public virtual void Draw(ScreenCanvas sc, int iPictX, int iPictY)
{
DrawPolyToSC(pointsTransformed, sc, iPictX, iPictY, RlColor.White);
}
public virtual void Draw(ScreenCanvas sc, int iPictX, int iPictY, RlColor penColor)
{
DrawPolyToSC(pointsTransformed, sc, iPictX, iPictY, penColor);
}
}
}