-
Notifications
You must be signed in to change notification settings - Fork 0
/
RobotDodge.cs
142 lines (134 loc) · 3.64 KB
/
RobotDodge.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using SplashKitSDK;
using System.Collections.Generic;
public class RobotDodge
{
private PlayerLives _playerlives;
private Player _player;
private Window _gamewindow;
public int Score;
private int minimumrobots = 3;
private List<Robot> _Robots = new List<Robot>();
// private bool removerobotbool = false;
public Robot RandomRobot(Window _gamewindow)
{
int robotgenerator = SplashKit.Rnd(0, 3);
if (robotgenerator >= 2)
{
return new Boxy(_gamewindow, _player);
}
if (robotgenerator < 2 && robotgenerator >= 1)
{
return new Spooky(_gamewindow, _player);
}
if (robotgenerator < 1)
{
return new Roundy(_gamewindow, _player);
}
else
{
return null;
}
}
public void Update(Timer tmr)
{
Robot removerobot = RandomRobot(_gamewindow);
bool robotoffscreen = false;
foreach (Robot r in _Robots)
{
if (r.IsOffScreen(_gamewindow) || _player.CollidedWith(r))
{
robotoffscreen = true;
removerobot = r;
}
}
if (Convert.ToInt32(tmr.Ticks) % 50 == 0)
{
minimumrobots += 1;
// Console.WriteLine($"{minimumrobots}");
}
if (robotoffscreen)
{
_Robots.Remove(removerobot);
}
if (_Robots.Count < minimumrobots)
{
_Robots.Add(RandomRobot(_gamewindow));
}
foreach (Robot r in _Robots)
{
r.Draw();
r.Update();
}
if (_player._bullet is Bullet)
{
_player._bullet.Update();
}
BulletInteractions();
}
public RobotDodge(Window w, Player p, PlayerLives plrlives)
{
_gamewindow = w;
_player = p;
_Robots.Add(RandomRobot(_gamewindow));
_playerlives = plrlives;
}
public void BulletInteractions()
{
// Robot robotcollision = RandomRobot(_gamewindow);
if (_player._bullet is Bullet)
{
foreach (Robot r in _Robots)
{
if (_player._bullet.CollidedWith(r))
{
_player._bullet.bulletcollision = true;
// removerobotbool = true;
// robotcollision = r;
_player._bullet = null;
_Robots.Remove(r);
return;
}
else
{
_player._bullet.bulletcollision = false;
}
}
if (_player._bullet.bulletoffscreen)
{
_player._bullet = null;
// Console.WriteLine("Bullet is offscreen");
}
}
}
public void Collision()
{
foreach (Robot r in _Robots)
{
if (_player.CollidedWith(r))
{
_playerlives.Life -= 1;
}
}
}
public void PrintScore(Window _gamewindow, Timer tmr)
{
Font font = new Font("Roboto", "Roboto-Regular.ttf");
Score = Convert.ToInt32(tmr.Ticks / 1000);
_gamewindow.DrawText($"SCORE: {Convert.ToString(Score)}", Color.Black, font, 11, _gamewindow.Width - 60, 70);
}
public void Draw(Window playerwindow)
{
playerwindow.Clear(Color.White);
foreach (Robot r in _Robots)
{
r.Draw();
}
_player.Draw();
_playerlives.Draw();
if (_player._bullet is Bullet)
{
_player._bullet.Draw();
}
}
}