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

@@ -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;}