mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-20 03:41:33 +02:00
#15 WebGL level selector
This commit is contained in:
@@ -818,9 +818,7 @@ namespace TR {
|
||||
uint16 puzzleSet;
|
||||
} extra;
|
||||
|
||||
Level(const char *name, bool demo) {
|
||||
Stream stream(name);
|
||||
|
||||
Level(Stream &stream, bool demo) {
|
||||
tiles4 = NULL;
|
||||
Tile8 *tiles8 = NULL;
|
||||
cluts = NULL;
|
||||
|
25
src/game.h
25
src/game.h
@@ -10,12 +10,9 @@
|
||||
namespace Game {
|
||||
Level *level;
|
||||
|
||||
void init() {
|
||||
Core::init();
|
||||
//level = new Level("LEVEL2_DEMO.PHD", true, false);
|
||||
//level = new Level("GYM.PSX", false, true);
|
||||
//level = new Level("LEVEL3A.PHD", false, false);
|
||||
level = new Level("LEVEL2.PSX", false, false);
|
||||
void startLevel(Stream &stream, bool demo, bool home) {
|
||||
delete level;
|
||||
level = new Level(stream, demo, home);
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
//Sound::play(Sound::openWAD("05_Lara's_Themes.wav"), 1, 1, 0);
|
||||
@@ -24,9 +21,23 @@ namespace Game {
|
||||
#endif
|
||||
}
|
||||
|
||||
void startLevel(const char *name, bool demo, bool home) {
|
||||
Stream stream(name);
|
||||
startLevel(stream, demo, home);
|
||||
}
|
||||
|
||||
void init() {
|
||||
Core::init();
|
||||
level = NULL;
|
||||
|
||||
//lstartLevel("LEVEL2_DEMO.PHD", true, false);
|
||||
//lstartLevel("GYM.PSX", false, true);
|
||||
//lstartLevel("LEVEL3A.PHD", false, false);
|
||||
startLevel("LEVEL2.PSX", false, false);
|
||||
}
|
||||
|
||||
void free() {
|
||||
delete level;
|
||||
|
||||
Core::free();
|
||||
}
|
||||
|
||||
|
@@ -216,7 +216,7 @@ struct Level {
|
||||
}
|
||||
} lightCache;
|
||||
*/
|
||||
Level(const char *name, bool demo, bool home) : level(name, demo), lara(NULL), time(0.0f) {
|
||||
Level(Stream &stream, bool demo, bool home) : level(stream, demo), lara(NULL), time(0.0f) {
|
||||
#ifdef _DEBUG
|
||||
Debug::init();
|
||||
#endif
|
||||
|
@@ -4,7 +4,6 @@
|
||||
<body>
|
||||
<span id="status">Starting...</span>
|
||||
<canvas id="canvas" width="854" height="480" oncontextmenu="event.preventDefault()"></canvas><br>
|
||||
<span id="info"><a target="_blank" href="https://github.com/XProger/OpenLara">OpenLara on github</a><br>controls:<br>keyboad: move - WASD / arrows, jump - Space, action - E/Ctrl, draw weapon - Q, change weapon - 1-4, walk - Shift, side steps - ZX/walk+direction, camera - MouseR)<br>gamepad: PSX controls on XBox controller<br>FullScreen: Alt + Enter</span>
|
||||
|
||||
<script type='text/javascript'>
|
||||
var statusElement = document.getElementById('status');
|
||||
@@ -101,8 +100,31 @@
|
||||
return "Really want to quit the game?";
|
||||
};
|
||||
|
||||
function readLevel(event, home) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(){
|
||||
var size = reader.result.byteLength;
|
||||
var data = Module._malloc(size);
|
||||
Module.writeArrayToMemory(new Uint8Array(reader.result), data);
|
||||
Module.ccall('game_level_load', 'null', ['number', 'number', 'number'], [data, size, home]);
|
||||
};
|
||||
reader.readAsArrayBuffer(event.target.files[0]);
|
||||
}
|
||||
</script>
|
||||
|
||||
<audio autoplay loop><source src="05.ogg" type="audio/ogg"></audio>
|
||||
|
||||
<span id="info">
|
||||
<input type="file" id="browseFile" style="display:none" accept=".phd,.psx" onchange="readLevel(event, document.getElementById('isHome').checked)" />
|
||||
<!-- <label for="browseFile">Browse Level</label> -->
|
||||
<input type="button" value="Browse Level" onclick="document.getElementById('browseFile').click();" /> (.PHD, .PSX)
|
||||
<input type="checkbox" id="isHome"><label>alternative model (home suit, gold etc.)</label>
|
||||
<br><br>
|
||||
<a target="_blank" href="https://github.com/XProger/OpenLara">OpenLara on github</a><br>
|
||||
controls:<br>
|
||||
keyboad: move - WASD / arrows, jump - Space, action - E/Ctrl, draw weapon - Q, change weapon - 1-4, walk - Shift, side steps - ZX/walk+direction, camera - MouseR)<br>
|
||||
gamepad: PSX controls on XBox controller<br>
|
||||
FullScreen: Alt + Enter
|
||||
</span>
|
||||
</body>
|
||||
</html>
|
@@ -16,6 +16,11 @@ extern "C" {
|
||||
void EMSCRIPTEN_KEEPALIVE snd_fill(Sound::Frame *frames, int count) {
|
||||
Sound::fill(frames, count);
|
||||
}
|
||||
|
||||
void EMSCRIPTEN_KEEPALIVE game_level_load(char *data, int size, int home) {
|
||||
Stream stream(data, size);
|
||||
Game::startLevel(stream, false, home);
|
||||
}
|
||||
}
|
||||
|
||||
InputKey joyToInputKey(int code) {
|
||||
|
Reference in New Issue
Block a user