rename
This commit is contained in:
parent
c4c2cccbcf
commit
338e0a1de0
3 changed files with 0 additions and 260 deletions
260
soup/main.c
260
soup/main.c
|
|
@ -1,260 +0,0 @@
|
|||
#include "libsuicmez/libsuicmez.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
void* gc_alloc(const TypeInfo* type, size_t size);
|
||||
void gc_init(void);
|
||||
void gc_shutdown(void);
|
||||
|
||||
// Helper for allocating arrays
|
||||
static void* suic_alloc_array(const TypeInfo* type, size_t elem_size, size_t len, void* init_data) {
|
||||
void* ptr = gc_alloc(type, elem_size * len);
|
||||
if (init_data) memcpy(ptr, init_data, elem_size * len);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Helper for allocating structs
|
||||
static void* suic_alloc_struct(const TypeInfo* type, size_t size, void* init_data) {
|
||||
void* ptr = gc_alloc(type, size);
|
||||
if (init_data) memcpy(ptr, init_data, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int suic_main(void);
|
||||
|
||||
|
||||
int suic_main(void) {
|
||||
suic_enable_msaa_4x();
|
||||
suic_init_window(1280, 720, suic_alloc_array(NULL, sizeof(char), 112, "Sui FPS Game - WASD to move, Mouse to look, SPACE to jump, SHIFT to sprint, F1 cursor, F2 hide FPS, F3 show FPS"));
|
||||
suic_show_fps_meter((suic_vec2){ .x = 10.000000, .y = 10.000000 });
|
||||
suic_disable_cursor();
|
||||
suic_ode_init();
|
||||
void* world = suic_ode_world_create();
|
||||
void* null_space = NULL;
|
||||
void* space = suic_ode_simple_space_create(null_space);
|
||||
suic_ode_world_set_gravity(world, 0.000000, -9.810000, 0.000000);
|
||||
void* contactgroup = suic_ode_joint_group_create(0);
|
||||
void* ground_geom = suic_ode_create_plane_geom(space, 0.000000, 1.000000, 0.000000, 0.000000);
|
||||
void* player_body = suic_ode_body_create(world);
|
||||
suic_ode_body_set_position(player_body, 0.000000, 2.000000, 0.000000);
|
||||
void* player_geom = suic_ode_create_box_geom(space, 0.800000, 1.600000, 0.800000);
|
||||
suic_ode_geom_set_body(player_geom, player_body);
|
||||
suic_ode_body_set_box_mass(player_body, 1.000000, 0.800000, 1.600000, 0.800000);
|
||||
void* cube1_body = suic_ode_body_create(world);
|
||||
suic_ode_body_set_position(cube1_body, 0.000000, 1.000000, -5.000000);
|
||||
suic_ode_body_set_box_mass(cube1_body, 1.000000, 1.000000, 1.000000, 1.000000);
|
||||
void* cube1_geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
|
||||
suic_ode_geom_set_body(cube1_geom, cube1_body);
|
||||
void* cube2_body = suic_ode_body_create(world);
|
||||
suic_ode_body_set_position(cube2_body, 5.000000, 1.000000, -3.000000);
|
||||
suic_ode_body_set_box_mass(cube2_body, 1.000000, 1.000000, 1.000000, 1.000000);
|
||||
void* cube2_geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
|
||||
suic_ode_geom_set_body(cube2_geom, cube2_body);
|
||||
void* cube3_body = suic_ode_body_create(world);
|
||||
suic_ode_body_set_position(cube3_body, -5.000000, 1.000000, -3.000000);
|
||||
suic_ode_body_set_box_mass(cube3_body, 1.000000, 1.000000, 1.000000, 1.000000);
|
||||
void* cube3_geom = suic_ode_create_box_geom(space, 1.000000, 1.000000, 1.000000);
|
||||
suic_ode_geom_set_body(cube3_geom, cube3_body);
|
||||
float forward_x = 0.000000;
|
||||
float forward_y = 0.000000;
|
||||
float forward_z = -1.000000;
|
||||
float right_x = 1.000000;
|
||||
float right_y = 0.000000;
|
||||
float right_z = 0.000000;
|
||||
float camera_x = 0.000000;
|
||||
float camera_y = 2.000000;
|
||||
float camera_z = 0.000000;
|
||||
float target_x = 0.000000;
|
||||
float target_y = 2.000000;
|
||||
float target_z = -5.000000;
|
||||
float yaw = 0.000000;
|
||||
float pitch = 0.000000;
|
||||
float mouse_sensitivity = 0.003000;
|
||||
int fps_meter_visible = 1;
|
||||
char** inventory = suic_alloc_array(NULL, sizeof(char*), 3, (char*[]){suic_alloc_array(NULL, sizeof(char), 6, "Sword"), suic_alloc_array(NULL, sizeof(char), 7, "Shield"), suic_alloc_array(NULL, sizeof(char), 7, "Potion")});
|
||||
bool inventory_open = false;
|
||||
float cube1_x = 0.000000;
|
||||
float cube1_y = 0.000000;
|
||||
float cube1_z = 0.000000;
|
||||
float cube2_x = 0.000000;
|
||||
float cube2_y = 0.000000;
|
||||
float cube2_z = 0.000000;
|
||||
float cube3_x = 0.000000;
|
||||
float cube3_y = 0.000000;
|
||||
float cube3_z = 0.000000;
|
||||
float player_x = 0.000000;
|
||||
float player_y = 2.000000;
|
||||
float player_z = 0.000000;
|
||||
while ((suic_window_should_close() == false)) {
|
||||
float delta_time = suic_get_frame_time();
|
||||
float mouse_delta_x = suic_get_mouse_delta_x();
|
||||
float mouse_delta_y = suic_get_mouse_delta_y();
|
||||
yaw = (yaw + (mouse_delta_x * mouse_sensitivity));
|
||||
pitch = (pitch - (mouse_delta_y * mouse_sensitivity));
|
||||
if ((pitch > 1.500000)) {
|
||||
pitch = 1.500000;
|
||||
}
|
||||
if ((pitch < -1.500000)) {
|
||||
pitch = -1.500000;
|
||||
}
|
||||
float cos_yaw = cos(yaw);
|
||||
float sin_yaw = sin(yaw);
|
||||
float cos_pitch = cos(pitch);
|
||||
float sin_pitch = sin(pitch);
|
||||
forward_x = sin_yaw;
|
||||
forward_y = sin_pitch;
|
||||
forward_z = -cos_yaw;
|
||||
right_x = cos_yaw;
|
||||
right_y = 0.000000;
|
||||
right_z = sin_yaw;
|
||||
float move_speed = 5.000000;
|
||||
float target_vx = 0.000000;
|
||||
float target_vz = 0.000000;
|
||||
if ((suic_is_key_down(KEY_W) != 0)) {
|
||||
target_vx = (target_vx + (forward_x * move_speed));
|
||||
target_vz = (target_vz + (forward_z * move_speed));
|
||||
}
|
||||
if ((suic_is_key_down(KEY_S) != 0)) {
|
||||
target_vx = (target_vx - (forward_x * move_speed));
|
||||
target_vz = (target_vz - (forward_z * move_speed));
|
||||
}
|
||||
if ((suic_is_key_down(KEY_D) != 0)) {
|
||||
target_vx = (target_vx + (right_x * move_speed));
|
||||
target_vz = (target_vz + (right_z * move_speed));
|
||||
}
|
||||
if ((suic_is_key_down(KEY_A) != 0)) {
|
||||
target_vx = (target_vx - (right_x * move_speed));
|
||||
target_vz = (target_vz - (right_z * move_speed));
|
||||
}
|
||||
float current_vx = 0.000000;
|
||||
float current_vy = 0.000000;
|
||||
float current_vz = 0.000000;
|
||||
suic_ode_body_get_linear_vel(player_body, ¤t_vx, ¤t_vy, ¤t_vz);
|
||||
if ((suic_is_jump_pressed() != 0)) {
|
||||
float dummy_x = 0.000000;
|
||||
float current_y = 0.000000;
|
||||
float dummy_z = 0.000000;
|
||||
suic_ode_body_get_position(player_body, &dummy_x, ¤t_y, &dummy_z);
|
||||
if ((current_y <= 1.300000)) {
|
||||
current_vy = 8.000000;
|
||||
}
|
||||
}
|
||||
suic_ode_body_set_linear_vel(player_body, target_vx, current_vy, target_vz);
|
||||
suic_ode_space_collide(world, space, contactgroup);
|
||||
if ((delta_time > 0.000000)) {
|
||||
suic_ode_world_step(world, delta_time);
|
||||
}
|
||||
suic_ode_joint_group_empty(contactgroup);
|
||||
suic_ode_body_get_position(player_body, &player_x, &player_y, &player_z);
|
||||
if (((suic_is_key_pressed(KEY_EQUAL) != 0) || (suic_is_key_pressed(KEY_KP_ADD) != 0))) {
|
||||
mouse_sensitivity = (mouse_sensitivity + 0.001000);
|
||||
}
|
||||
if (((suic_is_key_pressed(KEY_MINUS) != 0) || (suic_is_key_pressed(KEY_KP_SUBTRACT) != 0))) {
|
||||
mouse_sensitivity = (mouse_sensitivity - 0.001000);
|
||||
if ((mouse_sensitivity < 0.001000)) {
|
||||
mouse_sensitivity = 0.001000;
|
||||
}
|
||||
}
|
||||
if ((suic_is_key_pressed(KEY_F1) != 0)) {
|
||||
suic_enable_cursor();
|
||||
}
|
||||
if ((suic_is_key_pressed(KEY_F2) != 0)) {
|
||||
suic_hide_fps_meter();
|
||||
fps_meter_visible = 0;
|
||||
}
|
||||
if ((suic_is_key_pressed(KEY_F3) != 0)) {
|
||||
suic_show_fps_meter((suic_vec2){ .x = 10.000000, .y = 10.000000 });
|
||||
fps_meter_visible = 1;
|
||||
}
|
||||
if ((suic_is_key_pressed(KEY_I) != 0)) {
|
||||
if (inventory_open) {
|
||||
inventory_open = false;
|
||||
suic_disable_cursor();
|
||||
} else {
|
||||
inventory_open = true;
|
||||
suic_enable_cursor();
|
||||
}
|
||||
}
|
||||
camera_x = (player_x + (forward_x * 0.500000));
|
||||
camera_y = (player_y + 0.900000);
|
||||
camera_z = (player_z + (forward_z * 0.500000));
|
||||
target_x = (player_x + (forward_x * 5.000000));
|
||||
target_y = (player_y + (forward_y * 5.000000));
|
||||
target_z = (player_z + (forward_z * 5.000000));
|
||||
suic_ode_body_get_position(cube1_body, &cube1_x, &cube1_y, &cube1_z);
|
||||
suic_ode_body_get_position(cube2_body, &cube2_x, &cube2_y, &cube2_z);
|
||||
suic_ode_body_get_position(cube3_body, &cube3_x, &cube3_y, &cube3_z);
|
||||
suic_begin_drawing();
|
||||
suic_clear_background(135, 206, 235, 255);
|
||||
suic_begin_mode3d(camera_x, camera_y, camera_z, target_x, target_y, target_z, 0.000000, 1.000000, 0.000000, 45.000000, 0);
|
||||
suic_draw_cube(cube1_x, cube1_y, cube1_z, 1.000000, 1.000000, 1.000000, 255, 0, 0, 255);
|
||||
suic_draw_cube_wires(cube1_x, cube1_y, cube1_z, 1.000000, 1.000000, 1.000000, 0, 0, 0, 255);
|
||||
suic_draw_cube(cube2_x, cube2_y, cube2_z, 1.000000, 1.000000, 1.000000, 0, 255, 0, 255);
|
||||
suic_draw_cube_wires(cube2_x, cube2_y, cube2_z, 1.000000, 1.000000, 1.000000, 0, 0, 0, 255);
|
||||
suic_draw_cube(cube3_x, cube3_y, cube3_z, 1.000000, 1.000000, 1.000000, 0, 0, 255, 255);
|
||||
suic_draw_cube_wires(cube3_x, cube3_y, cube3_z, 1.000000, 1.000000, 1.000000, 0, 0, 0, 255);
|
||||
suic_rl_push_matrix();
|
||||
suic_rl_translate_f(player_x, player_y, player_z);
|
||||
suic_rl_rotate_f(((-yaw * 180.000000) / 3.141590), 0.000000, 1.000000, 0.000000);
|
||||
suic_draw_cube(0.000000, 0.000000, 0.000000, 0.800000, 1.600000, 0.800000, 255, 255, 0, 255);
|
||||
suic_draw_cube_wires(0.000000, 0.000000, 0.000000, 0.800000, 1.600000, 0.800000, 0, 0, 0, 255);
|
||||
suic_rl_pop_matrix();
|
||||
suic_end_mode3d();
|
||||
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 2, "N"), 1260, 20, 20, 255, 255, 255, 255);
|
||||
suic_draw_line(1270, 40, 1270, 60, 255, 255, 255, 255);
|
||||
suic_draw_rectangle(1100, 20, 150, 150, 0, 0, 0, 128);
|
||||
suic_draw_rectangle_lines(1100, 20, 150, 150, 255, 255, 255, 128);
|
||||
int minimap_center_x = 1175;
|
||||
int minimap_center_y = 95;
|
||||
suic_draw_circle(minimap_center_x, minimap_center_y, 3.000000, 255, 255, 0, 128);
|
||||
if (inventory_open) {
|
||||
suic_draw_rectangle(200, 100, 400, 300, 0, 0, 0, 200);
|
||||
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 10, "Inventory"), 220, 120, 24, 255, 255, 255, 255);
|
||||
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 6, "Sword"), 220, 160, 18, 200, 200, 200, 255);
|
||||
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 7, "Shield"), 220, 190, 18, 200, 200, 200, 255);
|
||||
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 7, "Potion"), 220, 220, 18, 200, 200, 200, 255);
|
||||
suic_draw_text(suic_alloc_array(NULL, sizeof(char), 17, "Press I to close"), 220, 350, 16, 150, 150, 150, 255);
|
||||
}
|
||||
suic_draw_rectangle(20, 680, 200, 20, 255, 0, 0, 128);
|
||||
suic_draw_rectangle(20, 680, 150, 20, 0, 255, 0, 128);
|
||||
int screen_width = 1280;
|
||||
int screen_height = 720;
|
||||
int crosshair_x = (screen_width / 2);
|
||||
int crosshair_y = (screen_height / 2);
|
||||
suic_draw_line((crosshair_x - 10), crosshair_y, (crosshair_x + 10), crosshair_y, 255, 255, 255, 255);
|
||||
suic_draw_line(crosshair_x, (crosshair_y - 10), crosshair_x, (crosshair_y + 10), 255, 255, 255, 255);
|
||||
suic_end_drawing();
|
||||
}
|
||||
suic_ode_geom_destroy(cube3_geom);
|
||||
suic_ode_body_destroy(cube3_body);
|
||||
suic_ode_geom_destroy(cube2_geom);
|
||||
suic_ode_body_destroy(cube2_body);
|
||||
suic_ode_geom_destroy(cube1_geom);
|
||||
suic_ode_body_destroy(cube1_body);
|
||||
suic_ode_geom_destroy(player_geom);
|
||||
suic_ode_body_destroy(player_body);
|
||||
suic_ode_geom_destroy(ground_geom);
|
||||
suic_ode_joint_group_destroy(contactgroup);
|
||||
suic_ode_space_destroy(space);
|
||||
suic_ode_world_destroy(world);
|
||||
suic_ode_close();
|
||||
suic_close_window();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Initialize GC
|
||||
gc_init();
|
||||
// init globals
|
||||
// init event loop
|
||||
int result = suic_main();
|
||||
// Shutdown GC
|
||||
gc_shutdown();
|
||||
return result;
|
||||
}
|
||||
|
||||
BIN
soup/main.o
BIN
soup/main.o
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue