Improved collisions and CG port. Still need to make the collisions less sticky.

This commit is contained in:
mibi88 2023-07-08 20:07:34 +02:00
parent 3fdc9fffe6
commit 23dde6593c
12 changed files with 114 additions and 88 deletions

View File

@ -44,15 +44,16 @@ set(SOURCES
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
set(ASSETS
assets/level0.json
assets/demo_player.png
# ...
)
set(ASSETS_cg
assets-cg/tileset2b_CG.png
assets-cg/demo_player.png
)
set(ASSETS_fx
assets-fx/demo_player.png
# ...
)

BIN
assets-cg/demo_player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 B

View File

@ -1,5 +1,7 @@
tileset2b_CG.png:
type: bopti-image
name: img_tilesetnpp
demo_player.png:
type: bopti-image
name: demo_player_img

View File

Before

Width:  |  Height:  |  Size: 105 B

After

Width:  |  Height:  |  Size: 105 B

View 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

View File

@ -1,7 +1,3 @@
*.json:
custom-type: map
name_regex: (.*)\.json map_\1
demo_player.png:
type: bopti-image
name: demo_player_img

6
src/config.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef CONFIG_H
#define CONFIG_H
#define USB_FEATURE 1
#endif

View File

@ -2,6 +2,10 @@
#include "map.h"
#include "config.h"
#include <gint/keyboard.h>
void game_logic(Game *game) {
// to be done
}
@ -12,3 +16,34 @@ void draw(Game *game) {
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
}

View File

@ -10,6 +10,15 @@
typedef struct {
Map *map_level; /* The level that the player is currently playing */
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;
/* (Mibi88) TODO: Describe what this function is doing. */
@ -18,5 +27,8 @@ void game_logic(Game *game);
/* Draws everything on screen. */
void draw(Game *game);
/* Handle key presses. */
void get_inputs(Game *game);
#endif

View File

@ -1,10 +1,12 @@
#include <gint/display.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.h>
#endif //USB_FEATURE
@ -27,65 +29,19 @@
/* Game data (defined in "game.h")*/
Game game = {
&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 */
#if USB_FEATURE==1
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
if (dgray_enabled())
usb_fxlink_screenshot_gray(false);
@ -93,12 +49,12 @@ static void get_inputs( void )
#endif
usb_fxlink_screenshot(false); // else we just let the usual screeshot function
screenshot = false;
usb_fxlink_screenshot(false); // else we just let the usual screeshot function
game.screenshot = false;
}
if (record && usb_is_open()) {
if (game.record && usb_is_open()) {
#ifdef GRAYMODEOK
@ -114,7 +70,20 @@ static void get_inputs( void )
#endif
/* Timer callback */
int update_time(void) {
game.frame_duration++;
return TIMER_CONTINUE;
}
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
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
@ -125,12 +94,11 @@ int main(void) {
/* start grayscale engine */
#ifdef GRAYMODEOK
dgray( DGRAY_ON );
dgray(DGRAY_ON);
#endif
do
{
do{
/* clear screen */
dclear(C_WHITE);
@ -149,16 +117,18 @@ int main(void) {
#endif
/* Management of the inputs */
get_inputs();
}
while (exittoOS == false); // want to exit ?
get_inputs(&game);
/* Run the game at max. 50fps */
while(game.frame_duration < 20) sleep();
/* Reset frame_duration for the next frame */
game.frame_duration = 0;
}while(!game.exittoOS); // want to exit ?
/* shutdown grayengine*/
#ifdef GRAYMODEOK
dgray( DGRAY_OFF );
dgray(DGRAY_OFF);
#endif
@ -167,7 +137,7 @@ int main(void) {
usb_close();
#endif
timer_stop(timer);
return 1;
}

View File

@ -15,7 +15,7 @@ void render_map(Player *player, Map *map_level) {
unsigned char mx, my;
/* dw and dh contain the amount of tiles that will be drawn on x and on
* 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. */
unsigned short int mw = map_level->w*T_WIDTH, mh = map_level->h*T_HEIGHT;
/* 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) {
/* Get the tile at (x, y) on layer l. Returns the tile ID or MAP_OUTSIDE if
* she's not found. */

View File

@ -2,17 +2,18 @@
#include "map.h"
#include <gint/display.h>
/* (Mibi88) TODO: Upscale the player for the CG50. */
/* The player should not be bigger than a tile because it may cause problems
* with the collisions. If it's a problem please ask me (Mibi88) to adapt that.
*/
#define P_WIDTH 8
#define P_HEIGHT 8
#ifdef FXCG50
#define P_WIDTH 16
#define P_HEIGHT 16
#else
#define P_WIDTH 8
#define P_HEIGHT 8
#endif
/* SPEED should NOT be 8 or bigger: it this may cause bugs when handling
* collisions! */
#ifdef FXCG50
#define SPEED 3
#define SPEED 2
#else
#define SPEED 1
#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(player_collision(map_level, player, direction)){
/* 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{
/* If he won't collide I just move him normally */
player->x += dx;