forked from craiggoddenpayne/AgentXIII
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShip.js
142 lines (129 loc) · 4.54 KB
/
Ship.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function Ship() {
Ship.prototype = this;
return this;
}
Ship.prototype = {
Boost: false,
Health: 500,
X: 100,
Y: 200,
Up: function () {
if (Ship.prototype.Y > 10) {
Ship.prototype.Y -= 2;
if (Ship.prototype.Boost) {
Ship.prototype.Y -= 1;
Ship.prototype.Boost = false;
}
}
},
Down: function () {
if (Ship.prototype.Y < Game.prototype.Settings.ViewPort().height - 20) {
Ship.prototype.Y += 2;
if (Ship.prototype.Boost) {
Ship.prototype.Y += 1;
Ship.prototype.Boost = false;
}
}
},
Left: function () {
if (Ship.prototype.X > 50) {
Ship.prototype.X -= 2;
if (Ship.prototype.Boost) {
Ship.prototype.X -= 1;
Ship.prototype.Boost = false;
}
}
},
Right: function () {
if (Ship.prototype.X < Game.prototype.Settings.ViewPort().width - 20) {
Ship.prototype.X += 2;
if (Ship.prototype.Boost) {
Ship.prototype.X += 1;
Ship.prototype.Boost = false;
}
}
},
Tick: function () {
},
ColourTick: 0,
Render: function (context) {
//render health
var linearGradient = context.createLinearGradient(0, 0, 320, 0);
linearGradient.addColorStop(0, 'red');
linearGradient.addColorStop(1, 'lime');
context.fillStyle = linearGradient;
//health
var healthSize = (600 / 500) * Game.prototype.Ship.Health;
context.fillRect(20, 20, healthSize, 10);
context.fillStyle = "white";
context.fillStyle = "white";
context.font = "bold 14px Courier New";
context.fillText("Earth Atmospheric Defence Level", 30, 40);
context.strokeStyle = "white";
context.lineWidth = 2;
context.beginPath();
context.moveTo(20, 20);
context.lineTo(620, 20);
context.lineTo(620, 30);
context.lineTo(20, 30);
context.closePath();
context.stroke();
//render ship
var ship = Game.prototype.Ship;
switch (ship.ColourTick) {
case 0: context.strokeStyle = "purple"; break;
case 1: context.strokeStyle = "red"; break;
case 2: context.strokeStyle = "orange"; break;
case 3: context.strokeStyle = "yellow"; break;
case 4: context.strokeStyle = "blue"; break;
case 5: context.strokeStyle = "lime"; break;
case 6: context.strokeStyle = "cyan"; break;
case 7: context.strokeStyle = "white"; break;
case 8: context.strokeStyle = "brown"; break;
case 9: context.strokeStyle = "pink"; break;
}
ship.ColourTick += 1;
if (ship.ColourTick == 9)
ship.ColourTick = 0;
context.fillStyle = "purple";
context.beginPath();
context.moveTo(ship.X + 5, ship.Y - 15);
context.lineTo(ship.X + 60, ship.Y);
context.lineTo(ship.X + 5, ship.Y + 15);
context.fill();
context.lineWidth = 2;
context.stroke();
context.fillStyle = "lime";
context.beginPath();
context.moveTo(ship.X, ship.Y);
context.lineTo(ship.X, ship.Y - 5);
context.lineTo(ship.X + 20, ship.Y - 10);
context.lineTo(ship.X - 10, ship.Y - 20);
context.lineTo(ship.X + 20, ship.Y);
context.lineTo(ship.X - 10, ship.Y + 20);
context.lineTo(ship.X + 20, ship.Y + 10);
context.lineTo(ship.X, ship.Y + 5);
context.lineTo(ship.X, ship.Y);
context.fill();
context.lineWidth = 2;
context.stroke();
context.fillStyle = "red";
var colour = Math.floor((Math.random() * 2) + 1);
if (colour == 0) {
context.fillStyle = "yellow";
Ship.prototype.frame = 1;
} else if (colour == 1) {
context.fillStyle = "orange";
Ship.prototype.frame = 1;
}
context.beginPath();
context.moveTo(ship.X, ship.Y);
context.lineTo(ship.X, ship.Y - 8);
context.lineTo(ship.X - 10, ship.Y);
context.lineTo(ship.X, ship.Y + 8);
context.lineTo(ship.X, ship.Y);
context.fill();
//context.fillStyle = "blue";
//context.fillRect(ship.X - 20, ship.Y - 20, 40, 40);
}
};