From f430bfe8f71430032bec689bf0bbdc94ac409c22 Mon Sep 17 00:00:00 2001 From: nasr Date: Sat, 11 Apr 2026 23:22:18 +0200 Subject: feature(main): enemy entitiy --- .gitignore | 1 + Makefile | 20 +++++++++++++++++ build.sh | 13 ----------- build/app | Bin 73272 -> 0 bytes build/core.o | Bin 3889350 -> 0 bytes build/libcore.a | Bin 3889418 -> 0 bytes build/libcore.so | Bin 69888 -> 0 bytes source/core/core.c | 64 +++++++++++++++++++++++++++++++---------------------- 8 files changed, 59 insertions(+), 39 deletions(-) create mode 100755 Makefile delete mode 100755 build.sh delete mode 100755 build/app delete mode 100644 build/core.o delete mode 100644 build/libcore.a delete mode 100755 build/libcore.so diff --git a/.gitignore b/.gitignore index 11180ab..ef92f11 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ idea/ idea idea/* .idea +/build diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..fc49e88 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: all clean + +CC := gcc +CFLAGS := -I. -Wall -Wextra -Wno-unused-function -Wno-unused-variable -DCORE_UNITY +LDLIBS := -lX11 -lm + +BUILD_DIR := build +TARGET := $(BUILD_DIR)/app +SOURCE := source/core/core.c + +all: $(TARGET) + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +$(TARGET): $(BUILD_DIR) $(SOURCE) + $(CC) $(CFLAGS) $(SOURCE) $(LDLIBS) -o $(TARGET) + +clean: + rm -rf $(BUILD_DIR) diff --git a/build.sh b/build.sh deleted file mode 100755 index b1e31be..0000000 --- a/build.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -set -eu -script_dir="$(dirname "$(readlink -f "$0")")" -cd "$script_dir" -build_dir="build" -mkdir -p "$build_dir" - -gcc -I. \ - -Wall -Wextra -Wno-unused-function -Wno-unused-variable \ - -DCORE_UNITY \ - source/core/core.c \ - -lX11 -lm \ - -o "$build_dir"/app diff --git a/build/app b/build/app deleted file mode 100755 index 75c3086..0000000 Binary files a/build/app and /dev/null differ diff --git a/build/core.o b/build/core.o deleted file mode 100644 index 036d103..0000000 Binary files a/build/core.o and /dev/null differ diff --git a/build/libcore.a b/build/libcore.a deleted file mode 100644 index 6048141..0000000 Binary files a/build/libcore.a and /dev/null differ diff --git a/build/libcore.so b/build/libcore.so deleted file mode 100755 index 1026809..0000000 Binary files a/build/libcore.so and /dev/null differ diff --git a/source/core/core.c b/source/core/core.c index fffcb47..f9d062a 100644 --- a/source/core/core.c +++ b/source/core/core.c @@ -69,53 +69,65 @@ int main() XMapWindow(MainDisplay, window); XEvent event; + f32 DELTA = 2.5; + u32 rect_width = 50; u32 rect_height = 50; + i32 rect_x_position = p.width / 2; i32 rect_y_position = p.height / 2; - u64 color = 0x0000ff00; + i32 rect_enemy_x_position = (p.width / 2) + 300; + i32 rect_enemy_y_position = (p.height / 2) + 300; + + u64 color = 0x0FF0FF00; GC gc = XCreateGC(MainDisplay, window, 0, NIL); XSetForeground(MainDisplay, gc, color); for (;running;) { + //- handle enemy movement + { + if(rect_enemy_x_position < rect_x_position) rect_enemy_x_position += DELTA*0.5; + if(rect_enemy_y_position < rect_y_position) rect_enemy_y_position += DELTA*0.5; + + if(rect_enemy_x_position > rect_x_position) rect_enemy_x_position -= DELTA*0.5; + if(rect_enemy_y_position > rect_y_position) rect_enemy_y_position -= DELTA*0.5; + } + XNextEvent(MainDisplay, &event); - KeySym keysym = XLookupKeysym(&event.xkey, 0); switch (event.type) { - case (KeyPress): - { - if(keysym == XK_h) rect_x_position -= 20; - else if(keysym == XK_l) rect_x_position += 20; - else if(keysym == XK_k) - { - rect_y_position -= 20; - } - else if(keysym == XK_j) + case(KeyPress): + { + + KeySym keysym = XLookupKeysym(&event.xkey, 0); + //- handle user movement { - rect_y_position += 20; + if(keysym == XK_h) rect_x_position -= DELTA*1.2; + else if(keysym == XK_l) rect_x_position += DELTA*1.2; + else if(keysym == XK_k) rect_y_position -= DELTA*1.2; + else if(keysym == XK_j) rect_y_position += DELTA*1.2; + else if(keysym == XK_s); + else if(keysym == XK_Escape || keysym == XK_q) goto exit; } - else if(keysym == XK_s) - { - } - else if(keysym == XK_Escape || keysym == XK_q) goto exit; + //- draw entities + { + XClearWindow(MainDisplay, window); - XClearWindow(MainDisplay, window); - XDrawRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); - XFillRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); + //-- + XDrawRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); + XFillRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); - break; - } + //-- + XDrawRectangle(MainDisplay, window, gc, rect_enemy_x_position, rect_y_position, 50, 50); + XFillRectangle(MainDisplay, window, gc, rect_enemy_x_position, rect_y_position, 50, 50); + } break; + } default: - { - - - } - } } exit: -- cgit v1.3