implementing the basis of player action

This commit is contained in:
SlyVTT 2023-08-16 19:25:24 +02:00
parent c5975889bc
commit 47b8bfa25a
15 changed files with 113 additions and 9 deletions

View file

@ -36,6 +36,10 @@ set(ASSETS
set(ASSETS_cg set(ASSETS_cg
assets-cg/demo_player.png assets-cg/demo_player.png
assets-cg/demo_PNJ.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/player_face.png
assets-cg/font.png assets-cg/font.png
) )
@ -55,6 +59,10 @@ set(ASSETS_cg_EGA64
set(ASSETS_fx set(ASSETS_fx
assets-fx/demo_player.png assets-fx/demo_player.png
assets-fx/demo_PNJ.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/player_face.png
assets-fx/font.png assets-fx/font.png
# ... # ...

BIN
assets-cg/INFO_Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
assets-cg/NPC_Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
assets-cg/SGN_Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
assets-cg/SignAction.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View file

@ -10,6 +10,22 @@ player_face.png:
type: bopti-image type: bopti-image
name: player_face_img 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: font.png:
name: fontRPG name: fontRPG
type: font type: font

BIN
assets-fx/INFO_Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
assets-fx/NPC_Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
assets-fx/SGN_Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
assets-fx/SignAction.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -10,6 +10,21 @@ player_face.png:
type: bopti-image type: bopti-image
name: player_face_img 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: font.png:
name: fontRPG name: fontRPG

View file

@ -6,13 +6,40 @@
#include <gint/keyboard.h> #include <gint/keyboard.h>
#include <gint/cpu.h> #include <gint/cpu.h>
#include <gint/display.h>
#include "stdlib.h"
extern bopti_image_t SignAction_img;
void game_logic(Game *game) { 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) { void draw(Game *game) {
@ -20,6 +47,7 @@ void draw(Game *game) {
render_map_by_layer(game, BACKGROUND); render_map_by_layer(game, BACKGROUND);
player_draw(game); player_draw(game);
render_map_by_layer(game, FOREGROUND); render_map_by_layer(game, FOREGROUND);
render_indicator( game );
} }
/* Key management */ /* Key management */
@ -51,6 +79,9 @@ void get_inputs(Game *game) {
if(keydown(KEY_F2)) { if(keydown(KEY_F2)) {
game->debug_player = !game->debug_player; game->debug_player = !game->debug_player;
} }
if(keydown(KEY_F3)) {
game->debug_extra = !game->debug_extra;
}
#endif #endif

View file

@ -1,6 +1,7 @@
#ifndef GAME_H #ifndef GAME_H
#define GAME_H #define GAME_H
#include <gint/display.h> #include <gint/display.h>
#include <stdint.h> #include <stdint.h>
@ -24,12 +25,16 @@ typedef enum {
/* Struct that define player parameters */ /* Struct that define player parameters */
typedef struct { typedef struct {
int x, y; /* The position of the player int the current map */ int16_t x, y; /* The position of the player int the current map */
unsigned int px, py; /* The position of the player on screen */ uint16_t px, py; /* The position of the player on screen */
int wx, wy; /* position of the player in the world */ int16_t wx, wy; /* position of the player in the world */
unsigned short int life; /* How many lives the player still has between 0 int16_t life; /* How many lives the player still has between 0
* and 100. */ * 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; } Player;
@ -103,6 +108,10 @@ void game_logic(Game *game);
/* Draws everything on screen. */ /* Draws everything on screen. */
void draw(Game *game); 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. */ /* Handle key presses. */
void get_inputs(Game *game); void get_inputs(Game *game);

View file

@ -32,11 +32,11 @@ extern Map *worldRPG[];
/* Game data (defined in "game.h")*/ /* Game data (defined in "game.h")*/
Game game = { Game game = {
NULL, 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 false, false, false, 0
/* debug variables*/ /* debug variables*/
, false, false, true , false, false, false
}; };
/* screen capture management code */ /* screen capture management code */
@ -142,7 +142,6 @@ int main(void) {
if (game.debug_extra) if (game.debug_extra)
{ {
dfont( NULL ); dfont( NULL );
//drect( 155, 80, 390, 150, C_WHITE );
for (int i=0; i<game.map_level->nbextradata; i++ ) 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 ); 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 );
} }

View file

@ -1,4 +1,5 @@
#include "player.h" #include "player.h"
#include "dialogs.h"
#include "map.h" #include "map.h"
#include "config.h" #include "config.h"
#include <gint/display.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 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) { 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; player->wy = game->map_level->ymin * PXSIZE + player->y;
} }
void player_action(Game *game) { 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, bool player_collision(Game *game, Direction direction,