mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +01:00
Improved collisions and CG port. Still need to make the collisions less sticky.
This commit is contained in:
parent
3fdc9fffe6
commit
23dde6593c
12 changed files with 114 additions and 88 deletions
|
@ -44,15 +44,16 @@ set(SOURCES
|
||||||
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
|
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
|
||||||
set(ASSETS
|
set(ASSETS
|
||||||
assets/level0.json
|
assets/level0.json
|
||||||
assets/demo_player.png
|
|
||||||
# ...
|
# ...
|
||||||
)
|
)
|
||||||
|
|
||||||
set(ASSETS_cg
|
set(ASSETS_cg
|
||||||
assets-cg/tileset2b_CG.png
|
assets-cg/tileset2b_CG.png
|
||||||
|
assets-cg/demo_player.png
|
||||||
)
|
)
|
||||||
|
|
||||||
set(ASSETS_fx
|
set(ASSETS_fx
|
||||||
|
assets-fx/demo_player.png
|
||||||
# ...
|
# ...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
BIN
assets-cg/demo_player.png
Normal file
BIN
assets-cg/demo_player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 117 B |
|
@ -1,5 +1,7 @@
|
||||||
|
|
||||||
tileset2b_CG.png:
|
tileset2b_CG.png:
|
||||||
type: bopti-image
|
type: bopti-image
|
||||||
name: img_tilesetnpp
|
name: img_tilesetnpp
|
||||||
|
|
||||||
|
demo_player.png:
|
||||||
|
type: bopti-image
|
||||||
|
name: demo_player_img
|
||||||
|
|
Before Width: | Height: | Size: 105 B After Width: | Height: | Size: 105 B |
12
assets-fx/fxconv-metadata.txt
Normal file
12
assets-fx/fxconv-metadata.txt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
tileset1b.png:
|
||||||
|
type: bopti-image
|
||||||
|
name: img_tilesetnpp
|
||||||
|
|
||||||
|
|
||||||
|
tileset2b.png:
|
||||||
|
type: bopti-image
|
||||||
|
name: img_tilesetnpp
|
||||||
|
|
||||||
|
demo_player.png:
|
||||||
|
type: bopti-image
|
||||||
|
name: demo_player_img
|
|
@ -1,7 +1,3 @@
|
||||||
*.json:
|
*.json:
|
||||||
custom-type: map
|
custom-type: map
|
||||||
name_regex: (.*)\.json map_\1
|
name_regex: (.*)\.json map_\1
|
||||||
|
|
||||||
demo_player.png:
|
|
||||||
type: bopti-image
|
|
||||||
name: demo_player_img
|
|
6
src/config.h
Normal file
6
src/config.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef CONFIG_H
|
||||||
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#define USB_FEATURE 1
|
||||||
|
|
||||||
|
#endif
|
35
src/game.c
35
src/game.c
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <gint/keyboard.h>
|
||||||
|
|
||||||
void game_logic(Game *game) {
|
void game_logic(Game *game) {
|
||||||
// to be done
|
// to be done
|
||||||
}
|
}
|
||||||
|
@ -12,3 +16,34 @@ void draw(Game *game) {
|
||||||
player_draw(&game->player);
|
player_draw(&game->player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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->map_level, &game->player, D_LEFT);
|
||||||
|
if(keydown(KEY_RIGHT)) player_move(game->map_level, &game->player, D_RIGHT);
|
||||||
|
if(keydown(KEY_UP)) player_move(game->map_level, &game->player, D_UP);
|
||||||
|
if(keydown(KEY_DOWN)) player_move(game->map_level, &game->player, D_DOWN);
|
||||||
|
if(keydown(KEY_SHIFT)) player_action(&game->player);
|
||||||
|
|
||||||
|
/* if USB is enabled - keybinding for screencapture */
|
||||||
|
|
||||||
|
#if USB_FEATURE==1
|
||||||
|
|
||||||
|
if(keydown(KEY_7)) game->screenshot = true;
|
||||||
|
if(keydown(KEY_8)) game->record = !game->record;
|
||||||
|
|
||||||
|
#endif //USB_FEATURE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
12
src/game.h
12
src/game.h
|
@ -10,6 +10,15 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Map *map_level; /* The level that the player is currently playing */
|
Map *map_level; /* The level that the player is currently playing */
|
||||||
Player player; /* The player data (see player.h). */
|
Player player; /* The player data (see player.h). */
|
||||||
|
/* Some global variables */
|
||||||
|
/* Set to true when asked for exit */
|
||||||
|
bool exittoOS;
|
||||||
|
/* Set to true when screenshot is required */
|
||||||
|
bool screenshot;
|
||||||
|
/* Set to true when recording a video of the screen is required */
|
||||||
|
bool record;
|
||||||
|
/* How many ms the frame already took. */
|
||||||
|
long int frame_duration;
|
||||||
} Game;
|
} Game;
|
||||||
|
|
||||||
/* (Mibi88) TODO: Describe what this function is doing. */
|
/* (Mibi88) TODO: Describe what this function is doing. */
|
||||||
|
@ -18,5 +27,8 @@ void game_logic(Game *game);
|
||||||
/* Draws everything on screen. */
|
/* Draws everything on screen. */
|
||||||
void draw(Game *game);
|
void draw(Game *game);
|
||||||
|
|
||||||
|
/* Handle key presses. */
|
||||||
|
void get_inputs(Game *game);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
90
src/main.c
90
src/main.c
|
@ -1,10 +1,12 @@
|
||||||
|
|
||||||
#include <gint/display.h>
|
#include <gint/display.h>
|
||||||
#include <gint/keyboard.h>
|
#include <gint/keyboard.h>
|
||||||
|
#include <gint/timer.h>
|
||||||
|
#include <gint/cpu.h>
|
||||||
|
|
||||||
#define USB_FEATURE 1
|
#include "config.h"
|
||||||
|
|
||||||
#if USB_FEATURE==1
|
#if USB_FEATURE
|
||||||
#include <gint/usb-ff-bulk.h>
|
#include <gint/usb-ff-bulk.h>
|
||||||
#include <gint/usb.h>
|
#include <gint/usb.h>
|
||||||
#endif //USB_FEATURE
|
#endif //USB_FEATURE
|
||||||
|
@ -27,63 +29,17 @@
|
||||||
/* Game data (defined in "game.h")*/
|
/* Game data (defined in "game.h")*/
|
||||||
Game game = {
|
Game game = {
|
||||||
&map_level0,
|
&map_level0,
|
||||||
{10, 5, 0, 0, 100}
|
{10, 5, 0, 0, 100},
|
||||||
|
false, false, false, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/* some global variables */
|
|
||||||
|
|
||||||
/* Set to true when asked for exit */
|
|
||||||
bool exittoOS = false;
|
|
||||||
|
|
||||||
/* Set to true when screenshot is required */
|
|
||||||
bool screenshot = false;
|
|
||||||
|
|
||||||
/* Set to true when recording a video of the screen is required */
|
|
||||||
bool record = false;
|
|
||||||
|
|
||||||
/* How many ms the frame already took. */
|
|
||||||
long int frame_duration;
|
|
||||||
|
|
||||||
/* Key management */
|
|
||||||
|
|
||||||
static void get_inputs( void )
|
|
||||||
{
|
|
||||||
key_event_t ev;
|
|
||||||
while((ev = pollevent()).type != KEYEV_NONE){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Key binding for the Player action */
|
|
||||||
|
|
||||||
/*************************************/
|
|
||||||
|
|
||||||
if(keydown(KEY_EXIT)) exittoOS = true;
|
|
||||||
|
|
||||||
/* Player actions - Prototypes in player.h and implementation in player.c */
|
|
||||||
if(keydown(KEY_LEFT)) player_move(game.map_level, &game.player, D_LEFT);
|
|
||||||
if(keydown(KEY_RIGHT)) player_move(game.map_level, &game.player, D_RIGHT);
|
|
||||||
if(keydown(KEY_UP)) player_move(game.map_level, &game.player, D_UP);
|
|
||||||
if(keydown(KEY_DOWN)) player_move(game.map_level, &game.player, D_DOWN);
|
|
||||||
if(keydown(KEY_SHIFT)) player_action(&game.player);
|
|
||||||
|
|
||||||
/* if USB is enabled - keybinding for screencapture */
|
|
||||||
|
|
||||||
#if USB_FEATURE==1
|
|
||||||
|
|
||||||
if(keydown(KEY_7)) screenshot = true;
|
|
||||||
if(keydown(KEY_8)) record = !record;
|
|
||||||
|
|
||||||
#endif //USB_FEATURE
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* screen capture management code */
|
/* screen capture management code */
|
||||||
|
|
||||||
#if USB_FEATURE==1
|
#if USB_FEATURE==1
|
||||||
|
|
||||||
void USB_feature( void )
|
void USB_feature( void )
|
||||||
{
|
{
|
||||||
if (screenshot && usb_is_open()) {
|
if (game.screenshot && usb_is_open()) {
|
||||||
|
|
||||||
#ifdef GRAYMODEOK // This is a trick, if GRAYMODEOK is defined then we make the code accessible
|
#ifdef GRAYMODEOK // This is a trick, if GRAYMODEOK is defined then we make the code accessible
|
||||||
|
|
||||||
|
@ -94,11 +50,11 @@ static void get_inputs( void )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
usb_fxlink_screenshot(false); // else we just let the usual screeshot function
|
usb_fxlink_screenshot(false); // else we just let the usual screeshot function
|
||||||
screenshot = false;
|
game.screenshot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (record && usb_is_open()) {
|
if (game.record && usb_is_open()) {
|
||||||
|
|
||||||
#ifdef GRAYMODEOK
|
#ifdef GRAYMODEOK
|
||||||
|
|
||||||
|
@ -114,7 +70,20 @@ static void get_inputs( void )
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Timer callback */
|
||||||
|
|
||||||
|
int update_time(void) {
|
||||||
|
game.frame_duration++;
|
||||||
|
return TIMER_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
int timer;
|
||||||
|
timer = timer_configure(TIMER_TMU, 1000, GINT_CALL(update_time));
|
||||||
|
if(timer < 0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
timer_start(timer);
|
||||||
|
|
||||||
#if USB_FEATURE==1
|
#if USB_FEATURE==1
|
||||||
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
|
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
|
||||||
|
@ -129,8 +98,7 @@ int main(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
do
|
do{
|
||||||
{
|
|
||||||
/* clear screen */
|
/* clear screen */
|
||||||
dclear(C_WHITE);
|
dclear(C_WHITE);
|
||||||
|
|
||||||
|
@ -149,10 +117,12 @@ int main(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Management of the inputs */
|
/* Management of the inputs */
|
||||||
get_inputs();
|
get_inputs(&game);
|
||||||
|
/* Run the game at max. 50fps */
|
||||||
}
|
while(game.frame_duration < 20) sleep();
|
||||||
while (exittoOS == false); // want to exit ?
|
/* Reset frame_duration for the next frame */
|
||||||
|
game.frame_duration = 0;
|
||||||
|
}while(!game.exittoOS); // want to exit ?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +137,7 @@ int main(void) {
|
||||||
usb_close();
|
usb_close();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
timer_stop(timer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
src/map.c
11
src/map.c
|
@ -15,7 +15,7 @@ void render_map(Player *player, Map *map_level) {
|
||||||
unsigned char mx, my;
|
unsigned char mx, my;
|
||||||
/* dw and dh contain the amount of tiles that will be drawn on x and on
|
/* dw and dh contain the amount of tiles that will be drawn on x and on
|
||||||
* y. */
|
* y. */
|
||||||
unsigned char dw = DWIDTH/T_WIDTH+1, dh = DHEIGHT/T_HEIGHT+1;
|
unsigned char dw = DWIDTH/T_WIDTH+2, dh = DHEIGHT/T_HEIGHT+1;
|
||||||
/* mw and mh will contain the height and the width of the map. */
|
/* mw and mh will contain the height and the width of the map. */
|
||||||
unsigned short int mw = map_level->w*T_WIDTH, mh = map_level->h*T_HEIGHT;
|
unsigned short int mw = map_level->w*T_WIDTH, mh = map_level->h*T_HEIGHT;
|
||||||
/* tile contains the tile to draw. */
|
/* tile contains the tile to draw. */
|
||||||
|
@ -87,15 +87,6 @@ void render_map(Player *player, Map *map_level) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* short int get_tile_at_pos(Map *map_level, int x, int y, int l) {
|
|
||||||
unsigned short int xtile = x/T_WIDTH;
|
|
||||||
unsigned short int xtile = x/T_HEIGHT;
|
|
||||||
unsigned short int map_w = map_level->w*T_WIDTH;
|
|
||||||
unsigned short int map_h = map_level->h*T_HEIGHT;
|
|
||||||
return x>=0 && x < map_w && y>=0 && y < map_h ?
|
|
||||||
map_level->layers[l][ytile * map_level->w + xtile] : MAP_OUTSIDE;
|
|
||||||
} */
|
|
||||||
|
|
||||||
short int get_tile(Map *map_level, int x, int y, int l) {
|
short int get_tile(Map *map_level, int x, int y, int l) {
|
||||||
/* Get the tile at (x, y) on layer l. Returns the tile ID or MAP_OUTSIDE if
|
/* Get the tile at (x, y) on layer l. Returns the tile ID or MAP_OUTSIDE if
|
||||||
* she's not found. */
|
* she's not found. */
|
||||||
|
|
13
src/player.c
13
src/player.c
|
@ -2,17 +2,18 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include <gint/display.h>
|
#include <gint/display.h>
|
||||||
|
|
||||||
/* (Mibi88) TODO: Upscale the player for the CG50. */
|
#ifdef FXCG50
|
||||||
/* The player should not be bigger than a tile because it may cause problems
|
#define P_WIDTH 16
|
||||||
* with the collisions. If it's a problem please ask me (Mibi88) to adapt that.
|
#define P_HEIGHT 16
|
||||||
*/
|
#else
|
||||||
#define P_WIDTH 8
|
#define P_WIDTH 8
|
||||||
#define P_HEIGHT 8
|
#define P_HEIGHT 8
|
||||||
|
#endif
|
||||||
|
|
||||||
/* SPEED should NOT be 8 or bigger: it this may cause bugs when handling
|
/* SPEED should NOT be 8 or bigger: it this may cause bugs when handling
|
||||||
* collisions! */
|
* collisions! */
|
||||||
#ifdef FXCG50
|
#ifdef FXCG50
|
||||||
#define SPEED 3
|
#define SPEED 2
|
||||||
#else
|
#else
|
||||||
#define SPEED 1
|
#define SPEED 1
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,7 +46,7 @@ void player_move(Map *map_level, Player *player, Direction direction) {
|
||||||
/* If the player will collide with a hard tile. */
|
/* If the player will collide with a hard tile. */
|
||||||
if(player_collision(map_level, player, direction)){
|
if(player_collision(map_level, player, direction)){
|
||||||
/* I fix his position so he won't be partially in the tile. */
|
/* I fix his position so he won't be partially in the tile. */
|
||||||
player_fix_position(player, dx, dy);
|
player_fix_position(player, 1, 1);
|
||||||
}else{
|
}else{
|
||||||
/* If he won't collide I just move him normally */
|
/* If he won't collide I just move him normally */
|
||||||
player->x += dx;
|
player->x += dx;
|
||||||
|
|
Loading…
Reference in a new issue