diff options
| author | nasr <nsrddyn@gmail.com> | 2026-04-11 23:22:18 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-11 23:22:18 +0200 |
| commit | f430bfe8f71430032bec689bf0bbdc94ac409c22 (patch) | |
| tree | 5feabe21a86716e7aa7f8348163bb4440cde4c12 | |
| parent | 2380741bea16d5e3d54195c266e335cb131ac642 (diff) | |
feature(main): enemy entitiy
| -rw-r--r-- | .gitignore | 1 | ||||
| -rwxr-xr-x | Makefile | 20 | ||||
| -rwxr-xr-x | build.sh | 13 | ||||
| -rwxr-xr-x | build/app | bin | 73272 -> 0 bytes | |||
| -rw-r--r-- | build/core.o | bin | 3889350 -> 0 bytes | |||
| -rw-r--r-- | build/libcore.a | bin | 3889418 -> 0 bytes | |||
| -rwxr-xr-x | build/libcore.so | bin | 69888 -> 0 bytes | |||
| -rw-r--r-- | source/core/core.c | 64 |
8 files changed, 59 insertions, 39 deletions
| @@ -2,3 +2,4 @@ idea/ | |||
| 2 | idea | 2 | idea |
| 3 | idea/* | 3 | idea/* |
| 4 | .idea | 4 | .idea |
| 5 | /build | ||
diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..fc49e88 --- /dev/null +++ b/Makefile | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | .PHONY: all clean | ||
| 2 | |||
| 3 | CC := gcc | ||
| 4 | CFLAGS := -I. -Wall -Wextra -Wno-unused-function -Wno-unused-variable -DCORE_UNITY | ||
| 5 | LDLIBS := -lX11 -lm | ||
| 6 | |||
| 7 | BUILD_DIR := build | ||
| 8 | TARGET := $(BUILD_DIR)/app | ||
| 9 | SOURCE := source/core/core.c | ||
| 10 | |||
| 11 | all: $(TARGET) | ||
| 12 | |||
| 13 | $(BUILD_DIR): | ||
| 14 | mkdir -p $(BUILD_DIR) | ||
| 15 | |||
| 16 | $(TARGET): $(BUILD_DIR) $(SOURCE) | ||
| 17 | $(CC) $(CFLAGS) $(SOURCE) $(LDLIBS) -o $(TARGET) | ||
| 18 | |||
| 19 | clean: | ||
| 20 | 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 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | set -eu | ||
| 3 | script_dir="$(dirname "$(readlink -f "$0")")" | ||
| 4 | cd "$script_dir" | ||
| 5 | build_dir="build" | ||
| 6 | mkdir -p "$build_dir" | ||
| 7 | |||
| 8 | gcc -I. \ | ||
| 9 | -Wall -Wextra -Wno-unused-function -Wno-unused-variable \ | ||
| 10 | -DCORE_UNITY \ | ||
| 11 | source/core/core.c \ | ||
| 12 | -lX11 -lm \ | ||
| 13 | -o "$build_dir"/app | ||
diff --git a/build/app b/build/app deleted file mode 100755 index 75c3086..0000000 --- a/build/app +++ /dev/null | |||
| Binary files differ | |||
diff --git a/build/core.o b/build/core.o deleted file mode 100644 index 036d103..0000000 --- a/build/core.o +++ /dev/null | |||
| Binary files differ | |||
diff --git a/build/libcore.a b/build/libcore.a deleted file mode 100644 index 6048141..0000000 --- a/build/libcore.a +++ /dev/null | |||
| Binary files differ | |||
diff --git a/build/libcore.so b/build/libcore.so deleted file mode 100755 index 1026809..0000000 --- a/build/libcore.so +++ /dev/null | |||
| Binary files 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() | |||
| 69 | XMapWindow(MainDisplay, window); | 69 | XMapWindow(MainDisplay, window); |
| 70 | XEvent event; | 70 | XEvent event; |
| 71 | 71 | ||
| 72 | f32 DELTA = 2.5; | ||
| 73 | |||
| 72 | u32 rect_width = 50; | 74 | u32 rect_width = 50; |
| 73 | u32 rect_height = 50; | 75 | u32 rect_height = 50; |
| 76 | |||
| 74 | i32 rect_x_position = p.width / 2; | 77 | i32 rect_x_position = p.width / 2; |
| 75 | i32 rect_y_position = p.height / 2; | 78 | i32 rect_y_position = p.height / 2; |
| 76 | 79 | ||
| 77 | u64 color = 0x0000ff00; | 80 | i32 rect_enemy_x_position = (p.width / 2) + 300; |
| 81 | i32 rect_enemy_y_position = (p.height / 2) + 300; | ||
| 82 | |||
| 83 | u64 color = 0x0FF0FF00; | ||
| 78 | 84 | ||
| 79 | GC gc = XCreateGC(MainDisplay, window, 0, NIL); | 85 | GC gc = XCreateGC(MainDisplay, window, 0, NIL); |
| 80 | XSetForeground(MainDisplay, gc, color); | 86 | XSetForeground(MainDisplay, gc, color); |
| 81 | 87 | ||
| 82 | for (;running;) | 88 | for (;running;) |
| 83 | { | 89 | { |
| 90 | //- handle enemy movement | ||
| 91 | { | ||
| 92 | if(rect_enemy_x_position < rect_x_position) rect_enemy_x_position += DELTA*0.5; | ||
| 93 | if(rect_enemy_y_position < rect_y_position) rect_enemy_y_position += DELTA*0.5; | ||
| 94 | |||
| 95 | if(rect_enemy_x_position > rect_x_position) rect_enemy_x_position -= DELTA*0.5; | ||
| 96 | if(rect_enemy_y_position > rect_y_position) rect_enemy_y_position -= DELTA*0.5; | ||
| 97 | } | ||
| 98 | |||
| 84 | XNextEvent(MainDisplay, &event); | 99 | XNextEvent(MainDisplay, &event); |
| 85 | KeySym keysym = XLookupKeysym(&event.xkey, 0); | ||
| 86 | 100 | ||
| 87 | switch (event.type) | 101 | switch (event.type) |
| 88 | { | 102 | { |
| 89 | case (KeyPress): | 103 | case(KeyPress): |
| 90 | { | 104 | { |
| 91 | if(keysym == XK_h) rect_x_position -= 20; | 105 | |
| 92 | else if(keysym == XK_l) rect_x_position += 20; | 106 | KeySym keysym = XLookupKeysym(&event.xkey, 0); |
| 93 | else if(keysym == XK_k) | 107 | //- handle user movement |
| 94 | { | ||
| 95 | rect_y_position -= 20; | ||
| 96 | } | ||
| 97 | else if(keysym == XK_j) | ||
| 98 | { | 108 | { |
| 99 | rect_y_position += 20; | 109 | if(keysym == XK_h) rect_x_position -= DELTA*1.2; |
| 110 | else if(keysym == XK_l) rect_x_position += DELTA*1.2; | ||
| 111 | else if(keysym == XK_k) rect_y_position -= DELTA*1.2; | ||
| 112 | else if(keysym == XK_j) rect_y_position += DELTA*1.2; | ||
| 113 | else if(keysym == XK_s); | ||
| 114 | else if(keysym == XK_Escape || keysym == XK_q) goto exit; | ||
| 100 | } | 115 | } |
| 101 | else if(keysym == XK_s) | ||
| 102 | { | ||
| 103 | 116 | ||
| 104 | } | 117 | //- draw entities |
| 105 | else if(keysym == XK_Escape || keysym == XK_q) goto exit; | 118 | { |
| 119 | XClearWindow(MainDisplay, window); | ||
| 106 | 120 | ||
| 107 | XClearWindow(MainDisplay, window); | 121 | //-- |
| 108 | XDrawRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); | 122 | XDrawRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); |
| 109 | XFillRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); | 123 | XFillRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50); |
| 110 | 124 | ||
| 111 | break; | 125 | //-- |
| 112 | } | 126 | XDrawRectangle(MainDisplay, window, gc, rect_enemy_x_position, rect_y_position, 50, 50); |
| 127 | XFillRectangle(MainDisplay, window, gc, rect_enemy_x_position, rect_y_position, 50, 50); | ||
| 128 | } break; | ||
| 129 | } | ||
| 113 | default: | 130 | default: |
| 114 | { | ||
| 115 | |||
| 116 | |||
| 117 | } | ||
| 118 | |||
| 119 | } | 131 | } |
| 120 | } | 132 | } |
| 121 | exit: | 133 | exit: |
