-
Notifications
You must be signed in to change notification settings - Fork 0
/
Level.cs
188 lines (172 loc) · 7.14 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Storage;
namespace PyramidPanic
{
public class Level
{
//fields
private PyramidPanic game;
private List<string> lines;
private Tile[,] tiles;
private Image background;
private string levelPath;
private Explorer explorer;
private Panel panel;
private List<Scorpion> scorpionList;
private List<Beetle> beetleList;
private List<Image> treasures;
private const int GRIDWIDTH = 32;
private const int GRIDHEIGHT = 32;
public List<Beetle> BeetleList
{
get { return this.beetleList; }
}
public List<Scorpion> ScorpionList
{
get { return this.scorpionList; }
}
public Tile[,] Tiles
{
get { return this.tiles; }
}
public List<Image> Treasures
{
get { return this.treasures; }
set { this.treasures = value; }
}
//construction
public Level(PyramidPanic game,int levelIndex)
{
this.game = game;
this.levelPath = @"Content\PlaySceneAssets\Levels\"+levelIndex+".txt";
this.loadAssets();
Score.initialize();
}
private void loadAssets()
{
this.lines = new List<string>();
this.treasures = new List<Image>();
this.scorpionList = new List<Scorpion>();
this.beetleList = new List<Beetle>();
this.panel = new Panel(this.game, new Vector2(0, 448));
StreamReader reader = new StreamReader(this.levelPath);
string line = reader.ReadLine();
int width = line.Length;
while(line != null)
{
lines.Add(line);
line = reader.ReadLine();
}
int height = lines.Count;
this.tiles = new Tile[width, height];
reader.Close();
for (int row = 0; row < height; row++)
{
for (int column = 0; column < width; column++)
{
char blockElement = this.lines[row][column];
this.tiles[column, row] = loadTile(blockElement, column * GRIDWIDTH, row * GRIDHEIGHT);
}
}
BeetleManager.Level = this;
ScorpionManager.Level = this;
ExplorerManager.Level = this;
}
private Tile loadTile(char blockElement, int x , int y)
{
switch (blockElement)
{
case 'B':
this.beetleList.Add(new Beetle(this.game, new Vector2(x, y), 2.0f));
return new Tile(this.game, @"Transparant", new Vector2(x, y), TileCollision.Passable, 'b');
case 'E':
this.explorer = new Explorer(this.game,new Vector2(x,y),2.5f);
return new Tile(this.game, @"Transparant", new Vector2(x, y), TileCollision.Passable, 'E');
case 'S':
this.scorpionList.Add(new Scorpion(this.game, new Vector2(x, y), 2.0f));
return new Tile(this.game, @"Transparant", new Vector2(x, y), TileCollision.Passable, 's');
case 'a':
this.treasures.Add(new Treasure('a',this.game, new Vector2(x, y),@"PlaySceneAssets\pickups\Scarab"));//scarab
return new Tile(this.game, @"transparant", new Vector2(x, y), TileCollision.Passable, 'a');
case 'b':
this.treasures.Add(new Treasure('b',this.game, new Vector2(x, y), @"PlaySceneAssets\pickups\Potion"));//potions
return new Tile(this.game, @"transparant", new Vector2(x, y), TileCollision.Passable, 'b');
case 'c':
this.treasures.Add(new Treasure('c',this.game, new Vector2(x, y), @"PlaySceneAssets\pickups\Treasure2"));//cat
return new Tile(this.game, @"transparant", new Vector2(x, y), TileCollision.Passable, 'c');
case 'd':
this.treasures.Add(new Treasure('d',this.game, new Vector2(x, y), @"PlaySceneAssets\pickups\Treasure1"));//ankh
return new Tile(this.game, @"transparant", new Vector2(x, y), TileCollision.Passable, 'd');
case '@':
this.background = new Image(this.game, new Vector2(x,y),@"PlaySceneAssets\background\Background2");
return new Tile(this.game, @"Wall2", new Vector2(x, y), TileCollision.Notpassable, '@');
case 'x':
return new Tile(this.game, @"Wall1", new Vector2(x, y), TileCollision.Notpassable, 'x');
case 'y':
return new Tile(this.game, @"Wall2", new Vector2(x, y), TileCollision.Notpassable, 'y');
case 'w':
return new Tile(this.game,@"Block",new Vector2(x,y),TileCollision.Notpassable,'w');
case '.':
return new Tile(this.game,@"transparant", new Vector2(x,y),TileCollision.Passable,'.');
case 'D':
return new Tile(this.game, @"Door", new Vector2(x, y), TileCollision.Passable, 'd');
default:
return new Tile(this.game, @"transparant", new Vector2(x, y), TileCollision.Passable, '.');
}
}
public void update(GameTime gametime)
{
foreach (Scorpion scorpion in this.scorpionList)
{
scorpion.Update(gametime);
}
foreach (Beetle beetle in this.beetleList)
{
beetle.Update(gametime);
}
if (this.explorer != null)
{
this.explorer.Update(gametime);
}
panel.update(gametime);
}
public void draw(GameTime gametime)
{
this.background.Draw(gametime);
this.panel.Draw(gametime);
for (int row = 0; row < this.tiles.GetLength(1); row++)
{
for (int column = 0; column < this.tiles.GetLength(0); column++)
{
this.tiles[column,row].draw(gametime);
}
}
foreach (Scorpion scorpion in this.scorpionList)
{
scorpion.Draw(gametime);
}
foreach (Beetle beetle in this.beetleList)
{
beetle.Draw(gametime);
}
foreach (Image image in this.treasures)
{
image.Draw(gametime);
}
if (this.explorer != null)
{
this.explorer.Draw(gametime);
}
}
}
}