add more pokemon class functions

This commit is contained in:
2025-04-07 20:22:34 -04:00
parent 54f64226e1
commit 8a8b6c73bb
4 changed files with 71 additions and 3 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ LDFLAGS = -lX11 -lGL -lpthread -lpng -lstdc++fs
TARGET = TerminalTrainers TARGET = TerminalTrainers
SOURCES = main.cpp SOURCES = main.cpp Pokemon.cpp
OBJECTS = $(SOURCES:.cpp=.o) OBJECTS = $(SOURCES:.cpp=.o)
+61 -1
View File
@@ -1,14 +1,74 @@
#include "Pokemon.h" #include "Pokemon.h"
#include "olcPixelGameEngine.h"
olc::vi2d tilesheetTiles = { 14, 11 };
olc::vi2d tileSize = { 16, 16 };
Pokemon::Pokemon(int id, string name) { Pokemon::Pokemon(int id, string name) {
this->id = id; this->id = id;
this->name = name; this->name = name;
this->worldPos = { 0, 0 };
}; };
Pokemon::Pokemon(int id, string name, olc::vi2d worldPos) {
this->id = id;
this->name = name;
this->worldPos = worldPos;
};
olc::vi2d Pokemon::getCoordinate() {
int y = (id / tilesheetTiles.x) * tileSize.x;
int x = (id % tilesheetTiles.x) * tileSize.y;
return { x, y };
};
int Pokemon::getRandomPokemonId() {
return (rand() % 151 + 1);
};
void Pokemon::draw(olc::PixelGameEngine *pge, olc::Sprite *pokemonSprite, int nOffsetX, int nOffsetY, float tileOffsetX, float tileOffsetY) {
int screenX = (worldPos.x - nOffsetX) * tileSize.x - tileOffsetX;
int screenY = (worldPos.y - nOffsetY) * tileSize.y - tileOffsetY;
if(screenX > 0 && screenY > 0 && screenX < pge->ScreenWidth() && screenY < pge->ScreenHeight()) {
olc::vi2d spritesheetCoord = getCoordinate();
pge->SetPixelMode(olc::Pixel::MASK);
pge->DrawPartialSprite(screenX, screenY, pokemonSprite, spritesheetCoord.x, spritesheetCoord.y, tileSize.x, tileSize.y);
pge->SetPixelMode(olc::Pixel::MASK);
}
}
void Pokemon::drawPokemon(olc::PixelGameEngine *pge, olc::Sprite *pokemonSprite, olc::vi2d worldPos) {
olc::vi2d spritesheetCoord = getCoordinate();
this->worldPos = worldPos;
olc::vi2d tileXY = {worldPos.x * tileSize.x, worldPos.y * tileSize.y};
pge->SetPixelMode(olc::Pixel::MASK);
pge->DrawPartialSprite(tileXY.x, tileXY.y, pokemonSprite, spritesheetCoord.x, spritesheetCoord.y, tileSize.x, tileSize.y);
pge->SetPixelMode(olc::Pixel::NORMAL);
};
void Pokemon::drawPokemon(olc::PixelGameEngine *pge, olc::Sprite *pokemonSprite, float tileOffsetX, float tileOffsetY) {
olc::vi2d spritesheetCoord = getCoordinate();
int tileX = worldPos.x * tileSize.x - tileOffsetX;
int tileY = worldPos.y * tileSize.y - tileOffsetY;
pge->SetPixelMode(olc::Pixel::MASK);
pge->DrawPartialSprite(tileX, tileY, pokemonSprite, spritesheetCoord.x, spritesheetCoord.y, tileSize.x, tileSize.y);
pge->SetPixelMode(olc::Pixel::NORMAL);
};
void Pokemon::drawPokemon(olc::PixelGameEngine *pge, olc::Sprite *pokemonSprite, int &tileX, int &tileY) {
olc::vi2d spritesheetCoord = getCoordinate();
pge->SetPixelMode(olc::Pixel::MASK);
pge->DrawPartialSprite(tileX, tileY, pokemonSprite, spritesheetCoord.x, spritesheetCoord.y, tileSize.x, tileSize.y);
pge->SetPixelMode(olc::Pixel::NORMAL);
};
vector<Pokemon> allPokemon = { vector<Pokemon> allPokemon = {
{1, "Bulbasaur"}, {1, "Bulbasaur", {1, 1}},
{2, "Ivysaur"}, {2, "Ivysaur"},
{3, "Venusaur"}, {3, "Venusaur"},
{4, "Charmander"}, {4, "Charmander"},
+9 -1
View File
@@ -10,14 +10,22 @@ class Pokemon {
public: public:
string name; string name;
int id; int id;
olc::vi2d worldPos;
Pokemon(int id, string name); Pokemon(int id, string name);
Pokemon(int id, string name, olc::vi2d worldPos);
void drawPokemon(int id); void drawPokemon(olc::PixelGameEngine *pge, olc::Sprite *pokemonSprite, olc::vi2d worldPos);
void drawPokemon(olc::PixelGameEngine *pge, olc::Sprite *pokemonSprite, float tileOffsetX, float tileOffsetY);
void drawPokemon(olc::PixelGameEngine *pge, olc::Sprite *pokemonSprite, int &tileX, int &tileY);
void drawPokemon(string name); void drawPokemon(string name);
void draw(olc::PixelGameEngine *pge, olc::Sprite *pokemonSprite, int nOffsetX, int nOffsetY, float tileOffsetX, float tileOffsetY);
int getRandomPokemonId();
int getID(string name); int getID(string name);
int getName(int it); int getName(int it);
olc::vi2d getCoordinate();
}; };
extern vector<Pokemon> allPokemon; extern vector<Pokemon> allPokemon;
BIN
View File
Binary file not shown.