draw shot ring
This commit is contained in:
parent
741a325a5f
commit
f68a4a682a
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
gl_FragColor = vec4(1.0, 0.1, 0.1, 1.0);
|
gl_FragColor = vec4(1.0, 0.1, 0.1, 0.5);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ using namespace std;
|
|||||||
#define SKY_DIST 2000
|
#define SKY_DIST 2000
|
||||||
#define NUM_SKY_STEPS 9
|
#define NUM_SKY_STEPS 9
|
||||||
#define LAVA_SIZE 100
|
#define LAVA_SIZE 100
|
||||||
#define SHOT_RING_WIDTH 20.0f
|
#define SHOT_RING_WIDTH 10.0f
|
||||||
#define NUM_SHOT_RING_STEPS 24
|
#define NUM_SHOT_RING_STEPS 24
|
||||||
|
|
||||||
/* points of a horizontal hexagon 1.0 units high */
|
/* points of a horizontal hexagon 1.0 units high */
|
||||||
@ -125,6 +125,12 @@ bool Client::initgl()
|
|||||||
"pos", 0, "tex_coord", 1, NULL,
|
"pos", 0, "tex_coord", 1, NULL,
|
||||||
"projection", "modelview", "tex", "shift", NULL))
|
"projection", "modelview", "tex", "shift", NULL))
|
||||||
return false;
|
return false;
|
||||||
|
if (!m_shot_ring_program.create(
|
||||||
|
CFS.get_file("shaders/shot-ring.v.glsl"),
|
||||||
|
CFS.get_file("shaders/shot-ring.f.glsl"),
|
||||||
|
"pos", 0, NULL,
|
||||||
|
"projection", "modelview", "scale", NULL))
|
||||||
|
return false;
|
||||||
if (!m_tank_obj.load("models/tank.obj", load_file))
|
if (!m_tank_obj.load("models/tank.obj", load_file))
|
||||||
{
|
{
|
||||||
cerr << "Error loading tank model" << endl;
|
cerr << "Error loading tank model" << endl;
|
||||||
@ -221,7 +227,7 @@ bool Client::initgl()
|
|||||||
cerr << "Error creating lava texture" << endl;
|
cerr << "Error creating lava texture" << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_obj_program.use();
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,27 +246,29 @@ void Client::redraw()
|
|||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
double dir_x = cos(m_players[current_player]->direction);
|
if (m_players.size() > 0)
|
||||||
double dir_y = sin(m_players[current_player]->direction);
|
|
||||||
m_modelview.load_identity();
|
|
||||||
m_modelview.look_at(
|
|
||||||
m_players[current_player]->x - dir_x * 25, m_players[current_player]->y - dir_y * 25, 30,
|
|
||||||
m_players[current_player]->x, m_players[current_player]->y, 20,
|
|
||||||
0, 0, 1);
|
|
||||||
|
|
||||||
// TODO: call draw_player() for each networked player
|
|
||||||
for(std::map<sf::Uint8, refptr<Player> >::iterator piter = m_players.begin(); piter != m_players.end(); piter++)
|
|
||||||
{
|
{
|
||||||
draw_player(piter->second);
|
double dir_x = cos(m_players[current_player]->direction);
|
||||||
|
double dir_y = sin(m_players[current_player]->direction);
|
||||||
|
m_modelview.load_identity();
|
||||||
|
m_modelview.look_at(
|
||||||
|
m_players[current_player]->x - dir_x * 25, m_players[current_player]->y - dir_y * 25, 30,
|
||||||
|
m_players[current_player]->x, m_players[current_player]->y, 20,
|
||||||
|
0, 0, 1);
|
||||||
|
|
||||||
|
for(std::map<sf::Uint8, refptr<Player> >::iterator piter = m_players.begin(); piter != m_players.end(); piter++)
|
||||||
|
{
|
||||||
|
draw_player(piter->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_map();
|
||||||
|
draw_sky();
|
||||||
|
draw_lava();
|
||||||
|
draw_shot_ring();
|
||||||
|
|
||||||
|
draw_overlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
draw_map();
|
|
||||||
draw_sky();
|
|
||||||
draw_lava();
|
|
||||||
|
|
||||||
draw_overlay();
|
|
||||||
|
|
||||||
m_window->display();
|
m_window->display();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +387,6 @@ void Client::draw_overlay()
|
|||||||
overlay_size, overlay_size);
|
overlay_size, overlay_size);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
m_overlay_program.use();
|
m_overlay_program.use();
|
||||||
GLMatrix proj;
|
GLMatrix proj;
|
||||||
const float span = 50 * 8;
|
const float span = 50 * 8;
|
||||||
@ -528,3 +535,26 @@ void Client::draw_lava()
|
|||||||
glDisableVertexAttribArray(0);
|
glDisableVertexAttribArray(0);
|
||||||
glDisableVertexAttribArray(1);
|
glDisableVertexAttribArray(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::draw_shot_ring()
|
||||||
|
{
|
||||||
|
if (m_drawing_shot)
|
||||||
|
{
|
||||||
|
m_shot_ring_program.use();
|
||||||
|
m_shot_ring_attributes.bind();
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE,
|
||||||
|
4 * sizeof(GLfloat), NULL);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
m_modelview.push();
|
||||||
|
m_modelview.translate(m_players[current_player]->x,
|
||||||
|
m_players[current_player]->y, 0.4);
|
||||||
|
m_projection.to_uniform(m_shot_ring_program.uniform("projection"));
|
||||||
|
m_modelview.to_uniform(m_shot_ring_program.uniform("modelview"));
|
||||||
|
glUniform1f(m_shot_ring_program.uniform("scale"), m_drawing_shot_distance);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, (NUM_SHOT_RING_STEPS + 1) * 2);
|
||||||
|
m_modelview.pop();
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
|
||||||
|
/* TODO: this should be moved to common somewhere */
|
||||||
|
#define MAX_SHOT_DISTANCE 250.0
|
||||||
|
#define SHOT_EXPAND_SPEED 75.0
|
||||||
|
|
||||||
Client::Client()
|
Client::Client()
|
||||||
{
|
{
|
||||||
m_net_client = new Network();
|
m_net_client = new Network();
|
||||||
@ -10,6 +14,8 @@ Client::Client()
|
|||||||
client_has_focus = true;
|
client_has_focus = true;
|
||||||
m_players.clear();
|
m_players.clear();
|
||||||
current_player = 0;
|
current_player = 0;
|
||||||
|
m_left_button_pressed = false;
|
||||||
|
m_drawing_shot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client::~Client()
|
Client::~Client()
|
||||||
@ -52,6 +58,18 @@ void Client::run(bool fullscreen, int width, int height, std::string pname)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case sf::Event::MouseButtonPressed:
|
||||||
|
if (event.mouseButton.button == sf::Mouse::Left)
|
||||||
|
m_left_button_pressed = true;
|
||||||
|
break;
|
||||||
|
case sf::Event::MouseButtonReleased:
|
||||||
|
if (event.mouseButton.button == sf::Mouse::Left)
|
||||||
|
{
|
||||||
|
m_drawing_shot = false;
|
||||||
|
m_left_button_pressed = false;
|
||||||
|
/* TODO: trigger shot network message */
|
||||||
|
}
|
||||||
|
break;
|
||||||
case sf::Event::Resized:
|
case sf::Event::Resized:
|
||||||
resize_window(event.size.width, event.size.height);
|
resize_window(event.size.width, event.size.height);
|
||||||
break;
|
break;
|
||||||
@ -72,10 +90,7 @@ void Client::run(bool fullscreen, int width, int height, std::string pname)
|
|||||||
client_timer.Update();
|
client_timer.Update();
|
||||||
|
|
||||||
update(elapsed_time);
|
update(elapsed_time);
|
||||||
if(m_players.size() > 0)
|
redraw();
|
||||||
{
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
last_time = current_time;
|
last_time = current_time;
|
||||||
|
|
||||||
// temporary for now. otherwise this thread consumed way too processing
|
// temporary for now. otherwise this thread consumed way too processing
|
||||||
@ -88,7 +103,6 @@ void Client::update(double elapsed_time)
|
|||||||
static bool registered_player = false;
|
static bool registered_player = false;
|
||||||
sf::Packet client_packet;
|
sf::Packet client_packet;
|
||||||
|
|
||||||
|
|
||||||
m_net_client->Receive();
|
m_net_client->Receive();
|
||||||
client_packet.clear();
|
client_packet.clear();
|
||||||
// Handle all received data (only really want the latest)
|
// Handle all received data (only really want the latest)
|
||||||
@ -188,6 +202,21 @@ void Client::update(double elapsed_time)
|
|||||||
}
|
}
|
||||||
rel_mouse_movement = sf::Mouse::getPosition(*m_window).x - m_width / 2;
|
rel_mouse_movement = sf::Mouse::getPosition(*m_window).x - m_width / 2;
|
||||||
sf::Mouse::setPosition(sf::Vector2i(m_width / 2, m_height / 2), *m_window);
|
sf::Mouse::setPosition(sf::Vector2i(m_width / 2, m_height / 2), *m_window);
|
||||||
|
|
||||||
|
if (m_left_button_pressed)
|
||||||
|
{
|
||||||
|
if (m_drawing_shot)
|
||||||
|
{
|
||||||
|
m_drawing_shot_distance += SHOT_EXPAND_SPEED * elapsed_time;
|
||||||
|
if (m_drawing_shot_distance > MAX_SHOT_DISTANCE)
|
||||||
|
m_drawing_shot_distance = MAX_SHOT_DISTANCE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_drawing_shot = true;
|
||||||
|
m_drawing_shot_distance = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send an update to the server if something has changed
|
// Send an update to the server if something has changed
|
||||||
|
@ -29,6 +29,7 @@ class Client
|
|||||||
void draw_overlay();
|
void draw_overlay();
|
||||||
void draw_sky();
|
void draw_sky();
|
||||||
void draw_lava();
|
void draw_lava();
|
||||||
|
void draw_shot_ring();
|
||||||
|
|
||||||
refptr<sf::Window> m_window;
|
refptr<sf::Window> m_window;
|
||||||
sf::Clock m_clock;
|
sf::Clock m_clock;
|
||||||
@ -43,6 +44,7 @@ class Client
|
|||||||
GLProgram m_overlay_hover_program;
|
GLProgram m_overlay_hover_program;
|
||||||
GLProgram m_sky_program;
|
GLProgram m_sky_program;
|
||||||
GLProgram m_lava_program;
|
GLProgram m_lava_program;
|
||||||
|
GLProgram m_shot_ring_program;
|
||||||
WFObj m_tank_obj;
|
WFObj m_tank_obj;
|
||||||
WFObj m_tile_obj;
|
WFObj m_tile_obj;
|
||||||
GLMatrix m_projection;
|
GLMatrix m_projection;
|
||||||
@ -56,6 +58,9 @@ class Client
|
|||||||
refptr<Network> m_net_client;
|
refptr<Network> m_net_client;
|
||||||
bool client_has_focus;
|
bool client_has_focus;
|
||||||
sf::Texture m_lava_texture;
|
sf::Texture m_lava_texture;
|
||||||
|
bool m_left_button_pressed;
|
||||||
|
bool m_drawing_shot;
|
||||||
|
float m_drawing_shot_distance;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user