Compare commits

92 Commits

Author SHA1 Message Date
15e6abc102 Parsing for SpriteComponent JSON 2023-08-27 19:46:16 -04:00
9218c9a4b1 Removed Boost libraries from project 2023-08-21 16:45:15 -04:00
de3b2dcdb0 Music completed, new tilemap, fixed collider 2023-08-14 23:48:20 -04:00
162f58b32f Merge branch 'macos' of https://lab.oakcityit.net/gitea/Zeronaut/KaijuSaveEarth into macos 2023-08-13 17:28:41 -04:00
f20e711380 Tilemap doesn't use hardcoded path instead uses generated path from Game.cpp 2023-08-13 17:27:07 -04:00
9b4ea773c3 Updated README.md
Updated README.md with Installation and Description
2023-08-13 03:39:09 +00:00
6bdaefdeb9 Clean up git merge on Game.cpp added assets 2023-08-12 23:27:14 -04:00
ff1863182e Merge Conflicts Resolved 2023-08-12 15:02:40 -04:00
1cbc8cbbc0 All asset paths corrected to use Boost::FS 2023-08-12 14:44:08 -04:00
f449eda43f Some paths to assets fixed with Boost::FS 2023-08-12 13:52:04 -04:00
a0c06ebe6a Initial build on macOS 2023-08-12 08:50:32 -04:00
bab3487115 Cleaned up old assets 2023-08-07 17:33:44 -04:00
2861296840 updated kaijuturtle .png and .json 2023-08-07 21:18:43 +00:00
3ad0265dbd updates to spritecomp and keyboard ctrlr 2023-08-07 17:14:17 -04:00
838426ead3 removed old Kaiju-Turtle.png 2023-08-07 16:43:55 -04:00
bcdd633d53 Merge branch 'main' of https://lab.oakcityit.net/gitea/Zeronaut/KaijuSaveEarth 2023-08-07 16:41:02 -04:00
2ba9b016eb Random updates to game.cpp 2023-08-07 16:36:44 -04:00
654142ae80 Uploaded new Kaiju spritesheet 2023-08-07 20:33:01 +00:00
936b6806eb Added sanity checks to tiles 2023-08-05 18:08:05 -04:00
7b2ed8e27b New tileset & map; todo fix tile sanity check 2023-08-04 22:05:07 -04:00
6568026886 refactored Text, box UI and reconfigured config.json 2023-08-04 14:34:43 -04:00
4c2049a1e0 Tiled map and tileset added 2023-08-02 14:27:59 -04:00
369ad6f83e Texture assets added 2023-08-02 14:06:19 -04:00
a3cc810e6d Upload files to 'assets/textures/ui'
Added UI Text Bubble image
2023-08-01 21:35:12 +00:00
3dd491f5a6 Upload files to 'assets/textures/ui'
Added LoRez5Font.png a 5x5 px font
2023-08-01 21:14:12 +00:00
9d61bcf621 Clean up various files 2023-08-01 16:58:06 -04:00
d51cd1d65c Merging in engine files 2023-08-01 16:46:05 -04:00
15c0ff5856 Pulling in engine files 2023-08-01 16:34:22 -04:00
f14960d5ab Merging Tileson to Master 2023-07-26 16:34:53 -04:00
4b1a80ec40 Cleaned up Tileson and TilemapComponent 2023-07-26 15:47:36 -04:00
1a0bd2ea4e Tileson fully refactored into engine 2023-07-26 15:13:45 -04:00
b4b83f098d TileSet Parsing and Setup Refactored 2023-07-25 16:48:12 -04:00
b15316c40e More work on Tileson integration 2023-07-24 13:41:02 -04:00
bbab18d361 Tileson working with tsj tileset 2023-07-21 00:08:23 -04:00
a3d13f32a5 cleaned up gitignore and build artifacts 2023-07-20 13:47:44 -04:00
9432b68efe added tileson still debugging 2023-07-20 12:31:37 -04:00
352034790c integrating tileson with the project for tmx parsing 2023-07-19 17:10:10 -04:00
8aa79741e4 Cleanup on aisle everywhere 2023-07-19 13:16:14 -04:00
8d6fe8556c Kdevelop included, libtmxparser excluded 2023-07-15 18:05:24 -04:00
e4c270a81d Kdevelop included, libtmxparser excluded 2023-07-15 18:05:24 -04:00
fd17014eef SDL libs back to dynamic, libtmxparser fixed 2023-07-15 18:05:23 -04:00
391fcedc37 libSDL2 static build and link 2022-09-30 16:09:12 -04:00
1dec4347e0 Built SDL2_image and _mixer static 2022-09-30 15:49:16 -04:00
e2605bf6c1 Changed to static libraries for libTmxParser 2022-07-18 18:09:09 -04:00
21c30b7f52 Before changing to static libraries 2022-07-04 09:42:42 -04:00
70402c5382 udpated SDL_GetTicks() to SDL_GetTicks64() 2022-05-30 14:02:21 -04:00
4aa7fe1692 predictCollisions working in debug mode 2022-05-14 17:52:05 -04:00
36adcdeac7 predictCollisions func added to Game.cpp 2022-05-13 23:20:08 -04:00
e28a9cebdb TileMap Debug Colliders Drawing 2022-05-01 17:35:58 -04:00
b94c2cff38 Debug menu scale fixed, Player Tile Position 2022-05-01 15:38:55 -04:00
fb20b8d868 Camera and Tilemaps fixed at 1x res 2022-05-01 11:00:51 -04:00
9f4007bb79 TileMaps and camera tuning 2022-04-29 21:31:34 -04:00
bc4262d552 Continued work on tilemaps/debug 2022-04-08 18:19:27 -04:00
2331110c71 TileMaps and cam debug added 2022-04-07 23:20:19 -04:00
c8aae59f26 TileMaps now render and move with camera 2022-04-04 18:16:20 -04:00
871e6d19c6 TileMaps now render each row correctly 2022-03-27 23:59:12 -04:00
72b4ac9229 TileMapComponent now takes a TMX to render tilemap 2022-03-24 23:34:17 -04:00
dc43e59ff6 halsafar/libtmx-parser added to project 2022-03-21 15:26:13 -04:00
66b8de6f40 Cleaned up UITextComponent and SpriteComponent 2022-02-06 20:12:12 -05:00
b5639e4f41 Basic WordWrap for UIText feature 2022-02-04 17:08:01 -05:00
72a941810d New UITextComponent implemented 2022-02-03 17:59:50 -05:00
40095cb8b7 Minor tweaks for debug text 2022-01-02 14:05:52 -05:00
af393e8acb a,d keys implemented and screen for 1080p 2021-12-30 13:42:55 -05:00
b9e9c04235 UI tweaks for more layers and debug 2021-11-07 20:47:58 -05:00
0cc31be0c7 Fixed Gravity to scale correctly with global scale 2021-11-05 21:54:18 -04:00
bd0c49b3ae Collider debug boxes with SDL_Rect 2021-11-03 17:37:56 -04:00
165052a617 Worked on Colliders 2021-08-25 17:11:46 -04:00
1e5beb5b88 ColliderComponent hidden prop 2021-08-16 17:36:21 -04:00
8713b76f83 added hidden property to Collider Component 2021-08-16 17:29:50 -04:00
586a774cde cleanup on aisle everywhere 2021-08-02 18:18:04 -04:00
fde99ef76b added Nic's collision pseudocode 2021-08-02 17:46:06 -04:00
363f28cb9c Fixed UIText class for non-uniform scale 2021-07-29 08:21:45 -04:00
31e16585d1 added a debug file with console output 2021-07-10 21:24:44 -04:00
10e5be7a65 Working on Collisions 2021-07-10 21:23:45 -04:00
de99b127b1 Added error checking for config.json 2021-03-08 20:51:58 -05:00
fe13bac080 Fixed input bug (see SDL2 Engine Deck) 2021-02-18 14:20:11 -05:00
e4de32f9f7 Added FSM and Game State Manager 2021-02-15 21:10:18 -05:00
78629be4d8 Fixed up collision boxes allowing custom colliders 2021-02-15 00:30:26 -05:00
19f160b6ea Fire animation finished 2021-02-06 20:04:42 -05:00
a7c7431f8a Fire Animation nearly complete 2021-02-06 15:18:31 -05:00
a02748d8c0 Final changes posted to GGJ21 2021-01-31 16:52:47 -05:00
a3c829f7c8 Added music and sfx 2021-01-31 16:29:42 -05:00
5d76cfe49c Fixed map, tweaked gravity/jump, added puppy 2021-01-31 14:29:29 -05:00
3481c20e4f Firefighter better animations added 2021-01-31 02:10:02 -05:00
697ab6f8fc Integrated new content, Fixed Map Collision 2021-01-30 20:14:26 -05:00
3f12951802 More Sprite work added 2021-01-30 15:28:33 -05:00
4169e6a568 Added Firefighter sprite 2021-01-30 11:14:00 -05:00
b691641494 Background and tilemap added 2021-01-30 01:34:02 -05:00
618bda931e Project imported into KDevelop 2021-01-29 22:20:54 -05:00
e89d9c577f Resolved merge conflicts on README and gitignore 2021-01-29 21:36:19 -05:00
b2acceb4b9 first commit 2021-01-29 21:14:20 -05:00
882951f340 Initial commit 2021-01-30 02:10:54 +00:00
118 changed files with 16713 additions and 8 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

14
.gitignore vendored
View File

@ -1,3 +1,10 @@
# ---> KDevelop4
#*.kdev4
#.kdev4/
# ---> build artifacts
build/*
# ---> C++
# Prerequisites
*.d
@ -98,4 +105,11 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
# CMake artifacts
CMakeCache.txt
# macOS finder files
.DS_Store
# VS Code project stuff
.vscode*

View File

@ -0,0 +1,94 @@
<<<<<<< HEAD
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00 \x00B\x00e\x00a\x00g\x00l\x00e\x00R\x00e\x00s\x00c\x00u\x00e\x00.\x00g\x00i\x00t)
[CMake]
Build Directory Count=1
Current Build Directory Index-Host System=0
[CMake][CMake Build Directory 0]
Build Directory Path=/home/ayoungblood/BeagleRescue.git/build
Build Type=Release
CMake Binary=/usr/bin/cmake
CMake Executable=/usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=
Runtime=Host System
[CustomDefinesAndIncludes][ProjectPath0]
Path=.
parseAmbiguousAsCPP=true
parserArguments=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++17
parserArgumentsC=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c99
parserArgumentsCuda=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11
parserArgumentsOpenCL=-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -cl-std=CL1.1
[CustomDefinesAndIncludes][ProjectPath0][Compiler]
Name=GCC
[Launch]
Launch Configurations=Launch Configuration 0
[Launch][Launch Configuration 0]
Configured Launch Modes=execute,debug
Configured Launchers=nativeAppLauncher,lldb
Name=BeagleRescue
Type=Native Application
[Launch][Launch Configuration 0][Data]
Arguments=
Break on Start=false
Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
Dependency Action=Nothing
EnvironmentGroup=
Executable=file:///home/ayoungblood/BeagleRescue.git/build/BeagleRescue
External Terminal=konsole --noclose --workdir %workdir -e %exe
Kill Before Executing Again=4194304
LLDB Arguments=
LLDB Config Script=
LLDB Environment=
LLDB Executable=
LLDB Inherit System Env=true
LLDB Remote Debugging=false
LLDB Remote Path=
LLDB Remote Server=
Project Target=BeagleRescue,BeagleRescue
Start With=ApplicationOutput
Use External Terminal=false
Working Directory=file:///home/ayoungblood/BeagleRescue.git
isExecutable=true
[Project]
VersionControlSupport=kdevgit
||||||| 8aa7974
=======
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00 \x00B\x00e\x00a\x00g\x00l\x00e\x00R\x00e\x00s\x00c\x00u\x00e\x00.\x00g\x00i\x00t)
[CMake]
Build Directory Count=1
Current Build Directory Index-Host System=0
[CMake][CMake Build Directory 0]
Build Directory Path=/home/ayoungblood/projects/BeagleRescue.git/build
Build Type=Release
CMake Binary=/usr/bin/cmake
CMake Executable=/usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=
Runtime=Host System
[Launch]
Launch Configurations=Launch Configuration 0
[Launch][Launch Configuration 0]
Configured Launch Modes=execute
Configured Launchers=nativeAppLauncher
Name=New Compiled Binary Launcher
Type=Native Application
[Project]
VersionControlSupport=kdevgit
>>>>>>> a3d13f32a5f0e4e11c618a4c3d524fd52fc0ed08

51
.kdev4/BeagleRescue.kdev4 Normal file
View File

@ -0,0 +1,51 @@
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x18\x00B\x00e\x00a\x00g\x00l\x00e\x00R\x00e\x00s\x00c\x00u\x00e)
[CMake]
Build Directory Count=2
Current Build Directory Index-Host System=0
Temporary Build Directory Index=1
[CMake][CMake Build Directory 0]
Build Directory Path=/home/ayoungblood/projects/BeagleRescue/build
Build Type=Release
CMake Binary=/usr/bin/cmake
CMake Executable=/usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=/usr/local
Runtime=Host System
[CMake][CMake Build Directory 1]
Build Directory Path=/home/ayoungblood/Projects/BeagleRescue/build
Build Type=Release
CMake Binary=/usr/bin/cmake
CMake Executable=/usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=
[Launch]
Launch Configurations=Launch Configuration 0
[Launch][Launch Configuration 0]
Configured Launch Modes=execute
Configured Launchers=nativeAppLauncher
Name=BeagleRescue
Type=Native Application
[Launch][Launch Configuration 0][Data]
Arguments=
Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
Dependency Action=Nothing
EnvironmentGroup=
Executable=file:///home/ayoungblood/Projects/BeagleRescue
External Terminal=konsole --noclose --workdir %workdir -e %exe
Kill Before Executing Again=4194304
Project Target=BeagleRescue,BeagleRescue
Use External Terminal=false
Working Directory=file:///home/ayoungblood/projects/BeagleRescue
isExecutable=true
[Project]
VersionControlSupport=kdevgit

View File

@ -0,0 +1,41 @@
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x1c\x00K\x00a\x00i\x00j\x00u\x00S\x00a\x00v\x00e\x00E\x00a\x00r\x00t\x00h)
[CMake]
Build Directory Count=1
Current Build Directory Index-Host System=0
[CMake][CMake Build Directory 0]
Build Directory Path=/home/ayoungblood/projects/KaijuSaveEarth/build
Build Type=Release
CMake Binary=/usr/bin/cmake
CMake Executable=/usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=/usr/local
Runtime=Host System
[Launch]
Launch Configurations=Launch Configuration 0
[Launch][Launch Configuration 0]
Configured Launch Modes=execute
Configured Launchers=nativeAppLauncher
Name=KaijuSaveEarth
Type=Native Application
[Launch][Launch Configuration 0][Data]
Arguments=
Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x02\x00\x00\x00\x1c\x00K\x00a\x00i\x00j\x00u\x00S\x00a\x00v\x00e\x00E\x00a\x00r\x00t\x00h\x00\x00\x00\x1c\x00K\x00a\x00i\x00j\x00u\x00S\x00a\x00v\x00e\x00E\x00a\x00r\x00t\x00h)
Dependency Action=Build
EnvironmentGroup=
Executable=file:///home/ayoungblood/projects/KaijuSaveEarth/build/KaijuSaveEarth
External Terminal=konsole --noclose --workdir %workdir -e %exe
Kill Before Executing Again=65536
Project Target=KaijuSaveEarth,KaijuSaveEarth
Use External Terminal=false
Working Directory=file:///home/ayoungblood/projects/KaijuSaveEarth
isExecutable=true
[Project]
VersionControlSupport=kdevgit

30
CMakeLists.txt Normal file
View File

@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.25.1)
project(KaijuSaveEarth VERSION 1.0.0 )
#set(CMAKE_CXX_STANDARD 11) # old requirements
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to be used") # new requirements for tileson
set(CMAKE_CXX_REQUIRED ON)
include(FetchContent)
include(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
PKG_SEARCH_MODULE(SDL2MIXER REQUIRED SDL2_mixer>=2.0.0)
#PKG_SEARCH_MODULE(BOOSTFILESYSTEM boost_filesystem >=)
#find_package(Boost COMPONENTS system filesystem REQUIRED)
# Point to our own cmake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
# Add global definitions
add_definitions("-Wall")
include_directories(${PROJECT_NAME} PRIVATE /usr/local/include/SDL2)
#add_custom_target(${TMXPARSER})
file(GLOB_RECURSE CSOURCES src/cjson/*.c)
file(GLOB_RECURSE CPPSOURCES src/*.cpp)
add_executable(${PROJECT_NAME} ${CSOURCES} ${CPPSOURCES})
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
target_link_libraries(${PROJECT_NAME} PRIVATE /usr/local/lib/libSDL2.dylib /usr/local/lib/libSDL2_image.dylib /usr/local/lib/libSDL2_mixer.dylib)

5
KaijuSaveEarth.kdev4 Normal file
View File

@ -0,0 +1,5 @@
[Project]
CreatedFrom=CMakeLists.txt
Manager=KDevCMakeManager
Name=KaijuSaveEarth
VersionControl=%{VERSIONCONTROLPLUGIN}

23
LICENSE
View File

@ -1,9 +1,24 @@
=======
MIT License
Copyright (c) <year> <copyright holders>
Copyright (c) 2023 Alan Youngblood
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=======

View File

@ -1,5 +1,37 @@
# KaijuSaveEarth
LowRezJam 2023
Kaiju Save Earth
A game where you play as a giant monster trying to save as many humans as possible before they destroy themselves and the world!
# Kaiju Saves Earth
Low Rez Jam 2023
![Kaiju Saves Earth Title Screen](assets/textures/ui/titlescreenbig.png "Kaiju Saves Earth")
In the distant future humans are panicked and pose a great risk to each other and themselves. Fortunately there is a giant monster "Kaiju" that come in to scoop up these people before they hurt anyone, storing them safely on its protected shell on its back. You play as the Kaiju trying to save as many people as possible before they hurt themselves.
Controls: w,a,s,d for movement and u,i,j,k for other actions, escape to quit.
Currently on builds on linux and macOS; uses CMake and should be easy enough to port to other systems.
By:
Alan Youngblood
## INSTALL
### Linux
1. Download and unzip the project files
2. Install KDevelop with your package manager
3. Install dependencies (listed as apt packages with debian/ubuntu and derivative distros): `sudo apt install libboost-dev cmake build-essential libsdl2-2.0-0 libsdl2-dev libsdl2-image-2.0.-0 libsdl2-image-dev libsdl2-mixer-2.0-0 libsdl2-mixer-dev`
4. Open the .kdev4 project file in KDevelop, configure launch to be the executable which should be KaijuSaveEarth/build/KaijuSaveEarth; build should be configured already.
5. Build in KDevelop.
6. Launch/Run from KDevelop.
7. Enjoy playing!
### macOS
1. Download and unzip the project files
2. Install Apple Mac Developer tools in terminal.app: xcode-select --install
3. Install dependencies, we recommend using brew: brew install boost cmake sdl2 sdl2_image sdl2_mixer<br>
4. In terminal: `cd KaijuSaveEarth/build`
5. `cmake ..`
6. `make`
7. `open ..`
8. Double Click the executable KaijuSaveEarth
9. Enjoy playing!

BIN
assets/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/audio/sfx/Bark1.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Bark2.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Bark3.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Bark4.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Bark5.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Fire.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/audio/sfx/bwoop.wav Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,12 @@
{
"automappingRulesFile": "",
"commands": [
],
"compatibilityVersion": 1100,
"extensionsPath": "extensions",
"folders": [
"."
],
"propertyTypes": [
]
}

View File

@ -0,0 +1,122 @@
{
"Map/SizeTest": {
"height": 4300,
"width": 2
},
"activeFile": "kaiju-city-map2.json",
"expandedProjectPaths": [
"."
],
"fileStates": {
"": {
"scaleInDock": 1
},
"Kaiju-City.tsj": {
"dynamicWrapping": true,
"scaleInDock": 3
},
"br-tiles.tsj": {
"scaleInDock": 1,
"scaleInEditor": 4
},
"kaiju-city-map.json": {
"expandedObjectLayers": [
3
],
"scale": 4,
"selectedLayer": 0,
"viewCenter": {
"x": 132.75,
"y": 137.875
}
},
"kaiju-city-map.json#kaiju-city": {
"scaleInDock": 1
},
"kaiju-city-map.tmj": {
"scale": 1.4114285714285715,
"selectedLayer": 0,
"viewCenter": {
"x": 232.3886639676113,
"y": 218.57287449392717
}
},
"kaiju-city-map.tmj#kaiju-city": {
"scaleInDock": 1
},
"kaiju-city-map.tmx": {
"scale": 1.4114285714285715,
"selectedLayer": 0,
"viewCenter": {
"x": 74.03846153846153,
"y": 116.19433198380568
}
},
"kaiju-city-map2.json": {
"scale": 2,
"selectedLayer": 1,
"viewCenter": {
"x": 169.5,
"y": 148.25
}
},
"kaiju-city-ts.tsj": {
"scaleInDock": 3,
"scaleInEditor": 1
},
"kaiju-city.tsj": {
"dynamicWrapping": false,
"scaleInDock": 1,
"scaleInEditor": 1
},
"kaiju-city.tsx": {
"scaleInDock": 3,
"scaleInEditor": 4
},
"kaiju-tokyo.tsj": {
"scaleInDock": 1,
"scaleInEditor": 4
},
"testmap.json": {
"scale": 0.5880952380952381,
"selectedLayer": 0,
"viewCenter": {
"x": 174.29149797570852,
"y": 578.1376518218623
}
}
},
"last.exportedFilePath": "/home/ayoungblood/projects/KaijuSaveEarth/assets/maps",
"last.externalTilesetPath": "/home/ayoungblood/projects/KaijuSaveEarth/assets/maps",
"last.imagePath": "/Users/ayoungblood/Projects/KaijuSaveEarth/assets/maps",
"lastUsedTilesetExportFilter": "JSON tileset files (*.tsj *.json)",
"map.height": 40,
"map.lastUsedExportFilter": "All Files (*)",
"map.lastUsedFormat": "json",
"map.layerDataFormat": null,
"map.tileHeight": 8,
"map.tileWidth": 8,
"map.width": 40,
"openFiles": [
"kaiju-city-map2.json"
],
"project": "kaiju-city-map.tiled-project",
"recentFiles": [
"kaiju-city-map2.json",
"kaiju-city-ts.tsj",
"kaiju-city-map.json",
"kaiju-city-map.tmj",
"kaiju-city.tsj",
"testmap.json",
"kaiju-tokyo.tsj",
"kaiju-city.tsx",
"br-tiles.tsj",
"kaiju-city-map.tmx"
],
"tileset.lastUsedFilter": "JSON tileset files (*.tsj *.json)",
"tileset.lastUsedFormat": "json",
"tileset.tileSize": {
"height": 8,
"width": 8
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,14 @@
{ "columns":16,
"image":"kaiju-city-ts.png",
"imageheight":128,
"imagewidth":128,
"margin":0,
"name":"kaiju-city-ts",
"spacing":0,
"tilecount":256,
"tiledversion":"1.10.1",
"tileheight":8,
"tilewidth":8,
"type":"tileset",
"version":"1.10"
}

View File

@ -0,0 +1,14 @@
{ "columns":8,
"image":"kaiju-city-tileset.png",
"imageheight":64,
"imagewidth":64,
"margin":0,
"name":"kaiju-city",
"spacing":0,
"tilecount":64,
"tiledversion":"1.8.2",
"tileheight":8,
"tilewidth":8,
"type":"tileset",
"version":"1.8"
}

BIN
assets/textures/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -0,0 +1,63 @@
{ "frames": [
{
"filename": "0",
"frame": { "x": 0, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
{
"filename": "1",
"frame": { "x": 0, "y": 32, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
{
"filename": "2",
"frame": { "x": 0, "y": 64, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
{
"filename": "3",
"frame": { "x": 0, "y": 96, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
{
"filename": "4",
"frame": { "x": 0, "y": 128, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
}
],
"meta": {
"app": "https://www.aseprite.org/",
"version": "1.2.40-x64",
"image": "kaijuturtle.png",
"format": "I8",
"size": { "w": 32, "h": 160 },
"scale": "1",
"frameTags": [
{ "name": "move-n", "from": 0, "to": 0, "direction": "forward" },
{ "name": "move-nw", "from": 1, "to": 1, "direction": "forward" },
{ "name": "move-w", "from": 2, "to": 2, "direction": "forward" },
{ "name": "move-sw", "from": 3, "to": 3, "direction": "forward" },
{ "name": "move-s", "from": 4, "to": 4, "direction": "forward" }
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 892 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

BIN
assets/textures/ui/font.ase Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 988 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

View File

@ -0,0 +1 @@
{"requests": [{"kind": "codemodel", "version": 2}, {"kind": "cmakeFiles", "version": 1}]}

BIN
build/.ninja_deps Normal file

Binary file not shown.

66
build/.ninja_log Normal file
View File

@ -0,0 +1,66 @@
# ninja log v5
5 1257 1680995986388821260 CMakeFiles/BeagleRescue.dir/src/ecs/ECS.cpp.o 2b68ee632af548aa
4 4614 1680995989752187549 CMakeFiles/BeagleRescue.dir/src/assetmgr/AssetManager.cpp.o eb4c2e382e340f10
4 68 1666035599307923948 libtmx-parser/liblibtmxparser.a 4a03bfde239caf5d
1829 5506 1680995990645529632 CMakeFiles/BeagleRescue.dir/src/ui/UIText.cpp.o 2e1a08cbe2ad039c
5 803 1665858094321634764 CMakeFiles/BeagleRescue.dir/libtmx-parser/src/base64.cpp.o 4bbee0e045ced8b2
8176 8273 1680995073021895354 libtmx-parser/liblibtmxparser.so 9df69ecfe8aa882a
3771 6588 1680995071338547771 libtmx-parser/CMakeFiles/libtmxparser.dir/libs/tinyxml2/tinyxml2.cpp.o 96043e32043d331c
13 8224 1680995993362222899 CMakeFiles/BeagleRescue.dir/src/game/Game.cpp.o 4ba02c1268a57ad0
5 3446 1665858096961659219 CMakeFiles/BeagleRescue.dir/libtmx-parser/src/tmxparser.cpp.o 15f574a728100366
4 1896 1680995987032160899 CMakeFiles/BeagleRescue.dir/src/cjson/cJSON.c.o 77f7fe5671dba050
5 4075 1680995989215515625 CMakeFiles/BeagleRescue.dir/src/assetmgr/TextureManager.cpp.o 811f88fdfc09263c
6990 7109 1680995071858552173 libtmx-parser/libs/tinyxml2/xmltest c7f1f4ebf26757c2
4036 6875 1680995071625216864 libtmx-parser/libs/tinyxml2/CMakeFiles/tinyxml2.dir/tinyxml2.cpp.o 660491a0c7495e62
1258 5876 1680995991015533256 CMakeFiles/BeagleRescue.dir/src/ui/UINineSlice.cpp.o 203c7ee19411f630
2059 8176 1680995072928561230 libtmx-parser/CMakeFiles/libtmxparser.dir/src/tmxparser.cpp.o ead5f95e0e72b1e0
4 794 1665858094311634671 CMakeFiles/BeagleRescue.dir/libtmx-parser/libs/tinyxml2/xmltest.cpp.o ee2e170a3bac274c
6978 6990 1680995071728551073 libtmx-parser/libs/tinyxml2/libtinyxml2.so d0fad9500a04c852
4 1088 1665858094604970721 CMakeFiles/BeagleRescue.dir/libtmx-parser/main.cpp.o 86331d80cf701d8d
13 638 1680995985768815183 CMakeFiles/BeagleRescue.dir/src/game/GameStateManager.cpp.o e18efa52ba3b4829
638 874 1680995986008817536 CMakeFiles/BeagleRescue.dir/src/game/StateMachine.cpp.o c995c41f2f407d79
5 3575 1680995988715510727 CMakeFiles/BeagleRescue.dir/src/assetmgr/MusicManager.cpp.o 743e525b8bc7e022
874 1829 1680995986968826945 CMakeFiles/BeagleRescue.dir/src/game/Vector2D.cpp.o d6bbbe0fad885aeb
6978 6990 1680995071728551073 libtmx-parser/libs/tinyxml2/libtinyxml2.so.2 d0fad9500a04c852
5127 6527 1680995071278547263 libtmx-parser/libs/tinyxml2/CMakeFiles/xmltest.dir/xmltest.cpp.o 88e42020838dcd8e
2957 4036 1680995068778526099 libtmx-parser/CMakeFiles/libtmxparser.dir/src/base64.cpp.o e84a5ef1b712902d
9777 9902 1680995074651909151 BeagleRescue e5cb768adc438473
4 4132 1680995989272182847 CMakeFiles/BeagleRescue.dir/src/assetmgr/GameObject.cpp.o ced4d92dc065c0bf
2 730 1681062043486327943 build.ninja bd959f8df49bfbdd
6 3453 1680995988588842819 CMakeFiles/BeagleRescue.dir/src/game/Collision.cpp.o d59bce856486c23e
6875 6978 1680995071728551073 libtmx-parser/libs/tinyxml2/libtinyxml2.so.2.2.0 8aed3caeabaa38d5
20 4401 1680995989538852126 CMakeFiles/BeagleRescue.dir/src/game/Main.cpp.o c1352eaae73a833f
4 2192 1665858095708314276 CMakeFiles/BeagleRescue.dir/libtmx-parser/libs/tinyxml2/tinyxml2.cpp.o 60acd5a4117a4833
4 2488 1681062059289774035 CMakeFiles/BeagleRescue.dir/src/assetmgr/MusicManager.cpp.o 743e525b8bc7e022
4 2608 1681062059413108248 CMakeFiles/BeagleRescue.dir/src/assetmgr/TextureManager.cpp.o 811f88fdfc09263c
4 2703 1681062059509775604 CMakeFiles/BeagleRescue.dir/src/game/Collision.cpp.o d59bce856486c23e
3 2706 1681062059513108961 CMakeFiles/BeagleRescue.dir/src/assetmgr/GameObject.cpp.o ced4d92dc065c0bf
5 2815 1681062059623109746 CMakeFiles/BeagleRescue.dir/src/game/Main.cpp.o c1352eaae73a833f
5 2962 1681062059769777459 CMakeFiles/BeagleRescue.dir/src/ui/UIText.cpp.o 2e1a08cbe2ad039c
5 3207 1681062060013112528 CMakeFiles/BeagleRescue.dir/src/ui/UINineSlice.cpp.o 203c7ee19411f630
3 3347 1681062060153113527 CMakeFiles/BeagleRescue.dir/src/assetmgr/AssetManager.cpp.o eb4c2e382e340f10
5 4194 1681062060999786234 CMakeFiles/BeagleRescue.dir/src/game/Game.cpp.o 4ba02c1268a57ad0
4194 4286 1681062061093120232 BeagleRescue e58e98489844e561
6 591 1681062457555937468 CMakeFiles/BeagleRescue.dir/src/game/GameStateManager.cpp.o e18efa52ba3b4829
591 742 1681062457719271959 CMakeFiles/BeagleRescue.dir/src/game/StateMachine.cpp.o c995c41f2f407d79
5 1761 1681062458725945758 CMakeFiles/BeagleRescue.dir/src/ecs/ECS.cpp.o 2b68ee632af548aa
3 1777 1681062458739279185 CMakeFiles/BeagleRescue.dir/src/cjson/cJSON.c.o 77f7fe5671dba050
742 1911 1681062458882613534 CMakeFiles/BeagleRescue.dir/src/game/Vector2D.cpp.o d6bbbe0fad885aeb
4 2480 1681062459459284286 CMakeFiles/BeagleRescue.dir/src/assetmgr/TextureManager.cpp.o 811f88fdfc09263c
4 2628 1681062459609285349 CMakeFiles/BeagleRescue.dir/src/assetmgr/MusicManager.cpp.o 743e525b8bc7e022
4 2658 1681062459635952204 CMakeFiles/BeagleRescue.dir/src/assetmgr/GameObject.cpp.o ced4d92dc065c0bf
5 2882 1681062459862620477 CMakeFiles/BeagleRescue.dir/src/game/Collision.cpp.o d59bce856486c23e
13 3065 1681062460045955109 CMakeFiles/BeagleRescue.dir/src/game/Main.cpp.o c1352eaae73a833f
3 3323 1681062460302623594 CMakeFiles/BeagleRescue.dir/src/assetmgr/AssetManager.cpp.o eb4c2e382e340f10
1777 4185 1681062461165963044 CMakeFiles/BeagleRescue.dir/src/ui/UIText.cpp.o 2e1a08cbe2ad039c
1761 4194 1681062461172629758 CMakeFiles/BeagleRescue.dir/src/ui/UINineSlice.cpp.o 203c7ee19411f630
5 4476 1681062461455965099 CMakeFiles/BeagleRescue.dir/src/game/Game.cpp.o 4ba02c1268a57ad0
4476 4568 1681062461545965736 BeagleRescue e58e98489844e561
6 3541 1689099824178728855 CMakeFiles/BeagleRescue.dir/src/assetmgr/GameObject.cpp.o ced4d92dc065c0bf
7 3541 1689099824178728855 CMakeFiles/BeagleRescue.dir/src/assetmgr/TextureManager.cpp.o 811f88fdfc09263c
7 3604 1689099824242062276 CMakeFiles/BeagleRescue.dir/src/assetmgr/MusicManager.cpp.o 743e525b8bc7e022
8 3817 1689099824455395905 CMakeFiles/BeagleRescue.dir/src/game/Main.cpp.o c1352eaae73a833f
7 3968 1689099824605396113 CMakeFiles/BeagleRescue.dir/src/game/Collision.cpp.o d59bce856486c23e
14 4213 1689099824852063121 CMakeFiles/BeagleRescue.dir/src/ui/UIText.cpp.o 2e1a08cbe2ad039c
6 4495 1689099825135396846 CMakeFiles/BeagleRescue.dir/src/assetmgr/AssetManager.cpp.o eb4c2e382e340f10
9 4558 1689099825195396929 CMakeFiles/BeagleRescue.dir/src/ui/UINineSlice.cpp.o 203c7ee19411f630

View File

@ -0,0 +1,27 @@
checkCollision(movingRect, moveVector, solidRect)
{
// Need to make additional similar checks for each side
if (moveVector.x > 0)
{
if (movingRect.xMax < solidRect.xMin &&
movingRect.xMax + moveVector.x > solidRect.xMin)
{
xHitRatio = (solidRect.xMin - moveingRect.xMax) / moveVector.x
}
}
// Also find hit ratio of y movement and see which one will hit first if either does.
if (xHitRatio < yHitRatio)
{
yHitPosMin = movingRect.yMin + moveVector.y * xHitRatio
yHitPosMax = movingRect.yMax + moveVector.y * xHitRatio
if (yHitPosMin < solidRect.yMax &&
yHitPosMax > solidRect.yMin)
{
// We know here now where we should collide, however if we stop here the collision will feel 'sticky'
// rather than just applying the ratio to the movement vector, we want to instead slide along the collision
output.x = movingRect.xOrigin + moveVector.x * xHitRatio
output.y = movingRect.yOrigin + moveVector.y // Here is where we should split off a new movement vector to check collision again really, since it is a new direction to check, so return the hit position with a new smaller vector to 'finish' the movement.
}
}
}

7
design/debug.txt Normal file
View File

@ -0,0 +1,7 @@
Collision Stats:
Player Center
x: 871
y: 690
ObjectCollider Center
x: 872
y: 696

BIN
src/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,70 @@
/*
* AssetManager.cpp
*
* Created on: Apr 4, 2020
* Author: ayoungblood
*/
#include "AssetManager.h"
#include "../ecs/Components.h"
#include "../ecs/ECS.h"
class Manager;
AssetManager::AssetManager(Manager* man) : manager(man)
{}
AssetManager::~AssetManager()
{}
// void AssetManager::CreateProjectile(Vector2D pos, Vector2D vel, int range, int speed, std::string id)
// {
// auto& projectile(manager->addEntity());
// projectile.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, 1);
// projectile.addComponent<SpriteComponent>(id);
// projectile.addComponent<ProjectileComponent>(range,speed,vel);
// projectile.addComponent<ColliderComponent>("projectile");
// projectile.addGroup(Game::groupProjectiles);
// ;}
//void AssetManager::CreateText(Vector2D pos, std::string textToDisplay, std::string id)
//{
// auto& text(manager->addEntity());
// text.addComponent<TransformComponent>(pos.x,pos.y,32,32,1);
//
// text.addGroup(Game::groupUI);
//}
void AssetManager::AddTexture(std::string id, const char* path)
{
textures.emplace(id, TextureManager::LoadTexture(path));
}
SDL_Texture* AssetManager::GetTexture(std::string id)
{
return textures[id];
}
//Sound Mixer
//Sound Clips
void AssetManager::AddSoundClip(std::string id, const char* path)
{
soundClips.emplace(id, MusicManager::LoadSound(path));
}
Mix_Chunk* AssetManager::GetSoundClip(std::string id)
{
return soundClips[id];
}
//Music
void AssetManager::AddMusicTrack(std::string id, const char* path)
{
musicTracks.emplace(id, MusicManager::LoadMusic(path));
}
Mix_Music* AssetManager::GetMusicTrack(std::string id)
{
return musicTracks[id];
}

View File

@ -0,0 +1,54 @@
/*
* AssetManager.h
*
* Created on: Apr 4, 2020
* Author: ayoungblood
*/
#ifndef SRC_ASSETMANAGER_H_
#define SRC_ASSETMANAGER_H_
#include <map>
#include <string>
#include "TextureManager.h"
#include "../game/Vector2D.h"
#include "../ecs/ECS.h"
#include "../game/Game.hpp"
#include "MusicManager.h"
class AssetManager
{
public:
AssetManager(Manager* man);
~AssetManager();
//gameobjects
// void CreateProjectile(Vector2D pos, Vector2D vel, int range, int speed, std::string id);
void CreateText(Vector2D pos, std::string textToDisplay, std::string id);
//texture management
void AddTexture(std::string id, const char* path);
SDL_Texture* GetTexture(std::string id);
//Sound Mixer
//Sound Clips
void AddSoundClip(std::string id, const char* path);
Mix_Chunk* GetSoundClip(std::string id);
//Music
void AddMusicTrack(std::string id, const char* path);
Mix_Music* GetMusicTrack(std::string id);
private:
Manager* manager;
std::map<std::string, SDL_Texture*> textures;
std::map<std::string, Mix_Chunk*> soundClips;
std::map<std::string, Mix_Music*> musicTracks;
};
#endif /* SRC_ASSETMANAGER_H_ */

View File

@ -0,0 +1,41 @@
/*
* GameObject.cpp
*
* Created on: Feb 11, 2020
* Author: ayoungblood
*/
#include "GameObject.h"
#include "TextureManager.h"
GameObject::GameObject(const char* texturesheet, int x, int y)
{
objTexture = TextureManager::LoadTexture(texturesheet);
xpos = x;
ypos = y;
}
void GameObject::Update()
{
xpos++;
// ypos = 0;
srcRect.h = 40;
srcRect.w = 30;
srcRect.x = 0;
srcRect.y = 0;
destRect.x = xpos;
destRect.y = ypos;
destRect.w = srcRect.w * 2;
destRect.h = srcRect.h * 2;
}
void GameObject::Render()
{
SDL_RenderCopy(Game::renderer, objTexture, &srcRect, &destRect);
}

34
src/assetmgr/GameObject.h Normal file
View File

@ -0,0 +1,34 @@
/*
* GameObject.h
*
* Created on: Feb 11, 2020
* Author: ayoungblood
*/
#ifndef SRC_GAMEOBJECT_H_
#define SRC_GAMEOBJECT_H_
#include "../game/Game.hpp"
class GameObject
{
public:
GameObject(const char* texturesheet, int x, int y);
~GameObject();
void Update();
void Render();
private:
int xpos;
int ypos;
SDL_Texture* objTexture;
SDL_Rect srcRect, destRect;
};
#endif /* SRC_GAMEOBJECT_H_ */

76
src/assetmgr/Map.cpp Normal file
View File

@ -0,0 +1,76 @@
/*
* Map.cpp
*
* Created on: Feb 13, 2020
* Author: ayoungblood
*/
#include "Map.h"
#include "../game/Game.hpp"
#include <fstream>
#include "../ecs/ECS.h"
#include "../ecs/Components.h"
#include <string>
#include <iostream>
extern Manager manager;
Map::Map(std::string tID, int ms, int ts) : texID(tID), mapScale(ms), tileSize(ts)
{
scaledSize = ms* ts;
width = 0;
height = 0;
tSize = ts;
}
Map::~Map()
{
}
void Map::LoadMap(std::string path, int sizeX, int sizeY, int scale)
{
char c;
std::fstream mapFile;
mapFile.open(path);
int srcX, srcY;
width = tSize*scale*sizeX;
height = tSize*scale*sizeY;
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
mapFile.get(c);
srcY = atoi(&c) * tileSize;
mapFile.get(c);
srcX = atoi(&c) * tileSize;
mapFile.ignore(2,',');
}
}
mapFile.ignore();
// colliders
for (int y =0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
mapFile.get(c);
if (c == '1')
{
auto& tcol(manager.addEntity());
tcol.addComponent<ColliderComponent>("terrain",x*scaledSize,y*scaledSize,tileSize,scale,texID);
tcol.addGroup(Game::groupColliders);
}
mapFile.ignore(2,',');
}
}
mapFile.close();
}
void Map::AddTile(int srcX, int srcY, int xpos, int ypos)
{
auto& tile(manager.addEntity());
tile.addComponent<TileComponent>(srcX,srcY,xpos,ypos,tileSize, mapScale, texID);
tile.addGroup(Game::groupMap);
}

33
src/assetmgr/Map.h Normal file
View File

@ -0,0 +1,33 @@
/*
* Map.h
*
* Created on: Feb 13, 2020
* Author: ayoungblood
*/
#ifndef SRC_MAP_H_
#define SRC_MAP_H_
#include <string>
class Map
{
public:
Map(std::string tID, int ms, int ts);
~Map();
void LoadMap(std::string path, int sizeX, int sizeY, int scale);
void AddTile(int srcX, int srcY, int xpos, int ypos);
int width;
int height;
int tSize;
private:
std::string texID;
int mapScale;
int tileSize;
int scaledSize;
};
#endif /* SRC_MAP_H_ */

View File

@ -0,0 +1,26 @@
/*
* MusicManager.cpp
*
* Created on: Apr 9, 2020
* Author: ayoungblood
*/
#include "MusicManager.h"
#include <SDL_mixer.h>
Mix_Music* MusicManager::LoadMusic(const char* path){
Mix_Music* music = Mix_LoadMUS(path);
return music;
}
Mix_Chunk* MusicManager::LoadSound(const char* path){
Mix_Chunk* sfx = Mix_LoadWAV(path);
return sfx;
}
void Play(Mix_Music* music, int replay)
{
}
void Pause(Mix_Music* music){}
void Stop(Mix_Music* music){}

View File

@ -0,0 +1,25 @@
/*
* MusicManager.h
*
* Created on: Apr 9, 2020
* Author: ayoungblood
*/
#ifndef SRC_MUSICMANAGER_H_
#define SRC_MUSICMANAGER_H_
#include "../game/Game.hpp"
#include <SDL_mixer.h>
class MusicManager
{
public:
static Mix_Music* LoadMusic(const char* path);
static void Play(Mix_Music* music);
static void Pause(Mix_Music* music);
static void Stop(Mix_Music* music);
static Mix_Chunk* LoadSound(const char* path);
};
#endif /* SRC_MUSICMANAGER_H_ */

View File

@ -0,0 +1,34 @@
/*
* TextureManager.cpp
*
* Created on: Feb 11, 2020
* Author: ayoungblood
*/
#include "TextureManager.h"
SDL_Texture* TextureManager::LoadTexture(const char* texture)
{
SDL_Surface* tempSurface = IMG_Load(texture);
SDL_Texture* tex = SDL_CreateTextureFromSurface(Game::renderer, tempSurface);
SDL_FreeSurface(tempSurface);
return tex;
}
void TextureManager::Draw(SDL_Texture* tex, SDL_Rect src, SDL_Rect dest, SDL_RendererFlip flip)
{
SDL_RenderCopyEx(Game::renderer, tex, &src, &dest, NULL, NULL, flip);
}
void TextureManager::DrawCollider(SDL_Rect colliderRect)
{
Vector2D pt1, pt2, pt3, pt4;
pt1 = Vector2D(colliderRect.x,colliderRect.y);
pt2 = Vector2D(colliderRect.w-2,colliderRect.y);
pt3 = Vector2D(colliderRect.x,colliderRect.h-2);
pt4 = Vector2D(colliderRect.w-2,colliderRect.h-2);
Game::drawLine(pt1,pt2,255,0,255);
Game::drawLine(pt1,pt3,255,255,0);
Game::drawLine(pt2,pt4,0,0,255);
Game::drawLine(pt3,pt4,0,255,0);
}

View File

@ -0,0 +1,21 @@
/*
* TextureManager.h
*
* Created on: Feb 11, 2020
* Author: ayoungblood
*/
#ifndef SRC_TEXTUREMANAGER_H_
#define SRC_TEXTUREMANAGER_H_
#include "../game/Game.hpp"
class TextureManager
{
public:
static SDL_Texture* LoadTexture(const char* fileName);
static void Draw(SDL_Texture* tex, SDL_Rect src, SDL_Rect dest, SDL_RendererFlip flip);
static void DrawCollider(SDL_Rect colliderRect);
};
#endif /* SRC_TEXTUREMANAGER_H_ */

3096
src/cjson/cJSON.c Normal file

File diff suppressed because it is too large Load Diff

293
src/cjson/cJSON.h Normal file
View File

@ -0,0 +1,293 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 14
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif

7
src/config/config.json Normal file
View File

@ -0,0 +1,7 @@
{
"GameName":"Kaiju Save Earth",
"WindowName":"Kaiju Save Earth",
"WindowSize":{"w":64,"h":64},
"WindowFullScreen": 0,
"GlobalScale": 10
}

6
src/config/credits.json Normal file
View File

@ -0,0 +1,6 @@
{
"GameName": "Kaiju Save Earth",
"Developers": "Alan Youngblood",
"LibraryDevelopers": "Sam Lantinga, Dave Gamble, Carl Birch, Job Vranish, David Lafreniere, Bayle Jonathan, Robin Berg Pettersen, Beman Dawes, Andrey Semashev",
"SpecialThanks": "Nic Allen, Brian Lhota, Rodrigo Monteiro"
}

7
src/config/intro.json Normal file
View File

@ -0,0 +1,7 @@
{
"intro": {
"1": "IN THE YEAR\n23YY ...\nHUMAN\nPARANOIA\nRUNS WILD\nCONSUMED\nBY FEAR\nAND GREED",
"2": "THEY DESTROY\nEACH OTHER\nAND EARTH\nWHO CAN\nSAVE THEM?\n",
"3": "SURELY NOT\nANOTHER\nHUMAN?!?\nPERHAPS\nONLY A\nGREATER\nMONSTER..."
}
}

28
src/ecs/Animation.h Normal file
View File

@ -0,0 +1,28 @@
/*
* Animation.h
*
* Created on: Mar 27, 2020
* Author: ayoungblood
*/
#ifndef SRC_ECS_ANIMATION_H_
#define SRC_ECS_ANIMATION_H_
struct Animation
{
int index;
int frames;
int speed;
Animation() {}
Animation(int i, int f, int s)
{
index = i;
frames = f;
speed = s;
}
};
#endif /* SRC_ECS_ANIMATION_H_ */

129
src/ecs/ColliderComponent.h Normal file
View File

@ -0,0 +1,129 @@
/*
* ColliderComponent.h
*
* Created on: Mar 8, 2020
* Author: ayoungblood
*/
#ifndef SRC_ECS_COLLIDERCOMPONENT_H_
#define SRC_ECS_COLLIDERCOMPONENT_H_
#include <string>
#include <SDL.h>
#include "Components.h"
#include "ECS.h"
#include "../assetmgr/TextureManager.h"
#include <iostream>
#include "../game/Vector2D.h"
class ColliderComponent : public Component
{
public:
SDL_Rect collider;
std::string tag;
SDL_Texture* tex;
SDL_Rect srcR, destR;
int offsetX = 0;
int offsetY = 0;
bool hidden = true;
Vector2D center;
TransformComponent* transform;
ColliderComponent()
{
center.Zero();
}
ColliderComponent(std::string t)
{
tag = t;
}
ColliderComponent(std::string t, int xpos, int ypos, int size, int scale, std::string texture)
{
tag = t;
collider.x = xpos;
collider.y = ypos;
collider.w = collider.h = size*scale;
if(texture != ""){
setTex(texture);
}
center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2;
}
ColliderComponent(std::string t, int width, int height, bool hasOffset, int oX, int oY, std::string texture)
{
tag = t;
collider.w = width;
collider.h = height;
offsetX = oX;
offsetY = oY;
if(texture != ""){
setTex(texture);
}
center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2;
}
void init() override
{
if (!entity->hasComponent<TransformComponent>())
{
entity->addComponent<TransformComponent>();
}
transform = &entity->getComponent<TransformComponent>();
collider.x = collider.x + offsetX;
collider.y = collider.y + offsetX;
tex = TextureManager::LoadTexture("assets/ColTex.png");
srcR = { 0, 0, 16, 16};
destR = { collider.x, collider.y, collider.w, collider.h };
}
void update() override
{
if(tag != "terrain")
{
collider.x = static_cast<int>(transform->position.x+offsetX);
collider.y = static_cast<int>(transform->position.y+offsetY);
}
destR.x = collider.x - Game::camera.x;
destR.y = collider.y - Game::camera.y;
center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2;
// collider.x = transform->position.x;
// collider.y = transform->position.y;
}
void draw() override
{
// if(tag == "terrain")
// {
// TextureManager::Draw(tex, srcR, destR, SDL_FLIP_NONE);
// }
if(hidden == false)
{
// TextureManager::Draw(tex, srcR,destR,SDL_FLIP_NONE);
SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
SDL_RenderDrawRect(Game::renderer, &destR);
// SDL_RenderDrawPoint(Game::renderer, center.x, center.y);
}
}
void setTex(std::string id)
{
tex = Game::assets->GetTexture(id);
}
};
#endif /* SRC_ECS_COLLIDERCOMPONENT_H_ */

22
src/ecs/Components.h Normal file
View File

@ -0,0 +1,22 @@
/*
* Components.h
*
* Created on: Feb 21, 2020
* Author: ayoungblood
*/
#ifndef SRC_COMPONENTS_H_
#define SRC_COMPONENTS_H_
#include "ECS.h"
#include "TransformComponent.h"
#include "SpriteComponent.h"
#include "KeyboardController.h"
#include "ColliderComponent.h"
#include "PlayerController.h"
#include "ProjectileComponent.h"
#include "TileComponent.h"
#include "TileMapComponent.h"
#include "UITextComponent.h"
#endif /* SRC_COMPONENTS_H_ */

19
src/ecs/ECS.cpp Normal file
View File

@ -0,0 +1,19 @@
/*
* ECS.cpp
*
* Created on: Mar 24, 2020
* Author: ayoungblood
*/
#include "ECS.h"
void Entity::addGroup(Group mGroup)
{
groupBitset[mGroup] = true;
manager.AddToGroup(this, mGroup);
}
void Entity::setTag(std::string t)
{
this->tag = t;
}

200
src/ecs/ECS.h Normal file
View File

@ -0,0 +1,200 @@
/*
* ECS.h
*
* Created on: Feb 21, 2020
* Author: ayoungblood
*/
#ifndef SRC_ECS_H_
#define SRC_ECS_H_
#include <iostream>
#include <vector>
#include <memory>
#include <algorithm>
#include <bitset>
#include <array>
class Component;
class Entity;
class Manager;
using ComponentID = std::size_t;
using Group = std::size_t;
inline ComponentID getNewComponentTypeID()
{
static ComponentID lastID = 0u;
return lastID++;
}
template <typename T> inline ComponentID getComponentTypeID() noexcept
{
static_assert (std::is_base_of<Component, T>::value, "");
static ComponentID typeID = getNewComponentTypeID();
return typeID;
}
constexpr std::size_t maxComponents = 32;
constexpr std::size_t maxGroups = 32;
constexpr std::size_t maxEntities = 32;
using ComponentBitSet = std::bitset<maxComponents>;
using GroupBitset = std::bitset<maxGroups>;
using ComponentArray = std::array<Component*, maxComponents>;
class Component
{
public:
Entity* entity;
virtual void init() {}
virtual void update() {}
virtual void draw() {}
virtual ~Component() {}
};
class Entity
{
private:
Manager& manager;
bool active = true;
std::vector<std::unique_ptr<Component>> components;
ComponentArray componentArray;
ComponentBitSet componentBitSet;
GroupBitset groupBitset;
public:
Entity(Manager& mManager) : manager(mManager) {}
void update()
{
for(auto& c : components) c->update();
}
void draw()
{
for(auto& c : components) c->draw();
}
bool isActive() const { return active; }
void destroy() { active = false; }
bool hasGroup(Group mGroup)
{
return groupBitset[mGroup];
}
void addGroup(Group mGroup);
void delGroup(Group mGroup)
{
groupBitset[mGroup] = false;
}
std::string tag;
void setTag(std::string t);
Entity* getEntity()
{
return this;
}
template <typename T> bool hasComponent() const
{
return componentBitSet[getComponentTypeID<T>()];
}
template <typename T, typename... TArgs>
T& addComponent(TArgs&&... mArgs)
{
T* c(new T(std::forward<TArgs>(mArgs)...));
c->entity = this;
std::unique_ptr<Component> uPtr{ c };
components.emplace_back(std::move(uPtr));
componentArray[getComponentTypeID<T>()] = c;
componentBitSet[getComponentTypeID<T>()] = true;
c->init();
return *c;
}
template<typename T> T& getComponent() const
{
auto ptr(componentArray[getComponentTypeID<T>()]);
return *static_cast<T*>(ptr);
}
};
class Manager
{
private:
std::vector<std::unique_ptr<Entity>> entities;
std::array<std::vector<Entity*>, maxGroups> groupedEntities;
std::vector<std::vector<Entity*>> taggedEntities;
public:
void update()
{
for (auto& e : entities) e->update();
}
void draw()
{
for (auto& e : entities) e->draw();
}
void refresh()
{
for (auto i(0u); i < maxGroups; i++)
{
auto& v(groupedEntities[i]);
v.erase(
std::remove_if(std::begin(v), std::end(v),
[i](Entity* mEntity)
{
return !mEntity->isActive() || !mEntity->hasGroup(i);
}),
std::end(v));
}
entities.erase(std::remove_if(std::begin(entities), std::end(entities),
[](const std::unique_ptr<Entity> &mEntity)
{
return !mEntity->isActive();
}),
std::end(entities));
}
void AddToGroup(Entity* mEntity, Group mGroup)
{
groupedEntities[mGroup].emplace_back(mEntity);
}
std::vector<Entity*> getEntitiesByTag(std::string t)
{
std::vector<Entity*> taggedEntities;
for (int e = 0; e<=entities.size(); e++)
{
if (entities[e]->tag == t)
{
taggedEntities.emplace_back(entities[e]->getEntity());
}
}
return taggedEntities;
}
std::vector<Entity*>& getGroup(Group mGroup)
{
return groupedEntities[mGroup];
}
Entity& addEntity()
{
Entity* e = new Entity(*this);
std::unique_ptr<Entity> uPtr{ e };
entities.emplace_back(std::move(uPtr));
return *e;
}
};
#endif /* SRC_ECS_H_ */

View File

@ -0,0 +1,281 @@
/*
* KeyboardController.h
*
* Created on: Mar 1, 2020
* Author: ayoungblood
*/
#ifndef SRC_ECS_KEYBOARDCONTROLLER_H_
#define SRC_ECS_KEYBOARDCONTROLLER_H_
#include "../game/Game.hpp"
#include "ECS.h"
#include "Components.h"
#include "PlayerController.h"
#include "../assetmgr/AssetManager.h"
#include "ColliderComponent.h"
#include <cmath>
// #include "../game/Vector2D.h"
class KeyboardController : public Component
{
public:
TransformComponent *transform;
SpriteComponent *sprite;
PlayerController *playerCtrl;
ColliderComponent *collider;
Game *game;
void init() override
{
transform = &entity->getComponent<TransformComponent>();
sprite = &entity->getComponent<SpriteComponent>();
// collider = &entity->getComponent<ColliderComponent>();
// playerCtrl = &entity->getComponent<PlayerController>();
}
void update() override
{
if (Game::event.type == SDL_KEYDOWN)
{
switch (Game::event.key.keysym.sym)
{
case SDLK_w:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
// if(transform->position.y>0){
// ====== Get Player.yTile and scan column up ScreenTilesHeight/2 on Player.xTile-1, Player.xTile, and Player.xTile+1 return first hit that is > 0 for each row.
// transform->tilePos.x
transform->velocity.y = -1;
// if(Game::playerIsGrounded){
sprite->Play("move-n");
// }
sprite->spriteFlip = SDL_FLIP_NONE;
// }
}
break;
case SDLK_s:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
if(transform->position.y<Game::levelMap.h){
transform->velocity.y = 1;
// if(Game::playerIsGrounded){
sprite->Play("move-s");
// }
int *borders;
borders = Game::predictCollisions();
sprite->spriteFlip = SDL_FLIP_NONE;
}
}
break;
case SDLK_a:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
if(transform->position.x>Game::levelMap.x){
transform->velocity.x = -1;
// if(Game::playerIsGrounded){
sprite->Play("move-w");
// }
sprite->spriteFlip = SDL_FLIP_NONE;
}
// if (playerCtrl == NULL){
// printf("No player controller found\n");
// } else {
// printf("playerctrl.lastsafepos .x: %g .y: %g \n",playerCtrl->lastSafePosition.x,playerCtrl->lastSafePosition.y);
// playerCtrl->lastSafePosition.x = transform->position.x;
// }
// transform->lastSafePos = Vector2D(transform->position.x,transform->position.y);
// printf("lastSafePos .x: %g .y: %g \n",transform->lastSafePos.x,transform->lastSafePos.y);
// Game::pTileX
// if(transform->position.x>0){
/*int *borders;
borders = Game::predictCollisions();
float max = borders[0];
for (int b=0;b<3;b++){
if (borders[b]>max){
max = borders[b];
}
}
float desiredMovement = -1*transform->speed*0.016; // 0.016 is the FrameTime from the Main.cpp core game loop. later, we will pass in the variable
float difference = std::abs(max-transform->position.x);
if(max*transform->scale<desiredMovement+transform->position.x){
Game::playerIsGrounded = false;
transform->velocity.x = -1;
sprite->Play("Walk");
sprite->spriteFlip = SDL_FLIP_NONE;
}else{
// transform->velocity.x = -difference/desiredMovement;
Game::playerIsGrounded = true;
transform->velocity.x = 0;
sprite->Play("Idle");
sprite->spriteFlip = SDL_FLIP_NONE;
}*/
}
break;
case SDLK_d:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
// &entity->getComponent<PlayerController>().setLastSafePos(Vector2D(transform->position.x,transform->position.y));
// playerCtrl->lastSafePosition.x = transform->position.x;
// transform->lastSafePos = Vector2D(transform->position.x,transform->position.y);
// =========
// Do a pre-check for tile-based smooth algorithm
// =========
// int intersectionTileX = collider->center.x;
if(transform->position.x<Game::levelMap.w){
transform->velocity.x = 1;
// if(Game::playerIsGrounded){
sprite->Play("move-w");
// }
sprite->spriteFlip = SDL_FLIP_HORIZONTAL;
}
}
break;
// case SDLK_a:
// if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
// transform->velocity.x = -1;
// if(Game::playerIsGrounded){
// sprite->Play("Walk");
// }
// sprite->spriteFlip = SDL_FLIP_NONE;
// }
// break;
// case SDLK_d:
// if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
// transform->velocity.x = 1;
// if(Game::playerIsGrounded){
// sprite->Play("Walk");
// }
// sprite->spriteFlip = SDL_FLIP_HORIZONTAL;
// }
// break;
case SDLK_k:
if (!Game::debugCollisionBoxes)
{ Game::debugCollisionBoxes = true; }
else
{Game::debugCollisionBoxes = false; }
if (!Game::debugMenu)
{ Game::debugMenu = true; }
else
{ Game::debugMenu = false; }
break;
case SDLK_j:
if(Game::playerIsGrounded){
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
if (Mix_PlayChannel(-1, Game::assets->GetSoundClip("bwoop"),0) == 0)
{
Mix_PlayChannel(-1, Game::assets->GetSoundClip("bwoop"),0);
}
// transform->lastSafePos = Vector2D(transform->position.x,transform->position.y);
Game::gravityOnPlayer = true;
// sprite->Play("Jump");
transform->velocity.y = -2;
}
}
break;
case SDLK_u:
Game::gsm->AdvanceState();
break;
case SDLK_i:
Game::gsm->GameOver();
break;
default:
break;
}
}
// ===============================================
// ON KEY UP
// ===============================================
else if (Game::event.type == SDL_KEYUP)
{
switch (Game::event.key.keysym.sym)
{
case SDLK_a:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.x = 0;
sprite->Play("move-w");
Game::playerIsGrounded = false;
// if (!Game::gravityOnPlayer){
// Game::gravityOnPlayer = true;
// // sprite->Play("Fall");
// }
}
break;
case SDLK_d:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.x = 0;
sprite->Play("move-w");
// if (!Game::gravityOnPlayer){
// Game::gravityOnPlayer = true;
// }
}
break;
case SDLK_w:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.y = 0;
sprite->Play("move-n");
// if (!Game::gravityOnPlayer){
// Game::gravityOnPlayer = true;
// // sprite->Play("Fall");
// }
}
break;
case SDLK_s:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.y = 0;
sprite->Play("move-s");
// if (!Game::gravityOnPlayer){
// Game::gravityOnPlayer = true;
// }
}
break;
// case SDLK_a:
// if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
// transform->velocity.x = 0;
// sprite->Play("Idle");
// if (!Game::gravityOnPlayer){
// Game::gravityOnPlayer = true;
// // sprite->Play("Fall");
// }
// }
// break;
// case SDLK_d:
// if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
// transform->velocity.x = 0;
// sprite->Play("Idle");
// if (!Game::gravityOnPlayer){
// Game::gravityOnPlayer = true;
// }
// }
// break;
case SDLK_k:
break;
// case SDLK_j:
// if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
// transform->velocity.y = 0;
// sprite->Play("Fall");
// Game::gravityOnPlayer = true;
// }
// break;
case SDLK_u:
break;
case SDLK_i:
break;
// case SDLK_d:
// if (Game::debugMenu == false){
// Game::debugMenu = true;}
// else {
// Game::debugMenu = false;
// }
// break;
case SDLK_ESCAPE: // exit the game when Escape pressed
Game::isRunning = false;
break;
default:
break;
}
}
}
};
#endif /* SRC_ECS_KEYBOARDCONTROLLER_H_ */

View File

@ -0,0 +1,77 @@
/*
* PlayerController.h
*
* Created on: Aug 27, 2021
* Author: ayoungblood
*/
#ifndef SRC_ECS_PlayerController_H_
#define SRC_ECS_PlayerController_H_
#include "Components.h"
#include "../game/Vector2D.h"
class PlayerController : public Component
{
public:
Vector2D lastSafePosition;
float jumpTime;
float jumpForce;
bool isJumping;
bool isGrounded;
PlayerController()
{
jumpTime = 0.0f;
jumpForce = 0.0f;
bool isJumping = false;
bool isGrounded = false;
lastSafePosition = Vector2D();
}
PlayerController(float jumpT, float jumpF, bool jumping, bool grounded, Vector2D lastPos)
{
jumpTime = jumpT;
jumpForce = jumpF;
bool isJumping = jumping;
bool isGrounded = grounded;
lastSafePosition = lastPos;
}
~PlayerController()
{
}
void init() override
{
lastSafePosition.Zero();
}
void update() override
{
}
void setLastSafePos(Vector2D prevSafePos)
{
lastSafePosition = prevSafePos;
}
// void init() override
// {
//
// }
};
#endif /* SRC_ECS_PlayerController_H_ */

View File

@ -0,0 +1,57 @@
/*
* Projectile.h
*
* Created on: Apr 4, 2020
* Author: ayoungblood
*/
#ifndef SRC_ECS_PROJECTILECOMPONENT_H_
#define SRC_ECS_PROJECTILECOMPONENT_H_
#include "ECS.h"
#include "Components.h"
#include "../game/Vector2D.h"
class ProjectileComponent : public Component
{
public:
ProjectileComponent(int rng, int sp, Vector2D vel) : range(rng), speed(sp), velocity(vel)
{}
~ProjectileComponent()
{}
void init() override
{
transform = &entity->getComponent<TransformComponent>();
transform->velocity = velocity;
}
void update() override
{
distance += speed;
if (distance > range)
{
entity->destroy();
}
else if (transform->position.x > Game::camera.x + Game::camera.w ||
transform->position.x < Game::camera.x ||
transform->position.y > Game::camera.y +Game::camera.h ||
transform->position.y < Game::camera.y)
{
entity->destroy();
}
}
private:
TransformComponent* transform;
int range;
int speed;
int distance;
Vector2D velocity;
};
#endif /* SRC_ECS_PROJECTILECOMPONENT_H_ */

218
src/ecs/SpriteComponent.h Normal file
View File

@ -0,0 +1,218 @@
/*
* SpriteComponent.h
*
* Created on: Feb 22, 2020
* Author: ayoungblood
*/
#ifndef SRC_ECS_SPRITECOMPONENT_H_
#define SRC_ECS_SPRITECOMPONENT_H_
#include "Components.h"
#include <SDL.h>
#include "../assetmgr/TextureManager.h"
#include "Animation.h"
#include <map>
#include "../assetmgr/AssetManager.h"
#include "../cjson/cJSON.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <string>
class SpriteComponent : public Component
{
private:
TransformComponent *transform;
SDL_Texture *texture;
SDL_Rect srcRect, destRect;
int frames = 0;
int speed = 100;
int scale = 1;
public:
enum SpriteType : std::size_t
{
spriteUIL0,
spriteUIL1,
spriteText,
spriteObject,
spriteTileMap,
spriteBackground,
spriteActor,
spriteAnimation,
spriteAtlas
};
SpriteType spriteType;
int animIndex = 0;
bool ui = false;
std::map<const char*, Animation> animations;
SDL_RendererFlip spriteFlip = SDL_FLIP_NONE;
// SpriteComponent() = default;
SpriteComponent(std::string id, SpriteType sType)
{
spriteType = sType;
setTex(id);
}
// One initializer to rule them all
SpriteComponent(std::string id, SpriteType sType, std::string json)
{
spriteType = sType;
if(sType == spriteAnimation)
{
//std::string fullPath = Game::projPath + json;
std::ifstream fin(json);
if(fin.fail()){
std::cerr<<"ERROR opening json file: " << json << std::endl;
} else if (fin.is_open()){
//printf("Opened a json file\n");
std::ifstream jsonText(json);
std::ostringstream tmp;
tmp << jsonText.rdbuf();
std::string aJson = tmp.str();
cJSON * animJson = cJSON_Parse(aJson.c_str());
std::cout << "animJson: " << std::endl;
std::cout << animJson << std::endl;
char * printOut = cJSON_Print(animJson);
//std::cout << animJson << std::endl;
cJSON * meta = cJSON_GetObjectItem(animJson, "meta");
cJSON * version = cJSON_GetObjectItem(animJson, "version");
cJSON * frameTags = cJSON_GetObjectItem(meta,"frameTags");
cJSON * frames = cJSON_GetObjectItem(animJson, "frames");
int tagsCount = cJSON_GetArraySize(frameTags);
int framesCount = cJSON_GetArraySize(frames);
//std::cout << "tagsCount: " << tagsCount << std::endl;
//std::cout << "version: " << version << std::endl;
const cJSON * aFrame = NULL;
const cJSON * aFrames = NULL;
aFrames =cJSON_GetObjectItemCaseSensitive(animJson, "frames");
cJSON_ArrayForEach(aFrame, aFrames){
cJSON *filename = cJSON_GetObjectItemCaseSensitive(aFrame, "filename");
if (!cJSON_IsNumber(aFrame)){
//printf("Not a number\n");
//printf("Json filename: %s\n",filename);
} else {
//std::cout << "animation frame number: " << aFrame->valueint<< std::endl;
}
}
for (int f = 0; f<framesCount; f++){
cJSON * crrntFrame = cJSON_GetArrayItem(frames, f);
std::string fileName = cJSON_GetObjectItem(crrntFrame, "filename")->valuestring;
std::cout << "Filename for frame is: " << fileName << std::endl;
}
for (int t = 0; t < tagsCount; t++)
{
cJSON * animItem = cJSON_GetArrayItem(frameTags,t);
cJSON * nameJson = cJSON_GetObjectItem(animItem, "name");
const char * name = cJSON_Print(nameJson);
int fromFrame = cJSON_GetObjectItem(animItem, "from")->valueint;
int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint;
Animation anim = Animation(fromFrame,toFrame,100);
animations.emplace(name, anim);
std::cout << "Animation Name: " << name << "from: " << fromFrame << "to: " << toFrame << std::endl;
Play(name);
}
}
Animation moveN = Animation(0,1,100);
animations.emplace("move-n", moveN);
Animation moveW = Animation(2,1,100);
animations.emplace("move-w", moveW);
Animation moveS = Animation(4,1,100);
animations.emplace("move-s", moveS);
//Animation fall = Animation(3,1,100);
//animations.emplace("Fall",fall);
Play("move-n");
}
setTex(id);
}
SpriteComponent(std::string id, SpriteType sType, SDL_Rect srcR, SDL_Rect destR)
{
spriteType = sType;
setTex(id);
srcRect = srcR;
destRect = destR;
}
~SpriteComponent()
{
SDL_DestroyTexture(texture);
}
void setTex(std::string id)
{
texture = Game::assets->GetTexture(id);
}
void init() override
{
transform = &entity->getComponent<TransformComponent>();
switch(spriteType)
{
case spriteUIL0: case spriteUIL1: case spriteBackground:
break;
case spriteActor: case spriteAnimation: case spriteAtlas: case spriteObject: case spriteTileMap:
srcRect.x = srcRect.y = 0;
srcRect.w = transform->width;
srcRect.h = transform->height;
break;
default:
break;
}
}
void update() override
{
switch(spriteType)
{
case spriteUIL0: case spriteUIL1: case spriteText: case spriteBackground:
destRect.x = static_cast<int>(transform->position.x);
destRect.y = static_cast<int>(transform->position.y);
break;
case spriteActor: case spriteObject: case spriteAtlas:
srcRect.y = animIndex * transform->height;
destRect.x = static_cast<int>(transform->position.x) - Game::camera.x;
destRect.y = static_cast<int>(transform->position.y) - Game::camera.y;
destRect.w = transform->width * transform->scale;
destRect.h = transform->height * transform->scale;
break;
case spriteTileMap:
break;
case spriteAnimation:
srcRect.x = srcRect.w * static_cast<int>((SDL_GetTicks()/speed) % frames);
srcRect.y = animIndex * transform->height;
destRect.x = static_cast<int>(transform->position.x) - Game::camera.x;
destRect.y = static_cast<int>(transform->position.y) - Game::camera.y;
destRect.w = transform->width * transform->scale;
destRect.h = transform->height * transform->scale;
break;
default:
break;
}
}
void draw() override
{
TextureManager::Draw(texture, srcRect, destRect, spriteFlip);
}
void Play(const char* animName)
{
frames = animations[animName].frames;
animIndex = animations[animName].index;
speed = animations[animName].speed;
}
};
#endif /* SRC_ECS_SPRITECOMPONENT_H_ */

58
src/ecs/TileComponent.h Normal file
View File

@ -0,0 +1,58 @@
/*
* TileComponent.h
*
* Created on: Mar 21, 2020
* Author: ayoungblood
*/
#ifndef SRC_ECS_TILECOMPONENT_H_
#define SRC_ECS_TILECOMPONENT_H_
#include "ECS.h"
#include <SDL.h>
#include "../assetmgr/AssetManager.h"
class TileComponent : public Component
{
public:
SDL_Texture* texture;
SDL_Rect srcRect, destRect;
Vector2D position;
TileComponent() = default;
~TileComponent()
{
SDL_DestroyTexture(texture);
}
TileComponent(int srcX, int srcY, int xpos, int ypos, int tsize, int tscale, std::string id)
{
texture = Game::assets->GetTexture(id);
position.x = xpos;
position.y = ypos;
srcRect.x = srcX;
srcRect.y = srcY;
srcRect.w = srcRect.h = tsize;
destRect.x = xpos;
destRect.y = ypos;
destRect.w = destRect.h = tsize * tscale;
}
void update() override
{
destRect.x = position.x - Game::camera.x;
destRect.y = position.y - Game::camera.y;
}
void draw() override
{
TextureManager::Draw(texture, srcRect, destRect, SDL_FLIP_NONE);
}
};
#endif /* SRC_ECS_TILECOMPONENT_H_ */

177
src/ecs/TileMapComponent.h Normal file
View File

@ -0,0 +1,177 @@
/*
*
* TileMapComponent.h
*
* Created on: Mar 21, 2020
* Author: ayoungblood
*/
#ifndef SRC_ECS_TILEMAPCOMPONENT_H_
#define SRC_ECS_TILEMAPCOMPONENT_H_
#include "ECS.h"
#include <SDL.h>
#include "../assetmgr/AssetManager.h"
#include <fstream>
#include <iostream>
#include <string>
#include <tuple>
#include "../tileson/tileson.hpp"
class TileMapComponent : public Component
{
public:
SDL_Texture* texture;
SDL_Rect srcRect, destRect;
tson::Tileson t;
std::unique_ptr<tson::Map> map;
int globalScale;
std::vector<SDL_Rect> tileSet;
std::vector<SDL_Rect> destRects;
std::vector<std::tuple<int,int>> initialPositions;
int tileSetTotal;
std::vector<std::vector<int>> colliders;
int tilesWide;
int tilesHigh;
int tileWidth;
TileMapComponent() = default;
~TileMapComponent()
{
SDL_DestroyTexture(texture);
}
TileMapComponent(std::string mapPath, std::string tsName, std::string tileLayerName, std::string collisionLayerName, int gScale, int offsetX, int offsetY)
{
// TILESON ~~~~~~~~~~~
const std::filesystem::path jsonPath = std::filesystem::u8path(mapPath);
//const std::filesystem::path jsonPath = std::filesystem::u8path("/Users/ayoungblood/Projects/KaijuSaveEarth/assets/maps/kaiju-city-map.json");
map = t.parse(jsonPath);
//std::cout << "Trying to load json tile map from: " << jsonPath << std::endl;
if(map->getStatus() == tson::ParseStatus::OK)
{
// printf("Map File Loaded!! \n");
tson::Tileset *tileset = map->getTileset(tsName);
//std::cout << "tsName: " << tsName << std::endl;
std::string fullPath = tileset->getImage();
//std::cout << "fullPath: " << fullPath << std::endl;
//size_t charPos = fullPath.find("assets");
//fullPath.erase(0,charPos);
std::string prependPath = std::string("assets/maps/");
std::string localPath = prependPath + fullPath;
std::string wholePath = "/Users/ayoungblood/Projects/KaijuSaveEarth/" + localPath;
//std::cout << "fullPath: " << wholePath << std::endl;
tson::Layer *tileLayer = map->getLayer(tileLayerName); //This is a Layer
std::string texName = tileLayer->getName();
Game::assets->AddTexture(texName, wholePath.c_str());
setTex(texName);
globalScale = gScale;
//printf("Added texture for tilemap.\n");
tson::Layer *collisionLayer = map->getLayer(collisionLayerName);
tilesWide = map->getSize().x;
tilesHigh = map->getSize().y;
tileWidth = map->getTileSize().x;
Game::levelMap.w = tilesWide*tileWidth*globalScale;
Game::levelMap.h = tilesHigh*tileWidth*globalScale;
// printf("First phase tile map init done, moving to Tileset\n");
// =========== Setup Tile Set ===========
tileSetTotal = tileset->getTileCount();
tileSet.resize(tileSetTotal);
int tileSetCols = tileset->getColumns();
int tileSetRows = tileSetTotal/tileSetCols;
for (int r=0;r<tileSetRows;r++){
for (int c=0;c<tileSetCols;c++){
srcRect.x = c*tileWidth;
srcRect.y = r*tileWidth;
srcRect.w = srcRect.h = tileWidth;
int element = r*tileSetCols+c;
tileSet[element] = srcRect;
}
}
//printf("Tile Set Setup Completed.\n");
if(tileLayer->getType() == tson::LayerType::TileLayer)
{
destRects.resize(tilesWide*tilesHigh);
initialPositions.resize(tilesWide*tilesHigh);
for (int r=0;r<tilesHigh;r++){
for (int c=0;c<tilesWide;c++){
int elem = c+r*tilesWide;
SDL_Rect thisRect = SDL_Rect();
thisRect.x = c*tileWidth*globalScale;
thisRect.y = r*tileWidth*globalScale;
thisRect.w = thisRect.h = tileWidth*globalScale;
std::tuple<int,int> ogPos = std::make_tuple(thisRect.x,thisRect.y);
initialPositions[elem] = ogPos;
thisRect.x = thisRect.x-offsetX*globalScale;
thisRect.y = thisRect.y=offsetY*globalScale;
destRects[elem] = thisRect;
}
}
destRect.w = destRect.h = tileWidth * gScale;
}
//printf("Tilemap setup completed\n");
//std::cout << "destRects.size " << destRects.size() << std::endl;
} else {
// printf("Failed to load Tileson map\n");
std::cout << map->getStatusMessage() << std::endl;
}
}
void update() override
{
// if (Game::gsm->currentState == GameStateManager::ST_COREGAME){
for (int i=0;i<destRects.size();i++){
destRects[i].x = std::get<0>(initialPositions[i]) - Game::camera.x;
destRects[i].y = std::get<1>(initialPositions[i]) - Game::camera.y;
}
// }
}
void draw() override
{
//iterate through rows and columns of the map to draw the tiles
//First cycle through rows
tson::Layer *myLayer = map->getLayer("Tile Layer 1");
tson::Layer *collisionLayer = map->getLayer("Collision");
for (int r = 0;r<map->getSize().y;r++){
// Next cycle through each column or tile in that row:
for (int c = 0;c<map->getSize().x;c++){
int i = r*map->getSize().x+c;
int elem = c+r*map->getSize().x;
tson::Tile *myTile = myLayer->getTileData(c,r);
if(!myTile){
// Found a nullptr, nothing to do or see here, move along
} else {
int tid = myTile->getId()-1;
int tileToDraw = tid;
TextureManager::Draw(texture, tileSet[tileToDraw], destRects[elem], SDL_FLIP_NONE);
}
if (Game::debugMenu){
if (!collisionLayer->getTileData(c,r)) {
// Nothing to see here, just returning a nullptr, move along...
} else {
SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
SDL_RenderDrawRect(Game::renderer, &destRects[elem]);
}
}
}
}
}
void setTex(std::string id)
{
texture = Game::assets->GetTexture(id);
}
};
#endif /* SRC_ECS_TILEMAPCOMPONENT_H_ */

Some files were not shown because too many files have changed in this diff Show More