implementing the basis of player action
|
@ -36,6 +36,10 @@ set(ASSETS
|
|||
set(ASSETS_cg
|
||||
assets-cg/demo_player.png
|
||||
assets-cg/demo_PNJ.png
|
||||
assets-cg/SignAction.png
|
||||
assets-cg/NPC_Icon.png
|
||||
assets-cg/SGN_Icon.png
|
||||
assets-cg/INFO_Icon.png
|
||||
assets-cg/player_face.png
|
||||
assets-cg/font.png
|
||||
)
|
||||
|
@ -55,6 +59,10 @@ set(ASSETS_cg_EGA64
|
|||
set(ASSETS_fx
|
||||
assets-fx/demo_player.png
|
||||
assets-fx/demo_PNJ.png
|
||||
assets-fx/SignAction.png
|
||||
assets-fx/NPC_Icon.png
|
||||
assets-fx/SGN_Icon.png
|
||||
assets-fx/INFO_Icon.png
|
||||
assets-fx/player_face.png
|
||||
assets-fx/font.png
|
||||
# ...
|
||||
|
|
BIN
assets-cg/INFO_Icon.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
assets-cg/NPC_Icon.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
assets-cg/SGN_Icon.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
assets-cg/SignAction.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
|
@ -10,6 +10,22 @@ player_face.png:
|
|||
type: bopti-image
|
||||
name: player_face_img
|
||||
|
||||
SignAction.png:
|
||||
type: bopti-image
|
||||
name: SignAction_img
|
||||
|
||||
INFO_Icon.png:
|
||||
type: bopti-image
|
||||
name: INFO_Icon_img
|
||||
|
||||
NPC_Icon.png:
|
||||
type: bopti-image
|
||||
name: NPC_Icon_img
|
||||
|
||||
SGN_Icon.png:
|
||||
type: bopti-image
|
||||
name: SGN_Icon_img
|
||||
|
||||
font.png:
|
||||
name: fontRPG
|
||||
type: font
|
||||
|
|
BIN
assets-fx/INFO_Icon.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
assets-fx/NPC_Icon.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
assets-fx/SGN_Icon.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
assets-fx/SignAction.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
|
@ -10,6 +10,21 @@ player_face.png:
|
|||
type: bopti-image
|
||||
name: player_face_img
|
||||
|
||||
SignAction.png:
|
||||
type: bopti-image
|
||||
name: SignAction_img
|
||||
|
||||
INFO_Icon.png:
|
||||
type: bopti-image
|
||||
name: INFO_Icon_img
|
||||
|
||||
NPC_Icon.png:
|
||||
type: bopti-image
|
||||
name: NPC_Icon_img
|
||||
|
||||
SGN_Icon.png:
|
||||
type: bopti-image
|
||||
name: SGN_Icon_img
|
||||
|
||||
font.png:
|
||||
name: fontRPG
|
||||
|
|
31
src/game.c
|
@ -6,13 +6,40 @@
|
|||
|
||||
#include <gint/keyboard.h>
|
||||
#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) {
|
||||
|
@ -20,6 +47,7 @@ void draw(Game *game) {
|
|||
render_map_by_layer(game, BACKGROUND);
|
||||
player_draw(game);
|
||||
render_map_by_layer(game, FOREGROUND);
|
||||
render_indicator( game );
|
||||
}
|
||||
|
||||
/* Key management */
|
||||
|
@ -51,6 +79,9 @@ void get_inputs(Game *game) {
|
|||
if(keydown(KEY_F2)) {
|
||||
game->debug_player = !game->debug_player;
|
||||
}
|
||||
if(keydown(KEY_F3)) {
|
||||
game->debug_extra = !game->debug_extra;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
|
19
src/game.h
|
@ -1,6 +1,7 @@
|
|||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
|
||||
#include <gint/display.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -24,12 +25,16 @@ typedef enum {
|
|||
|
||||
/* Struct that define player parameters */
|
||||
typedef struct {
|
||||
int x, y; /* The position of the player int the current map */
|
||||
unsigned int px, py; /* The position of the player on screen */
|
||||
int wx, wy; /* position of the player in the world */
|
||||
unsigned short int life; /* How many lives the player still has between 0
|
||||
int16_t x, y; /* The position of the player int the current map */
|
||||
uint16_t px, py; /* The position of the player on screen */
|
||||
int16_t wx, wy; /* position of the player in the world */
|
||||
int16_t life; /* How many lives the player still has between 0
|
||||
* and 100. */
|
||||
char speed; /* The speed of the movement of the player. */
|
||||
int8_t speed; /* The speed of the movement of the player. */
|
||||
|
||||
bool canDoSomething; /* set to true if a action can be done in the current position of the map */
|
||||
int32_t whichAction; /* indicates which data are relevant to the current action in the extradata layer of the map */
|
||||
bool isDoingAction;
|
||||
} Player;
|
||||
|
||||
|
||||
|
@ -103,6 +108,10 @@ void game_logic(Game *game);
|
|||
/* Draws everything on screen. */
|
||||
void draw(Game *game);
|
||||
|
||||
/* This render a small sign on the upper lecft corner of the screen */
|
||||
/* if the player can do an action */
|
||||
void render_indicator(Game *game);
|
||||
|
||||
/* Handle key presses. */
|
||||
void get_inputs(Game *game);
|
||||
|
||||
|
|
|
@ -32,11 +32,11 @@ extern Map *worldRPG[];
|
|||
/* Game data (defined in "game.h")*/
|
||||
Game game = {
|
||||
NULL,
|
||||
{12*PXSIZE, 36*PXSIZE, 0, 0, 10*PXSIZE, 48*PXSIZE, 100, SPEED},
|
||||
{12*PXSIZE, 36*PXSIZE, 0, 0, 10*PXSIZE, 48*PXSIZE, 100, SPEED, false, 0, false},
|
||||
false, false, false, 0
|
||||
|
||||
/* debug variables*/
|
||||
, false, false, true
|
||||
, false, false, false
|
||||
};
|
||||
|
||||
/* screen capture management code */
|
||||
|
@ -142,7 +142,6 @@ int main(void) {
|
|||
if (game.debug_extra)
|
||||
{
|
||||
dfont( NULL );
|
||||
//drect( 155, 80, 390, 150, C_WHITE );
|
||||
for (int i=0; i<game.map_level->nbextradata; i++ )
|
||||
dprint( 10, 90+i*15, C_RED, "X= %d - Y= %d - T: %s", game.map_level->extradata[i].x, game.map_level->extradata[i].y, game.map_level->extradata[i].dialog );
|
||||
}
|
||||
|
|
28
src/player.c
|
@ -1,4 +1,5 @@
|
|||
#include "player.h"
|
||||
#include "dialogs.h"
|
||||
#include "map.h"
|
||||
#include "config.h"
|
||||
#include <gint/display.h>
|
||||
|
@ -25,6 +26,9 @@ const char damage_taken_walkable[WALKABLE_TILE_MAX] = {
|
|||
};
|
||||
|
||||
extern bopti_image_t demo_player_img;
|
||||
extern bopti_image_t NPC_Icon_img;
|
||||
extern bopti_image_t SGN_Icon_img;
|
||||
extern bopti_image_t INFO_Icon_img;
|
||||
|
||||
|
||||
void player_draw(Game *game) {
|
||||
|
@ -77,8 +81,30 @@ void player_move(Game *game, Direction direction) {
|
|||
player->wy = game->map_level->ymin * PXSIZE + player->y;
|
||||
}
|
||||
|
||||
|
||||
void player_action(Game *game) {
|
||||
/* TODO */
|
||||
if( game->player.isDoingAction ) return; /* alreday doing something */
|
||||
|
||||
if( game->player.canDoSomething ) /* we can do something */
|
||||
{
|
||||
game->player.isDoingAction = true;
|
||||
|
||||
char *text = game->map_level->extradata[game->player.whichAction].dialog;
|
||||
bopti_image_t *face;
|
||||
|
||||
if (strcmp("PST", game->map_level->extradata[game->player.whichAction].type)==0)
|
||||
face = &INFO_Icon_img;
|
||||
else if (strcmp("NPC", game->map_level->extradata[game->player.whichAction].type)==0)
|
||||
face = &NPC_Icon_img;
|
||||
else if (strcmp("SGN", game->map_level->extradata[game->player.whichAction].type)==0)
|
||||
face = &NPC_Icon_img;
|
||||
else face = &demo_player_img;
|
||||
|
||||
showtext_dialog( game,
|
||||
face,
|
||||
text,
|
||||
true, true );
|
||||
}
|
||||
}
|
||||
|
||||
bool player_collision(Game *game, Direction direction,
|
||||
|
|