-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShipBlowUpScene.cs
More file actions
104 lines (86 loc) · 2.67 KB
/
ShipBlowUpScene.cs
File metadata and controls
104 lines (86 loc) · 2.67 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
using System;
using System.Collections.Generic;
using System.Drawing;
namespace AsteroidsGdiApp.GameObjects
{
public class ShipBlowUpScene
{
private List<Line> Lines;
private List<Point> _deltas;
Random _random = new Random((int)DateTime.Now.Ticks);
public void Start(PlayerShip ship)
{
Lines = ship.Sprite.ToLineList();
CreateDeltas();
}
private void CreateDeltas()
{
_deltas = new List<Point>();
for(int i = 0; i < Lines.Count; i++)
{
Point point = new Point();
point.X = _random.Next(6) - 3;
point.Y = _random.Next(6) - 3;
_deltas.Add(point);
}
}
public void End()
{
Lines = null;
}
public void Draw(Graphics graphics)
{
if(Lines == null)
return;
UpdateLines();
graphics.DrawLine(Pens.White, Lines[0].StartPoint, Lines[0].EndPoint);
graphics.DrawLine(Pens.White, Lines[1].StartPoint, Lines[1].EndPoint);
graphics.DrawLine(Pens.White, Lines[2].StartPoint, Lines[2].EndPoint);
}
private void UpdateLines()
{
if(Lines == null)
return;
for(int i = 0; i < Lines.Count; i++)
{
Lines[i].StartPoint.X += _deltas[i].X;
Lines[i].StartPoint.Y += _deltas[i].Y;
Lines[i].EndPoint.X += _deltas[i].X;
Lines[i].EndPoint.Y += _deltas[i].Y;
}
}
}
public class ScoredPointsDisplay
{
Point _location;
Point _startLocation;
int _points;
bool _active;
public void Display(Point location, int points)
{
_active = true;
_location = location;
_points = points;
_startLocation = _location;
}
public void Draw(Graphics graphics)
{
if (IsActive())
{
string points = string.Format("{0}", _points);
Font font = new Font("Courier New", 12);
graphics.DrawString(points, font, Brushes.White, _location.X, _location.Y);
}
}
public void Update()
{
_location = new Point(_location.X, _location.Y - 2);
if (_startLocation.Y - _location.Y > 40)
_active = false;
}
private bool IsActive()
{
return _active;
}
}
}