Field of view calculated with libfov.
This commit is contained in:
2
Makefile
2
Makefile
@@ -4,7 +4,7 @@ OBJECTS = obj/main.o obj/game_state.o obj/in_game.o obj/map.o
|
|||||||
TARGET = bin/cyjam
|
TARGET = bin/cyjam
|
||||||
CFLAGS = -Wall -I./include -std=c99
|
CFLAGS = -Wall -I./include -std=c99
|
||||||
LDFLAGS = -L./lib
|
LDFLAGS = -L./lib
|
||||||
LDLIBS = -lm -lfov -lncursesw
|
LDLIBS = -lfov -lncursesw -lm
|
||||||
|
|
||||||
all: CFLAGS += -O3
|
all: CFLAGS += -O3
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|||||||
BIN
lib/libfov.a
BIN
lib/libfov.a
Binary file not shown.
131
src/in_game.c
131
src/in_game.c
@@ -6,6 +6,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
|
#include <fov.h>
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "in_game.h"
|
#include "in_game.h"
|
||||||
@@ -16,6 +17,7 @@ typedef struct PLAYER {
|
|||||||
unsigned short y;
|
unsigned short y;
|
||||||
} player_t;
|
} player_t;
|
||||||
|
|
||||||
|
static bool **vis;
|
||||||
static bool ** wmap;
|
static bool ** wmap;
|
||||||
static bool w_mov = FALSE;
|
static bool w_mov = FALSE;
|
||||||
static bool uK, dK, lK, rK;
|
static bool uK, dK, lK, rK;
|
||||||
@@ -24,6 +26,7 @@ static player_t player;
|
|||||||
static map_cell_t ** map;
|
static map_cell_t ** map;
|
||||||
game_obj_t objs[MAX_OBJECTS];
|
game_obj_t objs[MAX_OBJECTS];
|
||||||
static int mW, mH, nO;
|
static int mW, mH, nO;
|
||||||
|
fov_settings_type fov_settings;
|
||||||
|
|
||||||
void input();
|
void input();
|
||||||
gsname_t update();
|
gsname_t update();
|
||||||
@@ -33,6 +36,8 @@ void setPlayerStart();
|
|||||||
void initObjects();
|
void initObjects();
|
||||||
void drawNeon(int, int);
|
void drawNeon(int, int);
|
||||||
void drawBar(int, int);
|
void drawBar(int, int);
|
||||||
|
void apply(void *, int, int, int, int, void *);
|
||||||
|
bool opaque(void *, int, int);
|
||||||
|
|
||||||
void initInGameState( gs_t * gs) {
|
void initInGameState( gs_t * gs) {
|
||||||
int i, j;
|
int i, j;
|
||||||
@@ -55,6 +60,14 @@ void initInGameState( gs_t * gs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vis = ( bool ** ) malloc ( sizeof ( bool * ) * MAX_MAP_SIZE);
|
||||||
|
for ( i = 0; i < MAX_MAP_SIZE; ++i ) {
|
||||||
|
vis[ i ] = ( bool * ) calloc ( MAX_MAP_SIZE, sizeof ( bool ) );
|
||||||
|
for(j = 0; j < MAX_MAP_SIZE; ++j){
|
||||||
|
vis[i][j] = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initObjects();
|
initObjects();
|
||||||
|
|
||||||
errcode_t rc = readMapData("map_file.map", &map, &mW, &mH);
|
errcode_t rc = readMapData("map_file.map", &map, &mW, &mH);
|
||||||
@@ -71,6 +84,10 @@ void initInGameState( gs_t * gs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPlayerStart();
|
setPlayerStart();
|
||||||
|
|
||||||
|
fov_settings_init(&fov_settings);
|
||||||
|
fov_settings_set_opacity_test_function(&fov_settings, opaque);
|
||||||
|
fov_settings_set_apply_lighting_function(&fov_settings, apply);
|
||||||
}
|
}
|
||||||
|
|
||||||
void input(){
|
void input(){
|
||||||
@@ -137,6 +154,8 @@ void render(int w, int h){
|
|||||||
ioff = (w - 28) / 2;
|
ioff = (w - 28) / 2;
|
||||||
joff = (h - 2) / 2;
|
joff = (h - 2) / 2;
|
||||||
|
|
||||||
|
fov_circle(&fov_settings, &map, NULL, player.x, player.y, (MAX_MAP_SIZE / 2) - 1);
|
||||||
|
|
||||||
for(i = 27; i < w - 1; i++){
|
for(i = 27; i < w - 1; i++){
|
||||||
for(j = 1; j < h - 1; j++){
|
for(j = 1; j < h - 1; j++){
|
||||||
move(j, i);
|
move(j, i);
|
||||||
@@ -147,56 +166,61 @@ void render(int w, int h){
|
|||||||
if( di < 0 || di >= mW || dj < 0 || dj >= mH ){
|
if( di < 0 || di >= mW || dj < 0 || dj >= mH ){
|
||||||
printw(" ");
|
printw(" ");
|
||||||
}else{
|
}else{
|
||||||
switch(map[dj][di].f){
|
if(vis[dj][di]){
|
||||||
case WATER:
|
switch(map[dj][di].f){
|
||||||
attron(COLOR_PAIR(DW_COLOR));
|
case WATER:
|
||||||
if(w_mov)
|
attron(COLOR_PAIR(DW_COLOR));
|
||||||
wmap[dj][di] = !wmap[dj][di];
|
if(w_mov)
|
||||||
if(wmap[dj][di])
|
wmap[dj][di] = !wmap[dj][di];
|
||||||
printw("\u2248");
|
if(wmap[dj][di])
|
||||||
else
|
printw("\u2248");
|
||||||
printw("~");
|
else
|
||||||
break;
|
printw("~");
|
||||||
|
break;
|
||||||
|
|
||||||
case VOID:
|
case VOID:
|
||||||
attron(COLOR_PAIR(MN_COLOR));
|
attron(COLOR_PAIR(MN_COLOR));
|
||||||
printw(" ");
|
printw(" ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EMPTY_FLOOR:
|
case EMPTY_FLOOR:
|
||||||
attron(COLOR_PAIR(MN_COLOR));
|
attron(COLOR_PAIR(MN_COLOR));
|
||||||
printw(" ");
|
printw(" ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RUG:
|
case RUG:
|
||||||
attron(COLOR_PAIR(SN_COLOR));
|
attron(COLOR_PAIR(SN_COLOR));
|
||||||
printw("\u2592");
|
printw("\u2592");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WINDOW_WALL:
|
case WINDOW_WALL:
|
||||||
attron(COLOR_PAIR(SW_COLOR));
|
attron(COLOR_PAIR(SW_COLOR));
|
||||||
printw("\u2591");
|
printw("\u2591");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLEAR_WALL:
|
case CLEAR_WALL:
|
||||||
attron(COLOR_PAIR(SW_COLOR));
|
attron(COLOR_PAIR(SW_COLOR));
|
||||||
printw("\u2588");
|
printw("\u2588");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SECRET_WALL:
|
case SECRET_WALL:
|
||||||
case SOLID_WALL:
|
case SOLID_WALL:
|
||||||
attron(COLOR_PAIR(MN_COLOR));
|
attron(COLOR_PAIR(MN_COLOR));
|
||||||
printw("\u2588");
|
printw("\u2588");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NEON_WALL:
|
case NEON_WALL:
|
||||||
drawNeon(dj, di);
|
drawNeon(dj, di);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BAR:
|
case BAR:
|
||||||
drawBar(dj, di);
|
drawBar(dj, di);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
attron(COLOR_PAIR(MN_COLOR));
|
||||||
|
printw(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,6 +231,12 @@ void render(int w, int h){
|
|||||||
printw(/*"\u263A"*/ "@");
|
printw(/*"\u263A"*/ "@");
|
||||||
|
|
||||||
drawGui(w, h);
|
drawGui(w, h);
|
||||||
|
|
||||||
|
for ( i = 0; i < MAX_MAP_SIZE; ++i ) {
|
||||||
|
for(j = 0; j < MAX_MAP_SIZE; ++j){
|
||||||
|
vis[i][j] = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawNeon(int i, int j){
|
void drawNeon(int i, int j){
|
||||||
@@ -410,3 +440,20 @@ void initObjects(){
|
|||||||
objs[i].unlocked = 0;
|
objs[i].unlocked = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void apply(void *map, int x, int y, int dx, int dy, void *src){
|
||||||
|
if(x < 0 || x >= MAX_MAP_SIZE) return;
|
||||||
|
if(y < 0 || y >= MAX_MAP_SIZE) return;
|
||||||
|
vis[y][x] = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool opaque(void *m, int x, int y){
|
||||||
|
if(x < 0 || x >= MAX_MAP_SIZE) return FALSE;
|
||||||
|
if(y < 0 || y >= MAX_MAP_SIZE) return FALSE;
|
||||||
|
|
||||||
|
if(map[y][x].f == SOLID_WALL || map[y][x].f == SECRET_WALL){
|
||||||
|
return TRUE;
|
||||||
|
}else{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user