forked from dasuxullebt/rapunzel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainScene.js
153 lines (125 loc) · 4.94 KB
/
MainScene.js
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
var printWorld = function(w = world) {
for(var x = 0; x < world.grid.length; ++x)
for(var y = 0; y < world.grid[x].length; ++y)
{
console.log("x = " + x + ", " + "y = " + y);
console.log(world.grid[x][y]);
for(var i = 0; i < world.grid[x][y].entities.length; ++i)
console.log(world.grid[x][y].entities[i]);
}
for(var i = 0; i < world.players.length; ++i)
{
console.log("Player: id=" + i);
console.log(world.players[i]);
}
}
var printMap = function(w = world) {
console.log("---------------------------------------------------------------------");
rows = "";
for (var y = 0; y < world.size.y; y++)
{
row = "(";
for (var x = 0; x < world.size.x; x++)
{
for (var i = 0; i < world.grid[x][y].entities.length; i++)
{
row += "," + world.grid[x][y].entities[i].type[0] + "";
}
if(world.players[0].tile.position.x == x && world.players[0].tile.position.y == y)
{
row += ",p";
}
row += ")\t(";
}
rows += row + ")\n";
}
console.log(rows);
console.log("---------------------------------------------------------------------");
}
//Anzeige der Spielwelt
var tile_height = 50;
var tile_width = 50;
var levelName = "test";
var world, mainScene;
game.module('game.game').body(function() //this is Pandajs feature
{
loadAssets(); //Look further down
var lr = new LevelReader();
mainScene = game.createScene('Game',
{
init: function()
{
this.world = lr.byFileName(levelName);
world = this.world;
this.display = new Display();
this.display.init(this.world);
this.input = new Input(this, this.world);
},
update: function()
{
if (world.levelFinished)
{
this.display.destroyStuff();
if (world.nextLevel)
{
levelName = world.nextLevel;
console.log("Level finished\n" + "Now playing " + levelName);
this.init();
}
else
{
console.log("Game Finished");
game.system.setScene('Main');
}
}
if (this.world.levelRestart)
{
console.log("Level restarted");
world = lr.byFileName(levelName);
this.init()
}
this.world.update();
this.display.update();
},
keydown: function(event)
{
//alert (event.toString() == "LEFT");
this.input.moveEvent(event);
}
});
});
loadAssets = function()
{
sprites = new Array( 'Wall','WallLeft','WallRight','WallUp','WallDown',
'WallLeftRight','WallUpDown','WallLeftDown',
'WallLeftUp','WallRightDown','WallRightUp',
'WallLeftRightUp','WallLeftRightDown',
'WallLeftUpDown','WallRightUpDown','WallLeftRightUpDown');
for (var i = 0; i < sprites.length; i++)
{
game.addAsset('sprites/Wall/' + sprites[i] + '.png', sprites[i]);
}
game.addAsset('sprites/Floor/floor.png', 'Floor');
game.addAsset('sprites/empty.png', 'Empty');
game.addAsset('sprites/Floor/exit.png', 'Exit');
game.addAsset('sprites/Player/player1.png', 'Player1');
game.addAsset('sprites/Player/player2.png', 'Player2');
game.addAsset('sprites/Player/gravestone.png', 'Player_Dead');
game.addAsset('sprites/Floor/Portal2.png', 'Portal');
game.addAsset('sprites/Floor/Portal3.png', 'DirectedPortal');
game.addAsset('sprites/Entities/bigbox.png', 'BigBox');
game.addAsset('sprites/Floor/doorclosed.png', 'Floor');
game.addAsset('sprites/Floor/dooropen.png', 'Door_Open');
game.addAsset('sprites/Floor/doorclosed.png', 'Door_Closed');
game.addAsset('sprites/Floor/DirectedPortal.png', 'DirectedPortal');
game.addAsset('sprites/Floor/platedefault.png', 'PressurePlate_notPressed');
game.addAsset('sprites/Floor/platelocked.png', 'PressurePlate_deactivated');
game.addAsset('sprites/Floor/platepressed.png', 'PressurePlate_Pressed');
game.addAsset('sprites/Entities/ice.png', 'ice');
game.addAsset('sprites/Entities/Lazor.png', 'LazorBeam');
game.addAsset('sprites/Entities/statueprototype.png', 'LazorEmitter');
game.addAsset('sprites/Entities/statueblueball.png', 'LazorReceiver');
game.addAsset('sprites/coloredTiles/RedTile.png', 'LazorMirror');
game.addAsset('sprites/Entities/Mirror1.png', 'Mirror1');
game.addAsset('sprites/Entities/Mirror2.png', 'Mirror2');
}