Compare commits

..

3 Commits

29 changed files with 142 additions and 58 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -12,7 +12,7 @@ PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0) PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
PKG_SEARCH_MODULE(SDL2MIXER REQUIRED SDL2_mixer>=2.0.0) PKG_SEARCH_MODULE(SDL2MIXER REQUIRED SDL2_mixer>=2.0.0)
#PKG_SEARCH_MODULE(BOOSTFILESYSTEM boost_filesystem >=) #PKG_SEARCH_MODULE(BOOSTFILESYSTEM boost_filesystem >=)
find_package(Boost COMPONENTS system filesystem REQUIRED) #find_package(Boost COMPONENTS system filesystem REQUIRED)
# Point to our own cmake modules # Point to our own cmake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
@ -27,4 +27,4 @@ file(GLOB_RECURSE CPPSOURCES src/*.cpp)
add_executable(${PROJECT_NAME} ${CSOURCES} ${CPPSOURCES}) add_executable(${PROJECT_NAME} ${CSOURCES} ${CPPSOURCES})
install(TARGETS ${PROJECT_NAME} DESTINATION bin) install(TARGETS ${PROJECT_NAME} DESTINATION bin)
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::system Boost::filesystem PRIVATE /usr/local/lib/libSDL2.dylib /usr/local/lib/libSDL2_image.dylib /usr/local/lib/libSDL2_mixer.dylib) target_link_libraries(${PROJECT_NAME} PRIVATE /usr/local/lib/libSDL2.dylib /usr/local/lib/libSDL2_image.dylib /usr/local/lib/libSDL2_mixer.dylib)

BIN
assets/.DS_Store vendored

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.

View File

@ -3,7 +3,7 @@
"height": 4300, "height": 4300,
"width": 2 "width": 2
}, },
"activeFile": "", "activeFile": "kaiju-city-map2.json",
"expandedProjectPaths": [ "expandedProjectPaths": [
"." "."
], ],
@ -24,7 +24,7 @@
3 3
], ],
"scale": 4, "scale": 4,
"selectedLayer": -1, "selectedLayer": 0,
"viewCenter": { "viewCenter": {
"x": 132.75, "x": 132.75,
"y": 137.875 "y": 137.875
@ -52,6 +52,18 @@
"y": 116.19433198380568 "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": { "kaiju-city.tsj": {
"dynamicWrapping": false, "dynamicWrapping": false,
"scaleInDock": 1, "scaleInDock": 1,
@ -76,19 +88,22 @@
}, },
"last.exportedFilePath": "/home/ayoungblood/projects/KaijuSaveEarth/assets/maps", "last.exportedFilePath": "/home/ayoungblood/projects/KaijuSaveEarth/assets/maps",
"last.externalTilesetPath": "/home/ayoungblood/projects/KaijuSaveEarth/assets/maps", "last.externalTilesetPath": "/home/ayoungblood/projects/KaijuSaveEarth/assets/maps",
"last.imagePath": "/home/ayoungblood/projects/KaijuSaveEarth/assets/maps", "last.imagePath": "/Users/ayoungblood/Projects/KaijuSaveEarth/assets/maps",
"lastUsedTilesetExportFilter": "JSON tileset files (*.tsj *.json)", "lastUsedTilesetExportFilter": "JSON tileset files (*.tsj *.json)",
"map.height": 32, "map.height": 40,
"map.lastUsedExportFilter": "All Files (*)", "map.lastUsedExportFilter": "All Files (*)",
"map.lastUsedFormat": "json", "map.lastUsedFormat": "json",
"map.layerDataFormat": null, "map.layerDataFormat": null,
"map.tileHeight": 8, "map.tileHeight": 8,
"map.tileWidth": 8, "map.tileWidth": 8,
"map.width": 32, "map.width": 40,
"openFiles": [ "openFiles": [
"kaiju-city-map2.json"
], ],
"project": "kaiju-city-map.tiled-project", "project": "kaiju-city-map.tiled-project",
"recentFiles": [ "recentFiles": [
"kaiju-city-map2.json",
"kaiju-city-ts.tsj",
"kaiju-city-map.json", "kaiju-city-map.json",
"kaiju-city-map.tmj", "kaiju-city-map.tmj",
"kaiju-city.tsj", "kaiju-city.tsj",

File diff suppressed because one or more lines are too long

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"
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
src/.DS_Store vendored

Binary file not shown.

View File

@ -52,7 +52,9 @@ public:
collider.x = xpos; collider.x = xpos;
collider.y = ypos; collider.y = ypos;
collider.w = collider.h = size*scale; collider.w = collider.h = size*scale;
if(texture != ""){
setTex(texture); setTex(texture);
}
center.x = collider.x+collider.w/2; center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2; center.y = collider.y+collider.h/2;
} }
@ -64,7 +66,9 @@ public:
collider.h = height; collider.h = height;
offsetX = oX; offsetX = oX;
offsetY = oY; offsetY = oY;
if(texture != ""){
setTex(texture); setTex(texture);
}
center.x = collider.x+collider.w/2; center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2; center.y = collider.y+collider.h/2;
} }

View File

@ -66,28 +66,48 @@ public:
spriteType = sType; spriteType = sType;
if(sType == spriteAnimation) if(sType == spriteAnimation)
{ {
/*boost::filesystem::path p{argv[0]}; //std::string fullPath = Game::projPath + json;
p = absolute(p).parent_path(); std::ifstream fin(json);
std::string configPath = "src/config/config.json";
std::string bps = p.string();
size_t charPos = bps.find("build");
bps.erase(charPos,bps.length());
std::string configurationPath = bps + json;*/
std::cout << "Project Path: " << Game::projPath << std::endl;
std::string fullPath = Game::projPath + json;
std::ifstream fin(fullPath);
if(fin.fail()){ if(fin.fail()){
std::cerr<<"ERROR opening json file: " << json << std::endl; std::cerr<<"ERROR opening json file: " << json << std::endl;
} else if (fin.is_open()){ } else if (fin.is_open()){
//printf("Opened a json file\n");
std::ifstream jsonText(json); std::ifstream jsonText(json);
std::ostringstream tmp; std::ostringstream tmp;
tmp << jsonText.rdbuf(); tmp << jsonText.rdbuf();
std::string aJson = tmp.str(); std::string aJson = tmp.str();
cJSON * animJson = cJSON_Parse(aJson.c_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 * meta = cJSON_GetObjectItem(animJson, "meta");
cJSON * version = cJSON_GetObjectItem(animJson, "version");
cJSON * frameTags = cJSON_GetObjectItem(meta,"frameTags"); cJSON * frameTags = cJSON_GetObjectItem(meta,"frameTags");
cJSON * frames = cJSON_GetObjectItem(animJson, "frames");
int tagsCount = cJSON_GetArraySize(frameTags); 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++) for (int t = 0; t < tagsCount; t++)
{ {
@ -98,6 +118,7 @@ public:
int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint; int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint;
Animation anim = Animation(fromFrame,toFrame,100); Animation anim = Animation(fromFrame,toFrame,100);
animations.emplace(name, anim); animations.emplace(name, anim);
std::cout << "Animation Name: " << name << "from: " << fromFrame << "to: " << toFrame << std::endl;
Play(name); Play(name);
} }
} }

View File

@ -147,14 +147,14 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
std::string kaijuTex = Game::projPath + "assets/textures/actors/kaijuturtle.png"; std::string kaijuTex = Game::projPath + "assets/textures/actors/kaijuturtle.png";
std::string fontTex = Game::projPath + "assets/textures/ui/ui-font-lorez5.png"; std::string fontTex = Game::projPath + "assets/textures/ui/ui-font-lorez5.png";
std::string textBoxTex = Game::projPath + "assets/textures/ui/ui-element-bubble.png"; std::string textBoxTex = Game::projPath + "assets/textures/ui/ui-element-bubble.png";
std::string musicFile = Game::projPath + "assets/audio/music/sillypuppy.ogg"; std::string musicFile = Game::projPath + "assets/audio/music/neuwave.ogg";
std::string sfxFile = Game::projPath + "assets/audio/sfx/bwoop.wav"; std::string sfxFile = Game::projPath + "assets/audio/sfx/bwoop.wav";
assets->AddTexture("player", kaijuTex.c_str()); assets->AddTexture("player", kaijuTex.c_str());
assets->AddTexture("font", fontTex.c_str()); assets->AddTexture("font", fontTex.c_str());
assets->AddTexture("textBox", textBoxTex.c_str()); assets->AddTexture("textBox", textBoxTex.c_str());
assets->AddMusicTrack("simonZ",musicFile.c_str()); assets->AddMusicTrack("neuwave",musicFile.c_str());
assets->AddSoundClip("bwoop",sfxFile.c_str()); assets->AddSoundClip("bwoop",sfxFile.c_str());
@ -179,11 +179,12 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
//ecs implementation //ecs implementation
player.addComponent<TransformComponent>(150*gScale,100*gScale,32,32,globalScale,3); // 180,120 player.addComponent<TransformComponent>(150*gScale,100*gScale,32,32,globalScale,2); // 180,120
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/kaijuturtle.json"); std::string playerJson = Game::projPath + "assets/textures/actors/kaijuturtle.json";
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, playerJson);
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero()); // player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
player.addComponent<ColliderComponent>("player",16*globalScale,32*globalScale, true, 2*globalScale,10*globalScale, "collider"); player.addComponent<ColliderComponent>("player",20*globalScale,20*globalScale, true, 0*globalScale,0*globalScale, "");
player.addComponent<KeyboardController>(); player.addComponent<KeyboardController>();
player.addGroup(groupPlayers); player.addGroup(groupPlayers);
@ -191,8 +192,8 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
levelMap.y = 0; levelMap.y = 0;
// printf("Trying to load Tilemap\n"); // printf("Trying to load Tilemap\n");
std::string mapPath = Game::projPath + "assets/maps/kaiju-city-map.json"; std::string mapPath = Game::projPath + "assets/maps/kaiju-city-map2.json";
gameScene.addComponent<TileMapComponent>(mapPath,"kaiju-city","Tile Layer 1","Collision",gScale,player.getComponent<TransformComponent>().position.x+player.getComponent<TransformComponent>().width/2,player.getComponent<TransformComponent>().position.y+player.getComponent<TransformComponent>().height/2); //150,100 gameScene.addComponent<TileMapComponent>(mapPath,"kaiju-city-ts","Tile Layer 1","Collision",gScale,player.getComponent<TransformComponent>().position.x+player.getComponent<TransformComponent>().width/2,player.getComponent<TransformComponent>().position.y+player.getComponent<TransformComponent>().height/2); //150,100
gameScene.addGroup(groupMap); gameScene.addGroup(groupMap);
// printf("Completed loading Tilemap\n"); // printf("Completed loading Tilemap\n");
@ -248,7 +249,7 @@ void Game::update()
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME) if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
{ {
// std::cout << "Play Music Now" << std::endl; // std::cout << "Play Music Now" << std::endl;
Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1); Mix_PlayMusic(assets->GetMusicTrack("neuwave"), -1);
} }
if (Mix_PlayingMusic() != 0 && gsm->currentState != GameStateManager::ST_COREGAME) if (Mix_PlayingMusic() != 0 && gsm->currentState != GameStateManager::ST_COREGAME)
{ {

View File

@ -11,44 +11,30 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <boost/filesystem.hpp>
Game *game = nullptr; Game *game = nullptr;
int main(int argc, const char * argv[]) int main(int argc, const char * argv[])
{ {
// printf("Program has started, but not initialized yet.\n");
const int FPS = 60; const int FPS = 60;
const int frameDelay = 1000 / FPS; const int frameDelay = 1000 / FPS;
Uint64 frameStart; Uint64 frameStart;
int frameTime; int frameTime;
boost::filesystem::path p{argv[0]};
p = absolute(p).parent_path();
// std::cout << "boost path: " << p << std::endl;
// ============================= // =============================
// Load cJSON config.json file // Load cJSON config.json file
// ============================= // =============================
// Starting with Error Checking
std::string configPath = "src/config/config.json"; std::string configPath = "src/config/config.json";
std::string bps = p.string(); std::string sdlBasePath = SDL_GetBasePath();
size_t charPos = bps.find("build"); size_t charPosSdl = sdlBasePath.find("build");
bps.erase(charPos,bps.length()); sdlBasePath.erase(charPosSdl,sdlBasePath.length());
// std::cout << "Trimmed Boost Path: " << bps << std::endl; std::string configurationPath = sdlBasePath + configPath;
std::string configurationPath = bps + configPath;
//std::string configPath = "/Users/ayoungblood/Projects/KaijuSaveEarth/src/config/config.json";
// /Users/ayoungblood/Projects/KaijuSaveEarth
// std::string fullPath = p.c_str() + "/" + configPath;
std::ifstream fin(configurationPath); std::ifstream fin(configurationPath);
// std::cout << "Attempting to load: " << configPath << std::endl;
// std::cout << "Current working Dir: " << std::filesystem::current_path() << std::endl;
if(!fin.is_open()){ if(!fin.is_open()){
std::cerr<<"ERROR: config.json not found or opened"<<std::endl; std::cerr<<"ERROR: config.json not found or opened"<<std::endl;
} else { } else {
printf("config.json loaded successfully.\n");
std::ifstream jsonText(configurationPath); std::ifstream jsonText(configurationPath);
std::ostringstream tmp; std::ostringstream tmp;
tmp << jsonText.rdbuf(); tmp << jsonText.rdbuf();
@ -60,12 +46,7 @@ int main(int argc, const char * argv[])
int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint; int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint;
int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint; int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint;
int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint; int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint;
/* int windowWidth = 64;
int windowHeight = 64;
int windowFS = 0;
int globalScale = 10;*/
bool isWindowFS; bool isWindowFS;
//std::string windowName = "KaijuSaveEarth";
if (windowFS==0) if (windowFS==0)
{ {
isWindowFS = false; isWindowFS = false;
@ -75,9 +56,9 @@ int main(int argc, const char * argv[])
} }
windowWidth = windowWidth*globalScale; windowWidth = windowWidth*globalScale;
windowHeight = windowHeight*globalScale; windowHeight = windowHeight*globalScale;
game = new Game(bps); game = new Game(sdlBasePath);
game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale); game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale);
// game->init(windowName.c_str(), windowWidth, windowHeight, isWindowFS, globalScale);
// cJSON memory management // cJSON memory management
cJSON_Delete(myJSON); cJSON_Delete(myJSON);