From 272d60b0aac66b0a6ef1fba6fcd2efb4c6d12bea Mon Sep 17 00:00:00 2001 From: SlyVTT Date: Mon, 14 Aug 2023 18:40:36 +0200 Subject: [PATCH] preparing stuff for map change when reaching borders during gameplay --- README.md | 8 +++---- assets/level1.tmx | 42 ++++++++++++++++----------------- assets/level2.tmx | 60 +++++++++++++++++++++++------------------------ assets/level3.tmx | 52 ++++++++++++++++++++-------------------- clean | 1 + src/game.h | 3 ++- src/main.c | 8 +++---- src/map.c | 28 ++++++++++++++++++++++ src/map.h | 3 +++ src/player.c | 23 ++++++++++++++++++ 10 files changed, 142 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index 76bbeeb..9189464 100644 --- a/README.md +++ b/README.md @@ -4,20 +4,20 @@ Plus d'infos sur ce projet ici : [Le projet Collaboratif de PC](https://www.plan ## Avencement du projet - A ce stade, on a déjà implémenté : - [x] Screenshots, etc. par USB -- [x] Affichage de la map selon la position du joueur +- [x] Affichage de la map courante selon la position du joueur - [x] Gestion des touches - [x] Gestion des collisions +- [x] Multiple cartes avec importation automatique des fichiers `world` issus de Tiled - [x] Carte Multilayer (Background, Foreground + accessibilité / Dommages) avec transparence du calque Foreground - [x] Personnage - [x] Dialogues (sauts de lignes et mots plus grands que l'écran pas supportés) - [ ] Fontes de caractères - [ ] Interaction - [ ] NPC -- [ ] Changement de map +- [ ] Changement de map durant le jeu (en cours) ## Crédits @@ -27,5 +27,5 @@ Les tiles sont issues de Game Boy Top-down RPG Fantasy Tileset (FREE) Converties en niveau de gris avec Gimp -Une version 1-bit (N&B) à été réalisée par Shadow15510 +Une version 1-bit (N&B) à été réalisée par Shadow15510 Et une version couleur CG à été réalisée par Fcalva diff --git a/assets/level1.tmx b/assets/level1.tmx index 9fd42bb..300ef70 100644 --- a/assets/level1.tmx +++ b/assets/level1.tmx @@ -1,7 +1,7 @@ - + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, @@ -58,32 +58,32 @@ 276,0,0,273,274,275,276,0,0,0,0,273,274,275,276,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,414,414,414,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0, -0,0,0,414,414,414,414,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,414,414,414,414,414,414,414,414,0,0,0,0,414,414, -0,0,414,414,414,414,414,414,414,414,414,414,414,414,0,0,0,0,0,0,0,0,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414, -412,414,414,414,414,414,414,414,414,414,414,414,414,414,0,0,412,412,0,0,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414, -0,414,414,414,414,414,414,414,414,414,414,414,414,414,414,0,0,0,0,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414, -0,0,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,0,0,414,414,414,414,414,414,414,414,414,414,414, -0,0,0,414,414,414,414,414,414,0,0,0,414,414,414,414,414,414,414,414,414,414,414,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,414,414,414,414,414,414,414, -0,0,0,0,414,414,414,414,0,0,0,0,414,414,414,414,414,414,414,414,414,414,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,414,414,414, -412,412,412,412,412,412,0,0,0,0,0,0,0,0,414,414,414,414,414,414,414,414,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,414,414,414, -0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0, +0,0,0,412,412,412,412,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,412,412,412,412,412,412,412,412,0,0,0,0,412,412, +0,0,412,412,412,412,412,412,412,412,412,412,412,412,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412, +410,412,412,412,412,412,412,412,412,412,412,412,412,412,0,0,410,410,0,0,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412, +0,412,412,412,412,412,412,412,412,412,412,412,412,412,412,0,0,0,0,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412, +0,0,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,0,0,412,412,412,412,412,412,412,412,412,412,412, +0,0,0,412,412,412,412,412,412,0,0,0,412,412,412,412,412,412,412,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412, +0,0,0,0,412,412,412,412,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412, +410,410,410,410,410,410,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,412,412,412, +0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0, -412,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0, -412,412,412,412,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,0,412,412,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,0,0,0,0,0,0,412,412,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0, +410,410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0, +410,410,410,410,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,410,410,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,0,0,0,410,410,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/assets/level2.tmx b/assets/level2.tmx index 0d65f1f..35d297c 100644 --- a/assets/level2.tmx +++ b/assets/level2.tmx @@ -1,7 +1,7 @@ - + 2,2,2,2,386,2,2,2,2,2,2,325,2,290,265,2,349,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,297,298,299, @@ -12,13 +12,13 @@ 2,2,2,2,2,2,2,2,2,2,2,2,2,290,266,2,2,2,385,2,297,298,299,300,2,2,2,2,2,2,2,9,10,2,2,283,283,3,115,111,112,113,3,312,312,131,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,386,266,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,33,34,385,2,283,283,3,114,114,115,114,3,312,312,132,385,2, 2,386,2,2,2,2,2,2,2,2,2,2,2,313,290,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,282,283,3,3,3,3,3,3,312,288,132,2,2, -2,2,2,297,298,299,300,2,345,346,347,348,2,265,266,2,2,149,150,151,152,149,150,151,152,149,150,151,152,149,150,151,152,2,2,282,283,3,3,3,3,3,3,287,288,132,2,2, -2,2,2,2,2,2,2,386,369,370,371,372,2,266,290,2,2,2,2,2,2,385,2,2,2,2,385,2,2,2,2,2,2,2,2,282,283,3,3,3,3,3,3,312,312,132,2,2, -2,2,2,2,2,2,386,2,393,394,395,396,2,290,266,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,282,283,3,3,3,3,3,3,312,288,132,2,2, -2,2,2,2,2,385,2,2,2,2,2,2,2,386,313,2,2,149,149,150,151,149,150,151,152,149,150,151,152,149,150,151,152,2,2,282,330,308,308,308,308,308,308,311,312,132,2,2, +2,2,2,297,298,299,300,2,345,346,347,348,2,265,266,2,2,374,375,151,152,149,150,151,152,149,150,374,375,149,150,151,152,2,2,282,283,3,3,3,3,3,3,287,288,132,2,2, +2,2,2,2,2,2,2,386,369,370,371,372,2,266,290,208,209,352,353,2,2,385,2,2,2,2,385,2,2,2,2,2,2,2,2,282,283,3,3,3,3,3,3,312,312,132,2,2, +2,2,2,2,2,2,386,2,393,394,395,396,2,290,266,232,233,376,377,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,282,283,3,3,3,3,3,3,312,288,132,2,2, +2,2,2,2,2,385,2,2,2,2,2,2,2,386,313,2,2,149,149,374,375,149,150,151,152,374,375,151,152,149,150,151,152,2,2,282,330,308,308,308,308,308,308,311,312,132,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,266,290,2,2,2,2,2,2,2,2,2,2,385,2,2,385,2,2,2,2,2,2,330,331,331,331,331,331,331,331,331,336,132,2,2, 2,297,298,299,300,2,2,2,2,2,2,2,2,265,266,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,90,91,92,162,163,164,165,90,91,92,132,2,2, -2,2,2,2,2,2,2,2,2,2,2,2,2,266,290,2,2,149,150,151,152,149,150,151,152,149,150,151,152,149,150,151,152,2,2,114,115,116,186,187,188,189,114,115,116,132,2,2, +2,2,2,2,2,2,2,2,2,2,2,2,2,266,290,2,2,149,150,151,152,149,150,154,154,149,150,151,152,149,150,151,152,2,2,114,115,116,186,187,188,189,114,115,116,132,2,2, 2,385,386,386,2,2,2,2,2,2,2,2,2,313,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,110,113,110,210,211,212,213,113,110,113,133,2,2, 2,385,2,2,2,2,2,2,2,2,2,2,2,290,265,2,2,2,2,2,2,2,2,386,2,2,2,2,385,2,2,2,2,2,2,2,2,2,234,290,265,237,2,2,2,2,385,2, 2,2,2,2,2,2,297,298,299,300,2,2,2,386,266,2,2,2,2,2,2,2,2,386,386,2,2,2,2,2,2,2,2,2,2,2,160,161,386,386,266,2,2,2,2,385,385,2, @@ -39,13 +39,13 @@ 0,0,0,201,202,203,204,0,0,0,0,0,0,0,0,0,0,0,0,0,273,274,275,276,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,225,226,227,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,249,250,251,252,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,273,274,275,276,0,0,0,0,0,0,0,0,0,0,125,126,127,128,125,126,127,128,125,126,127,128,125,126,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,273,274,275,276,0,0,0,0,0,0,0,0,0,0,350,351,127,128,125,126,127,128,125,126,350,351,125,126,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,201,202,203,204,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,225,226,227,228,0,0,0,0,0,0,0,0,0,0,0,0,125,125,126,127,125,126,127,128,125,126,127,128,125,126,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,225,226,227,228,0,0,0,0,0,0,0,0,0,0,0,0,125,125,350,351,125,126,127,128,350,351,127,128,125,126,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,249,250,251,252,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,273,274,275,276,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,201,202,203,204,0,0,0,0,0,0,0,125,126,127,128,125,126,127,128,125,126,127,128,125,126,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,201,202,203,204,0,0,0,0,0,0,0,125,126,173,128,125,126,130,174,125,126,127,128,125,126,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,225,226,227,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,249,250,251,252,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,273,274,275,276,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,136,137,0,0,0,0,0,0,0,0,0,0, @@ -60,29 +60,29 @@ -0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,412,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412, -0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0, -412,412,0,0,0,0,0,0,0,0,0,412,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,412,412,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,412,412,0,0,412,412,412,412,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,0,0,412,412,412,412,412,412,412,412,412,412,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,0,0,412,412,412,412,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,410,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410, +0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0, +410,410,0,0,0,0,0,0,0,0,0,410,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,410,410,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,410,410,0,0,410,410,410,410,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,410,411,411,411,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,411,411,411,411,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,0,0,410,410,410,410,410,410,410,410,410,410,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0,410,410,410,410,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/assets/level3.tmx b/assets/level3.tmx index f260e15..ea2adeb 100644 --- a/assets/level3.tmx +++ b/assets/level3.tmx @@ -1,7 +1,7 @@ - + 300,2,2,297,298,299,300,2,2,2,2,297,298,299,300,2,2,2,2,2,2,339,340,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, @@ -58,32 +58,32 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - + -0,0,0,0,412,412,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,0,412,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,0,412,412, -412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,412,0,412,412, -412,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,412,412,412,412,412,412,412,412,412,412,412,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,412,0,0,0, -412,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,412,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,412,0,0,0, -412,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,412,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,412,0,0,0, -412,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,412,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,412,0,0,412,412,412,412,0,0,412,0,0,0, -412,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,412,0,0,0,0,0,0,0,0,0,412,0,0,0,412,412,0,0,0,412,412,412,412,0,0,412,412,412,412,0,0,0, -412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,0,412,412,412,412,0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,412,412,412,412,412,412,412,412,0,412,412,412,412,0,412,412,412,412,0,0,412,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,0,0,412, -0,0,412,0,0,0,0,0,0,412,0,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,412,0,0,0,0,0,0,412,0,412,412,412,412,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,0,0,0,0,0,0,0,0, -0,0,412,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0, -0,0,412,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0, -0,0,412,0,0,412,412,412,412,412,0,0,0,0,0,0,412,412,412,412,412,412,412,412,412,412,412,412,0,0,0,0,412,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0, -0,0,412,412,412,412,0,0,412,412,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,412,0,0,0,0,0,0,412,0,0,0,0,412,412,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,412,0,0,412,412,412,412,412,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,412,412,412,412,0,0,412,412,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,0,0,0,0,0,0,412,412,412,412,412,0,0,0,0,0,0,0,0,0,0,0,412,412,0,412,412,412,412,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,412,412,412,412,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,0,412,412,0,0,0,0,0,412,412,412,412,0,0, -0,0,412,412,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,0,412,412,412,412,0,412,412,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,412,412,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,412,412,412,412,0,0,0,0,0,0,0,412,0,0,0,0,0,0 +0,0,0,0,410,410,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,410,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,410,410, +410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,410,0,410,410, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,410,410,410,410,410,410,410,410,410,410,410,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,410,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,410,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,410,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,410,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,410,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,410,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,410,0,0,410,410,410,410,0,0,410,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,410,0,0,0,0,0,0,0,0,0,410,0,0,0,410,410,0,0,0,410,410,410,410,0,0,410,410,410,410,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,410,410,410,410,0,0,0,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,410,410,410,410,410,410,410,410,0,410,410,410,410,0,410,410,410,410,0,0,410,410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,410, +0,0,410,0,0,0,0,0,0,410,0,410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,410,0,0,0,0,0,0,410,0,410,410,410,410,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,0,0,0,0,0,0,0,0, +0,0,410,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0, +0,0,410,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0, +0,0,410,0,0,410,410,410,410,410,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,410,410,0,0,0,0,410,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0, +0,0,410,410,410,410,0,0,410,410,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,410,0,0,0,0,0,0,410,0,0,0,0,410,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,410,0,0,410,410,410,410,410,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,410,410,410,410,0,0,410,410,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,0,0,0,0,410,410,410,410,410,0,0,0,0,0,0,0,0,0,0,0,410,410,0,410,410,410,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,410,410,0,0,0,0,0,410,410,410,410,0,0, +0,0,410,410,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,410,410,410,410,0,410,410,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,0,0,0,0,410,0,0,0,0,0,0 diff --git a/clean b/clean index 6cf836c..3e99971 100755 --- a/clean +++ b/clean @@ -1,5 +1,6 @@ cd assets rm -f *.json +rm -r __pycache__ cd .. rm -r build-cg rm -r build-fx diff --git a/src/game.h b/src/game.h index e13f3d4..b8b8615 100644 --- a/src/game.h +++ b/src/game.h @@ -23,8 +23,9 @@ typedef enum { /* Struct that define player parameters */ typedef struct { - int x, y; /* The position of the player */ + int x, y; /* The position of the player int the current map */ unsigned int px, py; /* The position of the player on screen */ + int wx, wy; /* position of the player in the world */ unsigned short int life; /* How many lives the player still has between 0 * and 100. */ char speed; /* The speed of the movement of the player. */ diff --git a/src/main.c b/src/main.c index deadd41..f448a84 100644 --- a/src/main.c +++ b/src/main.c @@ -32,11 +32,11 @@ extern Map *worldRPG[]; /* Game data (defined in "game.h")*/ Game game = { NULL, - {10*PXSIZE, 48*PXSIZE, 0, 0, 100, SPEED}, + {10*PXSIZE, 48*PXSIZE, 0, 0, 0, 0, 100, SPEED}, false, false, false, 0 /* debug variables*/ - , true, true + , false, false }; /* screen capture management code */ @@ -93,7 +93,7 @@ int main(void) { } timer_start(timer); - game.map_level = worldRPG[0]; + game.map_level = worldRPG[2]; #if USB_FEATURE @@ -137,7 +137,7 @@ int main(void) { { dfont( NULL ); drect( 5, 55,390, 75, C_WHITE ); - dprint( 10, 60, C_BLUE, "X= %d - Y= %d", game.player.x, game.player.y ); + dprint( 10, 60, C_BLUE, "X= %d - Y= %d / Wx= %d - Wy= %d", game.player.x, game.player.y, game.player.wx, game.player.wy ); } #endif diff --git a/src/map.c b/src/map.c index 7ea491d..e04091b 100644 --- a/src/map.c +++ b/src/map.c @@ -4,6 +4,9 @@ #include +extern Map *worldRPG[]; + + void render_map(Game *game) { Map *map_level = game->map_level; @@ -193,6 +196,7 @@ void render_map_by_layer(Game *game, int layer) { short int get_tile(Game *game, int x, int y, int l) { Map *map_level = game->map_level; + /* Get the tile at (x, y) on layer l. Returns the tile ID or MAP_OUTSIDE if * she's not found. */ return x>=0 && x < map_level->w && y>=0 && y < map_level->h ? @@ -208,3 +212,27 @@ short int get_walkable(Game *game, int x, int y) { map_level->walkable[y * map_level->w + x] : MAP_OUTSIDE; } +/* return the pointer to the map containing the given position */ +Map *get_map_for_coordinates( Game *game, int x, int y ) +{ + /* check if the current map contains the point */ + if (x>=game->map_level->xmin && xmap_level->xmax && + y>=game->map_level->ymin && ymap_level->ymax) + return game->map_level; + + /* else we check in worldRPG if there is a mal containing that point */ + int i = 0; + Map *current = worldRPG[i]; + do + { + if (x>=current->xmin && xxmax && + y>=current->ymin && yymax) + return current; + i++; + current = worldRPG[i]; + } + while (current!=NULL) + + /* else we return NULL cause the point is a not within a map */ + return NULL; +} \ No newline at end of file diff --git a/src/map.h b/src/map.h index e255291..1586186 100644 --- a/src/map.h +++ b/src/map.h @@ -33,4 +33,7 @@ short int get_tile(Game *game, int x, int y, int l); /* Returns what is in the walkable layer at (x, y). */ short int get_walkable(Game *game, int x, int y); +/* return the pointer to the map containing the given position */ +Map* get_map_for_coordinates(Game *game, int x, int y ); + #endif diff --git a/src/player.c b/src/player.c index 07a347e..48f0f4b 100644 --- a/src/player.c +++ b/src/player.c @@ -35,19 +35,24 @@ void player_draw(Game *game) { void player_move(Game *game, Direction direction) { Player *player = &game->player; + /* How this player movement will modify the player x and y. */ char dx, dy; + /* If the player will collide with a hard tile or if the will go outside of * the map. */ if(player_collision(game, direction, P_CENTER)){ + /* If the will collide with the center of the player. */ dx = one_px_mov[direction*2]*player->speed; dy = one_px_mov[direction*2+1]*player->speed; + player_fix_position(game, dx, dy); } else{ if(player_collision(game, direction, P_RIGHTDOWN) || player_collision(game, direction, P_LEFTUP)){ + /* If the will collide with the edges of the player. */ /* I fix his position so he won't be partially in the tile. */ /* I invert dx and dy to fix the axis where he is not moving on. */ @@ -55,14 +60,20 @@ void player_move(Game *game, Direction direction) { */ dx = one_px_mov[direction*2]*player->speed; dy = one_px_mov[direction*2+1]*player->speed; + player_fix_position(game, dx==0, dy==0); } + /* If he won't collide with the center, so I just move him normally */ dx = one_px_mov[direction*2]*player->speed; dy = one_px_mov[direction*2+1]*player->speed; + player->x += dx; player->y += dy; } + + player->wx = game->map_level->xmin * PXSIZE + player->x; + player->wy = game->map_level->ymin * PXSIZE + player->y; } void player_action(Game *game) { @@ -77,38 +88,50 @@ bool player_collision(Game *game, Direction direction, /* Where is the tile where he will go to from his position. */ char dx = one_px_mov[direction*2]; char dy = one_px_mov[direction*2+1]; + if(!dx){ dx += nomov_axis_check; }else if(!dy){ dy += nomov_axis_check; } + dx = dx*(P_WIDTH/2+1); dy = dy*(P_HEIGHT/2+1); + /* The tile he will go to. */ int player_tile_x = player->x+dx; int player_tile_y = player->y+dy; + /* Handle a negative position diffrently than a positive one. */ if(player_tile_x < 0) player_tile_x = player_tile_x/T_WIDTH-1; else player_tile_x = player_tile_x/T_WIDTH; + if(player_tile_y < 0) player_tile_y = player_tile_y/T_HEIGHT-1; else player_tile_y = player_tile_y/T_HEIGHT; + int on_walkable = get_walkable(game, player_tile_x, player_tile_y); + int speed = on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX ? walkable_speed[on_walkable] : 0; + /* if he's on a hard tile */ if(!speed){ return true; /* He will collide with it. */ } + player->speed = speed; + return false; /* He won't collide with a hard tile. */ } void player_fix_position(Game *game, bool fix_x, bool fix_y) { Player *player = &game->player; + /* I fix his poition on x or/and on y if y need to, so that he won't be over * the hard tile that he collided with. */ 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+P_HEIGHT/2; }