-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
144 lines (127 loc) · 3.29 KB
/
app.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
const STATUS_CODE_ERROR = -1
const STATUS_CODE_SUCCESS = 0
const STATUS_CODE_OK = 1
const TICK_DEACTIVE = 0
const TICK_ACTIVE = 1
const mapMock = {
Tracks: [
{
Name: 'Laufen',
Action: 'move', // move, jump, ...
Sound: 'kick', // hat, clap...
Show: true
// Pattern: [0,1,0,0,0,1,...] // optional
},
{
Name: 'Drehen',
Action: 'turnright', // move, jump, ...
Sound: 'openhat', // hat, clap...
Show: true
// Pattern: [0,1,0,0,0,1,...] // optional
},
{
Name: 'Warten',
Action: 'wait', // move, jump, ...
Sound: 'openhat2', // hat, clap...
Show: true
// Pattern: [0,1,0,0,0,1,...] // optional
},
{
Name: 'Lava',
Action: 'lava', // move, jump, ...
Sound: 'none', // hat, clap...
Show: false,
Pattern: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1] // optional
}
],
Ticks: 16,
Width: 5,
Height: 10,
Level: [
[0, 0, 0, 0, 9],
[2, 2, 2, 2, 2],
[2, 2, 0, 0, 2],
[0, 1, 2, 4, 2],
[2, 2, 2, 2, 2],
[2, 2, 0, 0, 2],
[2, 2, 0, 0, 2],
[2, 2, 2, 2, 2],
[2, 2, 2, 2, 2],
[0, 0, 0, 0, 9]
]
};
// Init
const hub = NewHub ();
const gamearea = NewGamearea ();
const gameRenderer = NewGameRendererCanvas ();
//const gameRenderer = NewGameRenderer ();
const sound = NewSoundMaschine ();
const patternRenderer = NewPatternmaschineRenderer ();
const timelineRenderer = NewTimelineRenderer ();
// HTML Elements
const nextLevel = document.getElementById('nextlevel');
const error = document.getElementById('error');
const levelnumber = document.getElementById('levelnumber');
const levelEditorStart = document.getElementById('open_leveleditor');
// Next Level
nextlevel.addEventListener('click', (e) => {
hub.LoadMap()
})
// LevelEditor
levelEditorStart.addEventListener('click', (e) => {
hub.OpenEditor();
})
// Hub
hub.onError((e) => {
error.innerHTML = e;
})
hub.onSetMap((map, number) => {
levelnumber.innerHTML = number + '/102';
nextLevel.innerHTML = '';
sound.SetMap(map)
})
// Gamearea
gamearea.onError(() => {
// Error only stop
sound.TogglePlay();
sound.Error();
});
gamearea.onSuccess(() => {
nextLevel.innerHTML = 'Load next Level';
sound.Success();
});
// GameRenderer
gameRenderer.Preload()
// SoundMaschine
sound.onChangedPlaymode(timelineRenderer.changedPlaymode)
sound.onToggleTick(patternRenderer.SetTickState);
sound.onSetMap((map) => {
error.innerHTML = '';
patternRenderer.SetMap(map);
gamearea.SetMap(map);
gameRenderer.SetState(gamearea.GetLevelClone());
gameRenderer.SetRobo(gamearea.GetRobo());
})
sound.onPlayTick((tickNumber, column) => {
patternRenderer.SetCurrentTick(tickNumber, column);
gamearea.PlayTick(tickNumber, column);
gameRenderer.SetState(gamearea.GetLevelClone());
gameRenderer.SetRobo(gamearea.GetRobo());
})
// PatternRenderer
patternRenderer.onClickTick(sound.ToggleTick);
// TimelineRenderer
timelineRenderer.onClickPlay(() => {
sound.TogglePlay();
gameRenderer.SetRobo(gamearea.GetRobo());
})
timelineRenderer.onClickReset(() => {
sound.Reset();
gamearea.Reset();
gameRenderer.Reset();
gameRenderer.SetRobo(gamearea.GetRobo());
})
// Init
hub.LoadMap() // Load Map from universe
//hub.SetMap(mapMock);
//hub.GenerateEmptyMap(4, 4);