there is now a player character and the world renders using a cammera

This commit is contained in:
2026-04-09 13:11:55 -07:00
parent 09c310cb4a
commit af639e62c3
47 changed files with 1737 additions and 83 deletions

View File

@@ -1,22 +1,139 @@
#include "client.h"
#include <bits/time.h>
#include <stdlib.h>
#include <string.h>
#include <tart.h>
#include <unistd.h>
#include <signal.h>
#include "../game_source/entities/Player.h"
#include <sys/random.h>
#include <stdio.h>
#include <locale.h>
#include <time.h>
#define jump tart_move_cursor
#define FPS 60
#define FRAME_TIME (1000.0 / FPS)
int e = 1;
void aOnExit() {
//printf("shutting Down");
e = 0;
}
void draw_button(tart_window *w,const t_char* label, tart_vec2 position) {
jump(w, (tart_vec2){position.x,position.y + 0});
tart_printf(w, 1, T"┏━━━");
int size = t_strlen(label);
for(int i = 0; i < size; i++ ) {
tart_printf(w, 1, T"");
}
tart_printf(w, 1, T"━━━┓");
jump(w, (tart_vec2){position.x,position.y + 1});
tart_printf(w, 1, T"┃ %ls ┃", label);
jump(w, (tart_vec2){position.x,position.y + 2});
tart_printf(w, 1, T"┗━━━");
for(int i = 0; i < size; i++ ) {
tart_printf(w, 1, T"");
}
tart_printf(w, 1, T"━━━┛");
}
int limit_fps(int fps, struct timespec* last_time) {
struct timespec current_time;
double frame_time = 1.0 / fps;
clock_gettime(CLOCK_MONOTONIC, &current_time);
double elapsed = (current_time.tv_sec - last_time->tv_sec) +
(current_time.tv_nsec - last_time->tv_nsec) / 1e9;
if (elapsed < frame_time) {
return 0;
}
clock_gettime(CLOCK_MONOTONIC, last_time);
return 1;
}
int client_auth(void* userdata);
int client_init(void* cli) {
setlocale(LC_CTYPE, "en_US.UTF-8");
client* c = (client*)cli;
int x = 0;
c->last_frame_time = clock();
tart_create_window(&c->w, (tart_vec2){150,50}, "testing", c->channel);
tart_init(&c->w);
//jump(&c->w, (tart_vec2){1,1});
//jump(&c->w, (tart_vec2){1,2});
tart_disable_cusor(&c->w);
c->world.size_x = 600;
c->world.size_y = 600;
CreateWorld(&c->world, clock());
InitWorld(&c->world);
entity* cen = CreatePlayer("testing", c, &c->world);
cen->position.x = 3;
cen->position.y = 3;
AddEntity(&c->world, cen);
GenerateWorld(&c->world);
CammeraInit(&c->cam, 150,50,0,0,&c->world, &c->w);
clock_gettime(CLOCK_MONOTONIC,&c->last_time);
return 0;
}
int client_update(ssh_terminal_data* td, void* cli) {
//signal(SIGINT, aOnExit);
client* c = (client*)cli;
strcpy(td->outputBuffer, "testing 1212\n\r");
tart_window w = c->w;
//tart_init(&w);
if(limit_fps(FPS, &c->last_time) == 1) {
int newSize = tart_draw_to_buffer(&w);
CammeraRender(&c->cam);
tart_jump(&w, (tart_vec2){w.windowSize.x, w.windowSize.y-1});
tart_insert_cell(&w, 5, 'a');
}
UpdateWorld(&c->world);
return 0;
}
int client_stop(void* cli) {
client* c = (client*)cli;
printf("Clossing connection\n");
tart_enable_cusor(&c->w);
tart_close(&c->w);
return 0;
}
int client_resize(int x, int y, void *userdata) {
client* c = (client*)userdata;
printf("client address %d\n", userdata);
printf("cammeraSize %d,%d\n", x, y);
int posx = 000000000000;
int posy = 000000000000;
CammeraInit(&c->cam, x, y, posx, posy, &c->world, &c->w);
tart_window_resize(&c->w, (tart_vec2){x-1,y});
//CammeraInit(&c->cam, c->cam.size_x, c->cam.size_y, c->cam.pos_x, c->cam.pos_y, &c->world, &c->w);
//c->cam.tw = &c->w;
return 0;
}