a quickfix in the morning
This commit is contained in:
parent
70b0fee526
commit
03a271c731
8 changed files with 64 additions and 54 deletions
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
@ -159,21 +159,21 @@ namespace game {
|
||||||
|
|
||||||
void State::quitPlayer(size_t playerId)
|
void State::quitPlayer(size_t playerId)
|
||||||
{
|
{
|
||||||
std::cout << playerId << " quit" << std::endl;
|
std::cout << playerId << " quit" << std::endl;
|
||||||
|
|
||||||
Player *player = playerForId(playerId);
|
Player *player = playerForId(playerId);
|
||||||
if (player != nullptr) {
|
if (player != nullptr) {
|
||||||
for (Missile *missile : player->missiles) {
|
for (Missile *missile : player->missiles) {
|
||||||
missile->player = nullptr;
|
missile->player = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
players.remove(player);
|
players.remove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::clear(size_t playerId)
|
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)
|
void State::setName(size_t playerId, std::string name)
|
||||||
|
@ -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();
|
||||||
|
@ -253,7 +252,7 @@ namespace game {
|
||||||
std::cout<<"player " << killer->id << " killed " << victim->id << std::endl;
|
std::cout<<"player " << killer->id << " killed " << victim->id << std::endl;
|
||||||
|
|
||||||
// destroy ship
|
// destroy ship
|
||||||
ships.remove(victim->ship);
|
ships.remove(victim->ship);
|
||||||
|
|
||||||
delete(victim->ship);
|
delete(victim->ship);
|
||||||
victim->ship = nullptr;
|
victim->ship = nullptr;
|
||||||
|
@ -274,7 +273,7 @@ namespace game {
|
||||||
for (Player *player : players) {
|
for (Player *player : players) {
|
||||||
|
|
||||||
std::vector<Missile*> rm;
|
std::vector<Missile*> rm;
|
||||||
for (Missile *missile : player->missiles) {
|
for (Missile *missile : player->missiles) {
|
||||||
const Missile::Event evt = missile->advance(this, dt);
|
const Missile::Event evt = missile->advance(this, dt);
|
||||||
const bool isHit = (evt.hit != Hit::Nothing);
|
const bool isHit = (evt.hit != Hit::Nothing);
|
||||||
|
|
||||||
|
@ -282,73 +281,73 @@ namespace game {
|
||||||
missile->trace->addPointFromMissile(isHit); // force point if missile gets destroyed a
|
missile->trace->addPointFromMissile(isHit); // force point if missile gets destroyed a
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isHit) {
|
if (!isHit) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool spawnExplosion = true;
|
bool spawnExplosion = true;
|
||||||
|
|
||||||
switch(evt.hit) {
|
switch(evt.hit) {
|
||||||
case Hit::Planet:
|
case Hit::Planet:
|
||||||
// TODO: add black spot on the planet.
|
// TODO: add black spot on the planet.
|
||||||
// TODO: if water planet, add waves
|
// TODO: if water planet, add waves
|
||||||
// TODO: if gas planet, add nice gas explosion effect
|
// TODO: if gas planet, add nice gas explosion effect
|
||||||
// and start burning on this spot for some time.
|
// and start burning on this spot for some time.
|
||||||
|
|
||||||
//std::cout<<"hit Planet" << std::endl;
|
//std::cout<<"hit Planet" << std::endl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Hit::Ship:
|
case Hit::Ship:
|
||||||
//std::cout<<"hit Player" << std::endl;
|
//std::cout<<"hit Player" << std::endl;
|
||||||
playerKillsPlayer(playerForId(evt.playerIdKiller), playerForId(evt.playerIdVictim));
|
playerKillsPlayer(playerForId(evt.playerIdKiller), playerForId(evt.playerIdVictim));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Hit::BorderOfUniverse:
|
case Hit::BorderOfUniverse:
|
||||||
//std::cout<<"missile left the universe." << std::endl;
|
//std::cout<<"missile left the universe." << std::endl;
|
||||||
spawnExplosion = false;
|
spawnExplosion = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawnExplosion) {
|
if (spawnExplosion) {
|
||||||
addExplosionFromHit(&evt);
|
addExplosionFromHit(&evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missile->trace != nullptr) {
|
if (missile->trace != nullptr) {
|
||||||
missile->trace->finish();
|
missile->trace->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
rm.push_back(missile);
|
rm.push_back(missile);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Missile *missile : rm) {
|
for (Missile *missile : rm) {
|
||||||
player->missiles.remove(missile);
|
player->missiles.remove(missile);
|
||||||
|
|
||||||
m_nextEvents.push_back(new MissileEvent(LifeCycle::Destroy, missile));
|
m_nextEvents.push_back(new MissileEvent(LifeCycle::Destroy, missile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::advanceExplosions(float dt)
|
void State::advanceExplosions(float dt)
|
||||||
{
|
{
|
||||||
std::vector<Explosion*> rm;
|
std::vector<Explosion*> rm;
|
||||||
|
|
||||||
for (Explosion *explosion : explosions) {
|
for (Explosion *explosion : explosions) {
|
||||||
explosion->age += dt;
|
explosion->age += dt;
|
||||||
if (explosion->age >= explosion->maxAge) {
|
if (explosion->age >= explosion->maxAge) {
|
||||||
rm.push_back(explosion);
|
rm.push_back(explosion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Explosion *explosion : rm) {
|
for (Explosion *explosion : rm) {
|
||||||
explosions.remove(explosion);
|
explosions.remove(explosion);
|
||||||
|
|
||||||
m_nextEvents.push_back(new ExplosionEvent(LifeCycle::Destroy, explosion));
|
m_nextEvents.push_back(new ExplosionEvent(LifeCycle::Destroy, explosion));
|
||||||
|
|
||||||
//delete(explosion);
|
//delete(explosion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::advance(float dt)
|
void State::advance(float dt)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue