xlib_playground

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 61d7d04323d277d68b25abb25e546fc2f9b434c7
parent 5eb1a066575df20b7049fed9a35548742a1c2b9b
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 17 Dec 2022 15:37:44 +0900

change behavior

Diffstat:
Mmain.c | 38++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/main.c b/main.c @@ -71,10 +71,12 @@ setup(void) gc = XCreateGC(display, window, 0, NULL); fgc = XCreateGC(display, window, 0, NULL); - wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False); + wm_delete_window = XInternAtom(display, + "WM_DELETE_WINDOW", False); XSetWMProtocols(display, window, &wm_delete_window, 1); - XSelectInput(display, window, ExposureMask|KeyPressMask|KeyReleaseMask); + XSelectInput(display, window, + ExposureMask|KeyPressMask|KeyReleaseMask); XSetForeground(display, gc, 0x00FF00); XSetForeground(display, fgc, 0xFF00FF); @@ -242,40 +244,52 @@ end_menu(void) } void -next_tick(float dt) +square_handle_inputs(void) { - square.vx = 0; if (key_state[Key_D] == Key_Down) - square.vx += 300; + square.vx = 300; if (key_state[Key_A] == Key_Down) - square.vx += -300; - if (key_state[Key_D] == Key_Up && key_state[Key_A] == Key_Up) - square.vx = 0; + square.vx = -300; +// if (key_state[Key_D] == Key_Up && key_state[Key_A] == Key_Up) +// square.vx = 0; if (key_state[Key_Space] == Key_Down && win_height <= square.py + square.height){ square.vy = -1000; } + square.ax = -square.vx * 0.5; +} - obj_next_tick(&square, dt); - +void +square_handle_collision(void) +{ if (square.px <= 0){ square.px = 0; + square.vx *= -0.7; } if (win_width <= square.px + square.width){ square.px = win_width - square.width; + square.vx *= -0.7; } square.ay = 980; if (square.py <= 0){ square.py = 0; - square.vy = 0; + square.vy *= -0.5; } if (win_height <= square.py + square.height){ square.py = win_height - square.height; - square.vy = 0; + square.vy *= -0.5; } } void +next_tick(float dt) +{ + square_handle_inputs(); + obj_next_tick(&square, dt); + square_handle_collision(); +} + +void cleanup(void) { XCloseDisplay(display);