there is now a player character and the world renders using a cammera
This commit is contained in:
82
source/game_source/cammera.c
Normal file
82
source/game_source/cammera.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "cammera.h"
|
||||
#include "entity.h"
|
||||
#include <tart.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define jump tart_move_cursor
|
||||
|
||||
int CammeraInit(cammera* c, int sx, int sy, int px, int py, world* w, tart_window* tw) {
|
||||
c->w = w;
|
||||
c->tw = tw;
|
||||
|
||||
c->pos_x = px;
|
||||
c->pos_y = py;
|
||||
|
||||
c->size_x = sx;
|
||||
c->size_y = sy;
|
||||
|
||||
c->tileCount = c->size_x * c->size_y;
|
||||
//c->frame = (tile*)malloc(c->tileCount * sizeof(tile));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CammeraResize(cammera* c, int sx, int sy) {
|
||||
tart_window_resize(c->tw, (tart_vec2){sx,sy});
|
||||
c->size_x = sx ;
|
||||
c->size_y = sy;
|
||||
|
||||
//free(c->frame);
|
||||
|
||||
c->tileCount = c->size_x * c->size_y;
|
||||
//c->frame = (tile*)malloc(c->tileCount * sizeof(tile));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CammeraRender(cammera*c) {
|
||||
jump(c->tw, (tart_vec2){0,0});
|
||||
for(int i = 0; i < c->size_y; i++) {
|
||||
for(int j = 0; j < c->size_x - 1; j++) {
|
||||
|
||||
if(c->pos_y+i < c->w->size_y-1 && c->pos_y+i >= 0 && c->pos_x+j < c->w->size_x-1 && c->pos_x+j >= 0){
|
||||
c->tw->palette[2].background.r = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].cell->tile.background.r;
|
||||
c->tw->palette[2].background.g = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].cell->tile.background.g;
|
||||
c->tw->palette[2].background.b = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].cell->tile.background.b;
|
||||
c->tw->palette[2].forground.r = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].cell->tile.forground.r;
|
||||
c->tw->palette[2].forground.g = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].cell->tile.forground.g;
|
||||
c->tw->palette[2].forground.b = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].cell->tile.forground.b;
|
||||
|
||||
tart_jump(c->tw, (tart_vec2){j,i});
|
||||
|
||||
for(int k = 0; k < 1; k++) {
|
||||
if(c->w->wells[at((c->pos_x+j) ,(c->pos_y+i),c->w)].entityIds[0] != 0000) {
|
||||
if(c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.background.r != 0 &&
|
||||
c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.background.r != 0 &&
|
||||
c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.background.r != 0) {
|
||||
|
||||
c->tw->palette[2].background.r = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.background.r;
|
||||
c->tw->palette[2].background.g = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.background.g;
|
||||
c->tw->palette[2].background.b = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.background.b;
|
||||
}
|
||||
c->tw->palette[2].forground.r = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.forground.r;
|
||||
c->tw->palette[2].forground.g = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.forground.g;
|
||||
c->tw->palette[2].forground.b = c->w->wells[at(c->pos_x+j,c->pos_y+i,c->w)].entityIds[k]->tile.forground.b;
|
||||
tart_insert_cell(c->tw, 2, c->w->wells[at((c->pos_x+j) ,(c->pos_y+i),c->w)]
|
||||
.entityIds[k]->tile.simble);
|
||||
printf("found entity %c\n", c->w->wells[at((c->pos_x+j) ,(c->pos_y+i),c->w)]
|
||||
.entityIds[k]->tile.simble);
|
||||
}
|
||||
}
|
||||
tart_insert_cell(c->tw, 2, c->w->wells[at((c->pos_x+j) ,(c->pos_y+i),c->w)]
|
||||
.cell->tile.simble);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CammeraFree(cammera *c) {
|
||||
//free(c->frame);
|
||||
}
|
||||
Reference in New Issue
Block a user