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
],
"scale": 4,
"selectedLayer": -1,
"selectedLayer": 0,
"viewCenter": {
"x": 132.75,
"y": 137.875
@ -52,6 +52,17 @@
"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": {
"dynamicWrapping": false,
"scaleInDock": 1,
@ -76,19 +87,20 @@
},
"last.exportedFilePath": "/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)",
"map.height": 32,
"map.height": 40,
"map.lastUsedExportFilter": "All Files (*)",
"map.lastUsedFormat": "json",
"map.layerDataFormat": null,
"map.tileHeight": 8,
"map.tileWidth": 8,
"map.width": 32,
"map.width": 40,
"openFiles": [
],
"project": "kaiju-city-map.tiled-project",
"recentFiles": [
"kaiju-city-ts.tsj",
"kaiju-city-map.json",
"kaiju-city-map.tmj",
"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,9 +52,11 @@ public:
collider.x = xpos;
collider.y = ypos;
collider.w = collider.h = size*scale;
setTex(texture);
center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2;
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)
@ -62,11 +64,13 @@ public:
tag = t;
collider.w = width;
collider.h = height;
offsetX = oX;
offsetY = oY;
setTex(texture);
center.x = collider.x+collider.w/2;
center.y = collider.y+collider.h/2;
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

View File

@ -80,15 +80,34 @@ public:
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");
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++)
{
cJSON * animItem = cJSON_GetArrayItem(frameTags,t);
@ -98,6 +117,7 @@ public:
int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint;
Animation anim = Animation(fromFrame,toFrame,100);
animations.emplace(name, anim);
std::cout << "Animation Name: " << name << std::endl;
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 fontTex = Game::projPath + "assets/textures/ui/ui-font-lorez5.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";
assets->AddTexture("player", kaijuTex.c_str());
assets->AddTexture("font", fontTex.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());
@ -179,11 +179,11 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
//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<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.addGroup(groupPlayers);
@ -191,8 +191,8 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
levelMap.y = 0;
// printf("Trying to load Tilemap\n");
std::string mapPath = Game::projPath + "assets/maps/kaiju-city-map.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
std::string mapPath = Game::projPath + "assets/maps/kaiju-city-map2.json";
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);
// printf("Completed loading Tilemap\n");
@ -248,7 +248,7 @@ void Game::update()
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
{
// 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)
{