-
Notifications
You must be signed in to change notification settings - Fork 0
/
Room.cs
183 lines (164 loc) · 4.25 KB
/
Room.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
using System.Linq;
using NHTI.GameObjects;
using Punk;
using System;
using System.Threading;
using System.Collections.Generic;
using GameObjects;
using NHTI.Entities;
using Punk.Graphics;
using Punk.Utils;
using SFML.Window;
using System.IO;
namespace NHTI
{
public enum HatType
{
Random,
NoHat,
TopHat,
WWIHat,
Trophy,
CatEars,
Ninja,
Tiara,
Raiden,
Banana,
Key,
Device,
Fez,
Dunce,
Bow
}
public enum BackGrounds
{
Mountain,
Arctic,
Space,
Boss
}
/// <summary>
/// Description of Room.
/// </summary>
public class Room : World
{
public Entity[] currentEnts;
public List<Entity> Doors = new List<Entity>();
public Dictionary<Entity, Entity[]> Rooms = new Dictionary<Entity, Entity[]>();
Thread roomLoader;
public Player player;
bool isFirst = true;
public bool RoomsAreLoading = true;
public int enterDoor;
public Door startDoor;
public Cursor cursor;
public Sfx musics;
public string[] backgrounds = new string[] {"assets/Scene1.png", "assets/Scene1.png", "assets/Scene1.png", "assets/Scene1.png", "assets/Scene2.png", "assets/Scene2.png", "assets/Scene2.png", "assets/Scene3.png", "assets/Scene3.png", "assets/Scene3.png", "assets/Scene4.png"};
public Room()
{
foreach (string file in Directory.EnumerateFiles("assets/Levels/", "*.oel"))
{
FP.Log("PreloadingXML");
Library.GetXml(file);
}
Library.GetBuffer("assets/Bossedd.ogg");
roomLoader = new Thread(LoadRooms);
roomLoader.IsBackground = true;
RegisterClass<wallColTile>("wallCollision");
RegisterClass<Platform>("platform");
RegisterClass<GfxTile>("wallGfx");
RegisterClass<Door>("door");
RegisterClass<PlayerSpawn>("playerSpawn");
RegisterClass<GroundEnemy>("groundEnemy");
RegisterClass<TextObj>("textObj");
RegisterClass<FlyingEnemy>("flyingEnemy");
RegisterClass<Chest>("chest");
RegisterClass<Boss>("bossSpawn");
RegisterClass<BackDrop>("backDrop");
AddList(currentEnts = BuildWorldAsArray("assets/Levels/Level01.oel"));
Add(cursor = new Cursor());
musics = new Sfx(Library.GetBuffer("assets/Preview2.ogg"));
}
public override void Begin()
{
base.Begin();
musics.Loop();
}
public override void Update()
{
base.Update();
if(isFirst)
{
GetType("Door", Doors);
roomLoader.Start();
isFirst = false;
List<Entity> l = new List<Entity>();
Add(player = new Player(300, 300, 1));
GetType("PlayerSpawn",l);
//FP.Log(l[0].);
player.X = l[0].X + player.HalfWidth;
player.Y = l[0].Y + player.HalfHeight;
}
if(Input.Down(Keyboard.Key.Escape))
FP.Screen.Close();
if(Input.Down(Keyboard.Key.PageDown))
Camera.Zoom -= 1*FP.Elapsed;
else if(Input.Down(Keyboard.Key.PageUp))
Camera.Zoom += 1*FP.Elapsed;
//FP.Log(roomLoader.IsAlive);
FP.Engine.ClearColor = FP.Color(0x123410);
}
public void NextRoom(Door d)
{
//
enterDoor = d.DoorLink;
if(d.RoomLink != "")
{
RemoveAll();
currentEnts = Rooms[d];
AddList(currentEnts);
Add(player);
Add(cursor);
Doors.Clear();
Rooms.Clear();
Doors = currentEnts.ToList().FindAll(e => e is Door);
roomLoader = new Thread(LoadRooms);
roomLoader.IsBackground = true;
roomLoader.Start();
}
var door = Doors.Find( e => (e as Door).DoorNum == enterDoor) as Door;
if(door.face == DoorFace.Left)
{
player.X = door.Left - player.HalfWidth;
player.Y = door.Bottom;
}
else if(door.face == DoorFace.Right)
{
player.X = door.Right + player.HalfWidth;
player.Y = door.Bottom;
}
else if(door.face == DoorFace.Up)
{
player.X = door.HalfWidth;
player.Y = door.Top;
}
else if(door.face == DoorFace.Down)
{
player.X = door.X + door.HalfWidth;
player.Y = door.Bottom + player.Height;
}
}
public void LoadRooms()
{
RoomsAreLoading = true;
foreach(Entity d in Doors)
{
if((d as Door).RoomLink != "")
{
Rooms.Add(d, BuildWorldAsArray("assets/Levels/" + (d as Door).RoomLink + ".oel"));
}
}
RoomsAreLoading = false;
}
}
}