diff --git a/.gitignore b/.gitignore index 4c9e5cd..edab7e4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ /*.g1a /*.g3a /hyperultra +/src/*.o +/src/*.d +/map/*.h # Python bytecode __pycache__/ diff --git a/CMakeLists.txt b/CMakeLists.txt index aa69c35..5b29e1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ project(MyAddin) include(GenerateG1A) include(GenerateG3A) include(Fxconv) +include_directories(map) find_package(Gint 2.9 REQUIRED) set(SOURCES diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..808de94 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +CC := gcc +LD := $(CC) +CFLAGS := -Os -std=c99 -Wall -Wextra -Imap -MMD +LDFLAGS := -lm -lSDL2 -lSDL2_image -lSDL2_mixer +NAME := hyperultra +EMBED := $(patsubst %.json,%.h,$(wildcard map/*.json)) +OBJ := $(patsubst %.c,%.o,$(wildcard src/*.c)) +DEP := $(patsubst %.o,%.d,$(OBJ)) + +all: + @make --no-print-directory $(EMBED) + @make --no-print-directory $(NAME) + +$(NAME): $(OBJ) + $(LD) -o $(NAME) $(OBJ) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +%.h: %.json + able -e -i $< -o $@ 2&>/dev/null + +run: re + ./$(NAME) + +clean: + rm -f $(NAME) $(OBJ) $(DEP) $(EMBED) + +re: + @make --no-print-directory clean + @make --no-print-directory all + +.PHONY: all run clean re + +-include $(DEP) diff --git a/build.sh b/build.sh deleted file mode 100755 index 149511a..0000000 --- a/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -gcc -std=c99 -Wall -Wextra -o hyperultra src/*.c \ - -lm -lSDL2 -lSDL2_image -lSDL2_mixer diff --git a/compile_flags.txt b/compile_flags.txt index c376403..bfdbe1a 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,3 +1,4 @@ -Wall -Wextra -std=c99 +-Imap diff --git a/map/00.json b/map/00.json new file mode 100644 index 0000000..2558349 --- /dev/null +++ b/map/00.json @@ -0,0 +1 @@ +{"width":25,"height":14,"data":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,1,1,1,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]} \ No newline at end of file diff --git a/res/tset.png b/res/tset.png index af367b9..b1d9e2f 100644 Binary files a/res/tset.png and b/res/tset.png differ diff --git a/src/background.c b/src/background.c index 4d17af3..3694ce8 100644 --- a/src/background.c +++ b/src/background.c @@ -2,7 +2,7 @@ #include "cfg.h" #include -static long tick = 0; +long tick = 0; static void rotate(double *x, double *y, double angle) diff --git a/src/entity.c b/src/entity.c index 94c0a47..fc45e2a 100644 --- a/src/entity.c +++ b/src/entity.c @@ -11,8 +11,8 @@ entity_collide(Entity *this, Game *g, int ox, int oy) const int y0 = this->pos[1] - this->height / 2 + oy; const int x1 = x0 + this->width - 1; const int y1 = y0 + this->height - 1; - return (map_get_px(x0, y0) == '0' || map_get_px(x0, y1) == '0' || - map_get_px(x1, y0) == '0' || map_get_px(x1, y1) == '0'); + return (map_get_px(x0, y0) == 1 || map_get_px(x0, y1) == 1 || + map_get_px(x1, y0) == 1 || map_get_px(x1, y1) == 1); } void diff --git a/src/map.c b/src/map.c index c82de49..8cade23 100644 --- a/src/map.c +++ b/src/map.c @@ -1,30 +1,14 @@ #include "map.h" #include "lzy.h" #include "cfg.h" - -static const char *map = - "0000000000000000000000000" - "0 0" - "0 0" - "0 0" - "0 0" - "0 0" - "0 0" - "0 0" - "0 0" - "0 0 0" - "00000000000000000000 0" - "0 0" - "0 0 0" - "0000000000000000000000000" -; +#include "00.h" int map_get(int x, int y) { - if (x < 0 || y < 0 || x >= 25 || y >= 14) + if (x < 0 || y < 0 || x >= map_00_json.width || y >= map_00_json.height) return 0; - return map[x + y * 25]; + return map_00_json.data[x + y * map_00_json.width]; } int @@ -38,11 +22,12 @@ map_get_px(int x, int y) void map_draw(void) { + extern long tick; + const int tile_id = 1 + tick / 18 % 2; for (int y = 0; y < 14; y++) - for (int x = 0; x < 25; x++) - if (map[x + y * 25] == '0') { + for (int x = 0; x < map_00_json.width; x++) + if (map_00_json.data[x + y * map_00_json.width] == 1) { LZY_DrawSetColor(BLACK); - LZY_DrawRect(x*16, y*16, 16, 16); - LZY_DrawFillRect(x*16, y*16, 16, 16); + LZY_DrawTile(tile_id, x * 16, y * 16); } } diff --git a/src/player.c b/src/player.c index 9281357..485296c 100644 --- a/src/player.c +++ b/src/player.c @@ -46,7 +46,7 @@ player_update(Entity *this, Game *g) } entity_move(this, g); - if (this->vel[0] == 0.0) + if (this->vel[0] == 0.0 && this->vel[1] >= -0.0) this->player.dirx *= -1; }