client/entities and client/client_utilities build

This commit is contained in:
2015-08-02 04:12:22 +10:00
parent 0150dbb929
commit 8838fcd14e
9 changed files with 94 additions and 16 deletions
+45
View File
@@ -0,0 +1,45 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "text_util.hpp"
#include <stdexcept>
SDL_Texture* renderPlainText(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
//make the surface (from SDL_ttf)
SDL_Surface* surface = TTF_RenderText_Solid(font, str.c_str(), color);
if (!surface) {
throw(std::runtime_error("Failed to create a TTF surface"));
}
//convert to texture
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
if (!texture) {
SDL_FreeSurface(surface);
throw(std::runtime_error("Failed to create a TTF texture"));
}
//cleanup
SDL_FreeSurface(surface);
//NOTE: free the texture yourself
return texture;
}
+33
View File
@@ -0,0 +1,33 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#pragma once
#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
#include <string>
constexpr SDL_Color COLOR_WHITE = {255, 255, 255, 255};
//TODO: some kind of persistent display widget
//TODO: I need a full suite of widgets
SDL_Texture* renderPlainText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
+7 -7
View File
@@ -30,16 +30,16 @@
void BaseCharacter::CorrectSprite() { void BaseCharacter::CorrectSprite() {
//NOTE: These must correspond to the sprite sheet in use //NOTE: These must correspond to the sprite sheet in use
if (motion.y > 0) { if (motion.y > 0) {
sprite.SetYIndex(0); sprite.SetIndexY(0);
} }
else if (motion.y < 0) { else if (motion.y < 0) {
sprite.SetYIndex(1); sprite.SetIndexY(1);
} }
else if (motion.x > 0) { else if (motion.x > 0) {
sprite.SetYIndex(3); sprite.SetIndexY(3);
} }
else if (motion.x < 0) { else if (motion.x < 0) {
sprite.SetYIndex(2); sprite.SetIndexY(2);
} }
//animation //animation
@@ -48,7 +48,7 @@ void BaseCharacter::CorrectSprite() {
} }
else { else {
sprite.SetDelay(0); sprite.SetDelay(0);
sprite.SetXIndex(0); sprite.SetIndexX(0);
} }
} }
@@ -72,9 +72,9 @@ std::string BaseCharacter::GetHandle() const {
return handle; return handle;
} }
std::string BaseCharacter::SetAvatar(std::string s) { std::string BaseCharacter::SetAvatar(SDL_Renderer* const renderer, std::string s) {
avatar = s; avatar = s;
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y); sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y);
return avatar; return avatar;
} }
+1 -1
View File
@@ -41,7 +41,7 @@ public:
int GetOwner(); int GetOwner();
std::string SetHandle(std::string s); std::string SetHandle(std::string s);
std::string GetHandle() const; std::string GetHandle() const;
std::string SetAvatar(std::string s); std::string SetAvatar(SDL_Renderer* const, std::string s);
std::string GetAvatar() const; std::string GetAvatar() const;
protected: protected:
+2 -2
View File
@@ -35,9 +35,9 @@ std::string BaseMonster::GetHandle() const {
return handle; return handle;
} }
std::string BaseMonster::SetAvatar(std::string s) { std::string BaseMonster::SetAvatar(SDL_Renderer* const renderer, std::string s) {
avatar = s; avatar = s;
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1); sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1);
return avatar; return avatar;
} }
+1 -1
View File
@@ -32,7 +32,7 @@ public:
std::string SetHandle(std::string s); std::string SetHandle(std::string s);
std::string GetHandle() const; std::string GetHandle() const;
std::string SetAvatar(std::string s); std::string SetAvatar(SDL_Renderer* const, std::string s);
std::string GetAvatar() const; std::string GetAvatar() const;
protected: protected:
+2 -2
View File
@@ -26,8 +26,8 @@ void Entity::Update() {
sprite.Update(0.016); sprite.Update(0.016);
} }
void Entity::DrawTo(SDL_Surface* const dest, int camX, int camY) { void Entity::DrawTo(SDL_Renderer* const renderer, int camX, int camY) {
sprite.DrawTo(dest, origin.x - camX, origin.y - camY); sprite.DrawTo(renderer, origin.x - camX, origin.y - camY);
} }
SpriteSheet* Entity::GetSprite() { SpriteSheet* Entity::GetSprite() {
+1 -1
View File
@@ -29,7 +29,7 @@
class Entity { class Entity {
public: public:
virtual void Update(); virtual void Update();
virtual void DrawTo(SDL_Surface* const, int camX, int camY); virtual void DrawTo(SDL_Renderer* const, int camX, int camY);
SpriteSheet* GetSprite(); SpriteSheet* GetSprite();
+2 -2
View File
@@ -29,8 +29,8 @@ OUT=$(addprefix $(OUTDIR)/,client)
#targets #targets
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
# $(MAKE) -C client_utilities $(MAKE) -C client_utilities
# $(MAKE) -C entities $(MAKE) -C entities
# $(MAKE) -C gameplay_scenes # $(MAKE) -C gameplay_scenes
# $(MAKE) -C menu_scenes # $(MAKE) -C menu_scenes
# $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) # $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)