adding multiplayer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
Player.c
|
||||
Player_c.c
|
||||
Player_e.c
|
||||
Centery.c
|
||||
Gun.c
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "Centery.h"
|
||||
#include "../../server_source/transactions.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int CenteryInit(void* self) {
|
||||
entity* ent = self;
|
||||
@@ -13,8 +15,42 @@ int CenteryUpdate(int arg, void* self) {
|
||||
entity* e = self;
|
||||
world* w = e->world;
|
||||
centery* cen = e->data;
|
||||
vec2 moveTo = {0,0};
|
||||
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(cen->cli->server.game_info.socket > 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);
|
||||
}
|
||||
|
||||
//do{
|
||||
// goodMove = EntityMove(e,(vec2){e->position.x+ 0, e-> position.y + 1});
|
||||
// if(goodMove == 1) {
|
||||
@@ -64,7 +100,7 @@ int CenteryUpdate(int arg, void* self) {
|
||||
|
||||
|
||||
|
||||
printf("name of entity %s\n",e->name);
|
||||
//printf("name of entity %s\n",e->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -78,7 +114,7 @@ int CenteryFree(void* self) {
|
||||
|
||||
|
||||
|
||||
entity* CreateCentery(int tear, int classification, world* w) {
|
||||
entity* CreateCentery(int tear, client* cli, world* w) {
|
||||
entity* ent = (entity*)malloc(sizeof(entity));
|
||||
centery* cen = (centery*)malloc(sizeof(centery));
|
||||
|
||||
@@ -94,6 +130,7 @@ entity* CreateCentery(int tear, int classification, world* w) {
|
||||
.str = 3,
|
||||
.wis = 3,
|
||||
.dex = 3,
|
||||
.cli = cli,
|
||||
};
|
||||
|
||||
*ent = (entity){
|
||||
@@ -103,7 +140,7 @@ entity* CreateCentery(int tear, int classification, world* w) {
|
||||
.tile = {
|
||||
.simble = 'C',
|
||||
.background = {0,0,0},
|
||||
.forground = {0x3f,0x5f,0x10},
|
||||
.forground = {0xff,0x10,0x10},
|
||||
},
|
||||
.position = (vec2){5,5},
|
||||
.data = cen,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#define CENTERY_ID 1
|
||||
#include "../entity.h"
|
||||
#include "../world.h"
|
||||
#include "../../client_source/client.h"
|
||||
|
||||
typedef struct {
|
||||
int weapon;
|
||||
@@ -17,9 +18,11 @@ typedef struct {
|
||||
int str;
|
||||
int wis;
|
||||
int dex;
|
||||
client* cli;
|
||||
|
||||
} centery;
|
||||
|
||||
entity* CreateCentery(int tear, int classification,world* w);
|
||||
entity* CreateCentery(int tear, client* cli,world* w);
|
||||
|
||||
int ServerUpdate(void*);
|
||||
int ClientUpdate(int, void*);
|
||||
|
||||
@@ -16,7 +16,7 @@ int GunUpdate(int action, void* data) {
|
||||
case SHOOT_W: bullet_pos.x -= 1; break;
|
||||
}
|
||||
}
|
||||
int entity_colied = EntityMove(e, bullet_pos);
|
||||
int entity_colied = EntityMove(e, &bullet_pos);
|
||||
if((entity_colied) && g->inpact == 0) {
|
||||
if(w->wells[at(bullet_pos.x, bullet_pos.y, w)].cell->id == 1) {
|
||||
w->wells[at(bullet_pos.x, bullet_pos.y, w)].cell = SetCell(2);
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include "../entity.h"
|
||||
#include "../../client_source/client.h"
|
||||
#include "../world.h"
|
||||
|
||||
typedef struct {
|
||||
int holding;
|
||||
int class;
|
||||
|
||||
int health;
|
||||
int ac;
|
||||
int str;
|
||||
int wis;
|
||||
int dex;
|
||||
client* cli;
|
||||
|
||||
|
||||
int invintory[30];
|
||||
} player;
|
||||
|
||||
entity* CreatePlayer(const char* username, client* cli ,world* w);
|
||||
|
||||
int PlayerServerUpdate(void*);
|
||||
int PlayerClientUpdate(int, void*);
|
||||
int PlayerInit(void*);
|
||||
int PlayerFree(void*);
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,17 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "Player.h"
|
||||
#include "Player_c.h"
|
||||
#include "Gun.h"
|
||||
#include "Centery.h"
|
||||
#include "../../client_source/client.h"
|
||||
#include "../../server_source/transactions.h"
|
||||
|
||||
typedef struct {
|
||||
player_data pd;
|
||||
client* cli;
|
||||
}player_c;
|
||||
|
||||
#define PlayerMove 1
|
||||
|
||||
|
||||
void Shoot(entity* e,int direction) {
|
||||
if(direction == SHOOT_N) {
|
||||
@@ -36,9 +44,9 @@ void Shoot(entity* e,int direction) {
|
||||
}
|
||||
}
|
||||
|
||||
int PlayerUpdate(int action, void* data) {
|
||||
int PlayerUpdateC(int action, void* data) {
|
||||
entity* e = (entity*)data;
|
||||
player* p= (player*)e->data;
|
||||
player_c* p= (player_c*)e->data;
|
||||
world* w = e->world;
|
||||
ssh_terminal_data* td = &p->cli->term;
|
||||
vec2 mv = {e->position.x, e->position.y};
|
||||
@@ -48,23 +56,46 @@ int PlayerUpdate(int action, void* data) {
|
||||
};
|
||||
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;}
|
||||
char* ib = td->inputBuffer;
|
||||
int ibsize = strlen(ib);
|
||||
|
||||
while(ib < ib+ibsize) {
|
||||
|
||||
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(!strcmp(ib, "\e[A")) {mv.y -= 1; ib += 3; continue;}
|
||||
if(!strcmp(ib, "\e[B")) {mv.y += 1; ib += 3; continue;}
|
||||
if(!strcmp(ib, "\e[D")) {mv.x -= 1; ib += 3; continue;}
|
||||
if(!strcmp(ib, "\e[C")) {mv.x += 1; ib += 3; continue;}
|
||||
|
||||
user_transaction st_move;
|
||||
memset(&st_move, 0, sizeof(st_move));
|
||||
|
||||
st_move = (user_transaction){
|
||||
.userArg = &mv,
|
||||
.action = PlayerMove,
|
||||
.id = SERVER_T_USER_FLAG,
|
||||
.argsize = sizeof(mv),
|
||||
};
|
||||
|
||||
|
||||
if(p->cli->server.game_info.socket > 0) {
|
||||
printf("Has Connection\n");
|
||||
if(SendUserTransaction(&st_move, p->cli->server.game_info.socket)) {
|
||||
printf("NG\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!strcmp(ib, "w")) {Shoot(e,SHOOT_N); ib += 1; continue;}
|
||||
if(!strcmp(ib, "d")) {Shoot(e,SHOOT_E); ib += 1; continue;}
|
||||
if(!strcmp(ib, "s")) {Shoot(e,SHOOT_S); ib += 1; continue;}
|
||||
if(!strcmp(ib, "a")) {Shoot(e,SHOOT_W); ib += 1; continue;}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int entity_can_move = EntityMove(e, &mv);
|
||||
|
||||
|
||||
if((e->position.x < cammera_pos.x - cammera_fallow_readious )){
|
||||
p->cli->cam.pos_x += - 1;
|
||||
@@ -83,10 +114,9 @@ int PlayerUpdate(int action, void* data) {
|
||||
|
||||
|
||||
|
||||
if(!entity_can_move) {
|
||||
w->wells[at(mv.x, mv.y, w)].cell = SetCell(6);
|
||||
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));
|
||||
|
||||
|
||||
|
||||
@@ -94,22 +124,20 @@ int PlayerUpdate(int action, void* data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
entity* CreatePlayer(const char* username, client* cli,world* w) {
|
||||
int PlayerCFree(void* data) {
|
||||
return 0;
|
||||
}
|
||||
int PlayerCInit(void* data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
entity* CreatePlayerCharecter(player_data pd, client* cli ,world* w) {
|
||||
entity* ent = malloc(sizeof(entity));
|
||||
player* p= malloc(sizeof(player));
|
||||
player_c* p= malloc(sizeof(player_c));
|
||||
|
||||
*p = (player){
|
||||
.holding = 0,
|
||||
.class = 0,
|
||||
|
||||
.health = 0,
|
||||
.ac = 0,
|
||||
.str = 0,
|
||||
.wis = 0,
|
||||
.dex = 0,
|
||||
.cli = cli,
|
||||
|
||||
|
||||
*p = (player_c){
|
||||
.pd = pd,
|
||||
.cli = cli,
|
||||
};
|
||||
|
||||
|
||||
@@ -126,9 +154,9 @@ entity* CreatePlayer(const char* username, client* cli,world* w) {
|
||||
.data = p,
|
||||
.world = w,
|
||||
.callback = {
|
||||
.init = PlayerInit,
|
||||
.update = PlayerUpdate,
|
||||
.free = PlayerFree,
|
||||
.init = PlayerCInit,
|
||||
.update = PlayerUpdateC,
|
||||
.free = PlayerCFree,
|
||||
},
|
||||
.cleanup = 0,
|
||||
|
||||
@@ -139,8 +167,3 @@ entity* CreatePlayer(const char* username, client* cli,world* w) {
|
||||
return ent;
|
||||
}
|
||||
|
||||
int PlayerServerUpdate(void*);
|
||||
int PlayerClientUpdate(int, void*);
|
||||
int PlayerInit(void* ent) {return 0;}
|
||||
int PlayerFree(void* ent) {return 0;}
|
||||
|
||||
13
source/game_source/entities/Player_c.h
Normal file
13
source/game_source/entities/Player_c.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef PLAYER_C_H
|
||||
#define PLAYER_C_H
|
||||
|
||||
#include "../entity.h"
|
||||
#include "../../client_source/client.h"
|
||||
#include "../world.h"
|
||||
#include "../player/player_data.h"
|
||||
|
||||
|
||||
entity* CreatePlayerCharecter(player_data pd, client* cli ,world* w);
|
||||
|
||||
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
|
||||
11
source/game_source/entities/Player_e.h
Normal file
11
source/game_source/entities/Player_e.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef PLAYER_E_H
|
||||
#define PLAYER_E_H
|
||||
|
||||
#include "../entity.h"
|
||||
#include "../world.h"
|
||||
#include "../player/player_data.h"
|
||||
|
||||
entity* CreatePlayerEntity(player_data pd, int serverfd, world* w);
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user