New tileset & map; todo fix tile sanity check

This commit is contained in:
Alan Youngblood 2023-08-04 22:05:07 -04:00
parent 6568026886
commit 7b2ed8e27b
11 changed files with 271 additions and 112 deletions

View File

@ -1,3 +1,6 @@
[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
@ -9,7 +12,7 @@ CMake Binary=/usr/bin/cmake
CMake Executable=/usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=
Install Directory=/usr/local
Runtime=Host System
[Launch]

View File

@ -1,5 +1,5 @@
{ "columns":10,
"image":"..\/..\/..\/Projects\/BeagleRescue\/assets\/maps\/br-tiles.png",
"image":"br-tiles.png",
"imageheight":80,
"imagewidth":160,
"margin":0,
@ -14,7 +14,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -40,7 +39,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -66,7 +64,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -92,7 +89,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -118,7 +114,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -144,7 +139,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -170,7 +164,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -196,7 +189,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -222,7 +214,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -248,7 +239,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -285,7 +275,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{
@ -311,7 +300,6 @@
"objectgroup":
{
"draworder":"index",
"id":2,
"name":"",
"objects":[
{

File diff suppressed because one or more lines are too long

View File

@ -5,11 +5,75 @@
},
"activeFile": "",
"expandedProjectPaths": [
"."
],
"fileStates": {
"": {
"scaleInDock": 1
},
"last.imagePath": "/Users/ayoungblood/Projects/KaijuSaveEarth/assets/maps",
"Kaiju-City.tsj": {
"dynamicWrapping": true,
"scaleInDock": 3
},
"br-tiles.tsj": {
"scaleInDock": 1,
"scaleInEditor": 4
},
"kaiju-city-map.json": {
"scale": 3,
"selectedLayer": 1,
"viewCenter": {
"x": 86.16666666666666,
"y": 10.666666666666671
}
},
"kaiju-city-map.json#kaiju-city": {
"scaleInDock": 1
},
"kaiju-city-map.tmj": {
"scale": 1.4114285714285715,
"selectedLayer": 0,
"viewCenter": {
"x": 232.38866396761134,
"y": 218.21862348178138
}
},
"kaiju-city-map.tmx": {
"scale": 1.4114285714285715,
"selectedLayer": 0,
"viewCenter": {
"x": 74.03846153846153,
"y": 116.19433198380568
}
},
"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": "/home/ayoungblood/projects/KaijuSaveEarth/assets/maps",
"lastUsedTilesetExportFilter": "JSON tileset files (*.tsj *.json)",
"map.height": 32,
"map.lastUsedExportFilter": "All Files (*)",
"map.lastUsedFormat": "json",
"map.layerDataFormat": null,
"map.tileHeight": 8,
@ -19,7 +83,16 @@
],
"project": "kaiju-city-map.tiled-project",
"recentFiles": [
"testmap.json",
"kaiju-tokyo.tsj",
"kaiju-city-map.json",
"kaiju-city.tsx",
"br-tiles.tsj",
"kaiju-city-map.tmx",
"kaiju-city-map.tmj",
"kaiju-city.tsj"
],
"tileset.lastUsedFilter": "JSON tileset files (*.tsj *.json)",
"tileset.lastUsedFormat": "json",
"tileset.tileSize": {
"height": 8,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 923 B

After

Width:  |  Height:  |  Size: 923 B

View File

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

View File

@ -3,5 +3,5 @@
"WindowName":"Kaiju Save Earth",
"WindowSize":{"w":64,"h":64},
"WindowFullScreen": 0,
"GlobalScale": 12
"GlobalScale": 10
}

View File

@ -42,7 +42,7 @@ public:
SDL_DestroyTexture(texture);
}
TileMapComponent(std::string mapPath, int gScale, int offsetX, int offsetY)
TileMapComponent(std::string mapPath, std::string tsName, std::string tileLayerName, std::string collisionLayerName, int gScale, int offsetX, int offsetY)
{
// TILESON ~~~~~~~~~~~
@ -51,18 +51,22 @@ public:
if(map->getStatus() == tson::ParseStatus::OK)
{
tson::Tileset *tileset = map->getTileset("br-tiles");
tson::Tileset *tileset = map->getTileset(tsName);
std::cout << "tsName: " << tsName << std::endl;
std::string fullPath = tileset->getImage();
size_t charPos = fullPath.find("assets");
fullPath.erase(0,charPos);
tson::Layer *tileLayer = map->getLayer("Tile Layer 1"); //This is a Layer
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 wholePath = prependPath + fullPath;
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, fullPath.c_str());
Game::assets->AddTexture(texName, wholePath.c_str());
setTex(texName);
globalScale = gScale;
tson::Layer *collisionLayer = map->getLayer("Collision");
tson::Layer *collisionLayer = map->getLayer(collisionLayerName);
tilesWide = map->getSize().x;
tilesHigh = map->getSize().y;
@ -71,7 +75,7 @@ public:
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();
@ -109,7 +113,31 @@ public:
}
destRect.w = destRect.h = tileWidth * gScale;
}
tson::Layer *myLayer = map->getLayer("Tile Layer 1");
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);
int tid = myTile->getId()-1;
//std::cout << myLayer->getTileData(1,1)->getId() << std::endl;
// TextureManager::Draw(texture, tileSet[tid], destRects[elem], SDL_FLIP_NONE);
std::cout << "c,r: " << c << ", " << r << std::endl;
if(!tid){
printf("got nullptr\n");
// printf("found valid tid\n");
} else {
std::cout << "tid: " << tid << std::endl;
}
//std::cout << " elem: " << elem << std::endl;
//std::cout << "i" << i << std::endl;
}
}
// tson::Tile *testTile = myLayer->getTileData(0,4);
// int myTid = testTile->getId()-1;
printf("Completed tilemap init\n");
//std::cout << "destRects.size " << destRects.size() << std::endl;
} else {
printf("Failed to load Tileson map\n");
std::cout << map->getStatusMessage();
@ -139,14 +167,16 @@ public:
int i = r*map->getSize().x+c;
int elem = c+r*map->getSize().x;
tson::Tile *myTile = myLayer->getTileData(c,r);
if(myTile){
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)) {
SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
SDL_RenderDrawRect(Game::renderer, &destRects[elem]);
}
if (Game::debugMenu){
// if (collisionLayer->getTileData(c,r)) {
// SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
// SDL_RenderDrawRect(Game::renderer, &destRects[elem]);
// }
}
}
}

View File

@ -157,51 +157,51 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
// map = new Map("terrain",globalScale,16);
// std::string myText = "Find lost puppies!\nThey need your help!";
std::string myText = "Press U to Start";
std::string myText = "U to Start";
//Set Font and UI NineSlice Sizes here
fontSize = Vector2D(5,5);
nineSliceSize = Vector2D(16,16);
uiTextInstructions.addComponent<TransformComponent>(18,22,138*gScale,20*gScale,gScale);
uiTextInstructions.addComponent<TransformComponent>(4,4,62*gScale,8*gScale,gScale);
uiTextInstructions.addComponent<UITextComponent>("font",myText,fontSize.x,fontSize.y,gScale);
uiTextInstructions.addGroup(groupUI_Layer1);
SDL_Rect myDestRect = SDL_Rect();
myDestRect.x = 12;
myDestRect.y = 8;
myDestRect.w = 160;
myDestRect.h = 40;
myDestRect.x = 1;
myDestRect.y = 1;
myDestRect.w = 62;
myDestRect.h = 16;
my9Slice = new UINineSlice("textBox");
my9Slice->MakeSlices("textBox",nineSliceSize.x,nineSliceSize.y,nineSliceX0,nineSliceX1,nineSliceY0,nineSliceY1,myDestRect,globalScale,Game::groupUI_Layer0);
// std::cout << "camera.w " << camera.w << std::endl;
uiInfo.addComponent<TransformComponent>(camera.w/gScale-94,10,72*gScale,96*gScale,gScale);
// uiInfo.addComponent<TransformComponent>(camera.w/gScale-94,10,72*gScale,96*gScale,gScale);
// uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", fontSize.x,fontSize.y, 1);
// uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : coll: Px2: tson: ", fontSize.x,fontSize.y, gScale);
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : coll: ", fontSize.x,fontSize.y, gScale);
uiInfo.addGroup(groupUI_Layer3);
uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,23,40*gScale,12*gScale,gScale);
uiCamXInfo.addComponent<UITextComponent>("font", "nan", fontSize.x,fontSize.y, gScale);
uiCamXInfo.addGroup(groupUI_Layer3);
uiCamYInfo.addComponent<TransformComponent>(camera.w/gScale-48,36,40*gScale,12*gScale,gScale);
uiCamYInfo.addComponent<UITextComponent>("font", "nan", fontSize.x,fontSize.y, gScale);
uiCamYInfo.addGroup(groupUI_Layer3);
uiPlayerXInfo.addComponent<TransformComponent>(camera.w/gScale-49,49,40*gScale,12*gScale,gScale);
uiPlayerXInfo.addComponent<UITextComponent>("font", "nan", fontSize.x,fontSize.y, gScale);
uiPlayerXInfo.addGroup(groupUI_Layer3);
uiPlayerYInfo.addComponent<TransformComponent>(camera.w/gScale-48,62,40*gScale,12*gScale,gScale);
uiPlayerYInfo.addComponent<UITextComponent>("font", "nan",fontSize.x,fontSize.y, gScale);
uiPlayerYInfo.addGroup(groupUI_Layer3);
uiBoundary1Info.addComponent<TransformComponent>(camera.w/gScale-48,75,128*gScale,12*gScale,gScale);
uiBoundary1Info.addComponent<UITextComponent>("font", "nan",fontSize.x,fontSize.y, gScale);
uiBoundary1Info.addGroup(groupUI_Layer3);
// uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : coll: ", fontSize.x,fontSize.y, gScale);
// uiInfo.addGroup(groupUI_Layer3);
//
// uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,23,40*gScale,12*gScale,gScale);
// uiCamXInfo.addComponent<UITextComponent>("font", "nan", fontSize.x,fontSize.y, gScale);
// uiCamXInfo.addGroup(groupUI_Layer3);
//
// uiCamYInfo.addComponent<TransformComponent>(camera.w/gScale-48,36,40*gScale,12*gScale,gScale);
// uiCamYInfo.addComponent<UITextComponent>("font", "nan", fontSize.x,fontSize.y, gScale);
// uiCamYInfo.addGroup(groupUI_Layer3);
//
// uiPlayerXInfo.addComponent<TransformComponent>(camera.w/gScale-49,49,40*gScale,12*gScale,gScale);
// uiPlayerXInfo.addComponent<UITextComponent>("font", "nan", fontSize.x,fontSize.y, gScale);
// uiPlayerXInfo.addGroup(groupUI_Layer3);
//
// uiPlayerYInfo.addComponent<TransformComponent>(camera.w/gScale-48,62,40*gScale,12*gScale,gScale);
// uiPlayerYInfo.addComponent<UITextComponent>("font", "nan",fontSize.x,fontSize.y, gScale);
// uiPlayerYInfo.addGroup(groupUI_Layer3);
//
// uiBoundary1Info.addComponent<TransformComponent>(camera.w/gScale-48,75,128*gScale,12*gScale,gScale);
// uiBoundary1Info.addComponent<UITextComponent>("font", "nan",fontSize.x,fontSize.y, gScale);
// uiBoundary1Info.addGroup(groupUI_Layer3);
// uiBoundary2Info.addComponent<TransformComponent>(camera.w/gScale-64,88,128*gScale,12*gScale,gScale);
// uiBoundary2Info.addComponent<UITextComponent>("font", "nan",fontSize.x,fontSize.y, gScale);
@ -212,13 +212,13 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
// uiBoundary3Info.addGroup(groupUI_Layer3);
// debug UI box
SDL_Rect debugBoxRect = SDL_Rect();
debugBoxRect.x = camera.w-(100*gScale);
debugBoxRect.y = 4*gScale;
debugBoxRect.w = 98*gScale;
debugBoxRect.h = 112*gScale;
debugBox = new UINineSlice("textBox");
debugBox->MakeSlices("textBox",nineSliceSize.x,nineSliceSize.y,nineSliceX0,nineSliceX1,nineSliceY0,nineSliceY1,debugBoxRect,globalScale,Game::groupUI_Layer2);
// SDL_Rect debugBoxRect = SDL_Rect();
// debugBoxRect.x = camera.w-(100*gScale);
// debugBoxRect.y = 4*gScale;
// debugBoxRect.w = 98*gScale;
// debugBoxRect.h = 112*gScale;
// debugBox = new UINineSlice("textBox");
// debugBox->MakeSlices("textBox",nineSliceSize.x,nineSliceSize.y,nineSliceX0,nineSliceX1,nineSliceY0,nineSliceY1,debugBoxRect,globalScale,Game::groupUI_Layer2);
//ecs implementation
@ -234,16 +234,19 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
levelMap.x = 0;
levelMap.y = 0;
gameScene.addComponent<TileMapComponent>("assets/maps/testmap.json",gScale,player.getComponent<TransformComponent>().position.x+player.getComponent<TransformComponent>().width/2,player.getComponent<TransformComponent>().position.y+player.getComponent<TransformComponent>().height/2); //150,100
// printf("Trying to load Tilemap\n");
gameScene.addComponent<TileMapComponent>("assets/maps/kaiju-city-map.json","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.addGroup(groupMap);
// printf("Completed loading Tilemap\n");
// std::cout << "LevelMap: " << levelMap.x << ", " << levelMap.y << ", " << levelMap.w << ", " << levelMap.h << std::endl;
playerPosition = Vector2D().Zero();
pVel = Vector2D().Zero();
puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
puppy.addGroup(groupObjects);
// puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
// puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
// puppy.addGroup(groupObjects);
printf("Init Completed\n");
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError());
isRunning = false;
@ -308,16 +311,16 @@ void Game::update()
for (auto& c : colliders)
{
SDL_Rect cCol = c->getComponent<ColliderComponent>().collider;
if(Collision::AABB(cCol, playerCol))
{
// if(!playerIsGrounded){
// player.getComponent<SpriteComponent>().Play("Idle");
// SDL_Rect cCol = c->getComponent<ColliderComponent>().collider;
// if(Collision::AABB(cCol, playerCol))
// {
// // if(!playerIsGrounded){
// // player.getComponent<SpriteComponent>().Play("Idle");
// // }
// // playerIsGrounded = true;
// // player.getComponent<TransformComponent>().position.y = player.getComponent<TransformComponent>().lastSafePos.y;
// // gravityOnPlayer = false;
// }
// playerIsGrounded = true;
// player.getComponent<TransformComponent>().position.y = player.getComponent<TransformComponent>().lastSafePos.y;
// gravityOnPlayer = false;
}
}
@ -349,13 +352,13 @@ void Game::update()
player.getComponent<TransformComponent>().updateTilePosition(pTileX,pTileY);
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string((int)player.getComponent<TransformComponent>().tilePos.x));
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string((int)player.getComponent<TransformComponent>().tilePos.y));
// uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string((int)player.getComponent<TransformComponent>().tilePos.x));
// uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string((int)player.getComponent<TransformComponent>().tilePos.y));
int playerX = player.getComponent<TransformComponent>().position.x;
int playerY = player.getComponent<TransformComponent>().position.y;
uiPlayerXInfo.getComponent<UITextComponent>().updateString(std::to_string(playerX));
uiPlayerYInfo.getComponent<UITextComponent>().updateString(std::to_string(playerY));
// uiPlayerXInfo.getComponent<UITextComponent>().updateString(std::to_string(playerX));
// uiPlayerYInfo.getComponent<UITextComponent>().updateString(std::to_string(playerY));
// int * foundBoundaries = predictCollisions();
// int max = foundBoundaries[0];
@ -369,12 +372,12 @@ void Game::update()
// uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[0]));
// uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((float)desiredMovementX));
if (playerIsGrounded) {
uiBoundary1Info.getComponent<UITextComponent>().updateString("yes");
// uiBoundary1Info.getComponent<UITextComponent>().updateString("yes");
} else {
uiBoundary1Info.getComponent<UITextComponent>().updateString("no");
// uiBoundary1Info.getComponent<UITextComponent>().updateString("no");
}
// uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[1]));
float difference = player.getComponent<TransformComponent>().position.x+desiredMovementX;
// float difference = player.getComponent<TransformComponent>().position.x+desiredMovementX;
//uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((float)difference));
//uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)(max*gScale)));