there is now a player character and the world renders using a cammera
This commit is contained in:
5
source/game_source/entities/CMakeLists.txt
Normal file
5
source/game_source/entities/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
Player.c
|
||||
Centery.c
|
||||
Gun.c
|
||||
)
|
||||
@@ -1,15 +1,129 @@
|
||||
#include "Centery.h"
|
||||
#include "entity_utils.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int CreateCentery(int tear, int classification) {
|
||||
int CenteryInit(void* self) {
|
||||
entity* ent = self;
|
||||
centery* cen = ent->data;
|
||||
cen->direction = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ServerUpdate(void * ent) {
|
||||
entity* e = (entity*)ent;
|
||||
centery* cen = (centery*)e->userdata;
|
||||
int CenteryUpdate(int arg, void* self) {
|
||||
entity* e = self;
|
||||
world* w = e->world;
|
||||
centery* cen = e->data;
|
||||
vec2 moveTo = {0,0};
|
||||
int goodMove;
|
||||
//do{
|
||||
// goodMove = EntityMove(e,(vec2){e->position.x+ 0, e-> position.y + 1});
|
||||
// if(goodMove == 1) {
|
||||
// switch (cen->direction) {
|
||||
// case 0:
|
||||
// moveTo = (vec2){e->position.x+ 0, e-> position.y + 1};
|
||||
// printf("moveing S\n");
|
||||
// break;
|
||||
// case 1:
|
||||
// moveTo = (vec2){e->position.x+ 1, e-> position.y + 1};
|
||||
// printf("moveing SE\n");
|
||||
// break;
|
||||
// case 2:
|
||||
// moveTo = (vec2){e->position.x+ 1, e-> position.y + 0};
|
||||
// printf("moveing E\n");
|
||||
// break;
|
||||
// case 3:
|
||||
// moveTo = (vec2){e->position.x+ 1, e-> position.y + -1};
|
||||
// printf("moveing NE\n");
|
||||
// break;
|
||||
// case 4:
|
||||
// moveTo = (vec2){e->position.x+ 0, e-> position.y + -1};
|
||||
// printf("moveing N\n");
|
||||
// break;
|
||||
// case 6:
|
||||
// moveTo = (vec2){e->position.x+ -1, e->position.y+ -1};
|
||||
// printf("moveing NW\n");
|
||||
// break;
|
||||
// case 7:
|
||||
// moveTo = (vec2){e->position.x+ -1, e->position.y + 0};
|
||||
// printf("moveing W\n");
|
||||
// break;
|
||||
// case 8:
|
||||
// moveTo = (vec2){e->position.x+ -1, e->position.y + 1};
|
||||
// printf("moveing SW\n");
|
||||
// break;
|
||||
// }
|
||||
// goodMove = EntityMove(e,moveTo);
|
||||
// if(cen->direction > 8) {
|
||||
// cen->direction = 0;
|
||||
// }else {
|
||||
// cen->direction ++;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}while(goodMove == 1);
|
||||
|
||||
|
||||
|
||||
printf("name of entity %s\n",e->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CenteryFree(void* self) {
|
||||
entity* ent = self;
|
||||
centery* cen = ent->data;
|
||||
free(cen);
|
||||
free(ent);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
entity* CreateCentery(int tear, int classification, world* w) {
|
||||
entity* ent = (entity*)malloc(sizeof(entity));
|
||||
centery* cen = (centery*)malloc(sizeof(centery));
|
||||
|
||||
*cen = (centery){
|
||||
.weapon = 1,
|
||||
.classification = 1,
|
||||
.tear = 3,
|
||||
.alert = 0,
|
||||
.mode = 0,
|
||||
|
||||
.health = 30,
|
||||
.ac = 3,
|
||||
.str = 3,
|
||||
.wis = 3,
|
||||
.dex = 3,
|
||||
};
|
||||
|
||||
*ent = (entity){
|
||||
.id = CENTERY_ID,
|
||||
.name = "Centery",
|
||||
.description = "Your Basic Bad giy",
|
||||
.tile = {
|
||||
.simble = 'C',
|
||||
.background = {0,0,0},
|
||||
.forground = {0x3f,0x5f,0x10},
|
||||
},
|
||||
.position = (vec2){5,5},
|
||||
.data = cen,
|
||||
.world = w,
|
||||
.callback = {
|
||||
.init = CenteryInit,
|
||||
.update = CenteryUpdate,
|
||||
.free = CenteryFree,
|
||||
},
|
||||
|
||||
.cleanup = 0,
|
||||
};
|
||||
|
||||
return ent;
|
||||
}
|
||||
|
||||
int ServerUpdate(void * ent) {
|
||||
//entity* e = (entity*)ent;
|
||||
//centery* cen = (centery*)e->userdata;
|
||||
|
||||
if(
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -17,6 +131,7 @@ int ClientUpdate(int action, void * centery) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int Init(void * ent){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#ifndef CENTERY_H
|
||||
#define CENTERY_H
|
||||
#define CENTERY_ID 1
|
||||
#include "../entity.h"
|
||||
#include "../world.h"
|
||||
|
||||
typedef struct {
|
||||
entity* target;
|
||||
int weapon;
|
||||
int classification;
|
||||
int tear;
|
||||
int alert;
|
||||
int mode;
|
||||
int direction;
|
||||
|
||||
int health;
|
||||
int ac;
|
||||
@@ -17,7 +19,7 @@ typedef struct {
|
||||
int dex;
|
||||
} centery;
|
||||
|
||||
int CreateCentery(int tear, int classification);
|
||||
entity* CreateCentery(int tear, int classification,world* w);
|
||||
|
||||
int ServerUpdate(void*);
|
||||
int ClientUpdate(int, void*);
|
||||
|
||||
99
source/game_source/entities/Gun.c
Normal file
99
source/game_source/entities/Gun.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "Gun.h"
|
||||
|
||||
int GunUpdate(int action, void* data) {
|
||||
printf("Running Gun\n");
|
||||
entity* e = (entity*)data;
|
||||
vec2 bullet_pos = e->position;
|
||||
Gun* g = (Gun*)e->data;
|
||||
world* w = (world*)e->world;
|
||||
if(g->inpact == 0) {
|
||||
switch (g->direction) {
|
||||
case SHOOT_N: bullet_pos.y -= 1; break;
|
||||
case SHOOT_E: bullet_pos.x += 1; break;
|
||||
case SHOOT_S: bullet_pos.y += 1; break;
|
||||
case SHOOT_W: bullet_pos.x -= 1; break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
g->inpact ++;
|
||||
}
|
||||
|
||||
if(g->inpact > 0) {
|
||||
e->tile.simble = '*';
|
||||
e->tile.background = (color){0xff,0x0a,0x0a};
|
||||
e->tile.forground = (color){0xff,0xff,0xff};
|
||||
g->inpact ++;
|
||||
}
|
||||
if(g->inpact > 25) {
|
||||
|
||||
e->tile.simble = 'o';
|
||||
e->tile.background = (color){0xff,0x20,0x20};
|
||||
e->tile.forground = (color){0xff,0x3f,0x3f};
|
||||
}
|
||||
if(g->inpact > 30) {
|
||||
|
||||
e->tile.simble = 'O';
|
||||
e->tile.background = (color){0x01,0x01,0x01};
|
||||
e->tile.forground = (color){0xff,0x0a,0x0a};
|
||||
}
|
||||
if(g->inpact > 40) {
|
||||
|
||||
e->tile.simble = '#';
|
||||
e->tile.background = (color){0x01,0x01,0x01};
|
||||
e->tile.forground = (color){0xff,0x0a,0x0a};
|
||||
}
|
||||
if(g->inpact > 75) {
|
||||
printf("tagged for cleanup\n");
|
||||
e->tile.simble = 'R';
|
||||
e->cleanup = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
entity* CreateGun(int direction, int bullet, world* w) {
|
||||
entity* ent = malloc(sizeof(entity));
|
||||
Gun* g= malloc(sizeof(Gun));
|
||||
|
||||
*g = (Gun){
|
||||
.direction = direction,
|
||||
.projectileId = bullet,
|
||||
.fuse = 10,
|
||||
.currentFuse = 0,
|
||||
.inpact = 0,
|
||||
};
|
||||
|
||||
|
||||
*ent = (entity){
|
||||
.id = 50,
|
||||
.name = "Gun",
|
||||
.description = "description",
|
||||
.tile = {
|
||||
.simble = '-',
|
||||
.background = {0,0,0},
|
||||
.forground = {0xff,0,0},
|
||||
},
|
||||
.position = (vec2){0,0},
|
||||
.data = g,
|
||||
.world = w,
|
||||
.callback = {
|
||||
.init = GunInit,
|
||||
.update = GunUpdate,
|
||||
.free = GunFree,
|
||||
},
|
||||
|
||||
.cleanup = 0,
|
||||
};
|
||||
|
||||
return ent;
|
||||
}
|
||||
|
||||
int GunInit(void* ent) {return 0;}
|
||||
int GunFree(void* ent) {return 0;}
|
||||
|
||||
26
source/game_source/entities/Gun.h
Normal file
26
source/game_source/entities/Gun.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef ENTITY_Gun_H
|
||||
#define ENTITY_Gun_H
|
||||
#include "../entity.h"
|
||||
#include "../world.h"
|
||||
|
||||
#define SHOOT_N 1
|
||||
#define SHOOT_E 2
|
||||
#define SHOOT_S 3
|
||||
#define SHOOT_W 4
|
||||
|
||||
|
||||
typedef struct {
|
||||
int projectileId;
|
||||
int direction;
|
||||
int fuse;
|
||||
int currentFuse;
|
||||
int inpact;
|
||||
} Gun;
|
||||
|
||||
entity* CreateGun(int direction,int bullet, world* w);
|
||||
|
||||
int GunUpdate(int, void*);
|
||||
int GunInit(void*);
|
||||
int GunFree(void*);
|
||||
|
||||
#endif // ENTITY_Gun_H
|
||||
146
source/game_source/entities/Player.c
Normal file
146
source/game_source/entities/Player.c
Normal file
@@ -0,0 +1,146 @@
|
||||
|
||||
#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;}
|
||||
|
||||
30
source/game_source/entities/Player.h
Normal file
30
source/game_source/entities/Player.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#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
|
||||
42
source/game_source/entities/templates/Template.c
Normal file
42
source/game_source/entities/templates/Template.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdlib.h>
|
||||
#include "Template.h"
|
||||
#include "../../client_source/client.h"
|
||||
|
||||
int templateUpdate(int action, void* data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
entity* Createtemplate() {
|
||||
entity* ent = malloc(sizeof(entity));
|
||||
template* p= malloc(sizeof(template));
|
||||
|
||||
*t = (template){
|
||||
};
|
||||
|
||||
|
||||
*ent = (entity){
|
||||
.id = ID,
|
||||
.name = "template",
|
||||
.description = "description",
|
||||
.tile = {
|
||||
.simble = 'T',
|
||||
.background = {0,0,0},
|
||||
.forground = {0,0,0},
|
||||
},
|
||||
.position = (vec2){0,0},
|
||||
.data = t,
|
||||
.world = w,
|
||||
.callback = {
|
||||
.init = PlayerInit,
|
||||
.update = PlayerUpdate,
|
||||
.free = PlayerFree,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
return ent;
|
||||
}
|
||||
|
||||
int templateInit(void* ent) {return 0;}
|
||||
int templateFree(void* ent) {return 0;}
|
||||
|
||||
16
source/game_source/entities/templates/Template.h
Normal file
16
source/game_source/entities/templates/Template.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef ENTITY_template_H
|
||||
#define ENTITY_template_H
|
||||
#include "../entity.h"
|
||||
#include "../world.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
} template;
|
||||
|
||||
entity* Createtemplate(initvar);
|
||||
|
||||
int templateUpdate(int, void*);
|
||||
int templateInit(void*);
|
||||
int templateFree(void*);
|
||||
|
||||
#endif // ENTITY_template_H
|
||||
Reference in New Issue
Block a user