Collab_RPG/src/game.c

97 lines
2.5 KiB
C
Raw Normal View History

#include "game.h"
#include "map.h"
#include "config.h"
#include <gint/keyboard.h>
2023-08-11 12:23:07 +02:00
#include <gint/cpu.h>
#include <gint/display.h>
#include "stdlib.h"
extern bopti_image_t SignAction_img;
void game_logic(Game *game) {
for( int i=0; i<game->map_level->nbextradata; i++ )
{
if ( (abs((int) game->player.x - (int) game->map_level->extradata[i].x*PXSIZE) < 8*PXSIZE)
&& (abs((int) game->player.y - (int) game->map_level->extradata[i].y*PXSIZE) < 8*PXSIZE))
{
game->player.canDoSomething = true;
game->player.whichAction = i;
return;
}
}
game->player.canDoSomething = false;
game->player.whichAction = -1;
return;
}
void render_indicator(Game *game)
{
if (game->player.canDoSomething==false)
return;
dimage(5, 5, &SignAction_img);
//dprint( 20, 20, C_RED, "X= %d - Y= %d / Xp= %d - Yp= %d", game->player.x, game->player.y, game->map_level->extradata[0].x*PXSIZE, game->map_level->extradata[0].y*PXSIZE );
//dprint( 20, 40, C_RED, "ABS1= %d - ABS2= %d", abs((int) game->player.x - (int) game->map_level->extradata[0].x*PXSIZE), abs((int) game->player.y - (int) game->map_level->extradata[0].y*PXSIZE) );
}
void draw(Game *game) {
2023-07-08 16:57:04 +02:00
/* Draw everything. */
render_map_by_layer(game, BACKGROUND);
player_draw(game);
render_map_by_layer(game, FOREGROUND);
render_indicator( game );
}
/* 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
2023-08-11 12:23:07 +02:00
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
}