-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel.cs
209 lines (190 loc) · 7.69 KB
/
Level.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
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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Text;
namespace Platformer_Game
{
public class Level
{
public bool Unlocked;
public bool Completed;
public Vector2 Finish_Point;
public int Id;
public Rectangle Window;
private Player Player;
public List<Platform> Platforms;
private List<Wall> Walls;
private List<Spike> Spikes;
private List<Lava> Lavas;
private List<Particle> Particles = new List<Particle>();
private List<Key> Keys = new List<Key>();
public Rectangle Player_Edge;
public Level(bool unlocked, bool completed, int id, Rectangle window, Vector2 finish_point, Player player, List<Platform> platforms, List<Wall> walls, List<Spike> spikes, List<Lava> lavas, Texture2D spriteSheet)
{
float w_ratio = 1;
float h_ratio = 1;
Unlocked = unlocked;
Completed = completed;
Id = id;
Window = window;
Player = player;
Platforms = platforms;
Walls = walls;
Spikes = spikes;
Lavas = lavas;
Finish_Point = new Vector2(finish_point.X * w_ratio, finish_point.Y * h_ratio);
foreach (Wall wall in walls)
{
if (!wall.Destructible)
{
Platforms.Add(new Platform(spriteSheet, new Vector2((wall.Position.X / w_ratio) - 1, (wall.Position.Y / h_ratio)), (wall.Width / w_ratio) - (float)0.25, (float)(7) / h_ratio));
}
}
for (int i = 0; i < walls.Count; i++)
{
walls[i].Position.Y += 7;
walls[i].Height -= 7;
}
foreach (Spike spike in spikes)
{
Platforms.Add(new Platform(spriteSheet, new Vector2(spike.Position.X / w_ratio, (spike.Position.Y + 10) / h_ratio), (float)spike.Length / w_ratio, 20));
}
}
public Level(bool unlocked, bool completed, int id, Rectangle window, Vector2 finish_point, Player player, List<Platform> platforms, List<Wall> walls, List<Spike> spikes, List<Lava> lavas, List<Key> keys, Texture2D spriteSheet)
{
float w_ratio = 1;
float h_ratio = 1;
Unlocked = unlocked;
Completed = completed;
Id = id;
Window = window;
Player = player;
Platforms = platforms;
Walls = walls;
Spikes = spikes;
Lavas = lavas;
Keys = keys;
Finish_Point = new Vector2(finish_point.X * w_ratio, finish_point.Y * h_ratio);
foreach (Wall wall in walls)
{
if (!wall.Destructible)
{
Platforms.Add(new Platform(spriteSheet, new Vector2((wall.Position.X / w_ratio) - 1, (wall.Position.Y / h_ratio)), (wall.Width / w_ratio) - (float)0.25, (float)(7) / h_ratio, wall.Colour));
}
}
for (int i = 0; i < walls.Count; i++)
{
walls[i].Position.Y += 7;
walls[i].Height -= 7;
}
foreach (Spike spike in spikes)
{
Platforms.Add(new Platform(spriteSheet, new Vector2(spike.Position.X / w_ratio, (spike.Position.Y + 10) / h_ratio), (float)spike.Length / w_ratio, 20));
}
}
public bool Update(GameTime gameTime)
{
Player.Update(gameTime, Platforms, Particles, Walls, Spikes, Lavas, Window.Height);
if (Player.Living_State == "dead")
{
Particles = new List<Particle>();
for (int i = 0; i < Platforms.Count; i++)
{
if (Platforms[i].Flashing || Platforms[i].Weak)
{
Platforms[i].Ticks = 0;
Platforms[i].Appear = Platforms[i].Start_Appear;
Platforms[i].Touched = false;
}
if (Platforms[i].Moving)
{
Platforms[i].Position = Platforms[i].Start_Position;
Platforms[i].Destination = Platforms[i].Start_Destination;
}
}
for (int i = 0; i < Walls.Count; i++)
{
if (Walls[i].Destructible)
{
Walls[i].Parts = new List<Rectangle>();
for (int x = (int)Walls[i].Position.X; x < (int)(Walls[i].Position.X + Walls[i].Width); x += 9)
{
for (int y = (int)Walls[i].Position.Y; y < (int)(Walls[i].Position.Y + Walls[i].Height); y += 9)
{
Walls[i].Parts.Add(new Rectangle(x, y, 9, 9));
}
}
}
}
for (int i = 0; i < Keys.Count; i++)
{
Keys[i].Position = Keys[i].Start_Position;
Keys[i].Width = 20;
Keys[i].Height = 20;
Player.Inventory.Remove(Keys[i].Colour);
}
}
Player_Edge = new Rectangle((int)Player.Position.X, (int)Player.Position.Y, (int)Player.Width, (int)Player.Height);
if (Player_Edge.Contains(Finish_Point))
{
Particles = new List<Particle>();
Player.Position = Player.Start_Position;
Player.Velocity = new Vector2(0, 0);
return true;
}
foreach (Platform platform in Platforms)
{
platform.Update(gameTime);
}
foreach (Particle particle in Particles)
{
particle.Update(gameTime, Platforms, Particles, Walls, Lavas);
}
foreach (Key key in Keys)
{
key.Update(gameTime, Player, Platforms, Particles, Walls, Lavas);
}
return false;
}
public void Draw(SpriteBatch spriteBatch, GameTime gameTime, Texture2D spriteSheet)
{
foreach (Platform platform in Platforms)
{
platform.Draw(spriteBatch, gameTime);
}
foreach (Spike spike in Spikes)
{
spike.Draw(spriteBatch, gameTime);
}
foreach (Wall wall in Walls)
{
wall.Draw(spriteBatch, gameTime);
}
foreach (Lava lava in Lavas)
{
lava.Draw(spriteBatch, gameTime);
}
Player.Draw(spriteBatch, gameTime);
foreach (Particle particle in Particles)
{
particle.Draw(spriteBatch, gameTime);
}
foreach (Key key in Keys)
{
key.Draw(spriteBatch, gameTime);
}
Particle finish_point = new Particle(spriteSheet, Finish_Point, new Vector2(0, 0), 0, Color.White);
finish_point.Draw(spriteBatch, gameTime);
finish_point.Position.X += finish_point.Width;
finish_point.Colour = Color.Black;
finish_point.Draw(spriteBatch, gameTime);
finish_point.Position.Y += finish_point.Width;
finish_point.Colour = Color.White;
finish_point.Draw(spriteBatch, gameTime);
finish_point.Position.X -= finish_point.Width;
finish_point.Colour = Color.Black;
finish_point.Draw(spriteBatch, gameTime);
}
}
}