Permalink
Browse files

Added initial firing effects to all guns using new particle system.

  • Loading branch information...
1 parent 51aa152 commit a39c635d4e62ebee2a2eb4cf78834881574bb39e @greywhind greywhind committed Nov 27, 2011
View
@@ -52,9 +52,15 @@ Client::Client() : m_network(this) {
m_weapon_switch_time = 0;
m_weapon_switch_delay = 300;
+
+ weapon_discharged_packet = NULL;
}
Client::~Client() {
+ if (weapon_discharged_packet != NULL) {
+ delete weapon_discharged_packet;
+ }
+
delete m_logic;
}
@@ -162,16 +168,23 @@ Player* Client::get_player(uint32_t id) {
return m_logic->get_player(id);
}
-void Client::attempt_firing() {
+Packet* Client::attempt_firing() {
if (get_weapon_switch_delay_remaining() > 0) {
- return;
+ return NULL;
}
- Packet weapon_discharged(WEAPON_DISCHARGED_PACKET);
- bool fired_successfully = m_logic->attempt_fire(m_player_id, m_curr_weapon, m_controller->get_aim(), &(weapon_discharged.weapon_discharged));
+ if (weapon_discharged_packet != NULL) {
+ delete weapon_discharged_packet;
+ }
+
+ weapon_discharged_packet = new Packet(WEAPON_DISCHARGED_PACKET);
+ bool fired_successfully = m_logic->attempt_fire(m_player_id, m_curr_weapon, m_controller->get_aim(), &(weapon_discharged_packet->weapon_discharged));
if (fired_successfully) {
- m_network.send_packet(&weapon_discharged);
+ m_network.send_packet(weapon_discharged_packet);
+ return weapon_discharged_packet;
}
+
+ return NULL;
}
void Client::check_player_hits() {
@@ -275,7 +288,7 @@ Map* Client::make_map() {
return new Map;
}
-Weapon* Client::make_weapon(WeaponReader& weapon_data) {
+Weapon* Client::make_weapon(uint32_t index, WeaponReader& weapon_data) {
return Weapon::new_weapon(weapon_data);
}
@@ -524,7 +537,7 @@ void Client::player_died(const Packet& p) {
void Client::weapon_info(const Packet& p) {
WeaponReader wr(*p.weapon_info.weapon_data);
DEBUG("Weapon: " << p.weapon_info.index);
- Weapon* weapon = make_weapon(wr);
+ Weapon* weapon = make_weapon(p.weapon_info.index, wr);
if (weapon != NULL && m_logic != NULL) {
DEBUG(weapon->get_name() << ", " << weapon->get_id());
View
@@ -53,6 +53,8 @@ namespace LM {
uint64_t m_weapon_switch_time;
uint64_t m_weapon_switch_delay;
uint64_t m_last_player_update;
+
+ Packet* weapon_discharged_packet;
bool m_running;
@@ -69,7 +71,7 @@ namespace LM {
Player* get_player(uint32_t id);
- void attempt_firing();
+ virtual Packet* attempt_firing();
void check_player_hits();
void generate_player_update(uint32_t id, Packet* p);
@@ -96,7 +98,7 @@ namespace LM {
virtual Player* make_player(const char* name, uint32_t id, char team);
virtual Map* make_map();
- virtual Weapon* make_weapon(WeaponReader& weapon_data);
+ virtual Weapon* make_weapon(uint32_t index, WeaponReader& weapon_data);
void set_controller(Controller* controller);
void set_config(Configuration* config);
@@ -112,6 +112,7 @@ bool StandardGun::parse_param(const char* param_string) {
Packet::WeaponDischarged* StandardGun::fire(b2World* physics, Player& player, Point start, float direction, Packet::WeaponDischarged* packet) {
m_last_fired_time = get_ticks();
m_last_fired_dir = direction;
+ b2Vec2 end_point;
m_hit_data.clear();
// Recharge ammo, if applicable
@@ -139,6 +140,40 @@ Packet::WeaponDischarged* StandardGun::fire(b2World* physics, Player& player, Po
if (!m_hit_data.back().empty()) {
sort(m_hit_data.back().begin(), m_hit_data.back().end(), compare_hit_data);
}
+
+ // Find the end point of the middle projectile
+ if (i == m_nbr_projectiles/2) {
+ bool found = false;
+ vector<HitData>::iterator thishit = m_hit_data.back().end();
+
+ // Discard invalid collisions until we find the closest good collision
+ while (!found) {
+ thishit--;
+
+ b2Body* body = (*thishit).fixture->GetBody();
+
+ if (body->GetUserData() == NULL) {
+ continue;
+ }
+
+ PhysicsObject* hitobj = static_cast<PhysicsObject*>(body->GetUserData());
+
+ if ((*thishit).fixture->IsSensor()) {
+ continue;
+ }
+
+ if (hitobj->get_type() == PhysicsObject::MAP_OBJECT) {
+ MapObject* object = static_cast<MapObject*>(hitobj);
+
+ if (!object->is_shootable()) {
+ continue;
+ }
+ }
+
+ found = true;
+ }
+ end_point = (*thishit).point;
+ }
currdirection += m_angle/(m_nbr_projectiles - 1.0);
}
@@ -147,9 +182,8 @@ Packet::WeaponDischarged* StandardGun::fire(b2World* physics, Player& player, Po
packet->weapon_id = get_id();
packet->start_x = start.x;
packet->start_y = start.y;
- // FIXME make this variable length
- packet->end_x = start.x;
- packet->end_y = start.y;
+ packet->end_x = to_game(end_point.x);
+ packet->end_y = to_game(end_point.y);
packet->direction = direction;
was_fired(physics, player, direction);
@@ -389,4 +423,3 @@ float32 StandardGun::ReportFixture(b2Fixture* fixture, const b2Vec2& point, cons
return 1;
}
-
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -9,6 +9,9 @@
max_penetration=3
normal=13,36:-15:front:back:rifle_noshot.png;4,20:-15:back:back:rifle_noshot.png
firing=13,36:-15:front:back:rifle_shot.png;4,20:-15:back:back:rifle_shot.png
+ firing_line_emitter_image_red=red_particle.png
+ firing_line_emitter_image_blue=blue_particle.png
+ firing_line_emitter=particle_speed=10.0|speed_variance=0.05|spawn_per_second=1000.0|spawn_variance=1.0|lifetime_millis=250|lifetime_variance=50|rotation_variance=6.28318|max_spawn=200|emitter_stop_spawning_millis=-1|emitter_lifetime_millis=-1|
1:SPREAD
name=Shotgun
@@ -21,6 +24,10 @@
recoil=1.5
normal=12,55:-15:front:back:sgun_noshot.png;5,20:-15:back:back:sgun_noshot.png
firing=12,55:-15:front:back:sgun_shot.png;5,20:-15:back:back:sgun_shot.png
+ firing_radial_emitter_image_red=red_gate.png
+ firing_radial_emitter_image_blue=blue_gate.png
+ firing_radial_emitter=particle_speed=1000.0|speed_variance=50.0|spawn_per_second=1000.0|spawn_variance=100.0|lifetime_millis=300|lifetime_variance=50|rotation_variance=0.4|max_spawn=5|emitter_stop_spawning_millis=-1|emitter_lifetime_millis=-1|
+
#2:IMPACT
# name=Impact Cannon
@@ -44,6 +51,9 @@
pivot=0,0;
shape=poly:1000,-100;1000,100;0,0;
# move=false; # not yet implemented
+ firing_radial_emitter_image_red=red_particle.png
+ firing_radial_emitter_image_blue=blue_particle.png
+ firing_radial_emitter=particle_speed=300.0|speed_variance=100.0|spawn_per_second=1000.0|spawn_variance=100.0|lifetime_millis=500|lifetime_variance=100|rotation_variance=0.8|max_spawn=50|emitter_stop_spawning_millis=-1|emitter_lifetime_millis=-1|
#3:CHARGE
# name=Machine Gun
@@ -244,3 +244,13 @@ Graphic* GraphicalPlayer::get_weapon_graphic(int partid) {
gunname << partid;
return m_graphic_root.get_graphic(gunname.str());
}
+
+Graphic* GraphicalPlayer::get_curr_visible_weapon_graphic() {
+ if (!get_weapon_graphic(PART_BACK_HAND|PART_BACK_ARM|PART_UNFIRED)->is_invisible()) {
+ return get_weapon_graphic(PART_BACK_HAND|PART_BACK_ARM|PART_UNFIRED);
+ } else if (!get_weapon_graphic(PART_BACK_HAND|PART_FRONT_ARM|PART_UNFIRED)->is_invisible()) {
+ return get_weapon_graphic(PART_BACK_HAND|PART_FRONT_ARM|PART_UNFIRED);
+ } else {
+ DEBUG("No part found.");
+ }
+}
@@ -74,6 +74,8 @@ namespace LM {
virtual void set_is_frozen(bool is_frozen, int64_t freeze_time = 0, PhysicsObject* source = NULL);
Graphic* get_weapon_graphic(int partid);
+
+ Graphic* get_curr_visible_weapon_graphic();
};
}
@@ -23,12 +23,18 @@
*/
#include "GraphicalWeapon.hpp"
+#include "ParticleManager.hpp"
+#include "SimpleLineEmitter.hpp"
+#include "SimpleRadialEmitter.hpp"
+#include "ResourceCache.hpp"
using namespace LM;
using namespace std;
GraphicalWeapon::GraphicalWeapon(ResourceCache* cache) {
m_cache = cache;
+ m_firing_line_emitter_settings = NULL;
+ m_firing_radial_emitter_settings = NULL;
}
bool GraphicalWeapon::parse_param(const char* param_string, Weapon* owner) {
@@ -37,6 +43,18 @@ bool GraphicalWeapon::parse_param(const char* param_string, Weapon* owner) {
type |= GraphicalPlayer::PART_UNFIRED;
} else if (strncasecmp(param_string, "firing=", 7) == 0) {
type |= GraphicalPlayer::PART_FIRED;
+ } else if (strncasecmp(param_string, "firing_line_emitter=", 20) == 0) {
+ m_firing_line_emitter_settings = SimpleLineEmitter::parse_settings_string(string(param_string+20));
+ } else if (strncasecmp(param_string, "firing_line_emitter_image_red=", 30) == 0) {
+ m_firing_line_emitter_image_name_red = string(param_string+30);
+ } else if (strncasecmp(param_string, "firing_line_emitter_image_blue=", 31) == 0) {
+ m_firing_line_emitter_image_name_blue = string(param_string+31);
+ } else if (strncasecmp(param_string, "firing_radial_emitter=", 22) == 0) {
+ m_firing_radial_emitter_settings = SimpleRadialEmitter::parse_settings_string(string(param_string+22));
+ } else if (strncasecmp(param_string, "firing_radial_emitter_image_red=", 32) == 0) {
+ m_firing_radial_emitter_image_name_red = string(param_string+32);
+ } else if (strncasecmp(param_string, "firing_radial_emitter_image_blue=", 33) == 0) {
+ m_firing_radial_emitter_image_name_blue = string(param_string+33);
} else {
return false;
}
@@ -86,3 +104,36 @@ void GraphicalWeapon::select(Player* player) {
sprite->set_rotation(m_gunpart[i].rotation);
}
}
+
+void GraphicalWeapon::generate_fired_emitter(ParticleManager* manager, ResourceCache* cache, float start_x, float start_y, float end_x, float end_y, float rotation, char team) {
+ if (m_firing_line_emitter_settings != NULL) {
+ string name = m_firing_line_emitter_image_name_blue;
+ if (team == 'B') {
+ name = m_firing_line_emitter_image_name_red;
+ }
+
+ SimpleLineEmitter* simple_emitter = new SimpleLineEmitter(manager, Point(start_x, start_y), (cache->get<Image>(name)), DrawContext::BLEND_ADD);
+
+ simple_emitter->set_endpoint(end_x, end_y);
+
+ simple_emitter->init(m_firing_line_emitter_settings);
+
+ manager->add_emitter(simple_emitter);
+ }
+
+ if (m_firing_radial_emitter_settings != NULL) {
+ string name = m_firing_radial_emitter_image_name_blue;
+ if (team == 'B') {
+ DEBUG("NAME: " << m_firing_radial_emitter_image_name_red);
+ name = m_firing_radial_emitter_image_name_red;
+ }
+
+ SimpleRadialEmitter* radial_emitter = new SimpleRadialEmitter(manager, Point(start_x, start_y), (cache->get<Image>(name)), DrawContext::BLEND_ADD);
+
+ radial_emitter->init(m_firing_radial_emitter_settings);
+
+ radial_emitter->set_rotation(rotation);
+
+ manager->add_emitter(radial_emitter);
+ }
+}
@@ -30,6 +30,9 @@
namespace LM {
class ResourceCache;
+ class ParticleManager;
+ struct SimpleLineEmitterSettings;
+ struct SimpleRadialEmitterSettings;
class GraphicalWeapon : public ClientWeapon {
private:
@@ -41,11 +44,21 @@ namespace LM {
ResourceCache* m_cache;
GunPart m_gunpart[GraphicalPlayer::PART_MAX];
+
+ std::string m_firing_line_emitter_image_name_red;
+ std::string m_firing_line_emitter_image_name_blue;
+ SimpleLineEmitterSettings* m_firing_line_emitter_settings;
+
+ std::string m_firing_radial_emitter_image_name_red;
+ std::string m_firing_radial_emitter_image_name_blue;
+ SimpleRadialEmitterSettings* m_firing_radial_emitter_settings;
public:
GraphicalWeapon(ResourceCache* cache);
virtual bool parse_param(const char* param_string, Weapon* owner);
virtual void select(Player* player);
+
+ virtual void generate_fired_emitter(ParticleManager* manager, ResourceCache* cache, float start_x, float start_y, float end_x, float end_y, float rotation, char team);
};
}
Oops, something went wrong.

0 comments on commit a39c635

Please sign in to comment.