commit 2829e7c6a7ba989662d8ce0a726bfb65d843404b Author: SlyVTT Date: Fri Apr 21 20:27:02 2023 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..baadade --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# Build files +/build-fx +/build-cg +/build-cg-push +/*.g1a +/*.g3a + +# Python bytecode +__pycache__/ + +# Common IDE files +*.sublime-project +*.sublime-workspace +.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..be22e43 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,83 @@ +# Configure with [fxsdk build-fx] or [fxsdk build-cg], which provide the +# toolchain file and module path of the fxSDK + +cmake_minimum_required(VERSION 3.15) +project(Npp VERSION 1.0 LANGUAGES CXX C ASM) + +include(GenerateG3A) +include(Fxconv) + +find_package(Azur 0.1 REQUIRED) +find_package(Gint 2.9 REQUIRED) +find_package(LibProf 2.4 REQUIRED) + + +fxconv_declare_converters(assets-cg/converters.py) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_LIST_DIR}/assets-cg/levels/level1.json" + COMMENT "Convert Tiled TMX map to usable JSON file" + COMMAND tiled --export-tileset json tilesetnpp.tsx tilesetnpp.json + COMMAND find | grep .*.tmx | sed 's/.tmx//g' | xargs -l bash -c 'tiled --export-map json $$0.tmx $$0.json' + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets-cg/levels/ + DEPENDS assets-cg/levels/level1.tmx + + OUTPUT "${CMAKE_CURRENT_LIST_DIR}/assets-cg/levels/level2.json" + COMMENT "Convert Tiled TMX map to usable JSON file" + COMMAND tiled --export-tileset json tilesetnpp.tsx tilesetnpp.json + COMMAND find | grep .*.tmx | sed 's/.tmx//g' | xargs -l bash -c 'tiled --export-map json $$0.tmx $$0.json' + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets-cg/levels/ + DEPENDS assets-cg/levels/level2.tmx + + OUTPUT "${CMAKE_CURRENT_LIST_DIR}/assets-cg/levels/level3.json" + COMMENT "Convert Tiled TMX map to usable JSON file" + COMMAND tiled --export-tileset json tilesetnpp.tsx tilesetnpp.json + COMMAND find | grep .*.tmx | sed 's/.tmx//g' | xargs -l bash -c 'tiled --export-map json $$0.tmx $$0.json' + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets-cg/levels/ + DEPENDS assets-cg/levels/level3.tmx + + assets-cg/converters.py + assets-cg/levels/tileset.png + assets-cg/levels/tilesetnpp.tsx) + + + +set(SOURCES + src/main.cpp + src/extrakeyboard.cpp + src/utilities.cpp + src/player.cpp + src/background.cpp + # ... +) +# Shared assets, fx-9860G-only assets and fx-CG-50-only assets +set(ASSETS + # ... +) + +set(ASSETS_cg + assets-cg/font.png + + #assets-cg/sprites/walking.png + #assets-cg/sprites/running.png + #assets-cg/sprites/static.png + assets-cg/sprites/rectangle.png + + assets-cg/levels/tileset.png + assets-cg/levels/level1.json + assets-cg/levels/level2.json + assets-cg/levels/level3.json + # ... +) + +fxconv_declare_assets(${ASSETS} ${ASSETS_cg} WITH_METADATA) + +add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}}) +target_compile_options(myaddin PRIVATE -Wall -Wextra -O3 -std=c++20) +target_link_options(myaddin PRIVATE -Wl,-Map=Build_Addin.map -Wl,--print-memory-usage) +target_link_libraries(myaddin Azur::Azur -lnum LibProf::LibProf Gint::Gint -lstdc++) + +if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) + generate_g3a(TARGET myaddin OUTPUT "NppClone.g3a" + NAME "cgN++" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) +endif() diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/assets-cg/converters.py b/assets-cg/converters.py new file mode 100644 index 0000000..b1917af --- /dev/null +++ b/assets-cg/converters.py @@ -0,0 +1,56 @@ +from random import randint +import fxconv +import json +import pathlib +import csv + +def convert(input, output, params, target): + if params["custom-type"] == "map": + convert_map(input, output, params, target) + return 0 + else: + return 1 + +def convert_map(input, output, params, target): + data = json.load(open(input, "r")) + + #find the tileset in use. it's a relative path (like ../tileset.tsx) + nameTileset = data["tilesets"][0]["source"].replace(".tsx","") + 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 + nbRetour = nameTileset.count("..")+1 + #create the tileset absolute path + tilesetPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".json" + + tileset = open(tilesetPath, "r") + data_tileset = json.load(tileset) + tileset_size = data_tileset.get("columns") + tileset.close() + + + #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) + + structMap = fxconv.Structure() + + structMap += fxconv.u32(w) + fxconv.u32(h) + fxconv.u32(nbTilelayer) + structMap += fxconv.ref(f"img_{nameTilesetFree}") + structMap += fxconv.u32(tileset_size) + + #generate the array of tiles from the layer + for i in range(nbTilelayer): + layer_data = bytes() + layer = data["layers"][i] + for tile in layer["data"]: + layer_data += fxconv.u16(tile) + + structMap += fxconv.ptr(layer_data) + + #generate ! + fxconv.elf(structMap, output, "_" + params["name"], **target) + diff --git a/assets-cg/example.png b/assets-cg/example.png new file mode 100644 index 0000000..8826800 Binary files /dev/null and b/assets-cg/example.png differ diff --git a/assets-cg/font.png b/assets-cg/font.png new file mode 100644 index 0000000..3cf3776 Binary files /dev/null and b/assets-cg/font.png differ diff --git a/assets-cg/fxconv-metadata.txt b/assets-cg/fxconv-metadata.txt new file mode 100644 index 0000000..5e3f5a8 --- /dev/null +++ b/assets-cg/fxconv-metadata.txt @@ -0,0 +1,4 @@ +*.png: + type: bopti-image + name_regex: (.*)\.png img_\1 + profile: p8_rgb565a diff --git a/assets-cg/icon-cg.xcf b/assets-cg/icon-cg.xcf new file mode 100644 index 0000000..5b854f0 Binary files /dev/null and b/assets-cg/icon-cg.xcf differ diff --git a/assets-cg/icon-sel.png b/assets-cg/icon-sel.png new file mode 100644 index 0000000..55c44a6 Binary files /dev/null and b/assets-cg/icon-sel.png differ diff --git a/assets-cg/icon-uns.png b/assets-cg/icon-uns.png new file mode 100644 index 0000000..2706c9d Binary files /dev/null and b/assets-cg/icon-uns.png differ diff --git a/assets-cg/levels/fxconv-metadata.txt b/assets-cg/levels/fxconv-metadata.txt new file mode 100644 index 0000000..1682884 --- /dev/null +++ b/assets-cg/levels/fxconv-metadata.txt @@ -0,0 +1,8 @@ +*.json: + custom-type: map + name_regex: (.*)\.json map_\1 + +tileset.png: + type: bopti-image + name: img_tilesetnpp + profile: p8_rgb565a diff --git a/assets-cg/levels/level1.json b/assets-cg/levels/level1.json new file mode 100644 index 0000000..a278493 --- /dev/null +++ b/assets-cg/levels/level1.json @@ -0,0 +1,44 @@ +{ "compressionlevel":-1, + "height":14, + "infinite":false, + "layers":[ + { + "data":[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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":14, + "id":2, + "name":"Foreground", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":25, + "x":0, + "y":0 + }], + "nextlayerid":3, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.8.0", + "tileheight":16, + "tilesets":[ + { + "firstgid":1, + "source":"tilesetnpp.tsx" + }], + "tilewidth":16, + "type":"map", + "version":"1.8", + "width":25 +} \ No newline at end of file diff --git a/assets-cg/levels/level1.tmx b/assets-cg/levels/level1.tmx new file mode 100644 index 0000000..2201472 --- /dev/null +++ b/assets-cg/levels/level1.tmx @@ -0,0 +1,40 @@ + + + + + +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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,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-cg/levels/level2.json b/assets-cg/levels/level2.json new file mode 100644 index 0000000..9985cc7 --- /dev/null +++ b/assets-cg/levels/level2.json @@ -0,0 +1,44 @@ +{ "compressionlevel":-1, + "height":14, + "infinite":false, + "layers":[ + { + "data":[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, 3, 0, 0, 0, 0, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 4, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 4, 2, 5, 6, 0, 7, 8, 2, 3, 0, 0, 0, 0, 0, 0, 4, 2, 2, 0, 0, 20, 2, 2, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 2, 19, 0, 0, 2, 2, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 2, 2, 0, 0, 0, 23, 24, 2, 21, 22, 0, 0, 0, 2, 2, 2, 2, 0, 0, 2, 2, 1, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 3, 1, 4, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 2, 2, 19, 0, 20, 2, 1, 0, 1, 2, 19, 0, 20, 2, 2, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 2, 2, 0, 0, 4, 2, 2, 2, 2, 2, 5, 6, 1, 2, 1, 7, 8, 2, 2, 2, 2, 2, 3, 0, 0, 2, 2, 19, 0, 0, 33, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 20, 2, 2, 2, 19, 0, 33, 0, 0, 1, 0, 0, 23, 24, 2, 21, 22, 1, 0, 0, 0, 0, 33, 0, 20, 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], + "height":14, + "id":1, + "name":"Background", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":25, + "x":0, + "y":0 + }, + { + "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 35, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 51, 0, 0, 0, 11, 0, 0, 0, 51, 0, 0, 0, 0, 0, 66, 0, 0, 0, 35, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":14, + "id":2, + "name":"Foreground", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":25, + "x":0, + "y":0 + }], + "nextlayerid":4, + "nextobjectid":3, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.8.0", + "tileheight":16, + "tilesets":[ + { + "firstgid":1, + "source":"tilesetnpp.tsx" + }], + "tilewidth":16, + "type":"map", + "version":"1.8", + "width":25 +} \ No newline at end of file diff --git a/assets-cg/levels/level2.tmx b/assets-cg/levels/level2.tmx new file mode 100644 index 0000000..7dda437 --- /dev/null +++ b/assets-cg/levels/level2.tmx @@ -0,0 +1,40 @@ + + + + + +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,3,0,0,0,0,4,2,2,2,2,2,2,2,2,2,3,0,0,0,0,4,2,2, +2,3,0,0,0,0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,0,0,51,0,0,0,11,0,0,0,51,0,0,0,0,0,66,0,0, +0,35,66,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,66,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,65,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,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-cg/levels/level3.json b/assets-cg/levels/level3.json new file mode 100644 index 0000000..a67d7d3 --- /dev/null +++ b/assets-cg/levels/level3.json @@ -0,0 +1,44 @@ +{ "compressionlevel":-1, + "height":14, + "infinite":false, + "layers":[ + { + "data":[1, 1, 1, 1, 23, 24, 2, 2, 21, 22, 1, 1, 1, 1, 1, 23, 24, 2, 2, 21, 22, 1, 1, 1, 1, 1, 1, 1, 20, 5, 6, 0, 34, 7, 8, 21, 22, 1, 23, 24, 5, 6, 34, 0, 7, 8, 19, 1, 1, 1, 1, 1, 20, 3, 0, 0, 0, 34, 0, 0, 4, 2, 2, 2, 3, 0, 0, 34, 0, 0, 0, 4, 19, 1, 1, 1, 20, 3, 0, 0, 0, 0, 34, 0, 0, 0, 10, 2, 9, 0, 0, 0, 34, 0, 0, 0, 0, 4, 19, 1, 42, 9, 0, 0, 0, 0, 2, 2, 0, 0, 0, 26, 2, 25, 0, 0, 0, 2, 2, 1, 1, 1, 1, 10, 41, 58, 25, 0, 0, 23, 24, 2, 2, 41, 0, 0, 0, 2, 0, 0, 0, 42, 2, 2, 21, 22, 0, 0, 26, 57, 2, 0, 0, 20, 2, 2, 2, 2, 57, 0, 0, 0, 0, 0, 0, 0, 58, 2, 2, 2, 2, 19, 0, 0, 2, 2, 0, 0, 4, 2, 2, 2, 2, 2, 21, 22, 0, 0, 0, 23, 24, 2, 2, 2, 2, 2, 3, 0, 0, 2, 10, 41, 0, 0, 7, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 6, 0, 0, 42, 9, 26, 57, 0, 0, 0, 0, 4, 2, 5, 6, 0, 0, 0, 0, 0, 7, 8, 2, 3, 0, 0, 0, 0, 58, 25, 1, 4, 19, 0, 0, 0, 0, 33, 0, 0, 0, 20, 2, 19, 0, 0, 0, 33, 0, 0, 0, 0, 20, 3, 1, 1, 1, 4, 19, 0, 0, 0, 33, 0, 0, 20, 2, 2, 2, 19, 0, 0, 33, 0, 0, 0, 20, 3, 1, 1, 1, 1, 1, 4, 21, 22, 0, 33, 23, 24, 5, 6, 1, 7, 8, 21, 22, 33, 0, 23, 24, 3, 1, 1, 1, 1, 1, 1, 1, 7, 8, 2, 2, 5, 6, 1, 1, 1, 1, 1, 7, 8, 2, 2, 5, 6, 1, 1, 1, 1], + "height":14, + "id":1, + "name":"Background", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":25, + "x":0, + "y":0 + }, + { + "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 66, 0, 0, 0, 66, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 66, 0, 0, 0, 66, 0, 0, 0, 0, 0, 66, 49, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], + "height":14, + "id":2, + "name":"Foreground", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":25, + "x":0, + "y":0 + }], + "nextlayerid":3, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.8.0", + "tileheight":16, + "tilesets":[ + { + "firstgid":1, + "source":"tilesetnpp.tsx" + }], + "tilewidth":16, + "type":"map", + "version":"1.8", + "width":25 +} \ No newline at end of file diff --git a/assets-cg/levels/level3.tmx b/assets-cg/levels/level3.tmx new file mode 100644 index 0000000..3984d01 --- /dev/null +++ b/assets-cg/levels/level3.tmx @@ -0,0 +1,40 @@ + + + + + +1,1,1,1,23,24,2,2,21,22,1,1,1,1,1,23,24,2,2,21,22,1,1,1,1, +1,1,1,20,5,6,0,34,7,8,21,22,1,23,24,5,6,34,0,7,8,19,1,1,1, +1,1,20,3,0,0,0,34,0,0,4,2,2,2,3,0,0,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0,0,0,0,66,0,0,0, +0,0,0,0,66,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,66,0,0,0,0, +0,0,0,0,0,66,0,0,0,0,1,1,1,1,1,0,0,0,0,66,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0 + + + diff --git a/assets-cg/levels/tileset.png b/assets-cg/levels/tileset.png new file mode 100644 index 0000000..0afb664 Binary files /dev/null and b/assets-cg/levels/tileset.png differ diff --git a/assets-cg/levels/tilesetnpp.json b/assets-cg/levels/tilesetnpp.json new file mode 100644 index 0000000..73c3fdb --- /dev/null +++ b/assets-cg/levels/tilesetnpp.json @@ -0,0 +1,14 @@ +{ "columns":16, + "image":"tileset.png", + "imageheight":256, + "imagewidth":256, + "margin":0, + "name":"tileset", + "spacing":0, + "tilecount":256, + "tiledversion":"1.8.0", + "tileheight":16, + "tilewidth":16, + "type":"tileset", + "version":"1.8" +} \ No newline at end of file diff --git a/assets-cg/levels/tilesetnpp.tsx b/assets-cg/levels/tilesetnpp.tsx new file mode 100644 index 0000000..b99293a --- /dev/null +++ b/assets-cg/levels/tilesetnpp.tsx @@ -0,0 +1,4 @@ + + + + diff --git a/assets-cg/sprites/fxconv-metadata.txt b/assets-cg/sprites/fxconv-metadata.txt new file mode 100644 index 0000000..5e3f5a8 --- /dev/null +++ b/assets-cg/sprites/fxconv-metadata.txt @@ -0,0 +1,4 @@ +*.png: + type: bopti-image + name_regex: (.*)\.png img_\1 + profile: p8_rgb565a diff --git a/assets-cg/sprites/rectangle.png b/assets-cg/sprites/rectangle.png new file mode 100644 index 0000000..0bfe089 Binary files /dev/null and b/assets-cg/sprites/rectangle.png differ diff --git a/assets-cg/sprites/running.png b/assets-cg/sprites/running.png new file mode 100644 index 0000000..03aa2ee Binary files /dev/null and b/assets-cg/sprites/running.png differ diff --git a/assets-cg/sprites/static.png b/assets-cg/sprites/static.png new file mode 100644 index 0000000..8dca238 Binary files /dev/null and b/assets-cg/sprites/static.png differ diff --git a/assets-cg/sprites/walking.png b/assets-cg/sprites/walking.png new file mode 100644 index 0000000..fa5fb60 Binary files /dev/null and b/assets-cg/sprites/walking.png differ diff --git a/build b/build new file mode 100755 index 0000000..ce81a8e --- /dev/null +++ b/build @@ -0,0 +1,3 @@ +rm -r build-cg +rm *.g3a +fxsdk build-cg -B VERBOSE=1 diff --git a/capture b/capture new file mode 100755 index 0000000..0332a60 --- /dev/null +++ b/capture @@ -0,0 +1 @@ +fxlink -iw diff --git a/clean b/clean new file mode 100755 index 0000000..0c58279 --- /dev/null +++ b/clean @@ -0,0 +1,2 @@ +rm -r build-cg/ +rm *.g3a diff --git a/send b/send new file mode 100755 index 0000000..b01e9b6 --- /dev/null +++ b/send @@ -0,0 +1 @@ +fxlink -sw *.g3a -u diff --git a/src/background.cpp b/src/background.cpp new file mode 100644 index 0000000..c70e889 --- /dev/null +++ b/src/background.cpp @@ -0,0 +1,97 @@ +#include "background.h" +#include "player.h" +#include +#include + +#include +#include + + + +extern struct Map map_level1; +extern struct Map map_level2; +extern struct Map map_level3; + +extern bool drawbackground; + +struct Map *map_level; + + +Background::Background( ) +{ + map_level = &map_level2; +} + +Background::~Background( ) +{ + +} + +void Background::ChangeMap( int level, Player *MyPlayer ) +{ + if(level==1) map_level = &map_level1; + else if(level==2) map_level = &map_level2; + else if(level==3) map_level = &map_level3; + else map_level = &map_level1; + + UpdateDataMap( MyPlayer ); +} + +void Background::UpdateDataMap( Player *MyPlayer ) +{ + for(int i=0; iw; i++) + { + for(int j=0; j<=map_level->h; j++) + { + uint16_t index = (j) * map_level->w + (i) % map_level->w; + uint16_t currentTile = map_level->layers[1][ index ]; + if (currentTile==11) + { + MyPlayer->x = libnum::num( i*16 - 4 + 8 ); + MyPlayer->y = libnum::num( j*16 + 8 ); + MyPlayer->vx = 0; + MyPlayer->vy = 0; + MyPlayer->Update( 0.0f, 0.0f, 0.0f ); + } + } + } +} + +void Background::Render( void ) +{ + for(int u=!drawbackground; unblayers;u++) + { + for(int i=0; iw; i++) + { + for(int j=0; j<=map_level->h; j++) + { + uint16_t index = (j) * map_level->w + (i) % map_level->w; + uint16_t currentTile = map_level->layers[u][ index ]; + if (currentTile!=0 && currentTile!=11) + { + uint16_t xtile = ((currentTile % map_level->tileset_size)-1) * 16; + uint16_t ytile = (currentTile / map_level->tileset_size) * 16; + azrp_subimage_p8( i*16-4, j*16, map_level->tileset, xtile, ytile, 16, 16, DIMAGE_NONE ); + } + } + } + } +} + +void Background::Update( float dt ) +{ + +} + +bool Background::CanGo( Player *MyPlayer ) +{ + int tileX = ((int) MyPlayer->x+4) >> 4 ; + int tileY = ((int) MyPlayer->y+8) >> 4; + + int tileIndex = tileY*map_level->w + tileX; + + int tileValue = map_level->layers[0][ tileIndex ]; + + if (tileValue==0 || tileValue==1) return true; + else return false; +} \ No newline at end of file diff --git a/src/background.h b/src/background.h new file mode 100644 index 0000000..74eeff7 --- /dev/null +++ b/src/background.h @@ -0,0 +1,45 @@ +#ifndef BACKGROUND_H +#define BACKGROUND_H + + +#include +#include + +#include + +#include +#include "num/num.h" + +#include "player.h" + +struct Map { + /*width, height and the number of layer of the map*/ + int w, h, nblayers; + + /*the tileset to use*/ + bopti_image_t *tileset; + int tileset_size; + + /*list of all the tiles*/ + short *layers[]; +}; + + +class Background +{ + public: + Background( ); + ~Background( ); + + void Update( float dt ); + void Render( ); + + void ChangeMap( int level, Player *MyPlayer ); + void UpdateDataMap( Player *MyPlayer ); + + bool CanGo( Player *MyPlayer ); +}; + + + +#endif diff --git a/src/extrakeyboard.cpp b/src/extrakeyboard.cpp new file mode 100644 index 0000000..29492d4 --- /dev/null +++ b/src/extrakeyboard.cpp @@ -0,0 +1,160 @@ +#include "extrakeyboard.h" +#include +#include +#include + + +typedef struct +{ + bool pressed; + uint32_t since = 0; +} keyinfo; + + +keyinfo MyKeyMapper[MYKEY_LASTENUM+1]; + + +KeyboardExtra::KeyboardExtra() +{ + uint32_t timer = rtc_ticks(); + now = timer; + for(int i=0; i<=MYKEY_LASTENUM; i++) MyKeyMapper[i] = { .pressed = false, .since = timer }; +} + + +KeyboardExtra::~KeyboardExtra() +{ + +} + + +void KeyboardExtra::Update( float dt ) +{ + uint32_t timer = rtc_ticks(); + + now = timer; + + key_event_t ev; + + int keycode = -1; + + while((ev = pollevent()).type != KEYEV_NONE) + { + if (ev.key == KEY_F1) keycode = MYKEY_F1; + else if(ev.key == KEY_F2) keycode = MYKEY_F2; + else if(ev.key == KEY_F3) keycode = MYKEY_F3; + else if(ev.key == KEY_F4) keycode = MYKEY_F4; + else if(ev.key == KEY_F5) keycode = MYKEY_F5; + else if(ev.key == KEY_F6) keycode = MYKEY_F6; + + else if(ev.key == KEY_SHIFT) keycode = MYKEY_SHIFT; + else if(ev.key == KEY_OPTN) keycode = MYKEY_OPTN; + else if(ev.key == KEY_VARS) keycode = MYKEY_VARS; + else if(ev.key == KEY_MENU) keycode = MYKEY_MENU; + else if(ev.key == KEY_LEFT) keycode = MYKEY_LEFT; + else if(ev.key == KEY_UP) keycode = MYKEY_UP; + + else if(ev.key == KEY_ALPHA) keycode = MYKEY_ALPHA; + else if(ev.key == KEY_SQUARE) keycode = MYKEY_SQUARE; + else if(ev.key == KEY_POWER) keycode = MYKEY_POWER; + else if(ev.key == KEY_EXIT) keycode = MYKEY_EXIT; + else if(ev.key == KEY_DOWN) keycode = MYKEY_DOWN; + else if(ev.key == KEY_RIGHT) keycode = MYKEY_RIGHT; + + else if(ev.key == KEY_XOT) keycode = MYKEY_XOT; + else if(ev.key == KEY_LOG) keycode = MYKEY_LOG; + else if(ev.key == KEY_LN) keycode = MYKEY_LN; + else if(ev.key == KEY_SIN) keycode = MYKEY_SIN; + else if(ev.key == KEY_COS) keycode = MYKEY_COS; + else if(ev.key == KEY_TAN) keycode = MYKEY_TAN; + + else if(ev.key == KEY_FRAC) keycode = MYKEY_FRAC; + else if(ev.key == KEY_FD) keycode = MYKEY_FD; + else if(ev.key == KEY_LEFTP) keycode = MYKEY_LEFTP; + else if(ev.key == KEY_RIGHTP) keycode = MYKEY_RIGHTP; + else if(ev.key == KEY_COMMA) keycode = MYKEY_COMMA; + else if(ev.key == KEY_ARROW) keycode = MYKEY_ARROW; + + else if(ev.key == KEY_7) keycode = MYKEY_7; + else if(ev.key == KEY_8) keycode = MYKEY_8; + else if(ev.key == KEY_9) keycode = MYKEY_9; + else if(ev.key == KEY_DEL) keycode = MYKEY_DEL; + + else if(ev.key == KEY_4) keycode = MYKEY_4; + else if(ev.key == KEY_5) keycode = MYKEY_5; + else if(ev.key == KEY_6) keycode = MYKEY_6; + else if(ev.key == KEY_MUL) keycode = MYKEY_MUL; + else if(ev.key == KEY_DIV) keycode = MYKEY_DIV; + + else if(ev.key == KEY_1) keycode = MYKEY_1; + else if(ev.key == KEY_2) keycode = MYKEY_2; + else if(ev.key == KEY_3) keycode = MYKEY_3; + else if(ev.key == KEY_ADD) keycode = MYKEY_ADD; + else if(ev.key == KEY_SUB) keycode = MYKEY_SUB; + + else if(ev.key == KEY_0) keycode = MYKEY_0; + else if(ev.key == KEY_DOT) keycode = MYKEY_DOT; + else if(ev.key == KEY_EXP) keycode = MYKEY_EXP; + else if(ev.key == KEY_NEG) keycode = MYKEY_NEG; + else if(ev.key == KEY_EXE) keycode = MYKEY_EXE; + + else if(ev.key == KEY_ACON) keycode = MYKEY_ACON; + + + if(keycode!=-1) + { + if (ev.type == KEYEV_DOWN) MyKeyMapper[keycode] = { .pressed = true, .since = timer }; + else if (ev.type == KEYEV_UP) MyKeyMapper[keycode] = { .pressed = false, .since = timer }; + else if (ev.type == KEYEV_HOLD) {} + } + else + { + // do nothing, just unstack the event from the events queue + }; + } +} + + +bool KeyboardExtra::IsKeyPressedEvent( int key ) +{ + return (MyKeyMapper[key].pressed && MyKeyMapper[key].since == now); +} + + +bool KeyboardExtra::IsKeyReleasedEvent( int key ) +{ + return (!MyKeyMapper[key].pressed && MyKeyMapper[key].since == now); +} + + +bool KeyboardExtra::IsKeyPressed( int key ) +{ + return MyKeyMapper[key].pressed; +} + + +bool KeyboardExtra::IsKeyReleased( int key ) +{ + return (!MyKeyMapper[key].pressed); +} + + +uint32_t KeyboardExtra::IsKeyHoldPressed( int key ) +{ + if (MyKeyMapper[key].pressed && MyKeyMapper[key].since < now) + return (uint32_t) (now-MyKeyMapper[key].since); + else return 0; +} + + +uint32_t KeyboardExtra::IsKeyHoldReleased( int key ) +{ + if (!MyKeyMapper[key].pressed && MyKeyMapper[key].since < now) + return (uint32_t) (now-MyKeyMapper[key].since); + else return 0; +} + +uint32_t KeyboardExtra::GetLastTickKeyEvent( int key ) +{ + return (uint32_t) MyKeyMapper[key].since; +} \ No newline at end of file diff --git a/src/extrakeyboard.h b/src/extrakeyboard.h new file mode 100644 index 0000000..151d1d1 --- /dev/null +++ b/src/extrakeyboard.h @@ -0,0 +1,94 @@ +#ifndef EXTRAKEYBOARD_H +#define EXTRAKEYBOARD_H + +#include + + +enum +{ + MYKEY_F1=0, + MYKEY_F2, + MYKEY_F3, + MYKEY_F4, + MYKEY_F5, + MYKEY_F6, + + MYKEY_SHIFT, + MYKEY_OPTN, + MYKEY_VARS, + MYKEY_MENU, + MYKEY_LEFT, + MYKEY_UP, + + MYKEY_ALPHA, + MYKEY_SQUARE, + MYKEY_POWER, + MYKEY_EXIT, + MYKEY_DOWN, + MYKEY_RIGHT, + + MYKEY_XOT, + MYKEY_LOG, + MYKEY_LN, + MYKEY_SIN, + MYKEY_COS, + MYKEY_TAN, + + MYKEY_FRAC, + MYKEY_FD, + MYKEY_LEFTP, + MYKEY_RIGHTP, + MYKEY_COMMA, + MYKEY_ARROW, + + MYKEY_7, + MYKEY_8, + MYKEY_9, + MYKEY_DEL, + + MYKEY_4, + MYKEY_5, + MYKEY_6, + MYKEY_MUL, + MYKEY_DIV, + + MYKEY_1, + MYKEY_2, + MYKEY_3, + MYKEY_ADD, + MYKEY_SUB, + + MYKEY_0, + MYKEY_DOT, + MYKEY_EXP, + MYKEY_NEG, + MYKEY_EXE, + + MYKEY_ACON, + + MYKEY_LASTENUM, +}; + + + +class KeyboardExtra +{ + public: + KeyboardExtra(); + ~KeyboardExtra(); + + void Update( float dt ); + bool IsKeyPressedEvent( int key ); + bool IsKeyReleasedEvent( int key ); + bool IsKeyPressed( int key ); + bool IsKeyReleased( int key ); + uint32_t IsKeyHoldPressed( int key ); + uint32_t IsKeyHoldReleased( int key ); + uint32_t GetLastTickKeyEvent( int key ); + + private: + uint32_t now; +}; + + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..17b2d42 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,308 @@ +#define DEBUG_MODE 1 +#define BIAS 1 +#define NOBIAS (1-BIAS) + + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "extrakeyboard.h" +#include "utilities.h" + +#include "player.h" +#include "background.h" + + +bool screenshot = false; +bool record = false; +bool textoutput = false; +bool exitToOS = false; +uint8_t texttodraw=1; + + +#define SCALE_PIXEL 1 +#define X_RESOL (DWIDTH / SCALE_PIXEL) +#define Y_RESOL (DHEIGHT / SCALE_PIXEL) + +float elapsedTime = 0.0f; +uint32_t time_update=0, time_render=0; +prof_t perf_update, perf_render; + + +static kmalloc_arena_t extended_ram = { 0 }; +static kmalloc_arena_t *_uram; +kmalloc_gint_stats_t *_uram_stats; +kmalloc_gint_stats_t *extram_stats; + + +KeyboardExtra MyKeyboard; +Background MyBackground; +Player MyPlayer( 198, 180 ); + + +bool drawbackground = true; + + +static void hook_prefrag(int id, void *fragment, int size) +{ + if(!screenshot && !record) + return; + + /* Screenshot takes precedence */ + char const *type = screenshot ? "image" : "video"; + + int pipe = usb_ff_bulk_output(); + + if(id == 0) { + usb_fxlink_header_t h; + usb_fxlink_image_t sh; + int size = azrp_width * azrp_height * 2; + + usb_fxlink_fill_header(&h, "fxlink", type, size + sizeof sh); + sh.width = htole32(azrp_width); + sh.height = htole32(azrp_height); + sh.pixel_format = htole32(USB_FXLINK_IMAGE_RGB565); + + usb_write_sync(pipe, &h, sizeof h, false); + usb_write_sync(pipe, &sh, sizeof sh, false); + } + + usb_write_sync(pipe, fragment, size, false); + + if(id == azrp_frag_count - 1) { + usb_commit_sync(pipe); + screenshot = false; + } +} + + +static void update( float dt ) +{ + MyPlayer.Update( dt, 0.0f, 1.0f ); +} + + +static void render( void ) +{ + + MyBackground.Render(); + MyPlayer.Render(); + + #if(BIAS) + if (texttodraw>=1) Azur_draw_text(1,01, "FPS = %.0f", (float) (1000000.0f / elapsedTime) ); + //if (texttodraw>=1) Azur_draw_text(1,11, "Part.= %d - Bull.= %d", MyParticles.size(), MyPlayerBullets.size() ); + //if (texttodraw>=1 && !MyEnemies.empty()) Azur_draw_text(1,21, "Ennmy Life= %d", MyEnemies[0]->life ); + + if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.3f ms", (float) time_update / 1000.0f ); + if (texttodraw>=2) Azur_draw_text(1,41, "Render = %.3f ms", (float) time_render / 1000.0f ); + if (texttodraw>=2) Azur_draw_text(1,51, ">Total = %.0f ms", (float) elapsedTime / 1000.0f ); + + if (texttodraw>=3) Azur_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory + extram_stats->used_memory); + if (texttodraw>=3) Azur_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory + extram_stats->free_memory); + if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory ); + #endif + +} + + + +static void get_inputs( float dt ) +{ + if (MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyHoldPressed(MYKEY_EXIT)) {exitToOS = true; }; + + + #if(DEBUG_MODE) + if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_7) && usb_is_open() ) {screenshot = true;}; + if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_8) && usb_is_open()) {record = true; }; + if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_9) && usb_is_open()) {record = false; }; + + if(MyKeyboard.IsKeyPressedEvent(MYKEY_VARS)) { drawbackground = !drawbackground; } + + if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_F1)) { texttodraw = 0; } + if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_F2)) { texttodraw = 1; } + if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_F3)) { texttodraw = 2; } + if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_F4)) { texttodraw = 3; } + + if(MyKeyboard.IsKeyPressedEvent(MYKEY_F1)) { MyBackground.ChangeMap(1, &MyPlayer); } + if(MyKeyboard.IsKeyPressedEvent(MYKEY_F2)) { MyBackground.ChangeMap(2, &MyPlayer); } + if(MyKeyboard.IsKeyPressedEvent(MYKEY_F3)) { MyBackground.ChangeMap(3, &MyPlayer); } + if(MyKeyboard.IsKeyPressedEvent(MYKEY_F4)) { MyBackground.ChangeMap(4, &MyPlayer); } + if(MyKeyboard.IsKeyPressedEvent(MYKEY_F5)) { MyBackground.ChangeMap(5, &MyPlayer); } + if(MyKeyboard.IsKeyPressedEvent(MYKEY_F6)) { MyBackground.ChangeMap(6, &MyPlayer); } + #endif + + + if(MyKeyboard.IsKeyPressed(MYKEY_ALPHA) && MyKeyboard.IsKeyPressed(MYKEY_LEFT)) + { + MyPlayer.Walk_Left( dt ); + } + else if(MyKeyboard.IsKeyPressed(MYKEY_ALPHA) && MyKeyboard.IsKeyPressed(MYKEY_RIGHT)) + { + MyPlayer.Walk_Right( dt ); + } + else if(MyKeyboard.IsKeyPressed(MYKEY_LEFT)) + { + MyPlayer.Run_Left( dt ); + } + else if(MyKeyboard.IsKeyPressed(MYKEY_RIGHT)) + { + MyPlayer.Run_Right( dt ); + } + else + { + MyPlayer.No_Order( dt ); + } + + if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT)) + { + MyPlayer.Jump( dt ); + } +} + + + +bool AddMoreRAM( void ) +{ + /* allow more RAM */ + char const *osv = (char*) 0x80020020; + + if((!strncmp(osv, "03.", 3) && osv[3] <= '6') && gint[HWCALC] == HWCALC_FXCG50) // CG-50 + { + extended_ram.name = "extram"; + extended_ram.is_default = true; + extended_ram.start = (void *)0x8c200000; + extended_ram.end = (void *)0x8c4e0000 ; + + kmalloc_init_arena(&extended_ram, true); + kmalloc_add_arena(&extended_ram ); + return true; + } + else if (gint[HWCALC] == HWCALC_PRIZM) // CG-10/20 + { + + extended_ram.name = "extram"; + extended_ram.is_default = true; + + uint16_t *vram1, *vram2; + dgetvram(&vram1, &vram2); + dsetvram(vram1, vram1); + + extended_ram.start = vram2; + extended_ram.end = (char *)vram2 + 396*224*2; + + kmalloc_init_arena(&extended_ram, true); + kmalloc_add_arena(&extended_ram ); + return false; + + } + else if (gint[HWCALC] == HWCALC_FXCG_MANAGER) // CG-50 EMULATOR + { + + extended_ram.name = "extram"; + extended_ram.is_default = true; + extended_ram.start = (void *)0x88200000; + extended_ram.end = (void *)0x884e0000 ; + + kmalloc_init_arena(&extended_ram, true); + kmalloc_add_arena(&extended_ram ); + return true; + } +} + +void FreeMoreRAM( void ) +{ + memset(extended_ram.start, 0, (char *)extended_ram.end - (char *)extended_ram.start); +} + + +int main(void) +{ + exitToOS = false; + + _uram = kmalloc_get_arena("_uram"); + + bool canWeAllocate3Mb = AddMoreRAM(); + + __printf_enable_fp(); + __printf_enable_fixed(); + + azrp_config_scale(SCALE_PIXEL); + + azrp_shader_clear_configure(); + azrp_shader_image_rgb16_configure(); + azrp_shader_image_p8_configure(); + azrp_shader_image_p4_configure(); + azrp_shader_triangle_configure(); + + azrp_hook_set_prefrag(hook_prefrag); + + usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL }; + usb_open(interfaces, GINT_CALL_NULL); + + prof_init(); + + do + { + perf_update = prof_make(); + prof_enter(perf_update); + + { + // all the stuff to be update should be put here + MyKeyboard.Update( elapsedTime ); + + get_inputs( elapsedTime ); + + update( elapsedTime ); + + // update the RAM consumption status + _uram_stats = kmalloc_get_gint_stats(_uram); + extram_stats = kmalloc_get_gint_stats(&extended_ram); + } + + prof_leave(perf_update); + time_update = prof_time(perf_update); + + perf_render = prof_make(); + prof_enter(perf_render); + + { + // all the stuff to be rendered should be put here + azrp_clear( C_WHITE ); + render(); + azrp_update(); + } + + prof_leave(perf_render); + time_render = prof_time(perf_render); + + elapsedTime = ((float) (time_update+time_render)); + + } + while (exitToOS==false); + + + prof_quit(); + usb_close(); + + + FreeMoreRAM( ); + + return 1; +} diff --git a/src/player.cpp b/src/player.cpp new file mode 100644 index 0000000..5bfd271 --- /dev/null +++ b/src/player.cpp @@ -0,0 +1,174 @@ +#include "player.h" +#include +#include +#include "background.h" + +/* +extern bopti_image_t img_walking; +extern bopti_image_t img_running; +extern bopti_image_t img_static; +*/ + +extern bopti_image_t img_rectangle; + + +static uint32_t framecounter = 0; + +extern Background MyBackground; + + +Player::Player( int16_t _x, int16_t _y ) +{ + x = libnum::num(_x); + y = libnum::num(_y); + + width = 8; + height = 8; + speed = 10; + + xmin = (int) x - width; + xmax = (int) x + width; + ymin = (int) y - height; + ymax = (int) y + height; + + last_tick = rtc_ticks(); +} + +Player::~Player() +{ + + +} + +void Player::Update( float dt, libnum::num ax, libnum::num ay ) +{ + libnum::num DeltaTime = libnum::num( dt / 60000.0f ); + vx += ax * DeltaTime; + vy += ay * DeltaTime; + + libnum::num xtemp = x + vx * DeltaTime; + libnum::num ytemp = y + vy * DeltaTime; + + if (MyBackground.CanGo( this )) + { + x = xtemp; + y = ytemp; + } + + xmin = (int) x - width; + xmax = (int) x + width; + ymin = (int) y - height; + ymax = (int) y + height; + +} + +void Player::Render( void ) +{ + uint32_t temptick = rtc_ticks(); + if (temptick-last_tick>=10) + { + last_tick = temptick; + framecounter++; + } + /* + if (action==RUN) + { + uint8_t frameinternal = framecounter % 8; + azrp_subimage_p8_effect(xmin, ymin, &img_running, frameinternal*16, 0, 16, 16, direction==RIGHT ? DIMAGE_NONE : IMAGE_HFLIP ); + } + else if (action==WALK) + { + uint8_t frameinternal = framecounter % 7; + azrp_subimage_p8_effect(xmin, ymin, &img_walking, frameinternal*16, 0, 16, 16, direction==RIGHT ? DIMAGE_NONE : IMAGE_HFLIP ); + } + else if (action==STATIC) + { + uint8_t frameinternal = framecounter % 8; + azrp_subimage_p8_effect(xmin, ymin, &img_static, frameinternal*16, 0, 16, 16, DIMAGE_NONE); + } + */ + + azrp_image_p8_effect(xmin, ymin, &img_rectangle, DIMAGE_NONE); + + +} + +void Player::Set_Speed( uint8_t _sp ) +{ + speed = _sp; +} + +void Player::Walk_Left( float dt ) +{ + libnum::num a = libnum::num( dt / 60000.0f ); + + x -= a * libnum::num( speed/3 ); + + this->direction = LEFT; + this->action = WALK; +} + +void Player::Walk_Right( float dt ) +{ + libnum::num a = libnum::num( dt / 60000.0f ); + + x += a * libnum::num( speed/3 ); + + this->direction = RIGHT; + this->action = WALK; +} + +void Player::Run_Left( float dt ) +{ + libnum::num a = libnum::num( dt / 60000.0f ); + + x -= a * libnum::num( speed ); + + this->direction = LEFT; + this->action = RUN; +} + +void Player::Run_Right( float dt ) +{ + libnum::num a = libnum::num( dt / 60000.0f ); + + x += a * libnum::num( speed ); + + this->direction = RIGHT; + this->action = RUN; +} + +void Player::Jump( float dt ) +{ + if (this->action==WALK) + { + //this->vx = speed / 3; + this->vy = -speed / 2; + } + else if (this->action==RUN) + { + //this->vx = speed; + this->vy = -speed; + } + else + { + //this->vx = 0; + this->vy = -speed /2; + } + + this->direction = LEFT; + this->action = JUMP; + + if (this->direction==LEFT) + { + this->vx = -this->vx; + } +} + +void Player::No_Order( float dt ) +{ + if (this->action == RUN || this->action == WALK) + { + this->action == BREAK; + } +} diff --git a/src/player.h b/src/player.h new file mode 100644 index 0000000..d40b56b --- /dev/null +++ b/src/player.h @@ -0,0 +1,69 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include +#include + +#include +#include + +#include + +enum +{ + LEFT = -2, + RIGHT = -1, + STATIC = 0, + BREAK = 1, + WALK = 2, + RUN = 3, + JUMP = 4, + FALL = 5, +}; + + + +class Player +{ + public: + Player( int16_t _x, int16_t _y ); + ~Player(); + + void Update( float dt, libnum::num ax, libnum::num ay ); + void Render( ); + + void Walk_Left( float dt ); + void Walk_Right( float dt ); + + void Run_Left( float dt ); + void Run_Right( float dt ); + + void No_Order( float dt ); + + void Jump( float dt ); + + + void Go_Up( int action, float dt ); + void Go_Down( int action, float dt ); + + + void Set_Speed( uint8_t _sp ); + + libnum::num x, y; // center position of the player + libnum::num vx, vy; // speed of the player as per x and y coordinates + + uint8_t width, height; // width and height - for the hitbox + int16_t xmin, xmax, ymin, ymax; // square hitbox (to speed up the impact calculations) + + int16_t life; + uint8_t speed; // speed of the player + uint32_t last_tick; + + int8_t direction = STATIC; + int8_t action = STATIC; +}; + + + + +#endif \ No newline at end of file diff --git a/src/utilities.cpp b/src/utilities.cpp new file mode 100644 index 0000000..570ddac --- /dev/null +++ b/src/utilities.cpp @@ -0,0 +1,27 @@ +#include +#include + +#include +#include +#include +#include + +/* Render text with Azur images - quite bad, but I don't have time lol. */ +void Azur_draw_text(int x, int y, char const *fmt, ...) +{ + char str[128]; + va_list args; + va_start(args, fmt); + vsnprintf(str, 128, fmt, args); + va_end(args); + + extern bopti_image_t img_font; + + for(int i = 0; str[i]; i++) { + if(str[i] < 32 || str[i] >= 0x7f) continue; + + int row = (str[i] - 32) >> 4; + int col = (str[i] - 32) & 15; + azrp_subimage(x + 5 * i, y, &img_font, 7 * col + 1, 9 * row + 1, 6, 8, DIMAGE_NONE); + } +} diff --git a/src/utilities.h b/src/utilities.h new file mode 100644 index 0000000..41fbdd3 --- /dev/null +++ b/src/utilities.h @@ -0,0 +1,6 @@ +#ifndef UTILITIES_H +#define UTILITIES_H + +void Azur_draw_text(int x, int y, char const *fmt, ...); + +#endif \ No newline at end of file