Merge branch 'dev' of git.planet-casio.com:Slyvtt/Collab_RPG into dev
|
@ -33,6 +33,7 @@ set(SOURCES
|
|||
src/dialogs.c
|
||||
src/npc.c
|
||||
src/events.c
|
||||
src/animation.c
|
||||
# ...
|
||||
)
|
||||
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
|
||||
|
@ -122,7 +123,7 @@ if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
|
|||
elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
|
||||
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}} ${ASSETS_${FXSDK_PLATFORM}_${COLORMODE_cg}} )
|
||||
elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G_G3A)
|
||||
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}} ${ASSETS_${FXSDK_PLATFORM}_${COLORMODE_fx}} )
|
||||
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}} ${ASSETS_${FXSDK_PLATFORM}_${COLORMODE_fx}} )
|
||||
endif()
|
||||
|
||||
target_link_options(myaddin PRIVATE -Wl,-Map=Build_Addin.map -Wl,--print-memory-usage)
|
||||
|
|
Before Width: | Height: | Size: 221 B After Width: | Height: | Size: 382 B |
Before Width: | Height: | Size: 206 B After Width: | Height: | Size: 327 B |
Before Width: | Height: | Size: 222 B After Width: | Height: | Size: 343 B |
Before Width: | Height: | Size: 220 B After Width: | Height: | Size: 344 B |
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 380 B |
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 324 B |
Before Width: | Height: | Size: 110 B After Width: | Height: | Size: 134 B |
Before Width: | Height: | Size: 107 B After Width: | Height: | Size: 126 B |
31
src/animation.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <gint/display.h>
|
||||
|
||||
#include "animation.h"
|
||||
|
||||
void animation_new(Animation *animation, bopti_image_t *image,
|
||||
unsigned char len, unsigned short frame_ms) {
|
||||
animation->image = image;
|
||||
animation->frame = 0;
|
||||
animation->len = len;
|
||||
animation->frame_ms = frame_ms;
|
||||
animation->current_ms = 0;
|
||||
animation->width = image->width/len;
|
||||
animation->height = image->height;
|
||||
animation->wrap_dest = 0;
|
||||
}
|
||||
|
||||
void animation_draw(Animation *animation, int x, int y) {
|
||||
dsubimage(x, y, animation->image, animation->frame*animation->width, 0,
|
||||
animation->width, animation->height, DIMAGE_NONE);
|
||||
}
|
||||
|
||||
void animation_update(Animation *animation, unsigned short frame_ms) {
|
||||
animation->current_ms += frame_ms;
|
||||
while(animation->current_ms > animation->frame_ms){
|
||||
animation->frame++;
|
||||
if(animation->frame >= animation->len){
|
||||
animation->frame = animation->wrap_dest;
|
||||
}
|
||||
animation->current_ms -= animation->frame_ms;
|
||||
}
|
||||
}
|
27
src/animation.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef ANIMATION_H
|
||||
#define ANIMATION_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned char frame : 8;
|
||||
bopti_image_t *image;
|
||||
unsigned char len : 8;
|
||||
unsigned short frame_ms : 16;
|
||||
int current_ms : 32;
|
||||
unsigned short width : 16;
|
||||
unsigned short height : 16;
|
||||
unsigned char wrap_dest : 8;
|
||||
} Animation;
|
||||
|
||||
/* TODO: Doc! */
|
||||
void animation_new(Animation *animation, bopti_image_t *image,
|
||||
unsigned char len, unsigned short frame_ms);
|
||||
|
||||
/* TODO: Doc! */
|
||||
void animation_draw(Animation *animation, int x, int y);
|
||||
|
||||
/* TODO: Doc! */
|
||||
void animation_update(Animation *animation, unsigned short frame_ms);
|
||||
|
||||
#endif
|
|
@ -209,3 +209,8 @@ void game_get_inputs(Game *game) {
|
|||
|
||||
#endif // USB_FEATURE
|
||||
}
|
||||
|
||||
void game_update_animations(Game *game, unsigned char ms) {
|
||||
animation_update(&game->npc_animation, ms);
|
||||
animation_update(&game->player.animation, ms);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <gint/display.h>
|
||||
#include <stdint.h>
|
||||
#include "animation.h"
|
||||
|
||||
/* The direction where the player is going to. */
|
||||
typedef enum { D_UP, D_DOWN, D_LEFT, D_RIGHT } Direction;
|
||||
|
@ -34,6 +35,8 @@ typedef struct {
|
|||
/* the player is interacting with a NPC */
|
||||
bool isInteractingWithNPC;
|
||||
bool is_male;
|
||||
|
||||
Animation animation;
|
||||
} Player;
|
||||
|
||||
typedef struct {
|
||||
|
@ -173,6 +176,8 @@ typedef struct {
|
|||
bool debug_player;
|
||||
bool debug_extra;
|
||||
|
||||
Animation npc_animation;
|
||||
|
||||
int mana; /* Only for testing events TODO: Remove this! */
|
||||
} Game;
|
||||
|
||||
|
@ -201,4 +206,7 @@ void game_render_indicator(Game *game);
|
|||
*/
|
||||
void game_get_inputs(Game *game);
|
||||
|
||||
/* TODO: Doc! */
|
||||
void game_update_animations(Game *game, unsigned char ms);
|
||||
|
||||
#endif
|
||||
|
|
15
src/main.c
|
@ -28,13 +28,16 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
extern bopti_image_t player_face_img;
|
||||
extern bopti_image_t player_male_img;
|
||||
extern bopti_image_t tiny_npc_male;
|
||||
|
||||
extern Map *worldRPG[];
|
||||
|
||||
/* Game data (defined in "game.h")*/
|
||||
Game game = {
|
||||
NULL,
|
||||
{12 * PXSIZE, 36 * PXSIZE, 0, 0, 100, SPEED, false, 0, false, false, true},
|
||||
{12 * PXSIZE, 36 * PXSIZE, 0, 0, 100, SPEED, false, 0, false, false, true,
|
||||
{}},
|
||||
{{}, {}, 0},
|
||||
false,
|
||||
false,
|
||||
|
@ -45,6 +48,7 @@ Game game = {
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
{},
|
||||
100};
|
||||
|
||||
/* screen capture management code. TODO: Clean this up! */
|
||||
|
@ -107,6 +111,12 @@ int main(void) {
|
|||
timer_start(timer);
|
||||
|
||||
game.map_level = worldRPG[0];
|
||||
/* NPC animation */
|
||||
animation_new(&game.npc_animation, &tiny_npc_male, 3, 250);
|
||||
/* Player animation */
|
||||
animation_new(&game.player.animation, &player_male_img, 3, 250);
|
||||
/* Wrapping back to 1 to skip the idle frame. */
|
||||
game.player.animation.wrap_dest = 1;
|
||||
events_init_handler(&game.handler);
|
||||
events_bind_variable(&game.handler, (int *)&game.player.life, "life");
|
||||
events_bind_variable(&game.handler, &game.mana, "mana");
|
||||
|
@ -189,6 +199,9 @@ int main(void) {
|
|||
/* Run the game at max. 50fps */
|
||||
while(game.frame_duration < 20)
|
||||
sleep();
|
||||
/* Calling it here to get the real frame duration (there is a lot of lag
|
||||
on cg) */
|
||||
game_update_animations(&game, (unsigned char)game.frame_duration);
|
||||
/* Reset frame_duration for the next frame */
|
||||
game.frame_duration = 0;
|
||||
} while(!game.exittoOS); // want to exit ?
|
||||
|
|
30
src/npc.c
|
@ -260,8 +260,9 @@ void update_npc(NPC *npc) {
|
|||
bopti_image_t *npc_sprites[FACES] = {&tiny_npc_male, &tiny_npc_female,
|
||||
&tiny_npc_milkman, &tiny_npc_police};
|
||||
|
||||
void npc_draw_single(NPC *npc, Player *pl) {
|
||||
void npc_draw_single(NPC *npc, Game *game) {
|
||||
|
||||
Player *pl = &game->player;
|
||||
/* Render the path if in debug and it has one*/
|
||||
#if DEBUGMODE
|
||||
if(npc->hasPath) {
|
||||
|
@ -270,16 +271,16 @@ void npc_draw_single(NPC *npc, Player *pl) {
|
|||
|
||||
int16_t deltaX1 =
|
||||
((int16_t)(npc->x + npc->xpath[v % NbPoints]) * PXSIZE) -
|
||||
(int16_t)pl->wx;
|
||||
(int16_t)pl->x;
|
||||
int16_t deltaY1 =
|
||||
((int16_t)(npc->y + npc->ypath[v % NbPoints]) * PXSIZE) -
|
||||
(int16_t)pl->wy;
|
||||
(int16_t)pl->y;
|
||||
int16_t deltaX2 =
|
||||
((int16_t)(npc->x + npc->xpath[(v + 1) % NbPoints]) * PXSIZE) -
|
||||
(int16_t)pl->wx;
|
||||
(int16_t)pl->x;
|
||||
int16_t deltaY2 =
|
||||
((int16_t)(npc->y + npc->ypath[(v + 1) % NbPoints]) * PXSIZE) -
|
||||
(int16_t)pl->wy;
|
||||
(int16_t)pl->y;
|
||||
|
||||
dline(pl->px + deltaX1, pl->py + deltaY1, pl->px + deltaX2,
|
||||
pl->py + deltaY2, PATH_COLOR);
|
||||
|
@ -289,19 +290,22 @@ void npc_draw_single(NPC *npc, Player *pl) {
|
|||
|
||||
int16_t delX = ((npc->curx * PXSIZE) >> PRECISION) - (int16_t)pl->x;
|
||||
int16_t delY = ((npc->cury * PXSIZE) >> PRECISION) - (int16_t)pl->y;
|
||||
bopti_image_t *face = npc_sprites[npc->face];
|
||||
dimage(pl->px - P_WIDTH / 2 + delX, pl->py - P_HEIGHT / 2 + delY, face);
|
||||
game->npc_animation.image = npc_sprites[npc->face];
|
||||
unsigned char frame = game->npc_animation.frame;
|
||||
if(npc->paused || !npc->hasPath) game->npc_animation.frame = 0;
|
||||
animation_draw(&game->npc_animation, pl->px - P_WIDTH / 2 + delX,
|
||||
pl->py - P_HEIGHT / 2 + delY);
|
||||
game->npc_animation.frame = frame;
|
||||
}
|
||||
|
||||
void npc_draw(Game *game) {
|
||||
Player *pl = &game->player;
|
||||
|
||||
uint32_t u;
|
||||
for(u = 0; u < npc_count; u++) {
|
||||
npc_draw_single(&npc_stack[u], pl);
|
||||
}
|
||||
|
||||
for(u = 0; u < game->map_level->nbNPC; u++) {
|
||||
npc_draw_single(&game->map_level->npcs[u], pl);
|
||||
npc_draw_single(&game->map_level->npcs[u], game);
|
||||
}
|
||||
for(u = 0; u < npc_count; u++) {
|
||||
npc_draw_single(&npc_stack[u], game);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
src/player.c
|
@ -7,6 +7,7 @@
|
|||
#include "npc.h"
|
||||
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
|
||||
extern bopti_image_t player_male_img;
|
||||
extern bopti_image_t player_female_img;
|
||||
|
@ -44,8 +45,15 @@ extern uint32_t nbNPC;
|
|||
|
||||
void player_draw(Game *game) {
|
||||
Player *player = &game->player;
|
||||
dimage(player->px - P_WIDTH / 2, player->py - P_HEIGHT / 2,
|
||||
player->is_male ? &player_male_img : &player_female_img);
|
||||
clearevents();
|
||||
if(!keydown(KEY_LEFT) && !keydown(KEY_RIGHT) && !keydown(KEY_UP) &&
|
||||
!keydown(KEY_DOWN)){
|
||||
game->player.animation.frame = 0;
|
||||
}
|
||||
player->animation.image = player->is_male ? &player_male_img :
|
||||
&player_female_img;
|
||||
animation_draw(&player->animation, player->px - P_WIDTH / 2,
|
||||
player->py - P_HEIGHT / 2);
|
||||
}
|
||||
|
||||
void player_move(Game *game, Direction direction) {
|
||||
|
|