Music completed, new tilemap, fixed collider

This commit is contained in:
Alan Youngblood 2023-08-14 23:48:20 -04:00
parent 162f58b32f
commit de3b2dcdb0
24 changed files with 118 additions and 20 deletions

BIN
.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

@ -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,17 @@
"y": 116.19433198380568 "y": 116.19433198380568
} }
}, },
"kaiju-city-map2.json": {
"scale": 2,
"selectedLayer": 1,
"viewCenter": {
"x": 170,
"y": 148.25
}
},
"kaiju-city-ts.tsj": {
"scaleInEditor": 1
},
"kaiju-city.tsj": { "kaiju-city.tsj": {
"dynamicWrapping": false, "dynamicWrapping": false,
"scaleInDock": 1, "scaleInDock": 1,
@ -76,19 +87,20 @@
}, },
"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": [
], ],
"project": "kaiju-city-map.tiled-project", "project": "kaiju-city-map.tiled-project",
"recentFiles": [ "recentFiles": [
"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.

After

Width:  |  Height:  |  Size: 3.5 KiB

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

@ -80,15 +80,34 @@ public:
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");
int tagsCount = cJSON_GetArraySize(frameTags); int tagsCount = cJSON_GetArraySize(frameTags);
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");
} else {
std::cout << "animation frame number: " << aFrame->valueint<< std::endl;
}
}
for (int t = 0; t < tagsCount; t++) for (int t = 0; t < tagsCount; t++)
{ {
cJSON * animItem = cJSON_GetArrayItem(frameTags,t); cJSON * animItem = cJSON_GetArrayItem(frameTags,t);
@ -98,6 +117,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 << 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,11 @@ 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"); player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/kaijuturtle.json");
// 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 +191,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 +248,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)
{ {