Compare commits
2 Commits
688def7e01
...
ca423994ea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca423994ea | ||
|
|
38931cf65e |
18
Animal.cpp
18
Animal.cpp
@@ -22,6 +22,7 @@ Animal::Animal(string skin) {
|
|||||||
cur = 0;
|
cur = 0;
|
||||||
viime_event = 0;
|
viime_event = 0;
|
||||||
state_changed = false;
|
state_changed = false;
|
||||||
|
animation_i = 0;
|
||||||
|
|
||||||
// set rand seed
|
// set rand seed
|
||||||
SDL_srand(0);
|
SDL_srand(0);
|
||||||
@@ -31,6 +32,11 @@ Animal::Animal(string skin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Animal::~Animal() {
|
Animal::~Animal() {
|
||||||
|
for (unsigned i = 0; i < states.size(); i++) {
|
||||||
|
if (states[i]) {
|
||||||
|
delete states[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *Animal::readImg(string skin, string state_name, int num) {
|
SDL_Surface *Animal::readImg(string skin, string state_name, int num) {
|
||||||
@@ -79,6 +85,12 @@ void Animal::readSkin(string skin) {
|
|||||||
State feat;
|
State feat;
|
||||||
char prev_chr;
|
char prev_chr;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < states.size(); i++) {
|
||||||
|
if (states[i]) {
|
||||||
|
delete states[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
states.clear();
|
states.clear();
|
||||||
special_states.clear();
|
special_states.clear();
|
||||||
random_states.clear();
|
random_states.clear();
|
||||||
@@ -150,11 +162,11 @@ void Animal::readSkinStep(string skin, char chr, string &buf, string &key, State
|
|||||||
prev_chr = chr;
|
prev_chr = chr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animal::readSkinFill(string skin, State feat) {
|
void Animal::readSkinFill(string skin, State &feat) {
|
||||||
states.push_back(feat);
|
cur_state = new State(feat);
|
||||||
|
states.push_back(cur_state);
|
||||||
|
|
||||||
// Load images to memory
|
// Load images to memory
|
||||||
cur_state = &states.back();
|
|
||||||
for (int x = 0; x < cur_state->count; x++) {
|
for (int x = 0; x < cur_state->count; x++) {
|
||||||
cur_state->imgs.push_back(NULL);
|
cur_state->imgs.push_back(NULL);
|
||||||
cur_state->imgs[x] = readImg(skin, cur_state->img_name, x);
|
cur_state->imgs[x] = readImg(skin, cur_state->img_name, x);
|
||||||
|
|||||||
11
Animal.h
11
Animal.h
@@ -30,6 +30,13 @@ class State {
|
|||||||
|
|
||||||
vector<SDL_Surface *> imgs;
|
vector<SDL_Surface *> imgs;
|
||||||
SoundData sound_data;
|
SoundData sound_data;
|
||||||
|
~State() {
|
||||||
|
for (unsigned i = 0; i < imgs.size(); i++) {
|
||||||
|
if (imgs[i]) {
|
||||||
|
SDL_DestroySurface(imgs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Animal {
|
class Animal {
|
||||||
@@ -40,7 +47,7 @@ class Animal {
|
|||||||
SDL_Surface *readImg(string skin, string state_name, int num);
|
SDL_Surface *readImg(string skin, string state_name, int num);
|
||||||
void readSkin(string file);
|
void readSkin(string file);
|
||||||
void readSkinStep(string skin, char chr, string &buf, string &key, State &state, char &prev_chr);
|
void readSkinStep(string skin, char chr, string &buf, string &key, State &state, char &prev_chr);
|
||||||
void readSkinFill(string skin, State state);
|
void readSkinFill(string skin, State &state);
|
||||||
void createShape(int num, int w, int h);
|
void createShape(int num, int w, int h);
|
||||||
void move();
|
void move();
|
||||||
void animate(bool reset);
|
void animate(bool reset);
|
||||||
@@ -57,7 +64,7 @@ class Animal {
|
|||||||
|
|
||||||
SDL_Rect disp_pos; // has display width and height and window posiion on it
|
SDL_Rect disp_pos; // has display width and height and window posiion on it
|
||||||
|
|
||||||
vector<State> states;
|
vector<State *> states;
|
||||||
vector<State *> special_states;
|
vector<State *> special_states;
|
||||||
State *cur_state;
|
State *cur_state;
|
||||||
vector<State *> random_states;
|
vector<State *> random_states;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../SDLHelpers.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -5,8 +7,6 @@ using namespace std;
|
|||||||
|
|
||||||
#include <SDL3_ttf/SDL_ttf.h>
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
|
|
||||||
#include "../SDLHelpers.h"
|
|
||||||
|
|
||||||
#include "Button.h"
|
#include "Button.h"
|
||||||
|
|
||||||
Button::Button(string text, SDL_Color color, SDL_Rect pos) : Item(pos) {
|
Button::Button(string text, SDL_Color color, SDL_Rect pos) : Item(pos) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../SDLHelpers.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -5,8 +7,6 @@ using namespace std;
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3_ttf/SDL_ttf.h>
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
|
|
||||||
#include "../SDLHelpers.h"
|
|
||||||
|
|
||||||
#include "Checkbox.h"
|
#include "Checkbox.h"
|
||||||
|
|
||||||
bool isBetween(float a, float b, float c) {
|
bool isBetween(float a, float b, float c) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../SDLHelpers.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -6,8 +8,6 @@ using namespace std;
|
|||||||
#include <SDL3_image/SDL_image.h>
|
#include <SDL3_image/SDL_image.h>
|
||||||
#include <SDL3_ttf/SDL_ttf.h>
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
|
|
||||||
#include "../SDLHelpers.h"
|
|
||||||
|
|
||||||
#include "Item.h"
|
#include "Item.h"
|
||||||
#include "Scrollbar.h"
|
#include "Scrollbar.h"
|
||||||
#include "Listbox.h"
|
#include "Listbox.h"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../SDLHelpers.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -12,12 +14,9 @@ using namespace std;
|
|||||||
#include <SDL3_ttf/SDL_ttf.h>
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
#include <SDL3/SDL_storage.h>
|
#include <SDL3/SDL_storage.h>
|
||||||
|
|
||||||
#include "../SDLHelpers.h"
|
|
||||||
|
|
||||||
#include "Item.h"
|
#include "Item.h"
|
||||||
#include "Button.h"
|
#include "Button.h"
|
||||||
#include "Dialog.h"
|
#include "Dialog.h"
|
||||||
#include "Frame.h"
|
|
||||||
|
|
||||||
#include "DlgMainMenu.h"
|
#include "DlgMainMenu.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../SDLHelpers.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -6,8 +8,6 @@ using namespace std;
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3_ttf/SDL_ttf.h>
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
|
|
||||||
#include "../SDLHelpers.h"
|
|
||||||
|
|
||||||
#include "DropDownList.h"
|
#include "DropDownList.h"
|
||||||
#include "DlgDropDownList.h"
|
#include "DlgDropDownList.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../SDLHelpers.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -5,8 +7,6 @@ using namespace std;
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3_ttf/SDL_ttf.h>
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
|
|
||||||
#include "../SDLHelpers.h"
|
|
||||||
|
|
||||||
#include "Listbox.h"
|
#include "Listbox.h"
|
||||||
|
|
||||||
Listbox::Listbox(vector<string> list, int item_size, SDL_Rect pos) : Item(pos) {
|
Listbox::Listbox(vector<string> list, int item_size, SDL_Rect pos) : Item(pos) {
|
||||||
|
|||||||
18
SDLHelpers.h
18
SDLHelpers.h
@@ -8,6 +8,10 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#ifdef SDL_PLATFORM_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static const char *font_paths[] = {"C:/windows/fonts/", "/usr/share/fonts/TTF/", "./"};
|
static const char *font_paths[] = {"C:/windows/fonts/", "/usr/share/fonts/TTF/", "./"};
|
||||||
static const short font_path_count = 3;
|
static const short font_path_count = 3;
|
||||||
|
|
||||||
@@ -31,12 +35,24 @@ static SDL_Color getColor(Uint8 r, Uint8 g, Uint8 b) {
|
|||||||
static TTF_Font *openFont(std::vector<std::string> fonts, int size) {
|
static TTF_Font *openFont(std::vector<std::string> fonts, int size) {
|
||||||
TTF_Font *font = NULL;
|
TTF_Font *font = NULL;
|
||||||
for (int x = 0; x < fonts.size(); x++) {
|
for (int x = 0; x < fonts.size(); x++) {
|
||||||
|
#ifdef SDL_PLATFORM_WINDOWS
|
||||||
|
TCHAR windir[MAX_PATH];
|
||||||
|
GetWindowsDirectory(windir, MAX_PATH);
|
||||||
|
std::string windir_s(windir);
|
||||||
|
windir_s.append("/fonts/");
|
||||||
|
windir_s.append(fonts[x]);
|
||||||
|
font = TTF_OpenFont(windir_s.c_str(), size);
|
||||||
|
if (font) {
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
for (int y = 0; y < font_path_count; y++) {
|
for (int y = 0; y < font_path_count; y++) {
|
||||||
std::string val(font_paths[y]);
|
std::string val(font_paths[y]);
|
||||||
val.append(fonts[x]);
|
val.append(fonts[x]);
|
||||||
font = TTF_OpenFont(val.c_str(), size);
|
font = TTF_OpenFont(val.c_str(), size);
|
||||||
if (font)
|
if (font) {
|
||||||
return font;
|
return font;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user