mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2025-04-20 01:47:34 +02:00
Collisions are working :D! I only need to add a framerate limit and add some comments, then everything will be good to merge!
This commit is contained in:
parent
908b971317
commit
8d316d0d0d
1 changed files with 7 additions and 4 deletions
11
src/player.c
11
src/player.c
|
@ -3,6 +3,9 @@
|
||||||
#include <gint/display.h>
|
#include <gint/display.h>
|
||||||
|
|
||||||
/* (Mibi88) TODO: Upscale the player for the CG50. */
|
/* (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_WIDTH 8
|
||||||
#define P_HEIGHT 8
|
#define P_HEIGHT 8
|
||||||
|
|
||||||
|
@ -56,9 +59,9 @@ bool player_collision(Map *map_level, Player *player, Direction direction) {
|
||||||
const char dx = one_px_mov[direction*2];
|
const char dx = one_px_mov[direction*2];
|
||||||
const char dy = one_px_mov[direction*2+1];
|
const char dy = one_px_mov[direction*2+1];
|
||||||
int player_tile_x = player->x/T_WIDTH;
|
int player_tile_x = player->x/T_WIDTH;
|
||||||
int player_tile_y = player->x/T_WIDTH;
|
int player_tile_y = player->y/T_HEIGHT;
|
||||||
for(i=0;i<map_level->nblayers;i++){
|
for(i=0;i<map_level->nblayers;i++){
|
||||||
if(is_in(hard_tiles, HARD_TILES_AMOUNT,
|
if(is_in((short int*)hard_tiles, HARD_TILES_AMOUNT,
|
||||||
get_tile(map_level, player_tile_x+dx, player_tile_y+dy, i))){
|
get_tile(map_level, player_tile_x+dx, player_tile_y+dy, i))){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +70,7 @@ bool player_collision(Map *map_level, Player *player, Direction direction) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_fix_position(Player *player, bool fix_x, bool fix_y) {
|
void player_fix_position(Player *player, bool fix_x, bool fix_y) {
|
||||||
if(fix_x) player->x = player->x/T_WIDTH*T_WIDTH;
|
if(fix_x) player->x = player->x/T_WIDTH*T_WIDTH+P_WIDTH/2;
|
||||||
if(fix_y) player->y = player->y/T_HEIGHT*T_HEIGHT;
|
if(fix_y) player->y = player->y/T_HEIGHT*T_HEIGHT+P_HEIGHT/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue