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);
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);

View file

@ -574,7 +574,7 @@ void RendererPolygon3d::renderMissiles() {
glm::mat4 model = computeModelMatrix(ship);
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);
m_shipModel->render();
@ -673,7 +673,8 @@ void RendererPolygon3d::renderMissiles() {
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);
for (const game::Trace::TracePoint &tp : trace->points) {
glVertex2f(tp.position.x, tp.position.y);

View file

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

View file

@ -19,12 +19,17 @@ namespace game {
float speed;
float energy;
float deadTimeCounter;
glm::vec3 color;
Ship *ship;
std::string name;
std::list<Missile*> missiles;
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);

View file

@ -5,10 +5,12 @@
namespace game {
class Ship : public Object {
public:
Ship(size_t id, const glm::vec2 &pos, float r) : Object(id, pos), radius(r)
{
}
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;
}
Ship *ship = new Ship(generateId(), spawnPos, m_shipRadius);
Ship *ship = new Ship(generateId(), spawnPos, player->color, m_shipRadius);
player->ship = ship;
ships.push_back(ship);
@ -159,21 +159,21 @@ namespace game {
void State::quitPlayer(size_t playerId)
{
std::cout << playerId << " quit" << std::endl;
std::cout << playerId << " quit" << std::endl;
Player *player = playerForId(playerId);
if (player != nullptr) {
for (Missile *missile : player->missiles) {
missile->player = nullptr;
}
Player *player = playerForId(playerId);
if (player != nullptr) {
for (Missile *missile : player->missiles) {
missile->player = nullptr;
}
players.remove(player);
}
players.remove(player);
}
}
void State::clear(size_t playerId)
{
std::cout << playerId << " clear" << std::endl;
std::cout << playerId << " clear" << std::endl;
}
void State::setName(size_t playerId, std::string name)
@ -226,9 +226,8 @@ namespace game {
(void) dt;
for (Player *player : players) {
if (player->alive) {
player->energy += dt;
player->energy += dt * ENERGY_PER_DT;
}
// try to execute as much queued commands as possible.
while (player->hasCommandInQueue()) {
Command *command = player->peekCommand();
@ -253,7 +252,7 @@ namespace game {
std::cout<<"player " << killer->id << " killed " << victim->id << std::endl;
// destroy ship
ships.remove(victim->ship);
ships.remove(victim->ship);
delete(victim->ship);
victim->ship = nullptr;
@ -274,7 +273,7 @@ namespace game {
for (Player *player : players) {
std::vector<Missile*> rm;
for (Missile *missile : player->missiles) {
for (Missile *missile : player->missiles) {
const Missile::Event evt = missile->advance(this, dt);
const bool isHit = (evt.hit != Hit::Nothing);
@ -282,73 +281,73 @@ namespace game {
missile->trace->addPointFromMissile(isHit); // force point if missile gets destroyed a
}
if (!isHit) {
continue;
}
if (!isHit) {
continue;
}
bool spawnExplosion = true;
switch(evt.hit) {
case Hit::Planet:
switch(evt.hit) {
case Hit::Planet:
// TODO: add black spot on the planet.
// TODO: if water planet, add waves
// TODO: if gas planet, add nice gas explosion effect
// and start burning on this spot for some time.
//std::cout<<"hit Planet" << std::endl;
break;
//std::cout<<"hit Planet" << std::endl;
break;
case Hit::Ship:
//std::cout<<"hit Player" << std::endl;
playerKillsPlayer(playerForId(evt.playerIdKiller), playerForId(evt.playerIdVictim));
break;
case Hit::Ship:
//std::cout<<"hit Player" << std::endl;
playerKillsPlayer(playerForId(evt.playerIdKiller), playerForId(evt.playerIdVictim));
break;
case Hit::BorderOfUniverse:
//std::cout<<"missile left the universe." << std::endl;
case Hit::BorderOfUniverse:
//std::cout<<"missile left the universe." << std::endl;
spawnExplosion = false;
break;
break;
default:
break;
}
default:
break;
}
if (spawnExplosion) {
addExplosionFromHit(&evt);
}
if (missile->trace != nullptr) {
missile->trace->finish();
}
if (missile->trace != nullptr) {
missile->trace->finish();
}
rm.push_back(missile);
rm.push_back(missile);
}
for (Missile *missile : rm) {
player->missiles.remove(missile);
for (Missile *missile : rm) {
player->missiles.remove(missile);
m_nextEvents.push_back(new MissileEvent(LifeCycle::Destroy, missile));
}
}
}
}
void State::advanceExplosions(float dt)
{
std::vector<Explosion*> rm;
std::vector<Explosion*> rm;
for (Explosion *explosion : explosions) {
for (Explosion *explosion : explosions) {
explosion->age += dt;
if (explosion->age >= explosion->maxAge) {
rm.push_back(explosion);
rm.push_back(explosion);
}
}
for (Explosion *explosion : rm) {
explosions.remove(explosion);
for (Explosion *explosion : rm) {
explosions.remove(explosion);
m_nextEvents.push_back(new ExplosionEvent(LifeCycle::Destroy, explosion));
//delete(explosion);
}
//delete(explosion);
}
}
void State::advance(float dt)

View file

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

View file

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