1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.Text; |
---|
5 | using Jypeli; |
---|
6 | using MathHelper; |
---|
7 | |
---|
8 | namespace Rooms |
---|
9 | { |
---|
10 | abstract class Room |
---|
11 | { |
---|
12 | public Vector Position { get; set; } |
---|
13 | public double width, height, thickness; |
---|
14 | private List<IPhysicsObject> roomObjects = new List<IPhysicsObject>(); |
---|
15 | private bool isBuilt = false; |
---|
16 | public Game Game { get; set; } |
---|
17 | |
---|
18 | public Room(Game game, Vector pos, Vector size, double thickness) |
---|
19 | { |
---|
20 | Game = game; |
---|
21 | Position = pos; |
---|
22 | width = size.X; |
---|
23 | height = size.Y; |
---|
24 | this.thickness = thickness; |
---|
25 | } |
---|
26 | |
---|
27 | public abstract void initRoom(); |
---|
28 | |
---|
29 | public void buildLevel() |
---|
30 | { |
---|
31 | if (roomObjects.Count == 0) throw new Exception("Cannot build empty room!"); |
---|
32 | |
---|
33 | foreach (IPhysicsObject obj in roomObjects) |
---|
34 | { |
---|
35 | Game.Add(obj); |
---|
36 | } |
---|
37 | |
---|
38 | isBuilt = true; |
---|
39 | } |
---|
40 | |
---|
41 | public void destroyLevel() |
---|
42 | { |
---|
43 | if (roomObjects.Count == 0) throw new Exception("Cannot destory empty room!"); |
---|
44 | if (!isBuilt) throw new Exception("Cannot destroy unbuilt room!"); |
---|
45 | |
---|
46 | foreach (IPhysicsObject obj in roomObjects) |
---|
47 | { |
---|
48 | obj.Destroy(); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | public void createBorders() |
---|
53 | { |
---|
54 | PhysicsObject wallTop = createWall(Position, width, thickness); |
---|
55 | PhysicsObject wallLeft = createWall(VecMath.sub(Position, new Vector(0, thickness)), thickness, height); |
---|
56 | PhysicsObject wallDown = createWall(VecMath.sub(Position, new Vector(0, height)), width, thickness); |
---|
57 | PhysicsObject wallRight = createWall(VecMath.add(Position, new Vector(width, 0)), thickness, height); |
---|
58 | roomObjects.Add(wallTop); |
---|
59 | roomObjects.Add(wallLeft); |
---|
60 | roomObjects.Add(wallDown); |
---|
61 | roomObjects.Add(wallRight); |
---|
62 | } |
---|
63 | |
---|
64 | public PhysicsObject createWall(Vector pos, double width, double height) |
---|
65 | { |
---|
66 | PhysicsObject wall = PhysicsObject.CreateStaticObject(width, height); |
---|
67 | wall.Left = pos.X; |
---|
68 | wall.Top = pos.Y; |
---|
69 | |
---|
70 | return wall; |
---|
71 | } |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | class RoomTemplates |
---|
76 | { |
---|
77 | |
---|
78 | } |
---|
79 | } |
---|