diff --git a/.gitignore b/.gitignore index 085829e..f834a6a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /build-fx /build-cg /build-cg-push +/build-fxg3a /*.g1a /*.g3a diff --git a/CMakeLists.txt b/CMakeLists.txt index 65291bf..aa873c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,8 @@ include(GenerateG1A) include(GenerateG3A) include(Fxconv) -find_package(Gint 2.9 REQUIRED) +find_package(Gint 2.11 REQUIRED) +# Gint 2.11 is required, because we're using the new macros like GINT_RENDER_RGB find_package(LibProf 2.4 REQUIRED) #set the color mode either to 1b or 2b @@ -36,9 +37,12 @@ set(ASSETS set(ASSETS_cg assets-cg/demo_player.png - assets-cg/demo_PNJ.png + assets-cg/npc/char/npc_male.png assets-cg/SignAction.png - assets-cg/NPC_Icon.png + assets-cg/npc/face/npc_male.png + assets-cg/npc/face/npc_female.png + assets-cg/npc/face/npc_milkman.png + assets-cg/npc/face/npc_police.png assets-cg/SGN_Icon.png assets-cg/INFO_Icon.png assets-cg/player_face.png @@ -59,9 +63,12 @@ set(ASSETS_cg_EGA64 set(ASSETS_fx assets-fx/demo_player.png - assets-fx/demo_PNJ.png + assets-fx/npc/char/npc_male.png assets-fx/SignAction.png - assets-fx/NPC_Icon.png + assets-fx/npc/face/npc_male.png + assets-fx/npc/face/npc_female.png + assets-fx/npc/face/npc_milkman.png + assets-fx/npc/face/npc_police.png assets-fx/SGN_Icon.png assets-fx/INFO_Icon.png assets-fx/player_face.png @@ -85,29 +92,8 @@ if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}} ${ASSETS_${FXSDK_PLATFORM}_${COLORMODE_fx}} ) elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}} ${ASSETS_${FXSDK_PLATFORM}_${COLORMODE_cg}} ) -endif() - -# fx colormode -if("${COLORMODE_fx}" STREQUAL 1b) - target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOR1BIT) -endif() - - -if("${COLORMODE_fx}" STREQUAL 2b) - target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOR2BIT) -endif() - -# cg colormode -if("${COLORMODE_cg}" STREQUAL 1b) - target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOR1BIT) -endif() - -if("${COLORMODE_cg}" STREQUAL 2b) - target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOR2BIT) -endif() - -if("${COLORMODE_cg}" STREQUAL EGA64) - target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOREGA) +elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G_G3A) + 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) @@ -115,6 +101,14 @@ target_link_libraries(myaddin LibProf::LibProf Gint::Gint) if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) + # fx colormode + if("${COLORMODE_fx}" STREQUAL 1b) + target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOR1BIT) + endif() + + if("${COLORMODE_fx}" STREQUAL 2b) + target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOR2BIT) + endif() if("${COLORMODE_fx}" STREQUAL 1b) generate_g1a(TARGET myaddin OUTPUT "RPG_1b.g1a" @@ -127,7 +121,20 @@ if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) endif() + elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) + # cg colormode + if("${COLORMODE_cg}" STREQUAL 1b) + target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOR1BIT) + endif() + + if("${COLORMODE_cg}" STREQUAL 2b) + target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOR2BIT) + endif() + + if("${COLORMODE_cg}" STREQUAL EGA64) + target_compile_options(myaddin PRIVATE -Wall -Wextra -Os -DCOLOREGA) + endif() if("${COLORMODE_cg}" STREQUAL 1b) generate_g3a(TARGET myaddin OUTPUT "RPG_1b.g3a" @@ -144,4 +151,19 @@ elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) NAME "RPG PC EGA" ICONS assets-cg/ega64/icon-uns-ega64.png assets-cg/ega64/icon-sel-ega64.png) endif() + + +elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G_G3A) + + if("${COLORMODE_fx}" STREQUAL 1b) + generate_g3a(TARGET myaddin OUTPUT "RPG_1bfx.g3a" + NAME "RPG PC 1b fx" ICONS assets-cg/1b/icon-uns-1b.png assets-cg/1b/icon-sel-1b.png) + endif() + + if("${COLORMODE_fx}" STREQUAL 2b) + generate_g3a(TARGET myaddin OUTPUT "RPG_2bfx.g3a" + NAME "RPG PC 2b fx" ICONS assets-cg/2b/icon-uns-2b.png assets-cg/2b/icon-sel-2b.png) + endif() + + endif() diff --git a/PROJECT_STRUCTURE.md b/PROJECT_STRUCTURE.md new file mode 100644 index 0000000..8ddbd80 --- /dev/null +++ b/PROJECT_STRUCTURE.md @@ -0,0 +1,26 @@ +# Project structure + + * `assets` contains the tiled maps, and the tiled map converters. + * `assets-cg` contains the assets for cg calculators like the cg-50. + * `assets-fx` contains the assets for monochrome calculators. + * `captures` contains screenshots. + * `src` This folder contains the source code. + * `config.h` This header file contains defines for the size of various + things on screen, like the size of a tile in the tilemap, the size of the + dialog box, etc. + * `dialogs.c` and `dialogs.h` contain various functions to display dialogs + and also let the user respond. + * `events.c` and `events.h` parse tags in the messages that are displayed + using the dialogs procedures to modify variables (and soon, call + procedures). + * `game.c` and `game.h` handles the rendering, the input, etc. + * `main.c` handles the USB connection and the gint gray rendering, for 2bpp + rendering on monochrome calculators. Contains the mainloop. Also contains + code to display debug informations. + * `map.c` and `map.h` contain code to render, get a tile in the map, see if + the tile is walkable, etc. + * `mapdata.h` contains the available maps. + * `memory.c` and `memory.h` procedures to handle arrays (currently: search + in an array of short ints). + * `npc.c` and `npc.h` npc rendering and movement (and soon pathfinding). + * `player.c` and `player.h` handle the player movement, collision, etc. diff --git a/README.md b/README.md index 03c5af6..09d5ec3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,12 @@ Plus d'infos sur ce projet ici : [Le projet Collaboratif de PC](https://www.planet-casio.com/Fr/forums/topic17343-last-projet-collaboratif-avec-toute-la-commu.html) -## Avencement du projet +## Contribuer! +Style du code [STYLE.md](STYLE.md). + +Structure du projet [PROJECT_STRUCTURE.md](PROJECT_STRUCTURE.md). + +## Avancement du projet A ce stade, on a déjà implémenté : @@ -13,12 +18,13 @@ A ce stade, on a déjà implémenté : - [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 avec fichiers externes `json` et séquenceage possible de ceux-ci via un arbre d'histoire (sauts de lignes et mots plus grands que l'écran pas supportés) +- [x] Dialogues avec fichiers externes `json` et séquenceage possible de ceux-ci via un arbre d'histoire (sauts de lignes et mots plus grands que l'écran pas supportés + limite d'un kibibyte) - [x] Fontes de caractères - [x] Interaction - [ ] NPC - [x] Changement de map durant le jeu - [ ] Système d'événements +- [ ] Pathfinding ## Crédits diff --git a/README_en.md b/README_en.md new file mode 100644 index 0000000..7a892d8 --- /dev/null +++ b/README_en.md @@ -0,0 +1,44 @@ +# Planet Casio Collaborative Project + +(maybe I should've used google translate) + +More informations can be found here (in french): +[Le projet Collaboratif de PC](https://www.planet-casio.com/Fr/forums/topic17343-last-projet-collaboratif-avec-toute-la-commu.html) + +## Contribute! +Style guidelines [STYLE.md](STYLE.md). + +Project structure [PROJECT_STRUCTURE.md](PROJECT_STRUCTURE.md). + +## Current state + +What we've implemented so far: + +- [x] Screenshots via USB +- [x] Displaying the current map at the players position +- [x] Handling keyboard inputs +- [x] Handling collisions. +- [x] Multiple maps with automatic `world` files import (made with Tiled) +- [x] Multilayer map (Background, Foreground + accessibility / damage) with + foreground layer transparency. +- [x] Player character. +- [x] Dialogs from external `json` files (line jumps and words bigger than the + screen are unsupported + 1 kibibyte per message limit) +- [x] Font +- [x] Interaction +- [ ] NPC +- [x] Changing map in game. +- [ ] Event system +- [ ] Pathfinding + + +## Credits + +The tiles are from Game Boy Top-down RPG Fantasy Tileset (FREE) +"Background Assets by Gumpy Function (gumpyfunction.itch.io)" +[Tiles Background Assets by Gumpy Function](https://gumpyfunction.itch.io/game-boy-rpg-fantasy-tileset-free) + +Converted to greyscale with gimp. + +1-bit (black and white) version by Shadow15510 +CG (palette EGA64) color version by Fcalva diff --git a/STYLE.md b/STYLE.md new file mode 100644 index 0000000..dc9e7e7 --- /dev/null +++ b/STYLE.md @@ -0,0 +1,33 @@ +# Style guidelines in Collab RPG + +(Mibi88) Fcalva, SlyVTT: What do you think of this? + +Wrap the code on 80 columns. Align the wrapped code with the last parantheses, +etc. + +Use curly braces with if, else, while and for statements if they can't hold on a +single line. + +Put the curly braces after if, else, while or for statements and declarations of +procedures on the same line. + +No spaces around parantheses, one space after a comma. + +Variables names in sneak_case. + +(Mibi88) SlyVTT, Fcalva, should be use a doc generation thing or do we describe +the procedures as I did so far? + +Document your procedures as following: + +```C +/* procedure_name() + * + * Describe what this procedure does. + * arg1: Describe this argument. If the text is too long, wrap it to the + * next line like this. + * long_name: Describe this argument, and so on. + */ +``` + +Have I forgotten something? diff --git a/assets-cg/NPC_Icon.png b/assets-cg/NPC_Icon.png deleted file mode 100644 index e9cc819..0000000 Binary files a/assets-cg/NPC_Icon.png and /dev/null differ diff --git a/assets-cg/demo_PNJ.png b/assets-cg/demo_PNJ.png deleted file mode 100644 index 8198c59..0000000 Binary files a/assets-cg/demo_PNJ.png and /dev/null differ diff --git a/assets-cg/demo_player.png b/assets-cg/demo_player.png index 04c4d34..7c1da00 100644 Binary files a/assets-cg/demo_player.png and b/assets-cg/demo_player.png differ diff --git a/assets-cg/ega64/tileset/tilesetEGA64_CG.png b/assets-cg/ega64/tileset/tilesetEGA64_CG.png index 86428c6..44ba3a7 100755 Binary files a/assets-cg/ega64/tileset/tilesetEGA64_CG.png and b/assets-cg/ega64/tileset/tilesetEGA64_CG.png differ diff --git a/assets-cg/npc/char/fxconv-metadata.txt b/assets-cg/npc/char/fxconv-metadata.txt new file mode 100644 index 0000000..b7658e5 --- /dev/null +++ b/assets-cg/npc/char/fxconv-metadata.txt @@ -0,0 +1,3 @@ +npc_male.png: + type: bopti-image + name: demo_PNJ_img diff --git a/assets-cg/npc/char/npc_male.png b/assets-cg/npc/char/npc_male.png new file mode 100644 index 0000000..f4d654b Binary files /dev/null and b/assets-cg/npc/char/npc_male.png differ diff --git a/assets-cg/npc/face/fxconv-metadata.txt b/assets-cg/npc/face/fxconv-metadata.txt new file mode 100644 index 0000000..664ce84 --- /dev/null +++ b/assets-cg/npc/face/fxconv-metadata.txt @@ -0,0 +1,12 @@ +npc_male.png: + type: bopti-image + name: npc_male +npc_female.png: + type: bopti-image + name: npc_female +npc_milkman.png: + type: bopti-image + name: npc_milkman +npc_police.png: + type: bopti-image + name: npc_police diff --git a/assets-cg/npc/face/npc_female.png b/assets-cg/npc/face/npc_female.png new file mode 100644 index 0000000..16321ae Binary files /dev/null and b/assets-cg/npc/face/npc_female.png differ diff --git a/assets-cg/npc/face/npc_male.png b/assets-cg/npc/face/npc_male.png new file mode 100644 index 0000000..c4f4820 Binary files /dev/null and b/assets-cg/npc/face/npc_male.png differ diff --git a/assets-cg/npc/face/npc_milkman.png b/assets-cg/npc/face/npc_milkman.png new file mode 100644 index 0000000..98b92bf Binary files /dev/null and b/assets-cg/npc/face/npc_milkman.png differ diff --git a/assets-cg/npc/face/npc_police.png b/assets-cg/npc/face/npc_police.png new file mode 100644 index 0000000..8888672 Binary files /dev/null and b/assets-cg/npc/face/npc_police.png differ diff --git a/assets-fx/2bpp_palette.png b/assets-fx/2bpp_palette.png new file mode 100644 index 0000000..05dc19d Binary files /dev/null and b/assets-fx/2bpp_palette.png differ diff --git a/assets-fx/NPC_Icon.png b/assets-fx/NPC_Icon.png deleted file mode 100644 index b353607..0000000 Binary files a/assets-fx/NPC_Icon.png and /dev/null differ diff --git a/assets-fx/demo_PNJ.png b/assets-fx/demo_PNJ.png deleted file mode 100644 index 8198c59..0000000 Binary files a/assets-fx/demo_PNJ.png and /dev/null differ diff --git a/assets-fx/demo_player.png b/assets-fx/demo_player.png index e522e61..7c1da00 100644 Binary files a/assets-fx/demo_player.png and b/assets-fx/demo_player.png differ diff --git a/assets-fx/fxconv-metadata.txt b/assets-fx/fxconv-metadata.txt index 499f659..12e9d02 100644 --- a/assets-fx/fxconv-metadata.txt +++ b/assets-fx/fxconv-metadata.txt @@ -2,10 +2,6 @@ demo_player.png: type: bopti-image name: demo_player_img -demo_PNJ.png: - type: bopti-image - name: demo_PNJ_img - player_face.png: type: bopti-image name: player_face_img @@ -18,10 +14,6 @@ INFO_Icon.png: type: bopti-image name: INFO_Icon_img -NPC_Icon.png: - type: bopti-image - name: NPC_Icon_img - SGN_Icon.png: type: bopti-image name: SGN_Icon_img @@ -34,4 +26,4 @@ font.png: grid.padding: 1 grid.border: 0 proportional: true - height: 5 \ No newline at end of file + height: 5 diff --git a/assets-fx/npc/char/fxconv-metadata.txt b/assets-fx/npc/char/fxconv-metadata.txt new file mode 100644 index 0000000..b7658e5 --- /dev/null +++ b/assets-fx/npc/char/fxconv-metadata.txt @@ -0,0 +1,3 @@ +npc_male.png: + type: bopti-image + name: demo_PNJ_img diff --git a/assets-fx/npc/char/npc_male.png b/assets-fx/npc/char/npc_male.png new file mode 100644 index 0000000..639504e Binary files /dev/null and b/assets-fx/npc/char/npc_male.png differ diff --git a/assets-fx/npc/face/fxconv-metadata.txt b/assets-fx/npc/face/fxconv-metadata.txt new file mode 100644 index 0000000..664ce84 --- /dev/null +++ b/assets-fx/npc/face/fxconv-metadata.txt @@ -0,0 +1,12 @@ +npc_male.png: + type: bopti-image + name: npc_male +npc_female.png: + type: bopti-image + name: npc_female +npc_milkman.png: + type: bopti-image + name: npc_milkman +npc_police.png: + type: bopti-image + name: npc_police diff --git a/assets-fx/npc/face/npc_female.png b/assets-fx/npc/face/npc_female.png new file mode 100644 index 0000000..b8ac9b6 Binary files /dev/null and b/assets-fx/npc/face/npc_female.png differ diff --git a/assets-fx/npc/face/npc_male.png b/assets-fx/npc/face/npc_male.png new file mode 100644 index 0000000..994a16d Binary files /dev/null and b/assets-fx/npc/face/npc_male.png differ diff --git a/assets-fx/npc/face/npc_milkman.png b/assets-fx/npc/face/npc_milkman.png new file mode 100644 index 0000000..f92f7bf Binary files /dev/null and b/assets-fx/npc/face/npc_milkman.png differ diff --git a/assets-fx/npc/face/npc_police.png b/assets-fx/npc/face/npc_police.png new file mode 100644 index 0000000..b5903ad Binary files /dev/null and b/assets-fx/npc/face/npc_police.png differ diff --git a/assets/converters.py b/assets/converters.py index 7b19bc8..7143aba 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -6,6 +6,7 @@ import pathlib import csv import os +DEBUG = 0 def convert(input, output, params, target): if params["custom-type"] == "map": @@ -34,8 +35,8 @@ def convert_world(input, output, params, target): data = json.load(open(input, "r")) nbMaps = ["fileName" in i for i in data["maps"]].count(True) - print( "We have to treat ", nbMaps, " maps") - print( "So let's go ... ") + if DEBUG: print( "We have to treat ", nbMaps, " maps") + if DEBUG: print( "So let's go ... ") structWorld = fxconv.Structure() #structExtra = fxconv.Structure() @@ -51,26 +52,26 @@ def convert_world(input, output, params, target): nameJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json" commandline = 'tiled --export-map json ' + nameTMX + ' ' + nameJSON - print( "TILED COMMAND LINE FOR MAPS : ", commandline ) + if DEBUG: print( "TILED COMMAND LINE FOR MAPS : ", commandline ) os.system( commandline ) mapPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json" - print("Map ", i , " name : ", mapPath ) + if DEBUG: print("Map ", i , " name : ", mapPath ) xmin = data["maps"][i]["x"] - print( "xmin = ", xmin ) + if DEBUG: print( "xmin = ", xmin ) ymin = data["maps"][i]["y"] - print( "ymin = ", ymin ) + if DEBUG: print( "ymin = ", ymin ) xmax = data["maps"][i]["x"] + data["maps"][i]["width"] - print( "xmax = ", xmax ) + if DEBUG: print( "xmax = ", xmax ) ymax = data["maps"][i]["y"] + data["maps"][i]["height"] - print( "ymax = ", ymax ) + if DEBUG: print( "ymax = ", ymax ) map = get_tile_map_data( mapPath, output, params, target, xmin, ymin, xmax, ymax) - print( "Map = ", map ) + if DEBUG: print( "Map = ", map ) structWorld += fxconv.ptr( map ) structWorld += fxconv.u32(0) @@ -85,7 +86,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): #find the tileset in use. it's a relative path (like ../tileset.tsx) nameTileset = data["tilesets"][0]["source"].replace(".tsx","") - print(nameTileset) + if DEBUG: print(nameTileset) #the name of the tileset without the .something nameTilesetFree = nameTileset.split("/")[-1] #count the number of "back" (cd ..) to locate the tileset on the computer @@ -95,7 +96,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): tilesetJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".json" commandline = 'tiled --export-tileset json ' + tilesetTSX + ' ' + tilesetJSON - print( "TILED COMMAND LINE FOR TILESET : ", commandline ) + if DEBUG: print( "TILED COMMAND LINE FOR TILESET : ", commandline ) os.system( commandline ) tileset = open(tilesetJSON, "r") @@ -105,14 +106,14 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): #find the ID of the first tile in the walkable tileset () indexWalkable = data["tilesets"][1]["firstgid"] - print(indexWalkable) + if DEBUG: print(indexWalkable) #Extract from the json the width, height w, h = data["width"], data["height"] #nbTileLayer is the number of "true" layers (without ObjectsLayer) nbTilelayer = ["data" in i for i in data["layers"]].count(True) - 1 - print( nbTilelayer) + if DEBUG: print( nbTilelayer) #index of the various layers (may change from one map to another) layer_walkable = 0 @@ -135,7 +136,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): datavalid = data["layers"][i] if datavalid["name"]=="Walkable": layer_walkable = i - print( "Walkable Tile Data in layer : ", layer_walkable) + if DEBUG: print( "Walkable Tile Data in layer : ", layer_walkable) break elif i==nbTilelayer: print( "ERROR : No Walkable layer data !!!" ) @@ -168,7 +169,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): nameDialog = data["properties"][0]["value"] dialogfile = "/".join(input.split("/")[:-nbRetour]) + "/" + nameDialog - print( "THE DIALOGS ARE CONTAINED IN THE FILE : ", dialogfile ) + if DEBUG: print( "THE DIALOGS ARE CONTAINED IN THE FILE : ", dialogfile ) nbdiag = 0 diagdata = fxconv.Structure() @@ -192,7 +193,7 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): datavalid = data["layers"][i] if datavalid["name"]=="Background": layer_background = i - print( "Background Tile Data in layer : ", layer_background) + if DEBUG: print( "Background Tile Data in layer : ", layer_background) break elif i==nbTilelayer: print( "ERROR : No Background layer data !!!" ) @@ -210,10 +211,10 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): datavalid = data["layers"][i] if datavalid["name"]=="Foreground": layer_foreground = i - print( "Foreground Tile Data in layer : ", layer_foreground) + if DEBUG: print( "Foreground Tile Data in layer : ", layer_foreground) break elif i==nbTilelayer: - printf( "ERROR : No Foreground layer data !!!" ) + print( "ERROR : No Foreground layer data !!!" ) layer_data = bytes() layer = data["layers"][layer_foreground] @@ -227,11 +228,11 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax): def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): - print( "WE ARE COMPUTING THE EXTRA DATA OF THE MAP : ", input ) + if DEBUG: print( "WE ARE COMPUTING THE EXTRA DATA OF THE MAP : ", input ) data = json.load(open(input, "r")) nblayer = ["id" in i for i in data["layers"]].count(True) - 1 - print( "I found ", nblayer, " of extradata") + if DEBUG: print( "I found ", nblayer, " of extradata") #index of the various layers (may change from one map to another) layer_extradata = 0 @@ -241,7 +242,7 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): datavalid = data["layers"][i] if datavalid["name"]=="ExtraData": layer_extradata = i - print( "Extra Data in layer : ", layer_extradata) + if DEBUG: print( "Extra Data in layer : ", layer_extradata) break elif i==nblayer: print( "ERROR : No ExtraData layer data !!!" ) @@ -272,6 +273,7 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): path_length = 0 xdata = None ydata = None + face_type = "MALE" #we now fill all the properties of this item for j in i["properties"]: @@ -281,42 +283,45 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): elif j["name"]=="needAction": needAction = j[ "value" ] else: - #Extra properties for NPCs (path) + #Extra properties for NPCs (path and face) if tpe=="NPC": - if j["name"]=="hasPath": + if j["name"]=="face": + face_type = j["value"] + elif j["name"]=="hasPath": pathID = None path = j[ "value" ] if path==1: - print( "PNJ has path - NOW LOOKING FOR RELEVANT DATA" ) + if DEBUG: print( "PNJ has path - NOW LOOKING FOR RELEVANT DATA" ) # we start looking for path data with first the ID of the path Object for u in i["properties"]: if u["name"]=="path": pathID = u[ "value" ] - print( "path ID is identified : ID= ", pathID ) + if DEBUG: print( "path ID is identified : ID= ", pathID ) for v in layer["objects"]: if v[ "id" ] == pathID: - print( "path data found : " ) + if DEBUG: print( "path data found : " ) xdata = bytes() ydata = bytes() for w in v[ "polyline" ]: path_length = path_length + 1 - print( "X= ", w[ "x" ], " Y= ", w[ "y" ] ) + if DEBUG: print( "X= ", w[ "x" ], " Y= ", w[ "y" ] ) xdata += fxconv.u16( int( w[ "x" ] ) ) ydata += fxconv.u16( int( w[ "y" ] ) ) else: - print( "PNJ has no Path" ) + if DEBUG: print( "PNJ has no Path" ) else: print( "UNIDENTIFIED PROPERTY : ", j["name"]) - print( "OBJECT X= ", x, " Y= ", y, "STR= ", dialogID ) - print( " Type= ", tpe, " Name= ", nme ) - print( " Action?= ", needAction ) + if DEBUG: + print( "OBJECT X= ", x, " Y= ", y, "STR= ", dialogID ) + print( " Type= ", tpe, " Name= ", nme, "Face =", face_type) + print( " Action?= ", needAction ) @@ -324,6 +329,7 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): structData += fxconv.u32( int(y) ) structData += fxconv.string( nme ) structData += fxconv.string( tpe ) + structData += fxconv.string(face_type) structData += fxconv.u32( int(dialogID) ) structData += fxconv.u32( int(needAction) ) @@ -345,9 +351,8 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): #else we do nothing (yet) else: - print( "Skip this object" ) + if DEBUG: print( "Skip this object" ) - return nbExtraData, structData @@ -372,16 +377,16 @@ def convert_font(input, output, params, target): def convert_dialogs(input, output, params, target): - print( "WE ARE COMPUTING THE DIALOGS FROM : ", input ) + if DEBUG: print( "WE ARE COMPUTING THE DIALOGS FROM : ", input ) data = json.load(open(input, "r")) structDialogs = fxconv.Structure() nbdialogs = 0 for d in data["dialogs"]: - print( int(d[ "ID" ])) + if DEBUG: print( int(d[ "ID" ])) # print( d[ "dialog" ] ) - print( int(d[ "isQuestion" ]) ) + if DEBUG: print( int(d[ "isQuestion" ]) ) # print( d[ "choice" ].replace('$', chr(0)) ) # print( d[ "conclusion1" ] ) # print( int(d[ "next1" ] ) ) @@ -402,4 +407,4 @@ def convert_dialogs(input, output, params, target): return nbdialogs, structDialogs - #fxconv.elf(structDialogs, output, "_" + params["name"], **target) \ No newline at end of file + #fxconv.elf(structDialogs, output, "_" + params["name"], **target) diff --git a/assets/level0.tmx b/assets/level0.tmx index 4cf2838..553ed3b 100644 --- a/assets/level0.tmx +++ b/assets/level0.tmx @@ -1,5 +1,5 @@ - + @@ -117,6 +117,7 @@ + @@ -126,6 +127,7 @@ + @@ -135,6 +137,7 @@ + diff --git a/assets/level1.tmx b/assets/level1.tmx index c3af03c..b635cb5 100644 --- a/assets/level1.tmx +++ b/assets/level1.tmx @@ -1,5 +1,5 @@ - + @@ -100,6 +100,7 @@ + diff --git a/assets/level2.tmx b/assets/level2.tmx index 3592373..b29cf1c 100644 --- a/assets/level2.tmx +++ b/assets/level2.tmx @@ -1,5 +1,5 @@ - + @@ -37,7 +37,7 @@ 250,251,252,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,297,298,299,300,0,0,0,225,226,227,228,225,226,227,228,0,0,0,0,0,273,274,275,276,0,0,0, 274,275,276,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,249,250,251,252,249,250,251,252,0,0,258,259,263,264,0,0,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,273,274,275,276,273,274,275,276,0,0,282,3,3,288,0,0,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,273,274,275,276,273,274,275,276,0,0,282,307,311,288,0,0,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,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, diff --git a/clean b/clean index 445982d..bcc4d2a 100755 --- a/clean +++ b/clean @@ -6,6 +6,7 @@ cd .. rm -r build-cg rm -r build-cg-push rm -r build-fx +rm -r build-fxg3a rm *.g1a rm *.g3a diff --git a/src/config.h b/src/config.h index ed692b7..a899255 100644 --- a/src/config.h +++ b/src/config.h @@ -2,27 +2,55 @@ #define CONFIG_H -#if !defined(FXCG50) && defined(COLOR2BIT) +#define USB_FEATURE 0 +#define DEBUGMODE 0 + +#include + +/* Enable GrayMode on either FX and FX_G3A targets */ +#if GINT_RENDER_MONO && defined(COLOR2BIT) #define GRAYMODEOK 1 #endif -#define USB_FEATURE 0 -#define DEBUGMODE 0 -#ifdef FXCG50 +#if GINT_RENDER_RGB + /* The tile size */ #define T_HEIGHT 16 #define T_WIDTH 16 + /* The size of a pixel */ + #define PXSIZE 2 + #define PATH_COLOR C_RED + /* The size of the player */ + #define P_WIDTH 16 + #define P_HEIGHT 16 #else + /* The tile size */ #define T_HEIGHT 8 #define T_WIDTH 8 -#endif - -#ifdef FXCG50 - #define PXSIZE 2 -#else + /* The pixel size */ #define PXSIZE 1 + #define PATH_COLOR C_BLACK + /* The player size */ + #define P_WIDTH 8 + #define P_HEIGHT 8 #endif +/* SPEED should NOT be 8 or bigger: it may cause bugs when handling + * collisions! */ +#define SPEED (PXSIZE*2) + +/* The face size (in the dialogs) */ +#define F_WIDTH (32*PXSIZE) +#define F_HEIGHT (32*PXSIZE) + +/* the color of the text to go to the next dialog phase */ +/* it improves readability to have something lighter */ +#if GRAYMODEOK || (GINT_RENDER_RGB && !defined(COLOR1BIT)) + #define NEXT_COLOR C_DARK +#else + #define NEXT_COLOR C_BLACK +#endif + #endif diff --git a/src/dialogs.c b/src/dialogs.c index 4757303..23a7890 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -25,20 +25,11 @@ extern font_t fontRPG; uint32_t *lightVRAMcurrent, *darkVRAMcurrent; #endif //GRAYMODEOK -/* the color of the text to go to the next dialog phase */ -/* it improves readability to have somathing lighter */ -#if GRAYMODEOK || (defined(FXCG50) && !defined(COLOR1BIT)) - #define NEXT_COLOR C_DARK -#else - #define NEXT_COLOR C_BLACK -#endif - -void blit() -{ +void blit() { dupdate(); - #if GRAYMODEOK + #if GRAYMODEOK && !GINT_HW_CG dgray_getvram( &lightVRAMnext, &darkVRAMnext ); dgray_getscreen( &lightVRAMcurrent, &darkVRAMcurrent ); @@ -48,13 +39,14 @@ void blit() } -int showtext_opt(Game *game, bopti_image_t *face, char *text, - int call_before_end(Game *game, unsigned int i), - bool start_anim, - bool end_anim, - void for_each_screen(Game *game, unsigned int i), - int line_duration, bool update_screen, unsigned int start_i, - bool wait_continue) { +int dialogs_text_opt(Game *game, bopti_image_t *face, char *text, + int call_before_end(Game *game, unsigned int i), + bool start_anim, + bool end_anim, + void for_each_screen(Game *game, unsigned int i), + int line_duration, bool update_screen, unsigned int start_i, + bool wait_continue) { + text = events_parse_string(&game->handler, text); dfont(&FONT_USED); unsigned int i, n, y = PXSIZE, l = 0; int line_max_chars, return_int = 0; @@ -67,7 +59,7 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, /* Redrawing the entire screen, because maybe there was no dialog displayed before. */ update_npc(game); - draw(game); + game_draw(game); /* Fill the dialog box with white */ drect(0, 0, DWIDTH, i*PXSIZE, C_WHITE); @@ -87,7 +79,7 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, }else{ /* Here I'm drawing the same as if start_anim is true, but whitout * making an animation. */ - draw(game); + game_draw(game); drect(0, 0, DWIDTH, BOX_HEIGHT*PXSIZE, C_WHITE); drect(0, BOX_HEIGHT*PXSIZE, DWIDTH, (BOX_HEIGHT+1)*PXSIZE, C_BLACK); dimage(4*PXSIZE, 2*PXSIZE, face); @@ -148,7 +140,12 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, if(l>=max_lines_amount-1){ /* If we drew one entire screen. */ /* Wait that the SHIFT key is pressed if we should. */ - if(wait_continue) while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & ~GETKEY_MOD_ALPHA, NULL).key != KEY_SHIFT) sleep(); + if(wait_continue){ + while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & + ~GETKEY_MOD_ALPHA, NULL).key != KEY_SHIFT){ + sleep(); + } + } /* Clear the text area. */ drect(BOX_HEIGHT*PXSIZE, 0, DWIDTH, (BOX_HEIGHT-1)*PXSIZE-2, C_WHITE); @@ -172,7 +169,12 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, dtext(BOX_HEIGHT*PXSIZE, y, NEXT_COLOR, "[SHIFT] : suite..."); /* Update the screen and wait for SHIFT being pressed, if needed. */ if(update_screen) blit(); - if(wait_continue) while(getkey_opt( GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & ~GETKEY_MOD_ALPHA, NULL).key != KEY_SHIFT) sleep(); + if(wait_continue){ + while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & + ~GETKEY_MOD_ALPHA, NULL).key != KEY_SHIFT){ + sleep(); + } + } } if(call_before_end) return_int = call_before_end(game, i); if(end_anim){ @@ -180,11 +182,11 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, for(i=BOX_HEIGHT;i>0;i--){ /* It is the same as the start animation. */ update_npc(game); - draw(game); + game_draw(game); drect(0, 0, DWIDTH, i*PXSIZE, C_WHITE); drect(0, i*PXSIZE, DWIDTH, (i+1)*PXSIZE, C_BLACK); dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, (i-8)*PXSIZE, - DIMAGE_NONE); + DIMAGE_NONE); dupdate(); @@ -195,12 +197,12 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, return return_int; } -void showtext_dialog(Game *game, bopti_image_t *face, char *text, - bool dialog_start, bool dialog_end) { +void dialogs_text(Game *game, bopti_image_t *face, char *text, + bool dialog_start, bool dialog_end) { /* Run showtext_opt with some default values. It makes it easier to use in * simple dialogs. */ - showtext_opt(game, face, text, NULL, dialog_start, dialog_end, NULL, 100, - true, 0, true); + dialogs_text_opt(game, face, text, NULL, dialog_start, dialog_end, NULL, 100, + true, 0, true); } @@ -301,9 +303,9 @@ int _choice_call_before_end(Game *game, [[maybe_unused]] unsigned int org_i) { for(i=DWIDTH/8+1;i>0;i--){ /* I'm drawing the same box as on the start animation */ update_npc(game); - draw(game); - showtext_opt(game, _face, _text, NULL, false, false, NULL, 0, false, - _i, false); + game_draw(game); + dialogs_text_opt(game, _face, _text, NULL, false, false, NULL, 0, false, + _i, false); drect(0, (BOX_HEIGHT+1)*PXSIZE+1, i*(DWIDTH/8), (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE); drect(i*(DWIDTH/8), BOX_HEIGHT*PXSIZE, i*(DWIDTH/8)+PXSIZE-1, @@ -319,9 +321,9 @@ int _choice_call_before_end(Game *game, [[maybe_unused]] unsigned int org_i) { return selected; } -int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start, - bool end, char *choices, int choices_amount, - int default_choice) { +int dialogs_ask(Game *game, bopti_image_t *face, char *text, bool start, + bool end, char *choices, int choices_amount, + int default_choice) { /* Put some arguments in global pointers and variables to make them * accessible by _choice_call_before_end. */ _choices = choices; @@ -331,16 +333,16 @@ int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start, _text = text; /* Run showtext_opt and return his return value (the return value of *_choice_call_before_end) */ - return showtext_opt(game, face, text, _choice_call_before_end, start, end, - _choice_screen_call, 100, true, 0, true); + return dialogs_text_opt(game, face, text, _choice_call_before_end, start, + end, _choice_screen_call, 100, true, 0, true); } -void initiate_dialog_sequence(Game *game, bopti_image_t *face, uint32_t dialogNumber ) -{ - Dialog *currentDiag = &game->map_level->dialogs[ dialogNumber ]; +void dialogs_initiate_sequence(Game *game, bopti_image_t *face, + uint32_t dialogNumber) { + Dialog *currentDiag = &game->map_level->dialogs[dialogNumber]; /* we collect the information */ char *text = currentDiag->dialog; @@ -354,27 +356,23 @@ void initiate_dialog_sequence(Game *game, bopti_image_t *face, uint32_t dialogNu int isQuestion = currentDiag->isQuestion; /* we treat the action - i.e. we show a dialog */ - if (isQuestion == 1) /* we have to manage a question */ - { - int answer = showtext_dialog_ask( game, face, text, true, true, choices, 2, 0 ); + if (isQuestion == 1){ + /* we have to manage a question */ + int answer = dialogs_ask(game, face, text, true, true, + choices, 2, 0); /* TO DO we need to split the strings conclusion1 and conclusion2 */ /* to extract the "gift" part */ - if (answer==0) - { - showtext_dialog( game, face, conclusion1, true, true ); - if (next1!=-1) initiate_dialog_sequence( game, face, next1 ); + if(answer==0){ + dialogs_text(game, face, conclusion1, true, true); + if (next1!=-1) dialogs_initiate_sequence(game, face, next1); + }else{ + dialogs_text(game, face, conclusion2, true, true); + if (next2!=-1) dialogs_initiate_sequence(game, face, next2); } - else - { - showtext_dialog( game, face, conclusion2, true, true ); - if (next2!=-1) initiate_dialog_sequence( game, face, next2 ); - } - } - else - { - showtext_dialog( game, face, text, true, true ); - if (nextOther!=-1) initiate_dialog_sequence( game, face, nextOther ); + }else{ + dialogs_text(game, face, text, true, true); + if (nextOther!=-1) dialogs_initiate_sequence(game, face, nextOther); } } \ No newline at end of file diff --git a/src/dialogs.h b/src/dialogs.h index 39729b7..d019d65 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -5,11 +5,9 @@ #include #include "game.h" #include "map.h" +#include "config.h" -#define F_WIDTH (32*PXSIZE) -#define F_HEIGHT (32*PXSIZE) - -/* showtext_opt() +/* dialogs_text_opt() * * Show some text in a box with word wrap for dialogs. * @@ -37,17 +35,17 @@ * wait_continue: If I should wait that EXE is pressed after drawing a page. */ -int showtext_opt(Game *game, bopti_image_t *face, char *text, - int call_before_end(Game *game, unsigned int i), - bool start_anim, - bool end_anim, - void for_each_screen(Game *game, unsigned int i), - int line_duration, bool update_screen, unsigned int start_i, - bool wait_continue); +int dialogs_text_opt(Game *game, bopti_image_t *face, char *text, + int call_before_end(Game *game, unsigned int i), + bool start_anim, + bool end_anim, + void for_each_screen(Game *game, unsigned int i), + int line_duration, bool update_screen, + unsigned int start_i, bool wait_continue); -/* showtext_dialog() +/* dialogs_text() * - * Calls showtext_opt with default parameters. + * Calls dialogs_text_opt with default parameters. * * game: The game struct of the current game. * face: A bopti_image_t of the face of the person who's saying this @@ -60,12 +58,12 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, * shown at the end of showtext_opt. */ -void showtext_dialog(Game *game, bopti_image_t *face, char *text, - bool dialog_start, bool dialog_end); +void dialogs_text(Game *game, bopti_image_t *face, char *text, + bool dialog_start, bool dialog_end); -/* showtext_dialog_ask() +/* dialogs_ask() * - * Like showtext_dialog, but lets the user choose between multiple possible + * Like dialogs_text, but lets the user choose between multiple possible * choices after displaying the text. * * game: The game struct of the current game. @@ -85,10 +83,12 @@ void showtext_dialog(Game *game, bopti_image_t *face, char *text, * default_choice: The choice choosen by default when the dialog just opened. */ -int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start, - bool end, char *choices, int choices_amount, - int default_choice); +int dialogs_ask(Game *game, bopti_image_t *face, char *text, bool start, + bool end, char *choices, int choices_amount, + int default_choice); -void initiate_dialog_sequence(Game *game, bopti_image_t *face, uint32_t dialogNumber ); +/* TODO: Doc. */ +void dialogs_initiate_sequence(Game *game, bopti_image_t *face, + uint32_t dialogNumber); #endif diff --git a/src/events.h b/src/events.h new file mode 100644 index 0000000..0cd503d --- /dev/null +++ b/src/events.h @@ -0,0 +1,64 @@ +#ifndef EVENTS_H +#define EVENTS_H + +/* The max amount of variables that can be bound. */ +#define MAX_VARIABLES 32 +/* The max. size of the message buffer. + * WARNING: Bigger messages will be truncated! */ +#define MESSAGE_BUFFER_SZ 1024 +/* The maximal size of a token. Bigger tokens will be truncated. */ +#define TOKEN_MAX_SZ 1024 + +typedef struct { + int *variables[MAX_VARIABLES]; + char *var_names[MAX_VARIABLES]; + unsigned int vars; +} EventHandler; + +typedef enum { + T_NULL, + T_VAR_EDIT, + T_AMOUNT +} Token; + +typedef enum { + OP_NULL, + OP_SET, + OP_ADD, + OP_SUB, + OP_DIV, + OP_MUL, + OP_MOD, + OP_AMOUNT +} Operation; + +/* events_init_handler() + * + * Initialize an event handler. + * handler: The Event handler to initialize. + */ +void events_init_handler(EventHandler *handler); +/* events_bind_variable() + * + * Bind a variable. Binding a variable allows it to be modified by messages + * passed to the event handler using tags written as following: + * `variable+number` (The backticks delimit the tag). Available operators: + * '=': Assign a value to the variable. + * '+': Addition. + * '-': Substraction. + * '*': Multiplication. + * '/': Division. + * '%': Modulo. + * handler: The event handler. + * var: A pointer to the variable to bind. + * name: The name of the variable. This is the name that will be used to + * refer to this variable in a tag. + */ +int events_bind_variable(EventHandler *handler, int *var, char *name); +/* events_parse_string() + * handler: The event handler. + * message: The message to parse. + */ +char *events_parse_string(EventHandler *handler, char *message); + +#endif diff --git a/src/game.c b/src/game.c index 899dbc4..32b4104 100644 --- a/src/game.c +++ b/src/game.c @@ -27,18 +27,16 @@ void game_logic(Game *game) { update_npc( game ); /* we check if interactions are possible close to the player */ - for( uint32_t i=0; imap_level->nbextradata; i++ ) - { + for( uint32_t i=0; imap_level->nbextradata; i++ ){ /* simple distance check along X and Y axis */ /* Be careful to use world coordinates, not local (i.e.map) ones */ - if ( (abs((int) game->player.wx - + if ((abs((int) game->player.wx - (int) game->map_level->extradata[i].x*PXSIZE ) < MAX_INTERACTION_DISTANCE*PXSIZE) && (abs((int) game->player.wy - (int) game->map_level->extradata[i].y*PXSIZE ) < MAX_INTERACTION_DISTANCE*PXSIZE) - && strcmp( game->map_level->extradata[i].type, "NPC") !=0 ) - { + && strcmp(game->map_level->extradata[i].type, "NPC") != 0){ /* the player can do something */ game->player.canDoSomething = true; /* we mark the action for futur treatment in player_action() */ @@ -49,18 +47,16 @@ void game_logic(Game *game) { } } - for( uint32_t i=0; iplayer.wx - + if ((abs((int) game->player.wx - (int) npcRPG[i].curx*PXSIZE ) < MAX_INTERACTION_DISTANCE*PXSIZE) && (abs((int) game->player.wy - (int) npcRPG[i].cury*PXSIZE ) < MAX_INTERACTION_DISTANCE*PXSIZE) - && strcmp( game->map_level->extradata[i].type, "NPC") !=0 ) - { + && strcmp( game->map_level->extradata[i].type, "NPC") !=0){ /* the player can do something */ game->player.canDoSomething = true; /* we mark the action for futur treatment in player_action() */ @@ -80,33 +76,31 @@ void game_logic(Game *game) { } -void render_indicator(Game *game) -{ +void game_render_indicator(Game *game) { /* nothing to do for the player so we quit */ - if (game->player.canDoSomething==false) - return; + if(game->player.canDoSomething==false) return; /* else we draw a small indicator on the screen */ dimage(5, 5, &SignAction_img); } -void draw(Game *game) { +void game_draw(Game *game) { /* Draw everything. */ - render_map_by_layer(game, BACKGROUND); - npc_draw( game ); + dclear(C_WHITE); + map_render_by_layer(game, BACKGROUND); + npc_draw(game); player_draw(game); - render_map_by_layer(game, FOREGROUND); - render_indicator( game ); + map_render_by_layer(game, FOREGROUND); + game_render_indicator(game); + dprint(8, 8, C_BLACK, "Lifes: %d", game->player.life); + dprint(8, 16, C_BLACK, "Mana: %d", game->mana); } /* Key management */ -void get_inputs(Game *game) { - key_event_t ev; - while((ev = pollevent()).type != KEYEV_NONE){ - /**/ - } +void game_get_inputs(Game *game) { + clearevents(); /* Key binding for the Player action */ @@ -143,4 +137,3 @@ void get_inputs(Game *game) { #endif //USB_FEATURE } - diff --git a/src/game.h b/src/game.h index 8d24797..8b0eb3a 100644 --- a/src/game.h +++ b/src/game.h @@ -70,6 +70,7 @@ typedef struct { char *name; /* its class (NPC, SGN, INFO, ... )*/ char *type; + char *face; /* the ID of the first element of the dialog */ /* (to be aligned with "dialogs.json" IDs)*/ @@ -150,15 +151,27 @@ typedef struct { /* (Mibi88) TODO: Describe what this function is doing. */ void game_logic(Game *game); -/* Draws everything on screen. */ -void draw(Game *game); +/* game_draw() + * + * Draws everything on screen. + * game: The game struct. + */ +void game_draw(Game *game); -/* This render a small sign on the upper lecft corner of the screen */ -/* if the player can do an action */ -void render_indicator(Game *game); +/* game_render_indicator() + * + * This render a small sign on the upper left corner of the screen + * if the player can do an action + * game: The game struct. + */ +void game_render_indicator(Game *game); -/* Handle key presses. */ -void get_inputs(Game *game); +/* game_get_inputs() + * + * Handle key presses. + * game: The game struct. + */ +void game_get_inputs(Game *game); #endif diff --git a/src/main.c b/src/main.c index 0375212..27e5656 100644 --- a/src/main.c +++ b/src/main.c @@ -42,7 +42,7 @@ Game game = { , false, false, false }; -/* screen capture management code */ +/* screen capture management code. TODO: Clean this up! */ #if USB_FEATURE @@ -128,9 +128,9 @@ int main(void) { dclear(C_WHITE); /* render the map */ - draw(&game); + game_draw(&game); - #if DEBUGMODE && FXCG50 + #if DEBUGMODE && GINT_RENDER_RGB if (game.debug_map) { dfont( NULL ); @@ -181,7 +181,7 @@ int main(void) { #endif /* Management of the inputs */ - get_inputs(&game); + game_get_inputs(&game); /* Run the game at max. 50fps */ while(game.frame_duration < 20) sleep(); /* Reset frame_duration for the next frame */ diff --git a/src/map.c b/src/map.c index d378263..bb6efad 100644 --- a/src/map.c +++ b/src/map.c @@ -8,7 +8,7 @@ extern Map *worldRPG[]; //extern ExtraData *extraRPG[]; -void render_map(Game *game) { +void map_render(Game *game) { Map *map_level = game->map_level; Player *player = &game->player; @@ -104,7 +104,7 @@ void render_map(Game *game) { } } -void render_map_by_layer(Game *game, int layer) { +void map_render_by_layer(Game *game, int layer) { Map *map_level = game->map_level; Player *player = &game->player; @@ -194,7 +194,7 @@ void render_map_by_layer(Game *game, int layer) { } } -short int get_tile(Game *game, int x, int y, int l) { +short int map_get_tile(Game *game, int x, int y, int l) { Map *map_level = game->map_level; @@ -204,7 +204,7 @@ short int get_tile(Game *game, int x, int y, int l) { map_level->layers[l][y * map_level->w + x] : MAP_OUTSIDE; } -short int get_walkable(Game *game, int x, int y) { +short int map_get_walkable(Game *game, int x, int y) { Map *map_level = game->map_level; /* Get the tile at (x, y). Returns the tile ID or MAP_OUTSIDE if she's not @@ -214,26 +214,25 @@ 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 ) +Map *map_get_for_coordinates( Game *game, int x, int y ) { /* check if the current map contains the point */ if (x>= (int)game->map_level->xmin && x< (int)game->map_level->xmax && - y>= (int)game->map_level->ymin && y< (int)game->map_level->ymax) + y>= (int)game->map_level->ymin && y< (int)game->map_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 - { + do{ if (x>= (int)current->xmin && x< (int)current->xmax && y>= (int)current->ymin && y< (int)current->ymax) return current; i++; current = worldRPG[i]; - } - while (current!=NULL); + }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 1586186..184948d 100644 --- a/src/map.h +++ b/src/map.h @@ -19,21 +19,48 @@ -/* Draws the map map on the entire screen to be viewed by the player player. */ -void render_map(Game *game); - -/* Draws the map layer on the entire screen to be viewed by the player player. +/* map_render() + * + * Draws the map map on the entire screen to be viewed by the player player. + * game: The game struct. */ -void render_map_by_layer(Game *game, int layer); +void map_render(Game *game); -/* Get the tile at (x, y) of the map map. If the tile is located outside of the - * screen, MAP_OUTSIDE is returned. */ -short int get_tile(Game *game, int x, int y, int l); +/* map_render_by_layer() + * + * Draws the map layer on the entire screen to be viewed by the player player. + * game: The game struct. + * layer: The layer to render. + */ +void map_render_by_layer(Game *game, int layer); -/* Returns what is in the walkable layer at (x, y). */ -short int get_walkable(Game *game, int x, int y); +/* map_get_tile() + * + * Get the tile at (x, y) of the map map. If the tile is located outside of the + * screen, MAP_OUTSIDE is returned. + * game: The game struct. + * x: The coordinates of the tile. + * y: The coordinates of the tile. + * l: The layer of the tile. + */ +short int map_get_tile(Game *game, int x, int y, int l); -/* return the pointer to the map containing the given position */ -Map* get_map_for_coordinates(Game *game, int x, int y ); +/* map_get_walkable() + * + * Returns what is in the walkable layer at (x, y). + * game: The game struct. + * x: The coordinates of the tile. + * y: The coordinates of the tile. + */ +short int map_get_walkable(Game *game, int x, int y); + +/* map_get_for_coordinates() + * + * return the pointer to the map containing the given position. + * game: The game struct. + * x: The coordinates to look at. + * y: The coordinates to look at. + */ +Map* map_get_for_coordinates(Game *game, int x, int y ); #endif diff --git a/src/memory.c b/src/memory.c index 9e3e58a..9bfcb47 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,6 +1,6 @@ #include "memory.h" -bool is_in(short int *array, short int array_length, short int item) { +bool memory_is_in(short int *array, short int array_length, short int item) { short int i; for(i=0;i - -bool is_in(short int *array, short int array_length, short int item); +/* memory_is_in() + * + * returns true if item is in array. + * array: The array to search in. + * array_length: The length of the array. + * item: The item to search for. + */ +bool memory_is_in(short int *array, short int array_length, short int item); #endif diff --git a/src/npc.c b/src/npc.c index 86a62b7..3f87086 100644 --- a/src/npc.c +++ b/src/npc.c @@ -14,15 +14,6 @@ extern bopti_image_t demo_PNJ_img; -/* the color of the text to go to the next dialog phase */ -/* it improves readability to have somathing lighter */ -#if defined(FXCG50) - #define PATH_COLOR C_RED -#else - #define PATH_COLOR C_BLACK -#endif - - NPC *npcRPG; uint32_t nbNPC = 0; @@ -106,6 +97,7 @@ void reload_npc(Game *game) npcRPG[currentNPC].xpath = Data->xpath; npcRPG[currentNPC].ypath = Data->ypath; npcRPG[currentNPC].paused = false; + npcRPG[currentNPC].face = Data->face; currentNPC++; } } diff --git a/src/npc.h b/src/npc.h index e7e1e12..a7dd906 100644 --- a/src/npc.h +++ b/src/npc.h @@ -31,6 +31,8 @@ typedef struct /* is the current NPC in pause (during dialog) */ bool paused; + + char *face; } NPC; diff --git a/src/player.c b/src/player.c index 2274b11..58d8e37 100644 --- a/src/player.c +++ b/src/player.c @@ -6,6 +6,28 @@ #include "npc.h" #include +#define FACES 4 + +struct Face { + const char *name; + bopti_image_t *face; +}; + +extern bopti_image_t demo_player_img; +extern bopti_image_t npc_male; +extern bopti_image_t npc_female; +extern bopti_image_t npc_milkman; +extern bopti_image_t npc_police; +extern bopti_image_t SGN_Icon_img; +extern bopti_image_t INFO_Icon_img; + +const struct Face faces[FACES] = { + {"MALE", &npc_male}, + {"FEMALE", &npc_female}, + {"MILKMAN", &npc_milkman}, + {"POLICE", &npc_police} +}; + const char one_px_mov[8] = { 0, -1, /* Up */ 0, 1, /* Down */ @@ -83,18 +105,13 @@ void player_move(Game *game, Direction direction) { player->wy = game->map_level->ymin * PXSIZE + player->y; } - -extern bopti_image_t demo_player_img; -extern bopti_image_t NPC_Icon_img; -extern bopti_image_t SGN_Icon_img; -extern bopti_image_t INFO_Icon_img; - - void player_action(Game *game) { - if( game->player.isDoingAction ) return; /* alreday doing something (action IS NOT with an NPC ) */ + register size_t i; + /* already doing something (action IS NOT with an NPC) */ + if(game->player.isDoingAction) return; - if( game->player.canDoSomething && !game->player.isInteractingWithNPC ) /* we can do something */ - { + if(game->player.canDoSomething && !game->player.isInteractingWithNPC){ + /* we can do something */ /* we indicate that the player is occupied */ game->player.isDoingAction = true; @@ -106,23 +123,33 @@ void player_action(Game *game) { /* we use the correct image as per the class of the item */ - if (strcmp("INFO", currentData->type)==0) + if (strcmp("INFO", currentData->type)==0){ face = &INFO_Icon_img; - //else if (strcmp("NPC", currentData->type)==0) - // face = &NPC_Icon_img; - else if (strcmp("SGN", currentData->type)==0) + }else if (strcmp("SGN", currentData->type)==0){ face = &SGN_Icon_img; - else face = &demo_player_img; + }else{ + /* It's a NPC */ + /* (Mibi88) TODO: Use string hash + strcmp if the hashes match for + * fast string comparison. */ + face = NULL; + for(i=0;iface)){ + face = current_face.face; + } + } + if(!face) face = &npc_male; + + } uint32_t dialogStart = currentData->dialogID; - initiate_dialog_sequence( game, face, dialogStart ); + dialogs_initiate_sequence(game, face, dialogStart); /* when done we release the occupied status of the player */ game->player.isDoingAction = false; - } - else if( game->player.canDoSomething && game->player.isInteractingWithNPC ) /* we can do something (action IS with an NPC ) */ - { + }else if(game->player.canDoSomething && game->player.isInteractingWithNPC){ + /* we can do something (action IS with an NPC) */ /* we indicate that the player is occupied */ game->player.isDoingAction = true; @@ -130,14 +157,28 @@ void player_action(Game *game) { /* we use the correct image as per the class of the item */ - bopti_image_t *face = &NPC_Icon_img; + ExtraData *currentData = &game->map_level->extradata[game->player.whichAction]; + bopti_image_t *face = &npc_male; + /* It's a NPC */ + /* (Mibi88) TODO: Use string hash + strcmp if the hashes match for + * fast string comparison. */ + face = NULL; + for(i=0;iface)){ + face = current_face.face; + } + if(!face) face = &npc_male; + } + dtext(2, 64, C_BLACK, currentData->type); uint32_t dialogStart = currentNPC->dialogID; - /* we setr this NPC to paused to avoid changing its position while talking (the rest of the NPCs pursue their action)*/ + /* we set this NPC to paused to avoid changing its position while + * talking (the rest of the NPCs pursue their action) */ currentNPC->paused = true; - initiate_dialog_sequence( game, face, dialogStart ); + dialogs_initiate_sequence(game, face, dialogStart); /* when done we release the occupied status of the player */ game->player.isDoingAction = false; @@ -174,15 +215,13 @@ bool player_collision(Game *game, Direction direction, /* check where the player is expected to go on the next move */ /* if outside the map, we check if there is a map on the other */ /* side of the current map*/ - if (get_walkable(game, player_tile_x, player_tile_y) == MAP_OUTSIDE) - { + if (map_get_walkable(game, player_tile_x, player_tile_y) == MAP_OUTSIDE){ // we compute the expected world coordinates accordingly // while taking care of the scaling between fx and cg models (PXSIZE) int worldX = (player->wx+dx) / PXSIZE; int worldY = (player->wy+dy) / PXSIZE; - Map *map = get_map_for_coordinates(game, worldX, worldY ); - if (map!=NULL && map!=game->map_level) - { + Map *map = map_get_for_coordinates(game, worldX, worldY); + if (map!=NULL && map!=game->map_level){ Map *backupmap = game->map_level; int backupx = player->x; int backupy = player->y; @@ -197,7 +236,7 @@ bool player_collision(Game *game, Direction direction, player->x = (worldX - map->xmin ) * PXSIZE; player->y = (worldY - map->ymin ) * PXSIZE; - int on_walkable = get_walkable(game, player->x/T_WIDTH, + int on_walkable = map_get_walkable(game, player->x/T_WIDTH, player->y/T_HEIGHT); int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX) ? @@ -217,7 +256,7 @@ bool player_collision(Game *game, Direction direction, /* we update the list of NPCs in the current map */ /* to follow the trajectories */ - reload_npc( game ); + reload_npc(game); return false; } @@ -231,7 +270,7 @@ bool player_collision(Game *game, Direction direction, 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 on_walkable = map_get_walkable(game, player_tile_x, player_tile_y); int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX) ? walkable_speed[on_walkable] : 0; diff --git a/src/player.h b/src/player.h index 7b69716..a36d988 100644 --- a/src/player.h +++ b/src/player.h @@ -1,21 +1,8 @@ #ifndef PLAYER_H #define PLAYER_H -/* The size of the player. */ -#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 may cause bugs when handling - * collisions! */ -#define SPEED PXSIZE*2 - #include - +#include "config.h" #include "game.h" #include "memory.h" @@ -25,27 +12,53 @@ /* only methods propotypes are now in dedicated header files */ -/* Draws the player player. This function should be called after drawing the - * map! */ +/* player_draw() + * + * Draws the player. This function should be called after drawing the + * map! + * game: The game struct which contains the player struct used. + */ void player_draw(Game *game); -/* Move the player player in the direction direction. */ +/* player_move() + * + * Move the player in a direction. + * game: The game struct. + * direction: The direction to move the player in. + */ void player_move(Game *game, Direction direction); /* (Mibi88) TODO: Describe this function please, I've no idea what she's for! */ void player_action(Game *game); -/* Check if the player is in collision with the map or a NPC. Checkpos is used - * to check the axis where the player is not moving. */ +/* player_collision() + * + * Check if the player is in collision with the map or a NPC. Checkpos is used + * to check the axis where the player is not moving. + * game: The game struct. + * direction: The direction the player is moving in. + * nomov_axis_check: The axis that isn't changed by this movement. + */ bool player_collision(Game *game, Direction direction, Checkpos nomov_axis_check); -/* Fix the position of the player so that he's not a bit inside of a hard block - * after a collision. */ +/* player_fix_position() + * + * Fix the position of the player so that he's not a bit inside of a hard block + * after a collision. + * game: The game struct. + * fix_x: If we should fix the position on the X axis. + * fix_y: If we should fix the position on the Y axis. + */ void player_fix_position(Game *game, bool fix_x, bool fix_y); -/* Apply damage to player */ +/* player_damage() + * + * Apply damage to player + * game: The game struct. + * amount: The amount of damage to apply. + */ void player_damage(Game *game, int amount); #endif