diff --git a/data.dat b/data.dat
index 38c52b6..25bd5cf 100644
Binary files a/data.dat and b/data.dat differ
diff --git a/html/README.md b/html/README.md
new file mode 100644
index 0000000..faefa40
--- /dev/null
+++ b/html/README.md
@@ -0,0 +1,9 @@
+HTML Template Files
+===================
+
+The files in this directory are html templates used by emscripten when
+generating html output. These are only used when the output of the compiler
+has the `.html` suffix (or when `-oformat=html` is specified).
+
+By default the `shell.html` file in this directory is used but an alternative
+can be specified using the `--shell-file` flag.
diff --git a/html/shell.css b/html/shell.css
new file mode 100644
index 0000000..d93a92d
--- /dev/null
+++ b/html/shell.css
@@ -0,0 +1,96 @@
+body {
+ font-family: arial;
+ margin: 0;
+ padding: none;
+}
+
+.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
+div.emscripten { text-align: center; }
+div.emscripten_border { border: 1px solid black; }
+/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
+canvas.emscripten { border: 0px none; background-color: black; }
+
+#emscripten_logo {
+ display: inline-block;
+ margin: 0;
+ padding: 6px;
+ width: 265px;
+}
+
+.spinner {
+ height: 30px;
+ width: 30px;
+ margin: 0;
+ margin-top: 20px;
+ margin-left: 20px;
+ display: inline-block;
+ vertical-align: top;
+
+ -webkit-animation: rotation .8s linear infinite;
+ -moz-animation: rotation .8s linear infinite;
+ -o-animation: rotation .8s linear infinite;
+ animation: rotation 0.8s linear infinite;
+
+ border-left: 5px solid rgb(235, 235, 235);
+ border-right: 5px solid rgb(235, 235, 235);
+ border-bottom: 5px solid rgb(235, 235, 235);
+ border-top: 5px solid rgb(120, 120, 120);
+
+ border-radius: 100%;
+ background-color: rgb(189, 215, 46);
+}
+
+@-webkit-keyframes rotation {
+ from {-webkit-transform: rotate(0deg);}
+ to {-webkit-transform: rotate(360deg);}
+}
+@-moz-keyframes rotation {
+ from {-moz-transform: rotate(0deg);}
+ to {-moz-transform: rotate(360deg);}
+}
+@-o-keyframes rotation {
+ from {-o-transform: rotate(0deg);}
+ to {-o-transform: rotate(360deg);}
+}
+@keyframes rotation {
+ from {transform: rotate(0deg);}
+ to {transform: rotate(360deg);}
+}
+
+#status {
+ display: inline-block;
+ vertical-align: top;
+ margin-top: 30px;
+ margin-left: 20px;
+ font-weight: bold;
+ color: rgb(120, 120, 120);
+}
+
+#progress {
+ height: 20px;
+ width: 300px;
+}
+
+#controls {
+ display: inline-block;
+ float: right;
+ vertical-align: top;
+ margin-top: 30px;
+ margin-right: 20px;
+}
+
+#output {
+ width: 100%;
+ height: 200px;
+ margin: 0 auto;
+ margin-top: 10px;
+ border-left: 0px;
+ border-right: 0px;
+ padding-left: 0px;
+ padding-right: 0px;
+ display: block;
+ background-color: black;
+ color: white;
+ font-family: 'Lucida Console', Monaco, monospace;
+ outline: none;
+}
diff --git a/html/shell.html b/html/shell.html
new file mode 100644
index 0000000..8e5f42b
--- /dev/null
+++ b/html/shell.html
@@ -0,0 +1,115 @@
+
+
+
+
+
+ Emscripten-Generated Code
+
+
+
+ {{{ SHELL_LOGO }}}
+
+
+ Downloading...
+
+
+ Resize canvas
+ Lock/hide mouse pointer
+
+
+
+
+
+
+
+
+
+
+
+
+ {{{ SCRIPT }}}
+#if MODULARIZE && !EXPORT_ES6
+
+#endif
+
+
diff --git a/html/shell_custom.html b/html/shell_custom.html
new file mode 100644
index 0000000..26a6ceb
--- /dev/null
+++ b/html/shell_custom.html
@@ -0,0 +1,51 @@
+
+
+
+
+
+ Flappy Bird Bullet Hell
+
+
+
+
+
+
+
+
+ {{{ SCRIPT }}}
+
+
diff --git a/html/shell_minimal.html b/html/shell_minimal.html
new file mode 100644
index 0000000..6a07b34
--- /dev/null
+++ b/html/shell_minimal.html
@@ -0,0 +1,152 @@
+
+
+
+
+
+ Emscripten-Generated Code
+
+
+
+
+ emscripten
+ Downloading...
+
+
+
+
+
+
+ Resize canvas
+ Lock/hide mouse pointer
+
+
+
+
+
+
+
+
+ {{{ SCRIPT }}}
+#if MODULARIZE && !EXPORT_ES6
+
+#endif
+
+
diff --git a/html/shell_minimal_runtime.html b/html/shell_minimal_runtime.html
new file mode 100644
index 0000000..74d50f0
--- /dev/null
+++ b/html/shell_minimal_runtime.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+
diff --git a/makefile b/makefile
index a882662..57c2571 100644
--- a/makefile
+++ b/makefile
@@ -17,7 +17,8 @@ LDFLAGS = -L./external/raylib/lib \
WEB_LDFLAGS = -L./external/raylib-web/lib \
-L./external/asset_packer/bin \
-sUSE_GLFW=3 \
- --preload-file $(ASSETS)
+ --preload-file $(ASSETS) \
+ --shell-file "./html/shell_custom.html"
LIBS = -lraylib -lwinmm -lgdi32 -lbox2d -lassetpacker
@@ -60,6 +61,7 @@ IMGUI_BACKEND = ./external/rlImGui/rlImGui.cpp
SRC_FILES = ./src/asset.cpp \
./src/movement.cpp \
./src/player.cpp \
+ ./src/fruit.cpp \
./src/render.cpp \
./src/scenes/scene.cpp \
./src/scenes/game_play_scene.cpp \
@@ -75,7 +77,7 @@ OBJS_FILES = $(patsubst ./src/%.cpp,./bin/%.o,$(SRC_FILES))
DEP_FILES = $(patsubst ./bin/%.o,./bin/%.d,$(OBJS_FILES))
-all: build-game run-desktop
+all: build-desktop run-desktop
./bin/%.o: ./external/imgui/%.cpp
@mkdir -p bin
@@ -110,7 +112,7 @@ build-gui-backend: $(IMGUI_BACKEND_OBJS)
build-core: $(OBJS_FILES)
-build-game: $(OBJS_FILES) $(IMGUI_OBJS) $(IMGUI_BACKEND_OBJS)
+build-desktop: $(OBJS_FILES) $(IMGUI_OBJS) $(IMGUI_BACKEND_OBJS)
@mkdir -p bin
$(CXX) $(CXXFLAGS) $(INCLUDES) $(ENTRY_POINT) $(OBJS_FILES) $(IMGUI_OBJS) $(IMGUI_BACKEND_OBJS) $(LDFLAGS) $(LIBS) -o ./bin/main.exe
cp ./assets ./bin -rf
@@ -128,11 +130,11 @@ build-debug:
web:
@mkdir -p web
- $(WEB_CXX) $(CXXFLAGS) $(WEB_INCLUDES) $(ENTRY_POINT) $(SRC_FILES) $(IMGUI_SRCS) $(IMGUI_BACKEND) $(WEB_LDFLAGS) $(WEB_LIBS) -o ./web/web.html
+ $(WEB_CXX) $(CXXFLAGS) $(WEB_INCLUDES) $(ENTRY_POINT) $(SRC_FILES) $(IMGUI_SRCS) $(IMGUI_BACKEND) $(WEB_LDFLAGS) $(WEB_LIBS) -o ./web/index.html
web-native:
@mkdir -p web
- em++ $(CXXFLAGS) $(WEB_INCLUDES) $(ENTRY_POINT) $(SRC_FILES) $(IMGUI_SRCS) $(IMGUI_BACKEND) $(WEB_LDFLAGS) $(WEB_LIBS) -o ./web/web.html
+ em++ $(CXXFLAGS) $(WEB_INCLUDES) $(ENTRY_POINT) $(SRC_FILES) $(IMGUI_SRCS) $(IMGUI_BACKEND) $(WEB_LDFLAGS) $(WEB_LIBS) -o ./web/index.html
clean-desktop:
@rm -r -f ./bin
@@ -155,7 +157,7 @@ open-browser:
start-server:
$(WSL) python -m http.server 3000 -d ./web
run-web:
- $(BROWSER) http://localhost:3000/web.html
+ $(BROWSER) http://localhost:3000/index.html
$(WSL) python -m http.server 3000 -d ./web
# $(WSL) node ./web/web.js
@@ -165,3 +167,8 @@ run-debug:
run-test: build-test
./bin/test.exe
+pack-assets:
+ ./external/asset_packer/bin/assetpacker.exe assets/
+
+
+
diff --git a/src/engine_variant.cpp b/src/engine_variant.cpp
deleted file mode 100644
index e69de29..0000000
diff --git a/src/fruit.cpp b/src/fruit.cpp
new file mode 100644
index 0000000..f0abf38
--- /dev/null
+++ b/src/fruit.cpp
@@ -0,0 +1,30 @@
+// src\fruit.cpp
+//
+#include
+#include
+
+#include
+
+entt::entity fruit;
+
+
+void create_fruit(entt::registry& registry,Texture* texture){
+ const auto entity = registry.create();
+ registry.emplace(entity,100.0f,0.0f);
+ registry.emplace(entity);
+ registry.emplace(entity,texture);
+}
+
+void update_fruit_system(entt::registry& registry,float dt){
+
+ auto view = registry.view();
+
+ for (entt::entity entity : view){
+
+ const Position& pos = view.get(entity);
+ Velocity& vel = view.get(entity);
+
+ }
+
+}
+
diff --git a/src/imgui.ini b/src/imgui.ini
deleted file mode 100644
index ff52523..0000000
--- a/src/imgui.ini
+++ /dev/null
@@ -1,8 +0,0 @@
-[Window][Debug##Default]
-Pos=60,60
-Size=400,400
-
-[Window][VBoxContainer]
-Pos=540,275
-Size=200,250
-
diff --git a/src/include/asset/asset.hpp b/src/include/asset/asset.hpp
index 9ddab55..08ef308 100644
--- a/src/include/asset/asset.hpp
+++ b/src/include/asset/asset.hpp
@@ -41,7 +41,6 @@ class AssetLoader{
std::unordered_map assets;
virtual void load_all_assets(std::string data_path) = 0;
virtual void unload_all_assets() = 0;
- AssetReader get_reader();
public:
AssetLoader(std::string asset_data);
@@ -49,6 +48,7 @@ class AssetLoader{
virtual void load_asset(std::string path) = 0;
virtual void unload_asset(std::string path) = 0;
virtual Asset get_asset(std::string path) = 0;;
+ AssetReader get_reader();
};
diff --git a/src/include/asset/raylib_asset.hpp b/src/include/asset/raylib_asset.hpp
index ac73934..5e82631 100644
--- a/src/include/asset/raylib_asset.hpp
+++ b/src/include/asset/raylib_asset.hpp
@@ -3,7 +3,7 @@
#include
#include
-class RaylibAssetLoader : AssetLoader{
+class RaylibAssetLoader : public AssetLoader{
protected:
void load_all_assets(std::string asset_list) override {};
void unload_all_assets() override;
diff --git a/src/include/components.hpp b/src/include/components.hpp
index c7be5c1..f95ab1f 100644
--- a/src/include/components.hpp
+++ b/src/include/components.hpp
@@ -13,6 +13,8 @@ struct Velocity{
struct Player{};
+struct Fruit{};
+
struct Sprite{
Texture *texture;
};
diff --git a/src/include/fruit.hpp b/src/include/fruit.hpp
new file mode 100644
index 0000000..d0486c2
--- /dev/null
+++ b/src/include/fruit.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include
+#include
+
+void create_fruit(entt::registry& registry,Texture* texture);
+
+void update_fruit_system(entt::registry& registry,float dt);
+
diff --git a/src/main.cpp b/src/main.cpp
index 8a42615..03b1d57 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -79,7 +79,7 @@ int main(){
SetTargetFPS(60);
// SetTraceLogLevel(TraceLogLevel::LOG_NONE);
- InitWindow(screen_width, screen_height, "Bullet bird");
+ InitWindow(screen_width, screen_height, "Snake");
SetWindowState(FLAG_WINDOW_RESIZABLE);
diff --git a/src/player.cpp b/src/player.cpp
index 97ea87b..91d3fb2 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -21,30 +21,48 @@ void update_player_system(entt::registry& registry,float dt){
auto view = registry.view();
// Constants for fine-tuning game feel
- const float GRAVITY = 900.0f; // Constant downward pull (pixels/sec^2)
- const float JUMP_FORCE = -350.0f; // Negative force to burst UPWARD
+ // const float GRAVITY = 900.0f; // Constant downward pull (pixels/sec^2)
+ // const float JUMP_FORCE = -350.0f; // Negative force to burst UPWARD
for (entt::entity entity : view){
const Position& pos = view.get(entity);
Velocity& vel = view.get(entity);
+ const float SPEED = 350;
- if (pos.x < -50 && vel.dx < 0){
- vel.dx *= -1;
- } else if (pos.x > (GetScreenWidth()-250) && vel.dx > 0){
- vel.dx *= -1;
+ if (IsKeyPressed(KEY_W)){
+ if (vel.dy > 0)
+ continue;
+ vel.dx = 0;
+ vel.dy = -SPEED;
+
+ } else if (IsKeyPressed(KEY_S)){
+ if (vel.dy < 0)
+ continue;
+ vel.dx = 0;
+ vel.dy = SPEED;
+ } else if (IsKeyPressed(KEY_A)){
+ if (vel.dx > 0)
+ continue;
+ vel.dx = -SPEED;
+ vel.dy = 0;
+ } else if (IsKeyPressed(KEY_D)){
+ if (vel.dx < 0)
+ continue;
+ vel.dx = SPEED;
+ vel.dy = 0;
}
- if (IsKeyPressed(KEY_SPACE)){
- vel.dy = JUMP_FORCE;
- }
- vel.dy += GRAVITY * dt;
+ // if (pos.x < -50 && vel.dx < 0){
+ // vel.dx *= -1;
+ // } else if (pos.x > (GetScreenWidth()-250) && vel.dx > 0){
+ // vel.dx *= -1;
+ // }
+
+ // if (IsKeyPressed(KEY_SPACE)){
+ // vel.dy = JUMP_FORCE;
+ // }
+ // vel.dy += GRAVITY * dt;
}
- view.each([dt,GRAVITY,JUMP_FORCE](entt::entity entity,const Position &position, auto &velocity){
- if (position.x > 100 && position.x < 120){
- velocity.dx += 20;
- }
-
- });
}
diff --git a/src/scenes/game_play_scene.cpp b/src/scenes/game_play_scene.cpp
index 3f20e38..f4ec0a7 100644
--- a/src/scenes/game_play_scene.cpp
+++ b/src/scenes/game_play_scene.cpp
@@ -1,23 +1,29 @@
-#include
#include
#include
#include
#include
-#include
+#include
+#include
+#include
+
+#include
#include
GamePlayScene::GamePlayScene() {
registry = entt::registry();
- asset_loader.load_asset("assets/bird.png");
- create_player(registry,asset_loader.get_texture("assets/bird.png"));
+ asset_loader.load_asset("assets/snake_head.png");
+ asset_loader.load_asset("assets/fruit.png");
+ create_player(registry,asset_loader.get_texture("assets/snake_head.png"));
+ create_fruit(registry,asset_loader.get_texture("assets/fruit.png"));
}
void GamePlayScene::update(float dt) {
update_movement_system(registry, dt);
update_player_system(registry, dt);
+ update_fruit_system(registry, dt);
}
@@ -49,5 +55,5 @@ void GamePlayScene::ui() {
GamePlayScene::~GamePlayScene(){
asset_loader.unload_asset("assets/bird.png");
-
+ asset_loader.unload_asset("assets/snake_head.png");
}