-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathScore.cs
More file actions
157 lines (126 loc) · 3.85 KB
/
Score.cs
File metadata and controls
157 lines (126 loc) · 3.85 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
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
using System;
using SplashKitSDK;
using System.Collections.Generic;
using static AsteroidsGame.Program;
public abstract class Score
{
protected SplashKitSDK.Timer _ScoreTimer;
//protected List<Bitmap> _LivesBitmap = new List<Bitmap>();
protected Bitmap _LivesBitmap;
protected Window _GameWindow;
public int Lives { get; private set; }
public bool IsDead { get; private set; }
protected int _PScore;
public string Name { get; protected set; }
public int CurrentScore
{
get { return _PScore; }
}
public Score(Window gameWindow, string player)
{
Lives = 5;
/* for (int i = 0; i < Lives; i++)
{
_LivesBitmap.Add(new Bitmap($"Lives {i}", "images/heart.png"));
} */
_ScoreTimer = new SplashKitSDK.Timer($"{player} Timer");
if (SplashKit.HasBitmap("Lives"))
{
_LivesBitmap = SplashKit.BitmapNamed("Lives");
}
else
{
_LivesBitmap = SplashKit.LoadBitmap("Lives", "heart.png");
}
_GameWindow = gameWindow;
_ScoreTimer.Start();
IsDead = false;
Name = player;
}
public void StartTimer()
{
_ScoreTimer.Start();
}
public void PauseTimer()
{
_ScoreTimer.Pause();
}
public bool isTimerPaused()
{
return _ScoreTimer.IsPaused;
}
public void ResumeTimer()
{
_ScoreTimer.Resume();
}
public abstract void Draw();
public bool DownLife()
{
//Returns true once no live are left
Lives -= 1;
if (Lives == 0)
{
_ScoreTimer.Pause();
IsDead = true;
return true;
}
return false;
}
public void ScoreUp(int Amount)
{
_PScore += Amount;
}
}
public class Player1Score : Score
{
public Player1Score(Window gameWindow, string Player) : base(gameWindow, Player) { }
public override void Draw()
{
int LivesOffset = (int)(40 * gameScale);
int ScoreOffsetX = (int)(5 * gameScale);
int ScoreOffsetY = (int)(40 * gameScale);
int Scoretmp = Convert.ToInt32(_ScoreTimer.Ticks / 1000);
int FontSize = (int)(40 * gameScale);
Scoretmp += _PScore;
if (IsDead)
{
SplashKit.DrawTextOnWindow(_GameWindow, "Game Over", Color.White, "pricedown_bl.otf", FontSize, 0, 0);
}
else
{
for (int i = 0; i < Lives; i++)
{
_LivesBitmap.Draw(LivesOffset * (i), 0);
}
}
SplashKit.DrawTextOnWindow(_GameWindow, Scoretmp.ToString("D6"), Color.White, "pricedown_bl.otf", FontSize, ScoreOffsetX, 0 + ScoreOffsetY);
}
}
public class Player2Score : Score
{
public Player2Score(Window gameWindow, string Player) : base(gameWindow, Player)
{
}
public override void Draw()
{
int LivesOffset = (int)(40 * gameScale);
int ScoreOffsetX = (int)(130 * gameScale);
int ScoreOffsetY = (int)(40 * gameScale);
int Scoretmp = Convert.ToInt32(_ScoreTimer.Ticks / 1000);
int FontSize = (int)(40 * gameScale);
Scoretmp += _PScore;
if (IsDead)
{
SplashKit.DrawTextOnWindow(_GameWindow, "Game Over", Color.White, "pricedown_bl.otf", FontSize, _GameWindow.Width - (190 * gameScale), 0);
}
else
{
for (int i = 0; i < Lives; i++)
{
_LivesBitmap.Draw(_GameWindow.Width - LivesOffset * (i + 1), 0);
}
}
SplashKit.DrawTextOnWindow(_GameWindow, Scoretmp.ToString("D6"), Color.White, "pricedown_bl.otf", FontSize, _GameWindow.Width - ScoreOffsetX, 0 + ScoreOffsetY);
}
}
//Credit for heart assest 'NicoleMarieProductions' https://opengameart.org/content/heart-1616