147 lines
3.8 KiB
C
147 lines
3.8 KiB
C
|
|
#include <stdlib.h>
|
|
#include "Player.h"
|
|
#include "Gun.h"
|
|
#include "Centery.h"
|
|
#include "../../client_source/client.h"
|
|
|
|
void Shoot(entity* e,int direction) {
|
|
if(direction == SHOOT_N) {
|
|
entity* g = CreateGun(SHOOT_N, 0, e->world);
|
|
g->position = (vec2){e->position.x, e->position.y-1};
|
|
world* w = e->world;
|
|
AddEntity(w, g);
|
|
printf("Shoot N\n");
|
|
}
|
|
if(direction == SHOOT_E) {
|
|
entity* g = CreateGun(SHOOT_E, 0, e->world);
|
|
world* w = e->world;
|
|
g->position = (vec2){e->position.x + 1, e->position.y};
|
|
AddEntity(w, g);
|
|
printf("Shoot E\n");
|
|
}
|
|
if(direction == SHOOT_S) {
|
|
entity* g = CreateGun(SHOOT_S, 0, e->world);
|
|
world* w = e->world;
|
|
g->position = (vec2){e->position.x, e->position.y+1};
|
|
AddEntity(w, g);
|
|
printf("Shoot S\n");
|
|
}
|
|
if(direction == SHOOT_W) {
|
|
entity* g = CreateGun(SHOOT_W, 0, e->world);
|
|
world* w = e->world;
|
|
g->position = (vec2){e->position.x - 1, e->position.y};
|
|
AddEntity(w, g);
|
|
printf("Shoot W\n");
|
|
}
|
|
}
|
|
|
|
int PlayerUpdate(int action, void* data) {
|
|
entity* e = (entity*)data;
|
|
player* p= (player*)e->data;
|
|
world* w = e->world;
|
|
ssh_terminal_data* td = &p->cli->term;
|
|
vec2 mv = {e->position.x, e->position.y};
|
|
vec2 cammera_pos = {
|
|
p->cli->cam.pos_x + (p->cli->cam.size_x/2),
|
|
p->cli->cam.pos_y + (p->cli->cam.size_y/2),
|
|
};
|
|
int cammera_fallow_readious = 14;
|
|
|
|
printf("input buffer for player %s\n", td->inputBuffer);
|
|
|
|
if(!strcmp(td->inputBuffer, "k")) {mv.y -= 1;}
|
|
if(!strcmp(td->inputBuffer, "j")) {mv.y += 1;}
|
|
if(!strcmp(td->inputBuffer, "h")) {mv.x -= 1;}
|
|
if(!strcmp(td->inputBuffer, "l")) {mv.x += 1;}
|
|
|
|
|
|
int entity_can_move = EntityMove(e, mv);
|
|
if(!strcmp(td->inputBuffer, "w")) {Shoot(e,SHOOT_N);}
|
|
if(!strcmp(td->inputBuffer, "d")) {Shoot(e,SHOOT_E);}
|
|
if(!strcmp(td->inputBuffer, "s")) {Shoot(e,SHOOT_S);}
|
|
if(!strcmp(td->inputBuffer, "a")) {Shoot(e,SHOOT_W);}
|
|
printf("Cammera Position %d,%d\n", cammera_pos.x, cammera_pos.y);
|
|
|
|
|
|
|
|
|
|
if((e->position.x < cammera_pos.x - cammera_fallow_readious )){
|
|
p->cli->cam.pos_x += - 1;
|
|
}
|
|
if ((e->position.x > cammera_pos.x + cammera_fallow_readious)) {
|
|
p->cli->cam.pos_x += 1;
|
|
}
|
|
|
|
if((e->position.y < cammera_pos.y - (cammera_fallow_readious / 2) )){
|
|
p->cli->cam.pos_y += - 1;
|
|
}
|
|
if ((e->position.y > cammera_pos.y + (cammera_fallow_readious / 2))) {
|
|
p->cli->cam.pos_y += 1;
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!entity_can_move) {
|
|
w->wells[at(mv.x, mv.y, w)].cell = SetCell(6);
|
|
}
|
|
printf("is this a good move? %d\n", EntityMove(e, mv));
|
|
|
|
|
|
|
|
memset(td->inputBuffer,0,32);
|
|
return 0;
|
|
}
|
|
|
|
entity* CreatePlayer(const char* username, client* cli,world* w) {
|
|
entity* ent = malloc(sizeof(entity));
|
|
player* p= malloc(sizeof(player));
|
|
|
|
*p = (player){
|
|
.holding = 0,
|
|
.class = 0,
|
|
|
|
.health = 0,
|
|
.ac = 0,
|
|
.str = 0,
|
|
.wis = 0,
|
|
.dex = 0,
|
|
.cli = cli,
|
|
|
|
|
|
};
|
|
|
|
|
|
*ent = (entity){
|
|
.id = 30,
|
|
.name = "Testing",
|
|
.description = "This is a player",
|
|
.tile = {
|
|
.simble = '@',
|
|
.background = {0,0,0},
|
|
.forground = {0x5f,0x3f,0x10},
|
|
},
|
|
.position = (vec2){5,5},
|
|
.data = p,
|
|
.world = w,
|
|
.callback = {
|
|
.init = PlayerInit,
|
|
.update = PlayerUpdate,
|
|
.free = PlayerFree,
|
|
},
|
|
.cleanup = 0,
|
|
|
|
};
|
|
|
|
p->cli->cam.pos_x = ent->position.x - (p->cli->cam.size_x/2);
|
|
p->cli->cam.pos_y = ent->position.y - (p->cli->cam.size_y/2);
|
|
return ent;
|
|
}
|
|
|
|
int PlayerServerUpdate(void*);
|
|
int PlayerClientUpdate(int, void*);
|
|
int PlayerInit(void* ent) {return 0;}
|
|
int PlayerFree(void* ent) {return 0;}
|
|
|