Rename Tileset to SpriteAtlas
This commit is contained in:
parent
a12e3b53f2
commit
1cf3ec5fc0
8 changed files with 34 additions and 31 deletions
|
@ -154,7 +154,7 @@
|
||||||
<ClCompile Include="src\Rng.cpp" />
|
<ClCompile Include="src\Rng.cpp" />
|
||||||
<ClCompile Include="src\Shaman.cpp" />
|
<ClCompile Include="src\Shaman.cpp" />
|
||||||
<ClCompile Include="src\Tilemap.cpp" />
|
<ClCompile Include="src\Tilemap.cpp" />
|
||||||
<ClCompile Include="src\Tileset.cpp" />
|
<ClCompile Include="src\SpriteAtlas.cpp" />
|
||||||
<ClCompile Include="src\WanderNode.cpp" />
|
<ClCompile Include="src\WanderNode.cpp" />
|
||||||
<ClCompile Include="src\World.cpp" />
|
<ClCompile Include="src\World.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -203,7 +203,7 @@
|
||||||
<ClInclude Include="src\stb_textedit.h" />
|
<ClInclude Include="src\stb_textedit.h" />
|
||||||
<ClInclude Include="src\stb_truetype.h" />
|
<ClInclude Include="src\stb_truetype.h" />
|
||||||
<ClInclude Include="src\Tilemap.h" />
|
<ClInclude Include="src\Tilemap.h" />
|
||||||
<ClInclude Include="src\Tileset.h" />
|
<ClInclude Include="src\SpriteAtlas.h" />
|
||||||
<ClInclude Include="src\vec2i.h" />
|
<ClInclude Include="src\vec2i.h" />
|
||||||
<ClInclude Include="src\WanderNode.h" />
|
<ClInclude Include="src\WanderNode.h" />
|
||||||
<ClInclude Include="src\wglew.h" />
|
<ClInclude Include="src\wglew.h" />
|
||||||
|
|
|
@ -123,9 +123,6 @@
|
||||||
<ClCompile Include="src\Tilemap.cpp">
|
<ClCompile Include="src\Tilemap.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\Tileset.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\WanderNode.cpp">
|
<ClCompile Include="src\WanderNode.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -138,6 +135,9 @@
|
||||||
<ClCompile Include="src\Shader.cpp">
|
<ClCompile Include="src\Shader.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\SpriteAtlas.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\Actor.h">
|
<ClInclude Include="src\Actor.h">
|
||||||
|
@ -266,9 +266,6 @@
|
||||||
<ClInclude Include="src\Tilemap.h">
|
<ClInclude Include="src\Tilemap.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="src\Tileset.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\vec2i.h">
|
<ClInclude Include="src\vec2i.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -287,5 +284,8 @@
|
||||||
<ClInclude Include="src\Shader.h">
|
<ClInclude Include="src\Shader.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\SpriteAtlas.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -7,7 +7,7 @@
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "Actor.h"
|
#include "Actor.h"
|
||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include "Tileset.h"
|
#include "SpriteAtlas.h"
|
||||||
#include "Mapgen.h"
|
#include "Mapgen.h"
|
||||||
#include "FieldOfView.h"
|
#include "FieldOfView.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
@ -22,7 +22,7 @@ InputAction player_action;
|
||||||
|
|
||||||
void PlayState::load() {
|
void PlayState::load() {
|
||||||
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Creating ascii tileset...\n");
|
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Creating ascii tileset...\n");
|
||||||
ascii = new Tileset(app->renderer, "./assets/12x12.bmp", 192, 192, 12, 12);
|
ascii = new SpriteAtlas(app->renderer, "./assets/12x12.bmp", 192, 192, 12, 12);
|
||||||
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Created ascii tileset.\n");
|
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Created ascii tileset.\n");
|
||||||
|
|
||||||
app->input->bind_key(SDLK_ESCAPE, ACTION_ESCAPE_MENU);
|
app->input->bind_key(SDLK_ESCAPE, ACTION_ESCAPE_MENU);
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
#include "Tilemap.h"
|
#include "Tilemap.h"
|
||||||
#include "FieldOfView.h"
|
#include "FieldOfView.h"
|
||||||
|
|
||||||
class Tileset;
|
class SpriteAtlas;
|
||||||
class Actor;
|
class Actor;
|
||||||
|
|
||||||
class PlayState : public Gamestate {
|
class PlayState : public Gamestate {
|
||||||
Tileset* ascii;
|
SpriteAtlas* ascii;
|
||||||
Tilemap tilemap;
|
Tilemap tilemap;
|
||||||
Actor * player_actor;
|
Actor * player_actor;
|
||||||
FieldOfView fov;
|
FieldOfView fov;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "Tileset.h"
|
#include "SpriteAtlas.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
|
||||||
Tileset::Tileset(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight) {
|
SpriteAtlas::SpriteAtlas(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight) {
|
||||||
int tilesX = imgWidth / tileWidth;
|
int tilesX = imgWidth / tileWidth;
|
||||||
int tilesY = imgHeight / tileHeight;
|
int tilesY = imgHeight / tileHeight;
|
||||||
tile_width = tileWidth;
|
tile_width = tileWidth;
|
||||||
|
@ -20,25 +20,25 @@ Tileset::Tileset(Renderer* renderer, std::string imgPath, int imgWidth, int imgH
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Tileset::~Tileset() {
|
SpriteAtlas::~SpriteAtlas() {
|
||||||
delete sprites;
|
delete sprites;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Tileset::get_amount() {
|
int SpriteAtlas::get_amount() {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite * Tileset::get_sprite(int tileId) {
|
Sprite * SpriteAtlas::get_sprite(int tileId) {
|
||||||
if (tileId >= 0 && tileId < amount) {
|
if (tileId >= 0 && tileId < amount) {
|
||||||
return &sprites[tileId];
|
return &sprites[tileId];
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Tileset::get_tile_width() {
|
int SpriteAtlas::get_tile_width() {
|
||||||
return tile_width;
|
return tile_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Tileset::get_tile_height() {
|
int SpriteAtlas::get_tile_height() {
|
||||||
return tile_height;
|
return tile_height;
|
||||||
}
|
}
|
|
@ -5,14 +5,14 @@ class Renderer;
|
||||||
struct Sprite;
|
struct Sprite;
|
||||||
|
|
||||||
// Automatically splits a tileset image to seperate sprites.
|
// Automatically splits a tileset image to seperate sprites.
|
||||||
class Tileset {
|
class SpriteAtlas {
|
||||||
Sprite* sprites;
|
Sprite* sprites;
|
||||||
int amount;
|
int amount;
|
||||||
int tile_width;
|
int tile_width;
|
||||||
int tile_height;
|
int tile_height;
|
||||||
public:
|
public:
|
||||||
Tileset(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight);
|
SpriteAtlas(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight);
|
||||||
~Tileset();
|
~SpriteAtlas();
|
||||||
int get_amount();
|
int get_amount();
|
||||||
int get_tile_width();
|
int get_tile_width();
|
||||||
int get_tile_height();
|
int get_tile_height();
|
|
@ -2,7 +2,7 @@
|
||||||
#include "vec2i.h"
|
#include "vec2i.h"
|
||||||
#include "Actor.h"
|
#include "Actor.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "Tileset.h"
|
#include "SpriteAtlas.h"
|
||||||
#include "FieldOfView.h"
|
#include "FieldOfView.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
@ -16,11 +16,7 @@ Tilemap::Tilemap(int width, int height) {
|
||||||
tilemap = std::vector<unsigned int>(width*height, 0);
|
tilemap = std::vector<unsigned int>(width*height, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tilemap::~Tilemap() {
|
Tilemap::~Tilemap() {}
|
||||||
for (auto var : actors) {
|
|
||||||
delete var;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int Tilemap::get_width() {
|
int Tilemap::get_width() {
|
||||||
return width;
|
return width;
|
||||||
|
@ -128,7 +124,13 @@ std::vector<Actor*>* Tilemap::get_actor_list() {
|
||||||
return &actors;
|
return &actors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tilemap::draw(Renderer *renderer, Tileset* tileset, int x, int y, int tx, int ty, int tw, int th, FieldOfView* view) {
|
void Tilemap::delete_actors() {
|
||||||
|
for (auto var : actors) {
|
||||||
|
delete var;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tilemap::draw(Renderer *renderer, SpriteAtlas* tileset, int x, int y, int tx, int ty, int tw, int th, FieldOfView* view) {
|
||||||
int w = tileset->get_tile_width();
|
int w = tileset->get_tile_width();
|
||||||
int h = tileset->get_tile_height();
|
int h = tileset->get_tile_height();
|
||||||
for (int ix = 0; ix < tw; ix++) {
|
for (int ix = 0; ix < tw; ix++) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Tileset.h"
|
#include "SpriteAtlas.h"
|
||||||
#include "Actor.h"
|
#include "Actor.h"
|
||||||
|
|
||||||
struct vec2i;
|
struct vec2i;
|
||||||
|
@ -26,7 +26,7 @@ public:
|
||||||
int get_tile(int x, int y);
|
int get_tile(int x, int y);
|
||||||
bool is_blocked(int x, int y); // Checks if there is an actor blocking the tile.
|
bool is_blocked(int x, int y); // Checks if there is an actor blocking the tile.
|
||||||
|
|
||||||
void draw(Renderer *renderer, Tileset *tileset, int x, int y, int tx, int ty, int tw, int th, FieldOfView* view);
|
void draw(Renderer *renderer, SpriteAtlas *tileset, int x, int y, int tx, int ty, int tw, int th, FieldOfView* view);
|
||||||
|
|
||||||
void add_actor(Actor *actor);
|
void add_actor(Actor *actor);
|
||||||
void remove_actor(Actor *actor);
|
void remove_actor(Actor *actor);
|
||||||
|
@ -36,5 +36,6 @@ public:
|
||||||
Entity* get_entity(int x, int y, EntityTypes type);
|
Entity* get_entity(int x, int y, EntityTypes type);
|
||||||
std::vector<Actor*> get_actors(int x, int y, int range);
|
std::vector<Actor*> get_actors(int x, int y, int range);
|
||||||
std::vector<Actor*>* get_actor_list();
|
std::vector<Actor*>* get_actor_list();
|
||||||
|
void delete_actors();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue