mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2025-01-01 06:23:40 +01:00
148 lines
4.1 KiB
C
148 lines
4.1 KiB
C
#include "game.h"
|
|
|
|
#include "map.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <gint/keyboard.h>
|
|
#include <gint/cpu.h>
|
|
#include <gint/display.h>
|
|
|
|
#include "npc.h"
|
|
|
|
|
|
extern bopti_image_t SignAction_img;
|
|
|
|
extern Dialog *dialogRPG;
|
|
extern NPC *npcRPG;
|
|
extern uint32_t nbNPC;
|
|
|
|
#define MAX_INTERACTION_DISTANCE 12
|
|
|
|
|
|
void game_logic(Game *game) {
|
|
|
|
update_npcs( game );
|
|
|
|
/* we check if interactions are possible close to the player */
|
|
for( uint32_t i=0; i<game->map_level->nbextradata; i++ )
|
|
{
|
|
/* simple distance check along X and Y axis */
|
|
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
|
if ( (abs((int) game->player.wx -
|
|
(int) game->map_level->extradata[i].x*PXSIZE )
|
|
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
|
&& (abs((int) game->player.wy -
|
|
(int) game->map_level->extradata[i].y*PXSIZE )
|
|
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
|
&& strcmp( game->map_level->extradata[i].type, "NPC") !=0 )
|
|
{
|
|
/* the player can do something */
|
|
game->player.canDoSomething = true;
|
|
/* we mark the action for futur treatment in player_action() */
|
|
game->player.whichAction = i;
|
|
/* this is not an interraction with a NPC */
|
|
game->player.isInteractingWithNPC = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
for( uint32_t i=0; i<nbNPC; i++ )
|
|
{
|
|
/* simple distance check along X and Y axis */
|
|
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
|
if ( (abs((int) game->player.wx -
|
|
(int) npcRPG[i].curx*PXSIZE )
|
|
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
|
&& (abs((int) game->player.wy -
|
|
(int) npcRPG[i].cury*PXSIZE )
|
|
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
|
&& strcmp( game->map_level->extradata[i].type, "NPC") !=0 )
|
|
{
|
|
/* the player can do something */
|
|
game->player.canDoSomething = true;
|
|
/* we mark the action for futur treatment in player_action() */
|
|
game->player.whichAction = i;
|
|
/* this is not an interraction with a NPC */
|
|
game->player.isInteractingWithNPC = true;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
/* else nothing to be done here */
|
|
game->player.canDoSomething = false;
|
|
game->player.whichAction = -1;
|
|
game->player.isInteractingWithNPC = false;
|
|
return;
|
|
}
|
|
|
|
|
|
void render_indicator(Game *game)
|
|
{
|
|
/* nothing to do for the player so we quit */
|
|
if (game->player.canDoSomething==false)
|
|
return;
|
|
|
|
/* else we draw a small indicator on the screen */
|
|
dimage(5, 5, &SignAction_img);
|
|
}
|
|
|
|
|
|
void draw(Game *game) {
|
|
/* Draw everything. */
|
|
render_map_by_layer(game, BACKGROUND);
|
|
npc_draw( game );
|
|
player_draw(game);
|
|
render_map_by_layer(game, FOREGROUND);
|
|
render_indicator( game );
|
|
dprint(8, 8, C_BLACK, "Lifes: %d", game->player.life);
|
|
dprint(8, 16, C_BLACK, "Mana: %d", game->mana);
|
|
}
|
|
|
|
/* Key management */
|
|
|
|
void get_inputs(Game *game) {
|
|
key_event_t ev;
|
|
while((ev = pollevent()).type != KEYEV_NONE){
|
|
/**/
|
|
}
|
|
|
|
/* Key binding for the Player action */
|
|
|
|
/*************************************/
|
|
|
|
if(keydown(KEY_EXIT)) game->exittoOS = true;
|
|
|
|
/* Player actions - Prototypes in player.h and implementation in player.c */
|
|
if(keydown(KEY_LEFT)) player_move(game, D_LEFT);
|
|
if(keydown(KEY_RIGHT)) player_move(game, D_RIGHT);
|
|
if(keydown(KEY_UP)) player_move(game, D_UP);
|
|
if(keydown(KEY_DOWN)) player_move(game, D_DOWN);
|
|
if(keydown(KEY_SHIFT)) player_action(game);
|
|
|
|
/* Display Debug Information on screen */
|
|
#if DEBUGMODE
|
|
if(keydown(KEY_F1)) {
|
|
game->debug_map = !game->debug_map;
|
|
}
|
|
if(keydown(KEY_F2)) {
|
|
game->debug_player = !game->debug_player;
|
|
}
|
|
if(keydown(KEY_F3)) {
|
|
game->debug_extra = !game->debug_extra;
|
|
}
|
|
#endif
|
|
|
|
|
|
/* if USB is enabled - keybinding for screencapture */
|
|
#if USB_FEATURE
|
|
|
|
if(keydown(KEY_7)) game->screenshot = true;
|
|
if(keydown(KEY_8)) game->record = !game->record;
|
|
|
|
#endif //USB_FEATURE
|
|
}
|
|
|