Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
projectile.hpp
Go to the documentation of this file.
6
7#include <optional>
8#include <deque>
9#include <iostream>
10#include <variant>
11
20class Projectile : public Object {
21public:
23 struct Options {
33 Options(bool isSpell, int damage, float h_mult, float v_mult,
34 bool homing, float homing_strength, int homing_duration,
35 std::optional<EntityID> target
36 ):
40 {
41 if (homing && !target.has_value()) {
42 std::cerr << "FATAL: homing projectile created without target.\n"
43 << "We could potentially implement this to home on the closest Player / Enemy object,\n"
44 << "But this isn't implemented yet.\n";
45 std::exit(1);
46 }
47 }
48
49 bool isSpell;
50 float h_mult;
51 float v_mult;
52 int damage;
53 bool homing;
56 std::optional<EntityID> target;
57 };
58
66 Projectile(glm::vec3 corner, glm::vec3 facing,
67 glm::vec3 dimensions, ModelType model,
68 std::optional<ServerSFX> destroy_sound, Options&& options);
69
70 void doCollision(Object* other, ServerGameState& state) override;
71
77 bool doTick(ServerGameState& state);
78
79 virtual SharedObject toShared() override;
80
81
82private:
83 Options opt;
84 std::optional<ServerSFX> destroy_sound;
85 PointLightProperties properties;
86
87};
88
89class HomingFireball : public Projectile {
90public:
91 inline static const int DAMAGE = 15;
92 inline static const float H_MULT = 0.4;
93 inline static const float V_MULT = 0.1;
94 inline static const float HOMING_STRENGTH = 0.1f;
95 inline static const int HOMING_DURATION_TICKS = 80; // 2.4s
96
97 HomingFireball(glm::vec3 corner, glm::vec3 facing, std::optional<EntityID> target):
98 Projectile(corner, facing, glm::vec3(0.4f, 0.4f, 0.4f), ModelType::Fireball, ServerSFX::FireballImpact,
100 {
101 this->physics.feels_gravity = false;
102 }
103};
104
110class Arrow : public Projectile {
111public:
112 inline static const int DAMAGE = 10;
113 inline static const float H_MULT = 0.55f;
114 inline static const float V_MULT = 0.0f; // not affected by gravity
115
116 Arrow(glm::vec3 corner, glm::vec3 facing, Direction dir):
117 Projectile(corner, facing, glm::vec3(0.0f, 0.0f, 0.0f), ModelType::Arrow, ServerSFX::ArrowImpact,
118 Options(false, DAMAGE, H_MULT, V_MULT, false, 0.0f, 0, {})), dir(dir)
119 {
120 const float clear_model_nudge = 1.5f;
121 switch (dir) {
122 case Direction::LEFT:
123 std::swap(this->physics.shared.dimensions.x, this->physics.shared.dimensions.z);
124 this->physics.shared.facing = glm::vec3(0.0f, 0.0f, -1.0f);
125 this->physics.shared.corner.x -= clear_model_nudge;
126 break;
127 case Direction::RIGHT:
128 std::swap(this->physics.shared.dimensions.x, this->physics.shared.dimensions.z);
129 this->physics.shared.facing = glm::vec3(0.0f, 0.0f, 1.0f);
130 // right doesn't need nudge for some reason
131 // this->physics.shared.corner.x += clear_model_nudge;
132 break;
133 case Direction::UP:
134 this->physics.shared.facing = glm::vec3(1.0f, 0.0f, 0.0f);
135 this->physics.shared.corner.z -= (2.0f * clear_model_nudge);
136 break;
137 case Direction::DOWN:
138 this->physics.shared.facing = glm::vec3(-1.0f, 0.0f, 0.0f);
139 this->physics.shared.corner.z += clear_model_nudge;
140 break;
141 }
142 }
143
145};
146
147class SpellOrb : public Projectile {
148public:
149 inline static const int DAMAGE = 25;
150 inline static const float H_MULT = 0.4;
151 inline static const float V_MULT = 0.0;
152 inline static const float HOMING_STRENGTH = 0.1f;
153
155
156 SpellOrb(glm::vec3 corner, glm::vec3 facing, SpellType type) :
157 Projectile(corner, facing, glm::vec3(0.4f, 0.4f, 0.4f), ModelType::SpellOrb, ServerSFX::FireballImpact,
158 Options(true, DAMAGE, H_MULT, V_MULT, false, 0.0f, 0, {}))
159 {
160 this->sType = type;
161 }
162};
Definition: projectile.hpp:110
Direction dir
Definition: projectile.hpp:144
static const float V_MULT
Definition: projectile.hpp:114
Arrow(glm::vec3 corner, glm::vec3 facing, Direction dir)
Definition: projectile.hpp:116
static const int DAMAGE
Definition: projectile.hpp:112
static const float H_MULT
Definition: projectile.hpp:113
Definition: projectile.hpp:89
static const float H_MULT
Definition: projectile.hpp:92
static const float HOMING_STRENGTH
Definition: projectile.hpp:94
HomingFireball(glm::vec3 corner, glm::vec3 facing, std::optional< EntityID > target)
Definition: projectile.hpp:97
static const int DAMAGE
Definition: projectile.hpp:91
static const float V_MULT
Definition: projectile.hpp:93
static const int HOMING_DURATION_TICKS
Definition: projectile.hpp:95
Definition: object.hpp:95
ObjectType type
Identifies this object's type (derived class)
Definition: object.hpp:118
Physics physics
Object's Physics-related properties.
Definition: object.hpp:123
Definition: projectile.hpp:20
virtual SharedObject toShared() override
Generates a SharedObject representation of this object.
Definition: projectile.cpp:113
void doCollision(Object *other, ServerGameState &state) override
Code to run when this object collides with another.
Definition: projectile.cpp:47
bool doTick(ServerGameState &state)
handle homing trajectory updates
Definition: projectile.cpp:19
The ServerGameState class contains all abstract game state data and logic for a single game state ins...
Definition: servergamestate.hpp:43
Representation of the Object class used by ServerGameState, containing exactly the subset of Object d...
Definition: sharedobject.hpp:302
Definition: projectile.hpp:147
static const float H_MULT
Definition: projectile.hpp:150
SpellType sType
Definition: projectile.hpp:154
SpellOrb(glm::vec3 corner, glm::vec3 facing, SpellType type)
Definition: projectile.hpp:156
static const float HOMING_STRENGTH
Definition: projectile.hpp:152
static const float V_MULT
Definition: projectile.hpp:151
static const int DAMAGE
Definition: projectile.hpp:149
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glad.h:1531
GLenum target
Definition: glad.h:2538
Direction
Definition: object.hpp:198
ModelType
Enumeration of every render model in the game.
Definition: sharedmodel.hpp:6
ServerSFX
Definition: soundtype.hpp:38
SpellType
Definition: spell.hpp:10
SharedPhysics shared
Shared physics properties (needed by both the server and the client)
Definition: object.hpp:50
bool feels_gravity
true if the object that contains this Physics struct feels gravity and false otherwise
Definition: object.hpp:63
Definition: point_light.hpp:5
Struct for options to configure the projectile.
Definition: projectile.hpp:23
bool isSpell
Definition: projectile.hpp:49
std::optional< EntityID > target
Definition: projectile.hpp:56
float v_mult
Definition: projectile.hpp:51
Options(bool isSpell, int damage, float h_mult, float v_mult, bool homing, float homing_strength, int homing_duration, std::optional< EntityID > target)
Definition: projectile.hpp:33
float h_mult
Definition: projectile.hpp:50
int homing_duration
Definition: projectile.hpp:55
int damage
Definition: projectile.hpp:52
float homing_strength
Definition: projectile.hpp:54
bool homing
Definition: projectile.hpp:53
glm::vec3 facing
3-D vector that denotes this object's facing direction.
Definition: sharedobject.hpp:189
glm::vec3 corner
3-D vector that denotes this object's bottom left corner (min x and z coordinates).
Definition: sharedobject.hpp:184
glm::vec3 dimensions
3-D vector that defines a rectangular prism which outlines the object that contains this SharedPhysic...
Definition: sharedobject.hpp:197