a quickfix in the morning

This commit is contained in:
j3d1 2016-10-06 03:30:09 +02:00
parent 70b0fee526
commit 03a271c731
8 changed files with 64 additions and 54 deletions

View file

@ -55,7 +55,7 @@ namespace endofthejedi {
XSetWMProtocols(m_display, m_window, &m_atomWmDeleteWindow, 1); XSetWMProtocols(m_display, m_window, &m_atomWmDeleteWindow, 1);
XMapWindow(m_display, m_window); XMapWindow(m_display, m_window);
XStoreName(m_display, m_window, "NAME"); XStoreName(m_display, m_window, "Kepler-Kriege");
m_glcontext = glXCreateContext(m_display, m_visualinfo, NULL, GL_TRUE); m_glcontext = glXCreateContext(m_display, m_visualinfo, NULL, GL_TRUE);

View file

@ -574,7 +574,7 @@ void RendererPolygon3d::renderMissiles() {
glm::mat4 model = computeModelMatrix(ship); glm::mat4 model = computeModelMatrix(ship);
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model)); glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model));
glm::vec3 c = glm::vec3(0.1, 1.0, 0.2); glm::vec3 c = ship->color;
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z); glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z);
m_shipModel->render(); m_shipModel->render();
@ -673,7 +673,8 @@ void RendererPolygon3d::renderMissiles() {
fade_out = 1.0 - (trace->age / trace->maxAge); fade_out = 1.0 - (trace->age / trace->maxAge);
} }
glColor3f(0.0, 0.5*fade_out, 0.5*fade_out); glLineWidth(3);
glColor4f(trace->player->color.x, trace->player->color.y, trace->player->color.z, fade_out);
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
for (const game::Trace::TracePoint &tp : trace->points) { for (const game::Trace::TracePoint &tp : trace->points) {
glVertex2f(tp.position.x, tp.position.y); glVertex2f(tp.position.x, tp.position.y);

View file

@ -32,8 +32,8 @@ namespace game {
{ {
(void) state; (void) state;
//return player->alive && player->energy >= player->speed; return player->alive && player->energy >= player->speed;
return player->alive; //return player->alive;
} }
void ChangeNameCommand::apply(Player *player, State *state) const void ChangeNameCommand::apply(Player *player, State *state) const

View file

@ -19,12 +19,17 @@ namespace game {
float speed; float speed;
float energy; float energy;
float deadTimeCounter; float deadTimeCounter;
glm::vec3 color;
Ship *ship; Ship *ship;
std::string name; std::string name;
std::list<Missile*> missiles; std::list<Missile*> missiles;
Player(size_t id) : id(id), alive(true), speed(1.0), energy(0.0), ship(nullptr), name("<unnamed>") Player(size_t id) : id(id), alive(true), speed(1.0), energy(0.0), ship(nullptr), name("<unnamed>")
{ {
float h = ((float) rand()) / (float) RAND_MAX;
float s = ((float) rand()) / (float) RAND_MAX;
float v = ((float) rand()) / (float) RAND_MAX;
color =glm::vec3(h,s,v);//glm::gtx::color_space::rgbColor( glm::vec3(h/360.0,1,1)) ;
} }
void addCommand(Command *cmd); void addCommand(Command *cmd);

View file

@ -5,10 +5,12 @@
namespace game { namespace game {
class Ship : public Object { class Ship : public Object {
public: public:
Ship(size_t id, const glm::vec2 &pos, float r) : Object(id, pos), radius(r)
{
}
float radius; float radius;
glm::vec3 color;
Ship(size_t id, const glm::vec2 &pos, const glm::vec3 &c, float r) : Object(id, pos), radius(r), color(c)
{
}
}; };
} }

View file

@ -139,7 +139,7 @@ namespace game {
return false; return false;
} }
Ship *ship = new Ship(generateId(), spawnPos, m_shipRadius); Ship *ship = new Ship(generateId(), spawnPos, player->color, m_shipRadius);
player->ship = ship; player->ship = ship;
ships.push_back(ship); ships.push_back(ship);
@ -226,9 +226,8 @@ namespace game {
(void) dt; (void) dt;
for (Player *player : players) { for (Player *player : players) {
if (player->alive) { if (player->alive) {
player->energy += dt; player->energy += dt * ENERGY_PER_DT;
} }
// try to execute as much queued commands as possible. // try to execute as much queued commands as possible.
while (player->hasCommandInQueue()) { while (player->hasCommandInQueue()) {
Command *command = player->peekCommand(); Command *command = player->peekCommand();

View file

@ -14,6 +14,8 @@
#include "state_update_event.hpp" #include "state_update_event.hpp"
#define ENERGY_PER_DT 0.3
// TODO: // TODO:
// give points for equipment / better weapons / more energy when: // give points for equipment / better weapons / more energy when:
// - player discovers the universe // - player discovers the universe

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <glm/vec3.hpp>
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
#include <vector> #include <vector>
@ -13,7 +14,7 @@ namespace game {
*/ */
class Trace { class Trace {
public: public:
Trace(Missile *missile, float maxAge=3.0); Trace(Missile *missile, float maxAge=12.0);
~Trace(); ~Trace();
// Add the current position of the missile as a new point on the // Add the current position of the missile as a new point on the