adding multiplayer
This commit is contained in:
105
source/game_source/entities/Player_e.c
Normal file
105
source/game_source/entities/Player_e.c
Normal file
@@ -0,0 +1,105 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "Player_e.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "../../server_source/transactions.h"
|
||||
|
||||
|
||||
#define PlayerMove 1
|
||||
|
||||
|
||||
|
||||
int PlayerEUpdate(int action, void* data) {
|
||||
entity* e = (entity*)data;
|
||||
player_data* p= (player_data*)e->data;
|
||||
world* w = e->world;
|
||||
vec2 moveTo = e->position;
|
||||
int goodMove;
|
||||
user_transaction pos_ut;
|
||||
memset(&pos_ut, 0, sizeof(pos_ut));
|
||||
printf("getting transaction\n");
|
||||
|
||||
//printf("Has Connection\n");
|
||||
//printf("cli sock %d, entity sock ,\n", e->server->socket);
|
||||
if(e->server > 0) {
|
||||
|
||||
|
||||
if(RecvUserTransaction(&pos_ut, e->server)) {
|
||||
printf("Centery NG\n");
|
||||
}else {
|
||||
|
||||
memcpy(&moveTo, pos_ut.userArg,sizeof(vec2));
|
||||
printf("size of post_ut %d\n", pos_ut.argsize);
|
||||
printf("move to %d,%d\n", moveTo.x,moveTo.y);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!EntityMove(e, &moveTo)) {
|
||||
|
||||
// st_move = (user_transaction){
|
||||
// .userArg = &mv,
|
||||
// .action = PlayerMove,
|
||||
// .id = SERVER_T_USER_FLAG,
|
||||
// .argsize = sizeof(mv),
|
||||
//};
|
||||
|
||||
|
||||
//w->wells[at(mv.x, mv.y, w)].cell = SetCell(6);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PlayerEFree(void* data) {
|
||||
return 0;
|
||||
}
|
||||
int PlayerEInit(void* data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
entity* CreatePlayerEntity(player_data pd, int serverfd,world* w) {
|
||||
entity* ent = malloc(sizeof(entity));
|
||||
player_data* p= malloc(sizeof(player_data));
|
||||
|
||||
*p = (player_data){
|
||||
.holding = pd.holding,
|
||||
.class = pd.class,
|
||||
|
||||
.health = pd.health,
|
||||
.ac = pd.ac,
|
||||
.str = pd.str,
|
||||
.wis = pd.wis,
|
||||
.dex = pd.dex,
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
*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 = PlayerEInit,
|
||||
.update = PlayerEUpdate,
|
||||
.free = PlayerEFree,
|
||||
},
|
||||
.cleanup = 0,
|
||||
|
||||
};
|
||||
|
||||
return ent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user