GAME READY

This commit is contained in:
Masashi 2025-12-20 18:30:21 +05:30
commit fdb93391d8
5 changed files with 83 additions and 78 deletions

Binary file not shown.

View file

@ -137,10 +137,10 @@ void suic_game_handle_input(struct GameState* game_state, float dt) {
float move_x = 0.000000; float move_x = 0.000000;
float move_z = 0.000000; float move_z = 0.000000;
if (suic_is_key_down(65)) { if (suic_is_key_down(65)) {
move_x = (((move_x)) + ((1.000000))); move_x = (((move_x)) - ((1.000000)));
} }
if (suic_is_key_down(68)) { if (suic_is_key_down(68)) {
move_x = (((move_x)) - ((1.000000))); move_x = (((move_x)) + ((1.000000)));
} }
if (suic_is_key_down(87)) { if (suic_is_key_down(87)) {
move_z = (((move_z)) + ((1.000000))); move_z = (((move_z)) + ((1.000000)));
@ -359,13 +359,13 @@ int suic_main(void) {
struct GameState game_state = ((struct GameState){ .cam_pos = ((struct SuicVec3){ .x = 0.000000, .y = 5.000000, .z = 6.000000 }), .yaw = 0.000000, .pitch = 0.000000, .prev_body_pos = ((struct SuicVec3){ .x = 0.000000, .y = 5.000000, .z = 6.000000 }), .current_target_body = ((struct SuicVec3){ .x = 0.000000, .y = 5.000000, .z = 6.000000 }), .interp_timer = 0.000000, .recoil_yaw = 0.000000, .recoil_pitch = 0.000000, .cross_spread = 0.000000, .scoped = false, .fire_cooldown = 0.000000, .shots_in_burst = 0, .burst_reset_timer = 0.000000, .client_tick = 0, .light = default_light }); struct GameState game_state = ((struct GameState){ .cam_pos = ((struct SuicVec3){ .x = 0.000000, .y = 5.000000, .z = 6.000000 }), .yaw = 0.000000, .pitch = 0.000000, .prev_body_pos = ((struct SuicVec3){ .x = 0.000000, .y = 5.000000, .z = 6.000000 }), .current_target_body = ((struct SuicVec3){ .x = 0.000000, .y = 5.000000, .z = 6.000000 }), .interp_timer = 0.000000, .recoil_yaw = 0.000000, .recoil_pitch = 0.000000, .cross_spread = 0.000000, .scoped = false, .fire_cooldown = 0.000000, .shots_in_burst = 0, .burst_reset_timer = 0.000000, .client_tick = 0, .light = default_light });
int screen_w = 1280; int screen_w = 1280;
int screen_h = 720; int screen_h = 720;
suic_init_window(screen_w, screen_h, suic_alloc_array(NULL, sizeof(char), 21, "Voxel Shooter Client")); suic_init_window(screen_w, screen_h, suic_alloc_array(NULL, sizeof(char), 5, "Soup"));
suic_set_target_fps(120); suic_set_target_fps(120);
suic_disable_cursor(); suic_disable_cursor();
(game_state).light = suic_light_create_default(); (game_state).light = suic_light_create_default();
char* username = suic_alloc_array(NULL, sizeof(char), 1, ""); char* username = suic_alloc_array(NULL, sizeof(char), 1, "");
suic_ui_username_prompt(username, SUIC_NET_USERNAME_MAX); suic_ui_username_prompt(username, SUIC_NET_USERNAME_MAX);
suic_game_init(((&game_state)), username, suic_alloc_array(NULL, sizeof(char), 10, "127.0.0.1"), 27015); suic_game_init(((&game_state)), username, suic_alloc_array(NULL, sizeof(char), 15, "24.240.181.107"), 27015);
while ((((suic_window_should_close())) == ((false)))) { while ((((suic_window_should_close())) == ((false)))) {
float dt = suic_get_frame_time(); float dt = suic_get_frame_time();
suic_game_handle_input(((&game_state)), dt); suic_game_handle_input(((&game_state)), dt);

View file

@ -1,7 +1,3 @@
# Game Client in Suicmez
# Full rewrite of the C client using Suicmez language
struct SuicVec3 struct SuicVec3
x: float, x: float,
y: float, y: float,
@ -132,10 +128,10 @@ fn suic_game_handle_input(game_state: *GameState, dt: float) -> () do
let mut move_x = 0.0 let mut move_x = 0.0
let mut move_z = 0.0 let mut move_z = 0.0
if is_key_down(65) do # KEY_A if is_key_down(65) do # KEY_A
move_x = move_x + 1.0 move_x = move_x - 1.0
end end
if is_key_down(68) do # KEY_D if is_key_down(68) do # KEY_D
move_x = move_x - 1.0 move_x = move_x + 1.0
end end
if is_key_down(87) do # KEY_W if is_key_down(87) do # KEY_W
move_z = move_z + 1.0 move_z = move_z + 1.0
@ -424,7 +420,7 @@ fn main() -> int do
let screen_w = 1280 let screen_w = 1280
let screen_h = 720 let screen_h = 720
init_window(screen_w, screen_h, "Voxel Shooter Client") init_window(screen_w, screen_h, "Soup")
defer close_window() defer close_window()
set_target_fps(120) set_target_fps(120)
disable_cursor() disable_cursor()
@ -436,7 +432,7 @@ fn main() -> int do
suic_ui_username_prompt(username, SUIC_NET_USERNAME_MAX) suic_ui_username_prompt(username, SUIC_NET_USERNAME_MAX)
# Initialize game subsystems # Initialize game subsystems
suic_game_init(&game_state, username, "127.0.0.1", 27015) suic_game_init(&game_state, username, "24.240.181.107", 6769) # 24.240.181.107 -> nishi.boats
# Main loop # Main loop
while window_should_close() == false do while window_should_close() == false do

Binary file not shown.

View file

@ -24,7 +24,7 @@ typedef int socklen_t;
#endif #endif
#define PROTOCOL_VERSION 67 #define PROTOCOL_VERSION 67
#define SERVER_PORT 27015 #define SERVER_PORT 6769
#define MAX_PLAYERS 16 #define MAX_PLAYERS 16
#define USERNAME_MAX 16 #define USERNAME_MAX 16
@ -993,71 +993,80 @@ int main(void) {
} }
} }
for (int i = 0; i < MAX_PLAYERS; i++) { for (int i = 0; i < MAX_PLAYERS; i++) {
Player *p = &players[i]; Player *p = &players[i];
if (!p->inUse || !p->alive) if (!p->inUse || !p->alive)
continue; continue;
const dReal *lvel = dBodyGetLinearVel(p->body); const dReal *lvel = dBodyGetLinearVel(p->body);
const dReal *avel = dBodyGetAngularVel(p->body); const dReal *avel = dBodyGetAngularVel(p->body);
float dx = p->moveX, dz = p->moveZ; float dx = p->moveX, dz = p->moveZ;
float len = sqrtf(dx * dx + dz * dz); float len = sqrtf(dx * dx + dz * dz);
if (len > 1e-6f) { if (len > 1e-6f) {
dx /= len; dx /= len;
dz /= len; dz /= len;
} }
float speed = 10.0f; float speed = 10.0f;
float fx = sinf(p->yaw) * dz - cosf(p->yaw) * dx; float fx = sinf(p->yaw) * dz - cosf(p->yaw) * dx;
float fz = cosf(p->yaw) * dz + sinf(p->yaw) * dx; float fz = cosf(p->yaw) * dz + sinf(p->yaw) * dx;
dBodySetLinearVel(p->body, fx * speed, lvel[1], fz * speed); dBodySetLinearVel(p->body, fx * speed, lvel[1], fz * speed);
dBodySetAngularVel(p->body, avel[0], 0, avel[2]); dBodySetAngularVel(p->body, avel[0], 0, avel[2]);
} }
// Border damage // Border damage
for (int i = 0; i < MAX_PLAYERS; i++) { for (int i = 0; i < MAX_PLAYERS; i++) {
Player *p = &players[i]; Player *p = &players[i];
if (!p->inUse || !p->alive) if (!p->inUse || !p->alive)
continue; continue;
const dReal *pos = dBodyGetPosition(p->body); const dReal *pos = dBodyGetPosition(p->body);
float px = (float)pos[0], pz = (float)pos[2]; float px = (float)pos[0], pz = (float)pos[2];
if (px < TERRAIN_MIN || px > TERRAIN_MAX || pz < TERRAIN_MIN || pz > TERRAIN_MAX) { if (px < TERRAIN_MIN || px > TERRAIN_MAX || pz < TERRAIN_MIN ||
p->borderDamageTimer += DT; pz > TERRAIN_MAX) {
if (p->borderDamageTimer >= 0.5f) { p->borderDamageTimer += DT;
p->borderDamageTimer -= 0.5f; if (p->borderDamageTimer >= 0.5f) {
p->hp -= 1; p->borderDamageTimer -= 0.5f;
if (p->hp <= 0) { p->hp -= 1;
p->hp = 0; if (p->hp <= 0) {
p->alive = 0; p->hp = 0;
// Drop loot as in shooting death p->alive = 0;
const dReal *pos2 = dBodyGetPosition(p->body); // Drop loot as in shooting death
float x = (float)pos2[0], z = (float)pos2[2]; const dReal *pos2 = dBodyGetPosition(p->body);
if (p->pistolAmmo > 0) { float x = (float)pos2[0], z = (float)pos2[2];
int qty = p->pistolAmmo; if (p->pistolAmmo > 0) {
if (qty > 12) qty = 12; int qty = p->pistolAmmo;
item_spawn(ITEM_AMMO_PISTOL, qty, x + frand_signed(&p->rng) * 2.0f, z + frand_signed(&p->rng) * 2.0f); if (qty > 12)
p->pistolAmmo -= qty; qty = 12;
} item_spawn(ITEM_AMMO_PISTOL, qty,
if (p->rifleAmmo > 0) { x + frand_signed(&p->rng) * 2.0f,
int qty = p->rifleAmmo; z + frand_signed(&p->rng) * 2.0f);
if (qty > 30) qty = 30; p->pistolAmmo -= qty;
item_spawn(ITEM_AMMO_RIFLE, qty, x + frand_signed(&p->rng) * 2.0f, z + frand_signed(&p->rng) * 2.0f); }
p->rifleAmmo -= qty; if (p->rifleAmmo > 0) {
} int qty = p->rifleAmmo;
if (p->medkits > 0) { if (qty > 30)
int qty = p->medkits; qty = 30;
if (qty > 2) qty = 2; item_spawn(ITEM_AMMO_RIFLE, qty,
item_spawn(ITEM_MEDKIT, qty, x + frand_signed(&p->rng) * 2.0f, z + frand_signed(&p->rng) * 2.0f); x + frand_signed(&p->rng) * 2.0f,
p->medkits -= qty; z + frand_signed(&p->rng) * 2.0f);
} p->rifleAmmo -= qty;
printf("Player %d died from border damage and dropped loot\n", i); }
} if (p->medkits > 0) {
} int qty = p->medkits;
} else { if (qty > 2)
p->borderDamageTimer = 0.0f; qty = 2;
} item_spawn(ITEM_MEDKIT, qty, x + frand_signed(&p->rng) * 2.0f,
} z + frand_signed(&p->rng) * 2.0f);
p->medkits -= qty;
}
printf("Player %d died from border damage and dropped loot\n", i);
}
}
} else {
p->borderDamageTimer = 0.0f;
}
}
MsgSnapshot snap = {0}; MsgSnapshot snap = {0};
snap.type = MSG_SNAPSHOT; snap.type = MSG_SNAPSHOT;