Added AiController - no real substance yet. UI shaders may now have a vertical 'fade' (darkening, ultimately). UI shader should have outlining be toggle-able via a boolean or similar (or perhaps separate shaders for text). GodHand now succesfully swaps entities when used. UI elements may be rotated now. Added a silly Ui Time element that simply rotates each tick. Added remove and check for Thing abilities. Need to flesh out needed Thing logic more. Also need to update Ui character sheet based on GodHand swap.
parent
798e298ca5
commit
191814cb7f
|
@ -18,7 +18,7 @@ OBJ=main.o fio.o Core.o Log.o QMap.o Tile.o Thought.o
|
||||||
OBJ+=render/Quat.o render/Mat4.o render/Vec.o render/Mesh.o render/Texture.o render/Program.o render/RenderScene.o render/RenderSet.o render/RenderObject.o render/RenderCamera.o render/RenderView.o render/Sprite.o
|
OBJ+=render/Quat.o render/Mat4.o render/Vec.o render/Mesh.o render/Texture.o render/Program.o render/RenderScene.o render/RenderSet.o render/RenderObject.o render/RenderCamera.o render/RenderView.o render/Sprite.o
|
||||||
OBJ+=render/Font.o render/Ui.o render/UiText.o
|
OBJ+=render/Font.o render/Ui.o render/UiText.o
|
||||||
OBJ+=states/GameState.o states/UiSubState.o
|
OBJ+=states/GameState.o states/UiSubState.o
|
||||||
OBJ+=Controller.o PlayerController.o
|
OBJ+=Controller.o PlayerController.o AiController.o
|
||||||
OBJ+=things/Thing.o things/Denizen.o things/SightSeer.o things/GnashingGibber.o
|
OBJ+=things/Thing.o things/Denizen.o things/SightSeer.o things/GnashingGibber.o
|
||||||
OBJ+=abilities/Ability.o abilities/GodHand.o abilities/VampiricNom.o
|
OBJ+=abilities/Ability.o abilities/GodHand.o abilities/VampiricNom.o
|
||||||
OBJ_DIR=obj
|
OBJ_DIR=obj
|
||||||
|
|
|
@ -14,4 +14,4 @@ void main() {
|
||||||
gl_FragColor = vec4(0.75, 0.5, 0.5, c);
|
gl_FragColor = vec4(0.75, 0.5, 0.5, c);
|
||||||
if (gl_FragColor.a == 0.0) discard;
|
if (gl_FragColor.a == 0.0) discard;
|
||||||
//gl_FragColor = vec4(0.5, 0.0, 0.0, 0.5);
|
//gl_FragColor = vec4(0.5, 0.0, 0.0, 0.5);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,34 @@
|
||||||
// uniforms
|
// uniforms
|
||||||
uniform sampler2D texture_sampler;
|
uniform sampler2D texture_sampler;
|
||||||
uniform float transparency;
|
uniform float transparency;
|
||||||
|
uniform float vertical_fade;
|
||||||
// input
|
// input
|
||||||
varying vec2 frag_uv;
|
varying vec2 frag_uv;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_FragColor = texture2D(texture_sampler, frag_uv);
|
gl_FragColor = texture2D(texture_sampler, frag_uv);
|
||||||
gl_FragColor.a -= transparency;
|
// grossly outline the UI element
|
||||||
gl_FragColor.a -= 0.10;
|
if (gl_FragColor.a < 0.1 && frag_uv.x >= 0.001 && frag_uv.x <= 0.999 && frag_uv.y >= 0.001 && frag_uv.y <= 0.999) {
|
||||||
|
vec4 t = texture2D(texture_sampler, frag_uv + vec2( 0.0f, -0.0025f ));
|
||||||
|
vec4 b = texture2D(texture_sampler, frag_uv + vec2( 0.0f, 0.0025f ));
|
||||||
|
vec4 l = texture2D(texture_sampler, frag_uv + vec2( -0.0025f, 0.0f ));
|
||||||
|
float c = 0.0f;
|
||||||
|
if (t.a > 0.75) {
|
||||||
|
gl_FragColor = vec4(0.5 - t.r, 0.5 - t.g, 0.5 - t.b, 1.0 - transparency);
|
||||||
|
} else if (b.a > 0.75) {
|
||||||
|
gl_FragColor = vec4(0.5 - b.r, 0.5 - b.g, 0.5 - b.b, 1.0 - transparency);
|
||||||
|
} else if (l.a > 0.75) {
|
||||||
|
gl_FragColor = vec4(0.5 - l.r, 0.5 - l.g, 0.5 - l.b, 1.0 - transparency);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gl_FragColor.a -= transparency;
|
||||||
|
gl_FragColor.a -= 0.10;
|
||||||
|
}
|
||||||
|
// modify alpha/color based on UV offsets.
|
||||||
|
if (vertical_fade > 0) {
|
||||||
|
//gl_FragColor.a -= 0.35 - frag_uv.y; // this increases alpha towards top
|
||||||
|
gl_FragColor.rgb -= (0.35 - frag_uv.y/2); // this darkens rgb towards top
|
||||||
|
}
|
||||||
if (gl_FragColor.a == 0.0) discard;
|
if (gl_FragColor.a == 0.0) discard;
|
||||||
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 423 B |
|
@ -0,0 +1,22 @@
|
||||||
|
#include "AiController.hpp"
|
||||||
|
#include "Thought.hpp"
|
||||||
|
#include "Thing.hpp"
|
||||||
|
#include "Core.hpp"
|
||||||
|
#include "Log.hpp"
|
||||||
|
|
||||||
|
AiController::AiController() {
|
||||||
|
}
|
||||||
|
AiController::~AiController() {
|
||||||
|
}
|
||||||
|
void AiController::doThink(int ticks) {
|
||||||
|
std::vector<Thing*>::iterator t_it, t_end;
|
||||||
|
for (t_it = things.begin(), t_end = things.end(); t_it != t_end; ++t_it) {
|
||||||
|
Thing *thing = *t_it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void AiController::controlThing(Thing *thing_) {
|
||||||
|
things.push_back(thing_);
|
||||||
|
}
|
||||||
|
void AiController::recvMessage(std::string string) {
|
||||||
|
LOG(LOG_INFO) << string;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef AICONTROLLER_HPP
|
||||||
|
#define AICONTROLLER_HPP
|
||||||
|
#include "Controller.hpp"
|
||||||
|
#include <vector>
|
||||||
|
class AiController : Controller {
|
||||||
|
friend class GameState;
|
||||||
|
public:
|
||||||
|
AiController();
|
||||||
|
~AiController();
|
||||||
|
virtual void doThink(int ticks);
|
||||||
|
virtual void controlThing(Thing *thing_);
|
||||||
|
virtual void recvMessage(std::string string);
|
||||||
|
protected:
|
||||||
|
std::vector<Thing*> things;
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
Controller::Controller() {
|
Controller::Controller() {
|
||||||
thing = NULL;
|
thing = NULL;
|
||||||
|
tick_rate = 50;
|
||||||
}
|
}
|
||||||
Controller::~Controller() {
|
Controller::~Controller() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,10 @@ class Controller {
|
||||||
Controller();
|
Controller();
|
||||||
~Controller();
|
~Controller();
|
||||||
virtual void recvMessage(std::string string) { return; };
|
virtual void recvMessage(std::string string) { return; };
|
||||||
|
virtual void doThink(int ticks) { return; };
|
||||||
|
virtual void controlThing(Thing *thing_) { thing = thing_; };
|
||||||
protected:
|
protected:
|
||||||
Thing *thing;
|
Thing *thing;
|
||||||
|
int tick_rate;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
21
src/Core.cpp
21
src/Core.cpp
|
@ -47,9 +47,22 @@ int Core::initSystem() {
|
||||||
LOG(LOG_ERROR) << TTF_GetError();
|
LOG(LOG_ERROR) << TTF_GetError();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// get our displayyyy
|
// ** Get our display, checking bounding boxes for multi monitor setups
|
||||||
|
int di = SDL_GetNumVideoDisplays()-1; // display index (monitor)
|
||||||
|
/*int mx, my;
|
||||||
|
SDL_GetGlobalMouseState(&mx, &my); // SDL 2.0.4
|
||||||
|
LOG(LOG_INFO) << "mouse: " << mx << "x" << my;
|
||||||
|
int dc = SDL_GetNumVideoDisplays();
|
||||||
|
for (di = 0; di < dc; di++) {
|
||||||
|
SDL_Rect dr;
|
||||||
|
SDL_GetDisplayBounds(di, &dr);
|
||||||
|
if ((mx >= dr.x && mx <= dr.x+dr.w) && (my >= dr.y && my <= dr.y+dr.h)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
// get our window size from display
|
||||||
SDL_DisplayMode dmode;
|
SDL_DisplayMode dmode;
|
||||||
SDL_GetDesktopDisplayMode(0, &dmode);
|
SDL_GetCurrentDisplayMode(di, &dmode);
|
||||||
v_width = dmode.w - dmode.w/4; // TEMP: just for a smaller window per-default
|
v_width = dmode.w - dmode.w/4; // TEMP: just for a smaller window per-default
|
||||||
v_height = dmode.h - dmode.h/4;
|
v_height = dmode.h - dmode.h/4;
|
||||||
v_flags = SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE;
|
v_flags = SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE;
|
||||||
|
@ -279,8 +292,8 @@ Font* Core::getFont(const char *font_name) {
|
||||||
char *fbuf = NULL;
|
char *fbuf = NULL;
|
||||||
size_t flen = 0;
|
size_t flen = 0;
|
||||||
flen = fileToMem(font_name, &fbuf);
|
flen = fileToMem(font_name, &fbuf);
|
||||||
font = new Font(font_name, 13, fbuf, flen);
|
font = new Font(font_name, 11, fbuf, flen);
|
||||||
font_table->set(font_name, font);
|
font_table->set(font_name, font);
|
||||||
}
|
}
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "GodHand.hpp"
|
#include "GodHand.hpp"
|
||||||
|
#include "QMap.hpp"
|
||||||
#include "Controller.hpp"
|
#include "Controller.hpp"
|
||||||
#include "Thing.hpp"
|
#include "Thing.hpp"
|
||||||
|
|
||||||
|
@ -11,10 +12,22 @@ GodHand::~GodHand() {
|
||||||
delete sprite;
|
delete sprite;
|
||||||
}
|
}
|
||||||
int GodHand::onUse() {
|
int GodHand::onUse() {
|
||||||
owner->getController()->recvMessage("The nature of Things have changed.");
|
Vec3 dir = owner->getDirection();
|
||||||
|
Thing *othing = owner->getMap()->checkThings(owner, dir.x, dir.y, 24, 24);
|
||||||
|
if (othing != NULL) {
|
||||||
|
Controller *ocontroller = othing->getController();
|
||||||
|
othing->setController(owner->getController());
|
||||||
|
owner->setController(ocontroller);
|
||||||
|
owner->remAbility(name);
|
||||||
|
othing->unshiftAbility(this);
|
||||||
|
owner->getController()->recvMessage("The nature of Things have changed.");
|
||||||
|
// TODO: haiku-based swap difference, each ability has 5 and 7 syllable versions that create a 5-7-5 message
|
||||||
|
} else {
|
||||||
|
owner->getController()->recvMessage("You yearn for a new host.");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int GodHand::onPrompt() {
|
int GodHand::onPrompt() {
|
||||||
owner->getController()->recvMessage("Soul swap with what?");
|
owner->getController()->recvMessage("Soul swap with what?");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,6 @@ void Sprite::doAnimation(unsigned int ticks) {
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
void Sprite::setOffset(int col_, int row_) {
|
void Sprite::setOffset(int col_, int row_) {
|
||||||
LOG(LOG_INFO) << x << "x" << y;
|
|
||||||
col = col_;
|
col = col_;
|
||||||
row = row_;
|
row = row_;
|
||||||
uv_x = col * uvw;
|
uv_x = col * uvw;
|
||||||
|
@ -76,4 +75,4 @@ void Sprite::setPosition(float xpos, float ypos) {
|
||||||
// NOTE: since we're using orthogonal rendering, we send ypos as the depth as well (so we don't have to sort)
|
// NOTE: since we're using orthogonal rendering, we send ypos as the depth as well (so we don't have to sort)
|
||||||
object->setTranslation(xpos, ypos, -ypos);
|
object->setTranslation(xpos, ypos, -ypos);
|
||||||
object->calcMatrix();
|
object->calcMatrix();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ Ui::Ui() {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
timeout_elapsed = 0;
|
timeout_elapsed = 0;
|
||||||
transparency = 0.0f;
|
transparency = 0.0f;
|
||||||
|
vertical_fade = 0.0f;
|
||||||
}
|
}
|
||||||
Ui::Ui(const char *filename, int width_, int height_) {
|
Ui::Ui(const char *filename, int width_, int height_) {
|
||||||
texture = NULL;
|
texture = NULL;
|
||||||
|
@ -19,6 +20,7 @@ Ui::Ui(const char *filename, int width_, int height_) {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
timeout_elapsed = 0;
|
timeout_elapsed = 0;
|
||||||
transparency = 0.0f;
|
transparency = 0.0f;
|
||||||
|
vertical_fade = 0.0f;
|
||||||
setImage(filename, width_, height_);
|
setImage(filename, width_, height_);
|
||||||
}
|
}
|
||||||
Ui::~Ui() {
|
Ui::~Ui() {
|
||||||
|
@ -71,6 +73,11 @@ void Ui::setPosition(float xpos, float ypos) {
|
||||||
x = xpos;
|
x = xpos;
|
||||||
y = ypos;
|
y = ypos;
|
||||||
}
|
}
|
||||||
|
void Ui::setRotation(int angle_) {
|
||||||
|
angle = angle_;
|
||||||
|
object->setRotation(0, angle, 0);
|
||||||
|
object->calcMatrix();
|
||||||
|
}
|
||||||
void Ui::setOffset(int col_, int row_) {
|
void Ui::setOffset(int col_, int row_) {
|
||||||
col = col_;
|
col = col_;
|
||||||
row = row_;
|
row = row_;
|
||||||
|
|
|
@ -15,12 +15,14 @@ class Ui {
|
||||||
virtual void setPosition(float x, float y);
|
virtual void setPosition(float x, float y);
|
||||||
void setOffset(int col, int row);
|
void setOffset(int col, int row);
|
||||||
void setTimeout(int time);
|
void setTimeout(int time);
|
||||||
|
void setRotation(int angle);
|
||||||
Texture *getTexture() { return texture; };
|
Texture *getTexture() { return texture; };
|
||||||
RenderObject *getObject() { return object; };
|
RenderObject *getObject() { return object; };
|
||||||
int getWidth() { return width; };
|
int getWidth() { return width; };
|
||||||
int getHeight() { return height; };
|
int getHeight() { return height; };
|
||||||
void doRefresh(float screen_w, float screen_h);
|
void doRefresh(float screen_w, float screen_h);
|
||||||
void doProcess(unsigned int ticks);
|
void doProcess(unsigned int ticks);
|
||||||
|
int getAngle() { return angle; };
|
||||||
int flags;
|
int flags;
|
||||||
enum Flags {
|
enum Flags {
|
||||||
UI_DESTROY = (1 << 1)
|
UI_DESTROY = (1 << 1)
|
||||||
|
@ -32,12 +34,14 @@ class Ui {
|
||||||
int width, height; // width and height of ui element
|
int width, height; // width and height of ui element
|
||||||
int col, row; // column and row in spritesheet
|
int col, row; // column and row in spritesheet
|
||||||
float x, y; // x and y in coordinates
|
float x, y; // x and y in coordinates
|
||||||
|
int angle; // angle in eular
|
||||||
int max_x, max_y; // max x and y coordinates derived from texture
|
int max_x, max_y; // max x and y coordinates derived from texture
|
||||||
float uv_x, uv_y; // uv x and y offsets
|
float uv_x, uv_y; // uv x and y offsets
|
||||||
float uvw, uvh; // sprite size in UV terms
|
float uvw, uvh; // sprite size in UV terms
|
||||||
float timeout; // time to keep this Ui up before closing it
|
float timeout; // time to keep this Ui up before closing it
|
||||||
float timeout_elapsed; // elapsed time for ^
|
float timeout_elapsed; // elapsed time for ^
|
||||||
float transparency; // alpha of this element, 1.0 = full transparent, 0.0 = full opacity
|
float transparency; // alpha of this element, 1.0 = full transparent, 0.0 = full opacity
|
||||||
|
float vertical_fade; // vertical fading to apply, 0 = none
|
||||||
};
|
};
|
||||||
|
|
||||||
bool destroyUi(Ui* ui);
|
bool destroyUi(Ui* ui);
|
||||||
|
|
|
@ -4,12 +4,14 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
UiText::UiText() {
|
UiText::UiText() {
|
||||||
|
vertical_fade = 1.0f;
|
||||||
}
|
}
|
||||||
UiText::UiText(const char *text_, Font *font_, SDL_Color color_) {
|
UiText::UiText(const char *text_, Font *font_, SDL_Color color_) {
|
||||||
text = text_;
|
text = text_;
|
||||||
font = font_;
|
font = font_;
|
||||||
color = color_;
|
color = color_;
|
||||||
texture = NULL;
|
texture = NULL;
|
||||||
|
vertical_fade = 1.0f;
|
||||||
setText(text_);
|
setText(text_);
|
||||||
}
|
}
|
||||||
UiText::~UiText() {
|
UiText::~UiText() {
|
||||||
|
@ -30,11 +32,15 @@ void UiText::setText(std::string text_) {
|
||||||
text = text_;
|
text = text_;
|
||||||
buildText(text);
|
buildText(text);
|
||||||
|
|
||||||
width = texture->w/2; height = texture->h/2;
|
|
||||||
x = y = 0;
|
x = y = 0;
|
||||||
row = col = 0;
|
row = col = 0;
|
||||||
|
width = texture->w/2; height = texture->h/2;
|
||||||
max_x = texture->w/2 / width;
|
max_x = texture->w/2 / width;
|
||||||
max_y = texture->h/2 / height;
|
max_y = texture->h/2 / height;
|
||||||
|
/*width = texture->w; height = texture->h;
|
||||||
|
max_x = texture->w / width;
|
||||||
|
max_y = texture->h / height;*/
|
||||||
|
|
||||||
object = new RenderObject();
|
object = new RenderObject();
|
||||||
object->setScale(1.0f, 1.0f, 1.0f);
|
object->setScale(1.0f, 1.0f, 1.0f);
|
||||||
object->calcMatrix();
|
object->calcMatrix();
|
||||||
|
@ -73,9 +79,7 @@ Texture *UiText::buildText(std::string string) {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
SDL_Surface *line_surface = NULL;
|
SDL_Surface *line_surface = NULL;
|
||||||
LOG(LOG_INFO) << "about to build!";
|
|
||||||
while(std::getline(ss, line, '\n')) {
|
while(std::getline(ss, line, '\n')) {
|
||||||
//LOG(LOG_INFO) << line;
|
|
||||||
line_surface = TTF_RenderUTF8_Blended(font->font, line.c_str(), color);
|
line_surface = TTF_RenderUTF8_Blended(font->font, line.c_str(), color);
|
||||||
if (line_surface == NULL) {
|
if (line_surface == NULL) {
|
||||||
line_surfaces.push_back(NULL);
|
line_surfaces.push_back(NULL);
|
||||||
|
@ -86,7 +90,6 @@ Texture *UiText::buildText(std::string string) {
|
||||||
height += line_surface->h;
|
height += line_surface->h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG(LOG_INFO) << "built!";
|
|
||||||
SDL_Surface *final_surface = SDL_CreateRGBSurface(0, width, height, line_surface->format->BitsPerPixel, line_surface->format->Rmask, line_surface->format->Gmask, line_surface->format->Bmask, line_surface->format->Amask);
|
SDL_Surface *final_surface = SDL_CreateRGBSurface(0, width, height, line_surface->format->BitsPerPixel, line_surface->format->Rmask, line_surface->format->Gmask, line_surface->format->Bmask, line_surface->format->Amask);
|
||||||
SDL_Rect offset = { 0, 0, 0, 0 };
|
SDL_Rect offset = { 0, 0, 0, 0 };
|
||||||
std::vector<SDL_Surface*>::iterator surface_it, surface_end;
|
std::vector<SDL_Surface*>::iterator surface_it, surface_end;
|
||||||
|
@ -105,4 +108,4 @@ Texture *UiText::buildText(std::string string) {
|
||||||
texture->buildTexture();
|
texture->buildTexture();
|
||||||
//SDL_FreeSurface(final_surface); // NOTE: surface is freed by the Texture
|
//SDL_FreeSurface(final_surface); // NOTE: surface is freed by the Texture
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,10 @@
|
||||||
GameState::GameState() {
|
GameState::GameState() {
|
||||||
camera = new RenderCamera();
|
camera = new RenderCamera();
|
||||||
camera->setRenderView(new RenderView(core.getWidth(), core.getHeight()));
|
camera->setRenderView(new RenderView(core.getWidth(), core.getHeight()));
|
||||||
camera->setPitch(90.0f);
|
//camera->setPitch(75.0f);
|
||||||
|
//camera->setPosition(0, 1000, 0);
|
||||||
/*camera->setPosition(0, core.getHeight()*2, 0);*/
|
/*camera->setPosition(0, core.getHeight()*2, 0);*/
|
||||||
camera->setPosition(0, 0, 0);
|
camera->setPitch(90.0f);
|
||||||
camera->setRenderMode(1);
|
camera->setRenderMode(1);
|
||||||
camera->setSize(core.getHeight());
|
camera->setSize(core.getHeight());
|
||||||
camera->updateProjection(core.getWidth(), core.getHeight());
|
camera->updateProjection(core.getWidth(), core.getHeight());
|
||||||
|
@ -48,14 +49,20 @@ GameState::GameState() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pc.thing = new GnashingGibber();
|
Thing *thing = new GnashingGibber();
|
||||||
pc.thing->setController(&pc);
|
thing->setController(&pc);
|
||||||
pc.thing->unshiftAbility(new GodHand());
|
thing->unshiftAbility(new GodHand());
|
||||||
current_map->addThing(pc.thing, 1, 1);
|
current_map->addThing(thing, 1, 1);
|
||||||
|
|
||||||
current_map->addThing(new Denizen(), 2, 2);
|
thing = new Denizen();
|
||||||
|
thing->setController(&ac);
|
||||||
|
|
||||||
current_map->addThing(new SightSeer(), 4, 4);
|
current_map->addThing(thing, 2, 2);
|
||||||
|
|
||||||
|
thing = new SightSeer();
|
||||||
|
thing->setController(&ac);
|
||||||
|
|
||||||
|
current_map->addThing(thing, 4, 4);
|
||||||
|
|
||||||
ui_state = new UiSubState();
|
ui_state = new UiSubState();
|
||||||
|
|
||||||
|
@ -65,6 +72,10 @@ GameState::GameState() {
|
||||||
ui_state->pushUi(ui_character);
|
ui_state->pushUi(ui_character);
|
||||||
ui_character->setImage("data/sprites/gnashing_gibber.png", 16, 32);
|
ui_character->setImage("data/sprites/gnashing_gibber.png", 16, 32);
|
||||||
|
|
||||||
|
ui_time = new Ui("data/sprites/ui_time.png", 16, 16);
|
||||||
|
ui_time->setPosition(32, 32);
|
||||||
|
ui_state->pushUi(ui_time);
|
||||||
|
|
||||||
SDL_Color color = { 128, 255, 128, 255 };
|
SDL_Color color = { 128, 255, 128, 255 };
|
||||||
ui_sheet_name = new UiText("Gnashing Gibber", core.getFont("data/fonts/default.ttf"), color);
|
ui_sheet_name = new UiText("Gnashing Gibber", core.getFont("data/fonts/default.ttf"), color);
|
||||||
ui_state->pushUi(ui_sheet_name);
|
ui_state->pushUi(ui_sheet_name);
|
||||||
|
@ -139,8 +150,14 @@ int GameState::onEvent(SDL_Event event) {
|
||||||
int GameState::doProcess(unsigned int ticks) {
|
int GameState::doProcess(unsigned int ticks) {
|
||||||
ui_state->doProcess(ticks);
|
ui_state->doProcess(ticks);
|
||||||
// 1. for each AiController, run their doThink
|
// 1. for each AiController, run their doThink
|
||||||
|
std::vector<Controller*>::iterator c_it, c_end;
|
||||||
|
for (c_it = controllers.begin(), c_end = controllers.end(); c_it != c_end; ++c_it) {
|
||||||
|
Controller *controller = *c_it;
|
||||||
|
controller->doThink(ticks);
|
||||||
|
}
|
||||||
// 2. for each thing, run their doThink
|
// 2. for each thing, run their doThink
|
||||||
if ((pc.thing->thoughts.size() <= 0 && pc.thing->thought_current.type == 0) && pc.thing->velocity.x == 0 && pc.thing->velocity.y == 0) return 0;
|
if ((pc.thing->thoughts.size() <= 0 && pc.thing->thought_current.type == 0) && pc.thing->velocity.x == 0 && pc.thing->velocity.y == 0) return 0;
|
||||||
|
ui_time->setRotation(ui_time->getAngle()+1);
|
||||||
std::vector<Thing*>::iterator thing_it, thing_end;
|
std::vector<Thing*>::iterator thing_it, thing_end;
|
||||||
for (thing_it = current_map->things.begin(), thing_end = current_map->things.end(); thing_it != thing_end; ++thing_it) {
|
for (thing_it = current_map->things.begin(), thing_end = current_map->things.end(); thing_it != thing_end; ++thing_it) {
|
||||||
Thing *thing = *thing_it;
|
Thing *thing = *thing_it;
|
||||||
|
@ -156,8 +173,8 @@ int GameState::doProcess(unsigned int ticks) {
|
||||||
thing->getSprite()->doAnimation(ticks);
|
thing->getSprite()->doAnimation(ticks);
|
||||||
float x = thing->velocity.x;
|
float x = thing->velocity.x;
|
||||||
float y = thing->velocity.y;
|
float y = thing->velocity.y;
|
||||||
if (x != 0) thing->velocity.x += -x/2;
|
if (x != 0) thing->velocity.x += -x/4;
|
||||||
if (y != 0) thing->velocity.y += -y/2;
|
if (y != 0) thing->velocity.y += -y/4;
|
||||||
if (thing->velocity.x > -0.05 && thing->velocity.x < 0.05) thing->velocity.x = 0;
|
if (thing->velocity.x > -0.05 && thing->velocity.x < 0.05) thing->velocity.x = 0;
|
||||||
if (thing->velocity.y > -0.05 && thing->velocity.y < 0.05) thing->velocity.y = 0;
|
if (thing->velocity.y > -0.05 && thing->velocity.y < 0.05) thing->velocity.y = 0;
|
||||||
if (x != 0 || y != 0) {
|
if (x != 0 || y != 0) {
|
||||||
|
@ -165,7 +182,6 @@ int GameState::doProcess(unsigned int ticks) {
|
||||||
if (othing != NULL) {
|
if (othing != NULL) {
|
||||||
thing->setVelocity(Vec3(0, 0, 0));
|
thing->setVelocity(Vec3(0, 0, 0));
|
||||||
thing->doTouch(othing);
|
thing->doTouch(othing);
|
||||||
othing->onTouch(thing);
|
|
||||||
}
|
}
|
||||||
Tile *tile = current_map->checkTiles(thing, x, y, thing->getSprite()->getWidth(), thing->getSprite()->getHeight()/3);
|
Tile *tile = current_map->checkTiles(thing, x, y, thing->getSprite()->getWidth(), thing->getSprite()->getHeight()/3);
|
||||||
if (tile == NULL) {
|
if (tile == NULL) {
|
||||||
|
@ -189,6 +205,7 @@ int GameState::doProcess(unsigned int ticks) {
|
||||||
}
|
}
|
||||||
// 4. Finally, set the camera to the player's current thing
|
// 4. Finally, set the camera to the player's current thing
|
||||||
camera->setPosition(pc.thing->position.x, camera->getPosition().y, -pc.thing->position.y);
|
camera->setPosition(pc.thing->position.x, camera->getPosition().y, -pc.thing->position.y);
|
||||||
|
//camera->setPosition(pc.thing->position.x, camera->getPosition().y, -pc.thing->position.y*1.5);
|
||||||
camera->doRefresh();
|
camera->doRefresh();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -306,6 +323,9 @@ int GameState::doRender() {
|
||||||
int GameState::refreshUi() {
|
int GameState::refreshUi() {
|
||||||
int width = core.getWidth();
|
int width = core.getWidth();
|
||||||
int height = core.getHeight();
|
int height = core.getHeight();
|
||||||
|
|
||||||
|
ui_time->setPosition(16, 16);
|
||||||
|
ui_time->doRefresh(width, height);
|
||||||
|
|
||||||
ui_sheet->setPosition(width - ui_sheet->getWidth()*2, 0);
|
ui_sheet->setPosition(width - ui_sheet->getWidth()*2, 0);
|
||||||
ui_sheet->doRefresh(width, height);
|
ui_sheet->doRefresh(width, height);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define GAMESTATE_HPP
|
#define GAMESTATE_HPP
|
||||||
#include "State.hpp"
|
#include "State.hpp"
|
||||||
#include "Controller.hpp"
|
#include "Controller.hpp"
|
||||||
|
#include "AiController.hpp"
|
||||||
#include "PlayerController.hpp"
|
#include "PlayerController.hpp"
|
||||||
#include "QMap.hpp"
|
#include "QMap.hpp"
|
||||||
#include "Ui.hpp"
|
#include "Ui.hpp"
|
||||||
|
@ -23,6 +24,7 @@ class GameState : public State {
|
||||||
std::vector<QMap*> maps;
|
std::vector<QMap*> maps;
|
||||||
std::vector<Controller*> controllers;
|
std::vector<Controller*> controllers;
|
||||||
PlayerController pc;
|
PlayerController pc;
|
||||||
|
AiController ac;
|
||||||
// rendering
|
// rendering
|
||||||
GLuint program;
|
GLuint program;
|
||||||
// get our uniforms (move elsewhere)
|
// get our uniforms (move elsewhere)
|
||||||
|
@ -52,6 +54,7 @@ class GameState : public State {
|
||||||
UiText *ui_sheet_name;
|
UiText *ui_sheet_name;
|
||||||
UiText *ui_map_name;
|
UiText *ui_map_name;
|
||||||
Ui *ui_controls;
|
Ui *ui_controls;
|
||||||
|
Ui *ui_time;
|
||||||
UiText *ui_console;
|
UiText *ui_console;
|
||||||
UiText *ui_intro;
|
UiText *ui_intro;
|
||||||
std::vector<Ui*> ui_abilities;
|
std::vector<Ui*> ui_abilities;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "Core.hpp"
|
#include "Core.hpp"
|
||||||
#include <algorithm> // remove_if
|
#include <algorithm> // remove_if
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include "Log.hpp"
|
||||||
|
|
||||||
UiSubState::UiSubState() {
|
UiSubState::UiSubState() {
|
||||||
// UI camera
|
// UI camera
|
||||||
|
@ -21,6 +22,7 @@ UiSubState::UiSubState() {
|
||||||
ui_program_texture = glGetUniformLocation(ui_program, "texture_sampler");
|
ui_program_texture = glGetUniformLocation(ui_program, "texture_sampler");
|
||||||
ui_program_uv_offset = glGetUniformLocation(ui_program, "uv_offset");
|
ui_program_uv_offset = glGetUniformLocation(ui_program, "uv_offset");
|
||||||
ui_program_transparency = glGetUniformLocation(ui_program, "transparency");
|
ui_program_transparency = glGetUniformLocation(ui_program, "transparency");
|
||||||
|
ui_program_v_fade = glGetUniformLocation(ui_program, "vertical_fade"); // FIXME: should this be a bool?
|
||||||
// get our attributes
|
// get our attributes
|
||||||
ui_program_vp = glGetAttribLocation(ui_program, "vp");
|
ui_program_vp = glGetAttribLocation(ui_program, "vp");
|
||||||
ui_program_uv = glGetAttribLocation(ui_program, "uv");
|
ui_program_uv = glGetAttribLocation(ui_program, "uv");
|
||||||
|
@ -74,8 +76,11 @@ int UiSubState::doRender() {
|
||||||
glUniform2f(ui_program_uv_offset, 0.0f, 0.0f);
|
glUniform2f(ui_program_uv_offset, 0.0f, 0.0f);
|
||||||
// send alpha
|
// send alpha
|
||||||
glUniform1f(ui_program_transparency, ui->transparency);
|
glUniform1f(ui_program_transparency, ui->transparency);
|
||||||
|
// send fade amount
|
||||||
|
glUniform1f(ui_program_v_fade, ui->vertical_fade);
|
||||||
|
LOG(LOG_INFO) << "vfade is " << ui->vertical_fade;
|
||||||
// draw
|
// draw
|
||||||
glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size());
|
glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ class UiSubState {
|
||||||
GLuint ui_program_modelview;
|
GLuint ui_program_modelview;
|
||||||
GLuint ui_program_texture;
|
GLuint ui_program_texture;
|
||||||
GLuint ui_program_transparency;
|
GLuint ui_program_transparency;
|
||||||
|
GLuint ui_program_v_fade;
|
||||||
// get our attributes
|
// get our attributes
|
||||||
GLuint ui_program_vp;
|
GLuint ui_program_vp;
|
||||||
GLuint ui_program_uv;
|
GLuint ui_program_uv;
|
||||||
|
|
|
@ -53,6 +53,8 @@ int GnashingGibber::onThought(Thought thought) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int GnashingGibber::onTouch(Thing *thing) {
|
int GnashingGibber::onTouch(Thing *touched) {
|
||||||
|
controller->recvMessage("You bite "+touched->getName());
|
||||||
|
touched->getController()->recvMessage(name+" bites you");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,8 @@ int Thing::doThink(unsigned int ticks) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int Thing::doTouch(Thing *touched) {
|
int Thing::doTouch(Thing *touched) {
|
||||||
if (controller != NULL) controller->recvMessage("You hit "+touched->name);
|
onTouch(touched);
|
||||||
return 0;
|
touched->onTouched(this);
|
||||||
}
|
|
||||||
int Thing::onTouch(Thing *toucher) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int Thing::onThought(Thought thought) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* ======== Adding/Access ======== */
|
/* ======== Adding/Access ======== */
|
||||||
|
@ -68,6 +63,25 @@ Ability *Thing::getAbility(int number) {
|
||||||
}
|
}
|
||||||
return abilities.at(number);
|
return abilities.at(number);
|
||||||
}
|
}
|
||||||
|
Ability* Thing::remAbility(std::string ability_name) {
|
||||||
|
std::deque<Ability*>::iterator abil_it, abil_end;
|
||||||
|
for (abil_it = abilities.begin(), abil_end = abilities.end(); abil_it != abil_end; ++abil_it) {
|
||||||
|
Ability *abil = *abil_it;
|
||||||
|
if (abil->getName() == ability_name) {
|
||||||
|
abilities.erase(abil_it);
|
||||||
|
return abil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
int Thing::hasAbility(std::string ability_name) {
|
||||||
|
std::deque<Ability*>::iterator abil_it, abil_end;
|
||||||
|
for (abil_it = abilities.begin(), abil_end = abilities.end(); abil_it != abil_end; ++abil_it) {
|
||||||
|
Ability *abil = *abil_it;
|
||||||
|
if (abil->getName() == ability_name) return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
/* ======== Velocity/Position ======== */
|
/* ======== Velocity/Position ======== */
|
||||||
void Thing::addVelocity(Vec3 vel) {
|
void Thing::addVelocity(Vec3 vel) {
|
||||||
velocity += vel;
|
velocity += vel;
|
||||||
|
|
|
@ -20,17 +20,20 @@ class Thing {
|
||||||
~Thing();
|
~Thing();
|
||||||
// interface
|
// interface
|
||||||
int doThink(unsigned int ticks);
|
int doThink(unsigned int ticks);
|
||||||
virtual int doTouch(Thing *touched);
|
int doTouch(Thing *touched);
|
||||||
virtual int onTouch(Thing *thing);
|
virtual int onTouch(Thing *touched) { return 0; };
|
||||||
virtual int onThought(Thought thought);
|
virtual int onTouched(Thing *toucher) { return 0; };
|
||||||
|
virtual int onThought(Thought thought) { return 0; };
|
||||||
//
|
//
|
||||||
int pushThought(Thought thought);
|
int pushThought(Thought thought);
|
||||||
//
|
//
|
||||||
Ability *getAbility(int number);
|
Ability *getAbility(int number);
|
||||||
int pushAbility(Ability *ability);
|
int pushAbility(Ability *ability);
|
||||||
int unshiftAbility(Ability *ability);
|
int unshiftAbility(Ability *ability);
|
||||||
|
int hasAbility(std::string ability);
|
||||||
|
Ability* remAbility(std::string ability_name);
|
||||||
//
|
//
|
||||||
void setController(Controller *controller_) { controller = controller_; };
|
void setController(Controller *controller_) { controller_->controlThing(this); controller = controller_; };
|
||||||
Controller* getController() { return controller; };
|
Controller* getController() { return controller; };
|
||||||
void printMsg(std::string string);
|
void printMsg(std::string string);
|
||||||
std::string getName() { return name; };
|
std::string getName() { return name; };
|
||||||
|
@ -52,9 +55,11 @@ class Thing {
|
||||||
// getters for internal stuff
|
// getters for internal stuff
|
||||||
Sprite *getSprite() { return sprite; };
|
Sprite *getSprite() { return sprite; };
|
||||||
// oh boy oh boy, our stats!
|
// oh boy oh boy, our stats!
|
||||||
int speed;
|
int health; // total health
|
||||||
int health;
|
int armor; // armor, reduces incoming damage
|
||||||
int damage;
|
int speed; // movement speed
|
||||||
|
int damage; // physical damage
|
||||||
|
int power; // magical power
|
||||||
protected:
|
protected:
|
||||||
QMap *map; // the map to which we belong (this is bad)
|
QMap *map; // the map to which we belong (this is bad)
|
||||||
Controller *controller;
|
Controller *controller;
|
||||||
|
|
Loading…
Reference in New Issue