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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ShiftOS
{
public partial class CreditScroller : Form
{
public CreditScroller()
{
InitializeComponent();
}
#region pong visualizer variables
bool pongVisible = false;
Random rand = new Random();
int xVel = 7;
int yVel = 8;
int computerspeed = 8;
int level = 1;
int secondsleft = 60;
int casualposition;
double xveldec = 3.0;
double yveldec = 3.0;
double incrementx = 0.4;
double incrementy = 0.2;
int levelxspeed = 3;
int levelyspeed = 3;
int beatairewardtotal;
int beataireward = 1;
int[] levelrewards = new int[50];
int countdown = 3;
#endregion
int offset = 0;
private void tmrredraw_Tick(object sender, EventArgs e)
{
pgcontents.Visible = pongVisible;
lbcreditstext.Top = pnlscroll.Height - offset;
if(pongVisible)
lbcreditstext.Left = (pnlscroll.Width - lbcreditstext.Width);
else
lbcreditstext.Left = (pnlscroll.Width - lbcreditstext.Width) / 2;
offset += 1;
}
private void CreditScroller_Load(object sender, EventArgs e)
{
Audio.Play("hackerbattle_ambient");
tmrredraw.Interval = 50;
lbcreditstext.Text = Properties.Resources.Credits.Replace("#VER#", Consts.Version);
tmrredraw.Start();
newgame();
}
private void btnclose_Click(object sender, EventArgs e)
{
this.Close();
}
private void pongGameTimer_Tick(object sender, EventArgs e)
{
//Move player according to ball
if(ball.Left < 250 + xVel / 10 && xVel < 0)
{
if(ball.Top > paddleHuman.Top + 50)
{
paddleHuman.Top += computerspeed * 2 + ((int)yveldec / 2);
}
else if(ball.Top < paddleHuman.Top + 50)
{
paddleHuman.Top -= computerspeed * 2 + ((int)yveldec / 2);
}
}
//Set the computer player to move according to the ball's position.
if (ball.Location.X > 500 - xVel * 10 && xVel > 0)
{
if (ball.Location.Y > paddleComputer.Location.Y + 50)
{
paddleComputer.Location = new Point(paddleComputer.Location.X, paddleComputer.Location.Y + computerspeed * 2 + ((int)yveldec / 2));
}
if (ball.Location.Y < paddleComputer.Location.Y + 50)
{
paddleComputer.Location = new Point(paddleComputer.Location.X, paddleComputer.Location.Y - computerspeed * 2 + ((int)yveldec / 2));
}
casualposition = rand.Next(-150, 201);
}
//Set Xvel and Yvel speeds from decimal
if (xVel > 0)
xVel = (int)Math.Round(xveldec);
if (xVel < 0)
xVel = (int)-Math.Round(xveldec);
if (yVel > 0)
yVel = (int)Math.Round(yveldec);
if (yVel < 0)
yVel = (int)-Math.Round(yveldec);
// Move the game ball.
ball.Location = new Point(ball.Location.X + xVel, ball.Location.Y + yVel);
// Check for top wall.
if (ball.Location.Y < 0)
{
ball.Location = new Point(ball.Location.X, 0);
yVel = -yVel;
}
// Check for bottom wall.
if (ball.Location.Y > pgcontents.Height - ball.Height)
{
ball.Location = new Point(ball.Location.X, pgcontents.Height - ball.Size.Height);
yVel = -yVel;
}
// Check for player paddle.
if (ball.Bounds.IntersectsWith(paddleHuman.Bounds))
{
ball.Location = new Point(paddleHuman.Location.X + ball.Size.Width, ball.Location.Y);
//randomly increase x or y speed of ball
switch (rand.Next(1, 3))
{
case 1:
xveldec = xveldec + incrementx;
break;
case 2:
if (yveldec > 0)
yveldec = yveldec + incrementy;
if (yveldec < 0)
yveldec = yveldec - incrementy;
break;
}
xVel = -xVel;
}
// Check for computer paddle.
if (ball.Bounds.IntersectsWith(paddleComputer.Bounds))
{
ball.Location = new Point(paddleComputer.Location.X - paddleComputer.Size.Width + 1, ball.Location.Y);
xveldec = xveldec + incrementx;
xVel = -xVel;
}
// Check for left wall.
if (ball.Location.X < -100)
{
ball.Location = new Point(pgcontents.Size.Width / 2 + 200, pgcontents.Size.Height / 2);
paddleComputer.Location = new Point(paddleComputer.Location.X, ball.Location.Y);
paddleHuman.Location = new Point(paddleHuman.Location.X, ball.Location.Y);
if (xVel > 0)
xVel = -xVel;
pongGameTimer.Stop();
tmrcountdown.Start();
counter.Stop();
}
// Check for right wall.
if (ball.Location.X > pgcontents.Width - ball.Size.Width - paddleComputer.Width + 100)
{
ball.Location = new Point(pgcontents.Size.Width / 2 + 200, pgcontents.Size.Height / 2);
paddleComputer.Location = new Point(paddleComputer.Location.X, ball.Location.Y);
paddleHuman.Location = new Point(paddleHuman.Location.X, ball.Location.Y);
if (xVel > 0)
xVel = -xVel;
beatairewardtotal = beatairewardtotal + beataireward;
tmrcountdown.Start();
pongGameTimer.Stop();
counter.Stop();
}
//lblstats.Text = "Xspeed: " & Math.Abs(xVel) & " Yspeed: " & Math.Abs(yVel) & " Human Location: " & paddleHuman.Location.ToString & " Computer Location: " & paddleComputer.Location.ToString & Environment.NewLine & " Ball Location: " & ball.Location.ToString & " Xdec: " & xveldec & " Ydec: " & yveldec & " Xinc: " & incrementx & " Yinc: " & incrementy
lblstatsX.Text = "Xspeed: " + xveldec;
lblstatsY.Text = "Yspeed: " + yveldec;
lbllevelandtime.Text = "Level: " + level;
if (xVel > 20 || xVel < -20)
{
paddleHuman.Width = Math.Abs(xVel);
paddleComputer.Width = Math.Abs(xVel);
}
else
{
paddleHuman.Width = 20;
paddleComputer.Width = 20;
}
computerspeed = Math.Abs(yVel);
// pgcontents.Refresh()
// pgcontents.CreateGraphics.FillRectangle(Brushes.Black, ball.Location.X, ball.Location.Y, ball.Width, ball.Height)
}
private void counter_Tick(object sender, EventArgs e)
{
secondsleft = secondsleft - 1;
if (secondsleft == -1)
{
secondsleft = 60;
level = level + 1;
}
}
private void tmrcountdown_Tick(object sender, EventArgs e)
{
switch (countdown)
{
case 0:
countdown = 3;
lblcountdown.Hide();
pongGameTimer.Start();
counter.Start();
tmrcountdown.Stop();
break;
case 1:
lblcountdown.Text = "1";
countdown = countdown - 1;
break;
case 2:
lblcountdown.Text = "2";
countdown = countdown - 1;
break;
case 3:
lblcountdown.Text = "3";
countdown = countdown - 1;
lblcountdown.Show();
break;
}
}
private void newgame()
{
level = 1;
beataireward = 2;
beatairewardtotal = 0;
secondsleft = 60;
//reset stats text
lblstatsX.Text = "Xspeed: ";
lblstatsY.Text = "Yspeed: ";
levelxspeed = 3;
levelyspeed = 3;
incrementx = 0.4;
incrementy = 0.2;
xveldec = levelxspeed;
yveldec = levelyspeed;
tmrcountdown.Start();
if (xVel < 0)
xVel = Math.Abs(xVel);
lbllevelandtime.Text = "Level: " + level + " - " + secondsleft + " Seconds Left";
}
}
}
|