Compare commits
2 commits
17666c232a
...
d6f9adad13
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d6f9adad13 | ||
![]() |
83967090c2 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,4 +4,5 @@ domino-dungeon.html
|
|||
domino-dungeon.js
|
||||
domino-dungeon.wasm
|
||||
src_build/domino_assets
|
||||
index.*
|
||||
|
||||
|
|
6
Makefile
6
Makefile
|
@ -5,7 +5,7 @@ LDFLAGS = -lglfw -lm -lGL -I./glad/include
|
|||
SOURCES = main.c game.c game.h glad/src/glad.c assets/white_and_blue_dominoes.h assets/red_and_peach_dominoes.h domino.c domino.h
|
||||
|
||||
domino-dungeon: ${SOURCES}
|
||||
$(CC) ${CFLAGS} -o $@ $^ ${LDFLAGS}
|
||||
$(CC) ${CFLAGS} -o $@ $^ ${LDFLAGS}
|
||||
|
||||
assets/%.h: src_build/domino_assets
|
||||
$< assets/1bit_dominoes_asset_pack/$*.png $* > $@
|
||||
|
@ -14,6 +14,6 @@ src_build/domino_assets: src_build/domino_assets.c
|
|||
$(CC) -o $@ $^ -lm
|
||||
|
||||
# https://gist.github.com/ousttrue/0f3a11d5d28e365b129fe08f18f4e141
|
||||
domino-dungeon.html: ${SOURCES}
|
||||
emcc -sUSE_WEBGL2=1 -sUSE_GLFW=3 -sWASM=1 -I./glad/include $(filter %.c,$^) -o $@
|
||||
index.html: ${SOURCES}
|
||||
emcc -sUSE_WEBGL2=1 -sUSE_GLFW=3 -sWASM=1 --shell-file=minshell.html -I./glad/include $(filter %.c,$^) -o $@
|
||||
|
||||
|
|
20
game.c
20
game.c
|
@ -36,6 +36,13 @@ int goal_x = 5;
|
|||
int goal_y = 5;
|
||||
bool is_goal_reached = 0;
|
||||
|
||||
struct enemy {
|
||||
int x, y, attack, health;
|
||||
};
|
||||
|
||||
struct enemy enemies[20] = {0};
|
||||
size_t enemy_count = 0;
|
||||
|
||||
#define DIRECTIONS 6
|
||||
struct eye direction[DIRECTIONS] = {
|
||||
{.x = 0, .y = -1},
|
||||
|
@ -257,6 +264,14 @@ void print(struct image canvas, char *string, size_t xpos, size_t ypos, struct c
|
|||
}
|
||||
}
|
||||
|
||||
void draw_enemy(struct image canvas, int attack, int health, size_t xpos, size_t ypos) {
|
||||
char a[] = {(attack + '0'), 0};
|
||||
char h[] = {(health + '0'), 0};
|
||||
draw_glyph(canvas, (uint32_t) 0b00111011111101011111111111101010, camera_x + xpos * EYE_SIZE + 2, camera_y + ypos * EYE_SIZE + 3, (struct color) {255, 0, 0, 255});
|
||||
print(canvas, a, camera_x + xpos * EYE_SIZE + 8, camera_y + ypos * EYE_SIZE, (struct color) {255, 0, 0, 255});
|
||||
print(canvas, h, camera_x + xpos * EYE_SIZE + 8, camera_y + ypos * EYE_SIZE + 6, (struct color) {255, 0, 0, 255});
|
||||
}
|
||||
|
||||
void render(struct image canvas) {
|
||||
for (size_t i = 0; i < canvas.bufsize; i++) canvas.buf[i] = 0;
|
||||
|
||||
|
@ -273,6 +288,8 @@ void render(struct image canvas) {
|
|||
|
||||
draw_glyph(canvas, (uint32_t) 0b00011000111001100010000100011100, camera_x + goal_x * EYE_SIZE + 3, camera_y + goal_y * EYE_SIZE + 3, (struct color) {255, 255, 0, 255});
|
||||
|
||||
draw_enemy(canvas, 6, 3, 0, 3);
|
||||
|
||||
// hand
|
||||
for (size_t i = 0; i < hand_count; i++) {
|
||||
struct brick *b = &hand[i];
|
||||
|
@ -295,6 +312,9 @@ void render(struct image canvas) {
|
|||
print(canvas, "Drag Dominos from your inventory onto the chain to", 3, 2, (struct color) {255, 255, 255, 255});
|
||||
print(canvas, "reach the goal. Press [R] to rotate", 3, 9, (struct color) {255, 255, 255, 255});
|
||||
|
||||
draw_glyph(canvas, 0b00010101111111111011100010000000, 3, 20, (struct color) {255, 0, 0, 255});
|
||||
print(canvas, "10", 10, 20, (struct color) {255, 255, 255, 255});
|
||||
|
||||
if (is_goal_reached) {
|
||||
print(canvas, game_over, (canvas.width - (sizeof(game_over)-1) * 5) / 2, 20, (struct color) {255, 255, 255, 255});
|
||||
}
|
||||
|
|
58
minshell.html
Normal file
58
minshell.html
Normal file
|
@ -0,0 +1,58 @@
|
|||
<!doctype html>
|
||||
<html lang="EN-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
|
||||
<title>domino dungeon</title>
|
||||
|
||||
<style>
|
||||
body { margin: 0px; overflow: hidden; background-color: black; }
|
||||
canvas.emscripten { width: 100%; border: 0px none; background-color: black; }
|
||||
</style>
|
||||
<script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js"> </script>
|
||||
<script type='text/javascript'>
|
||||
function saveFileFromMEMFSToDisk(memoryFSname, localFSname) // This can be called by C/C++ code
|
||||
{
|
||||
var isSafari = false; // Not supported, navigator.userAgent access is being restricted
|
||||
//var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||
var data = FS.readFile(memoryFSname);
|
||||
var blob;
|
||||
|
||||
if (isSafari) blob = new Blob([data.buffer], { type: "application/octet-stream" });
|
||||
else blob = new Blob([data.buffer], { type: "application/octet-binary" });
|
||||
|
||||
// NOTE: SaveAsDialog is a browser setting. For example, in Google Chrome,
|
||||
// in Settings/Advanced/Downloads section you have a setting:
|
||||
// 'Ask where to save each file before downloading' - which you can set true/false.
|
||||
// If you enable this setting it would always ask you and bring the SaveAsDialog
|
||||
saveAs(blob, localFSname);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
|
||||
<p id="output" />
|
||||
<script>
|
||||
var Module = {
|
||||
print: (function() {
|
||||
var element = document.getElementById('output');
|
||||
if (element) element.value = ''; // clear browser cache
|
||||
return function(text) {
|
||||
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
|
||||
console.log(text);
|
||||
if (element) {
|
||||
element.value += text + "\n";
|
||||
element.scrollTop = element.scrollHeight; // focus on bottom
|
||||
}
|
||||
};
|
||||
})(),
|
||||
canvas: (function() {
|
||||
var canvas = document.getElementById('canvas');
|
||||
return canvas;
|
||||
})()
|
||||
};
|
||||
</script>
|
||||
{{{ SCRIPT }}}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue