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 --- source/core/core.c | 64 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'source') 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