Removed UNIX (..) from headers
Cleaned up the weapon class moved mousestate.h out of gameplay into utility
This commit is contained in:
parent
6164458aa7
commit
7e7dfd97b7
41 changed files with 213 additions and 176 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
find_package(SDL2_IMAGE REQUIRED)
|
find_package(SDL2_IMAGE REQUIRED)
|
||||||
|
|
||||||
|
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/YuppleMayham")
|
||||||
include_directories(SYSTEM "c:/sdks/glad/include")
|
include_directories(SYSTEM "c:/sdks/glad/include")
|
||||||
include_directories(SYSTEM "c:/sdks/tinyxml2-10.0.0/debug/include")
|
include_directories(SYSTEM "c:/sdks/tinyxml2-10.0.0/debug/include")
|
||||||
include_directories(SYSTEM "c:/sdks/glm")
|
include_directories(SYSTEM "c:/sdks/glm")
|
||||||
|
|
@ -21,7 +22,7 @@ include_directories(${PROJECT_SOURCE_DIR}/YupplyMayham/gameplay/weapons)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/YupplyMayham)
|
include_directories(${PROJECT_SOURCE_DIR}/YupplyMayham)
|
||||||
|
|
||||||
# Add source to this project's executable.
|
# Add source to this project's executable.
|
||||||
add_executable (YuppleMayham "src/main.cpp" "c:/sdks/glad/src/glad.c" "graphics/glwindow.h" "src/graphics/sprite.cpp" "src/graphics/mesh.cpp" "src/gameplay/entity.cpp" "src/gameplay/gameactor.cpp" "src/graphics/shader.cpp" "src/util.cpp" "gameplay/camera.h" "src/gameplay/camera.cpp" "src/utility/command.cpp" "src/gameplay/input.cpp" "gameplay/mousestate.h" "src/gameplay/weapons/bullet.cpp" "gameplay/weapons/bulletmanager.h" "src/gameplay/weapons/bulletmanager.cpp" "src/gameplay/scene.cpp" "gameplay/scene.h" "graphics/tile.h" "graphics/texture.h" "src/graphics/texture.cpp" "src/graphics/tile.cpp" "graphics/tiletype.h" "utility/resourcemanager.h" "src/utility/resourcemanager.cpp" "utility/xmlloader.h" "src/utility/xmlloader.cpp" "gameplay/game.h" "src/gameplay/game.cpp" "src/graphics/instancedraw.cpp" "gameplay/map.h" "src/gameplay/map.cpp" "src/gameplay/weapons/weapon.cpp" "gameplay/physics.h" "src/gameplay/physics.cpp" "utility/events.h" "utility/debugdraw.h" "src/utility/debugdraw.cpp" "utility/script.h" "src/utility/script.cpp" "gameplay/ai.h" "utility/raycaster.h" "src/gameplay/ai.cpp" "utility/ftfont.h" "src/utility/ftfont.cpp" "utility/direction.h")
|
add_executable (YuppleMayham "src/main.cpp" "c:/sdks/glad/src/glad.c" "graphics/glwindow.h" "src/graphics/sprite.cpp" "src/graphics/mesh.cpp" "src/gameplay/entity.cpp" "src/gameplay/gameactor.cpp" "src/graphics/shader.cpp" "src/util.cpp" "gameplay/camera.h" "src/gameplay/camera.cpp" "src/utility/command.cpp" "src/gameplay/input.cpp" "utility/mousestate.h" "src/gameplay/weapons/bullet.cpp" "gameplay/weapons/bulletmanager.h" "src/gameplay/weapons/bulletmanager.cpp" "src/gameplay/scene.cpp" "gameplay/scene.h" "graphics/tile.h" "graphics/texture.h" "src/graphics/texture.cpp" "src/graphics/tile.cpp" "graphics/tiletype.h" "utility/resourcemanager.h" "src/utility/resourcemanager.cpp" "utility/xmlloader.h" "src/utility/xmlloader.cpp" "gameplay/game.h" "src/gameplay/game.cpp" "src/graphics/instancedraw.cpp" "gameplay/map.h" "src/gameplay/map.cpp" "src/gameplay/weapons/weapon.cpp" "gameplay/physics.h" "src/gameplay/physics.cpp" "utility/events.h" "utility/debugdraw.h" "src/utility/debugdraw.cpp" "utility/script.h" "src/utility/script.cpp" "gameplay/ai.h" "utility/raycaster.h" "src/gameplay/ai.cpp" "utility/ftfont.h" "src/utility/ftfont.cpp" "utility/direction.h")
|
||||||
|
|
||||||
add_custom_command(TARGET YuppleMayham PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Resources/ $<TARGET_FILE_DIR:YuppleMayham>)
|
add_custom_command(TARGET YuppleMayham PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Resources/ $<TARGET_FILE_DIR:YuppleMayham>)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef _H_CAMERA_H
|
#ifndef _H_CAMERA_H
|
||||||
#define _H_CAMERA_H
|
#define _H_CAMERA_H
|
||||||
|
|
||||||
#include "entity.h"
|
#include "gameplay/entity.h"
|
||||||
|
|
||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
#include "../graphics/shader.h"
|
#include "graphics/shader.h"
|
||||||
|
|
||||||
class Camera;
|
class Camera;
|
||||||
struct PhysicsComponent;
|
struct PhysicsComponent;
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <SDL_timer.h>
|
#include <SDL_timer.h>
|
||||||
|
|
||||||
#include "entity.h"
|
#include "gameplay/entity.h"
|
||||||
#include "mousestate.h"
|
#include "utility/mousestate.h"
|
||||||
|
|
||||||
class Component;
|
class Component;
|
||||||
class AI;
|
class AI;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <SDL_keycode.h>
|
#include <SDL_keycode.h>
|
||||||
#include <SDL_events.h>
|
#include <SDL_events.h>
|
||||||
|
|
||||||
#include "mousestate.h"
|
#include "utility/mousestate.h"
|
||||||
|
|
||||||
class Command;
|
class Command;
|
||||||
class MouseCommand;
|
class MouseCommand;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "../graphics/instancedraw.h"
|
#include "graphics/instancedraw.h"
|
||||||
|
|
||||||
//class TileTextureInstance;
|
//class TileTextureInstance;
|
||||||
class Shader;
|
class Shader;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef _H_BULLET_H
|
#ifndef _H_BULLET_H
|
||||||
#define _H_BULLET_H
|
#define _H_BULLET_H
|
||||||
|
|
||||||
#include "../entity.h"
|
#include "gameplay/entity.h"
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
class Component;
|
class Component;
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,11 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "../../util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include "../../gameplay/entity.h"
|
#include "gameplay/entity.h"
|
||||||
#include "../../utility/direction.h"
|
#include "gameplay/weapons/bullet.h"
|
||||||
|
#include "utility/direction.h"
|
||||||
|
|
||||||
// TODO: Put all weapons inside of this base, we don't need a class for every weapon, we only need one class!
|
// TODO: Put all weapons inside of this base, we don't need a class for every weapon, we only need one class!
|
||||||
|
|
||||||
|
|
@ -35,6 +36,21 @@ public:
|
||||||
void render(const std::shared_ptr<Camera>& camera);
|
void render(const std::shared_ptr<Camera>& camera);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
struct BulletData {
|
||||||
|
glm::vec3 origin;
|
||||||
|
glm::vec2 direction;
|
||||||
|
float mass;
|
||||||
|
float sizeMod;
|
||||||
|
float speedMod;
|
||||||
|
float dropMod;
|
||||||
|
};
|
||||||
|
|
||||||
|
void adjustWeapon();
|
||||||
|
|
||||||
|
BulletData genBulletData();
|
||||||
|
std::shared_ptr<Bullet> createBullet(const BulletData& data);
|
||||||
|
|
||||||
glm::vec2 weaponSize;
|
glm::vec2 weaponSize;
|
||||||
glm::vec2 weaponOffset;
|
glm::vec2 weaponOffset;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "../utility/direction.h"
|
#include "utility/direction.h"
|
||||||
|
|
||||||
enum class TileType;
|
enum class TileType;
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "../../gameplay/ai.h"
|
#include "gameplay/ai.h"
|
||||||
#include "../../gameplay/gameactor.h"
|
#include "gameplay/gameactor.h"
|
||||||
|
|
||||||
#include "../../utility/raycaster.h"
|
#include "utility/raycaster.h"
|
||||||
#include "../../utility/script.h"
|
#include "utility/script.h"
|
||||||
|
|
||||||
|
|
||||||
AI::AI(const std::shared_ptr<GameActor>& actor, const std::shared_ptr<Raycaster>& raycaster)
|
AI::AI(const std::shared_ptr<GameActor>& actor, const std::shared_ptr<Raycaster>& raycaster)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../gameplay/camera.h"
|
#include "gameplay/camera.h"
|
||||||
|
|
||||||
void Camera::update(float deltaTime)
|
void Camera::update(float deltaTime)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../../gameplay/entity.h"
|
#include "gameplay/entity.h"
|
||||||
#include "../../gameplay/camera.h"
|
#include "gameplay/camera.h"
|
||||||
#include "../../gameplay/physics.h"
|
#include "gameplay/physics.h"
|
||||||
|
|
||||||
void Entity::setPosition(const glm::vec3& position)
|
void Entity::setPosition(const glm::vec3& position)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
#include "../../gameplay/game.h"
|
#include "gameplay/game.h"
|
||||||
#include "../../graphics/glwindow.h"
|
#include "gameplay/input.h"
|
||||||
#include "../../gameplay/input.h"
|
#include "gameplay/scene.h"
|
||||||
#include "../../utility/command.h"
|
|
||||||
#include "../../gameplay/scene.h"
|
#include "utility/command.h"
|
||||||
#include "../../utility/resourcemanager.h"
|
#include "utility/resourcemanager.h"
|
||||||
#include "../../utility/ftfont.h"
|
#include "utility/ftfont.h"
|
||||||
|
|
||||||
|
#include "graphics/glwindow.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#include "../../gameplay/gameactor.h"
|
#include "gameplay/gameactor.h"
|
||||||
#include "../../utility/component.h"
|
#include "gameplay/entity.h"
|
||||||
#include "../../gameplay/entity.h"
|
#include "gameplay/physics.h"
|
||||||
#include "../../gameplay/physics.h"
|
#include "gameplay/weapons/weapon.h"
|
||||||
#include "../../gameplay/weapons/weapon.h"
|
#include "utility/events.h"
|
||||||
#include "../../utility/events.h"
|
#include "utility/direction.h"
|
||||||
#include "../../utility/direction.h"
|
#include "utility/component.h"
|
||||||
|
|
||||||
GameActor::~GameActor() { }
|
GameActor::~GameActor() { }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../../gameplay/input.h"
|
#include "gameplay/input.h"
|
||||||
#include "../../utility/command.h"
|
#include "utility/command.h"
|
||||||
#include "../../gameplay/gameactor.h"
|
#include "gameplay/gameactor.h"
|
||||||
|
|
||||||
#include <SDL_timer.h>
|
#include <SDL_timer.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#include "../../gameplay/map.h"
|
#include "gameplay/map.h"
|
||||||
//#include "../../graphics/instancedraw.h"
|
#include "utility/xmlloader.h"
|
||||||
#include "../../utility/xmlloader.h"
|
#include "graphics/tiletype.h"
|
||||||
#include "../../graphics/tiletype.h"
|
#include "graphics/shader.h"
|
||||||
#include "../../graphics/shader.h"
|
#include "gameplay/camera.h"
|
||||||
#include "../../gameplay/camera.h"
|
|
||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../../gameplay/physics.h"
|
#include "gameplay/physics.h"
|
||||||
#include "../../gameplay/weapons/bullet.h"
|
#include "gameplay/weapons/bullet.h"
|
||||||
#include "../../utility/events.h"
|
#include "utility/events.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
@ -115,6 +115,7 @@ void PhysicsEngine::resolvePossibleCollisions()
|
||||||
glm::vec3 correctionVector = normal * (penetrationDepth / ((1 / objs.first->rigidBody.mass) + (1 / objs.second->rigidBody.mass)));
|
glm::vec3 correctionVector = normal * (penetrationDepth / ((1 / objs.first->rigidBody.mass) + (1 / objs.second->rigidBody.mass)));
|
||||||
glm::vec3 vrel = objs.first->rigidBody.velocity - objs.second->rigidBody.velocity;
|
glm::vec3 vrel = objs.first->rigidBody.velocity - objs.second->rigidBody.velocity;
|
||||||
|
|
||||||
|
// smallest elasticity of the two colliders
|
||||||
float e = std::min(objs.first->rigidBody.elasticity, objs.second->rigidBody.elasticity);
|
float e = std::min(objs.first->rigidBody.elasticity, objs.second->rigidBody.elasticity);
|
||||||
float impulseMag = (-(1 + e) * glm::dot(vrel, normal)) / ((1 / objs.first->rigidBody.mass) + (1 / objs.second->rigidBody.mass));
|
float impulseMag = (-(1 + e) * glm::dot(vrel, normal)) / ((1 / objs.first->rigidBody.mass) + (1 / objs.second->rigidBody.mass));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
#include "../../gameplay/scene.h"
|
#include "gameplay/scene.h"
|
||||||
#include "../../gameplay/camera.h"
|
#include "gameplay/camera.h"
|
||||||
#include "../../gameplay/gameactor.h"
|
#include "gameplay/gameactor.h"
|
||||||
#include "../../gameplay/weapons/weapons.h"
|
#include "gameplay/weapons/weapons.h"
|
||||||
#include "../../gameplay/map.h"
|
#include "gameplay/map.h"
|
||||||
#include "../../gameplay/physics.h"
|
#include "gameplay/physics.h"
|
||||||
#include "../../gameplay/ai.h"
|
#include "gameplay/ai.h"
|
||||||
|
|
||||||
#include "../../graphics/tile.h"
|
#include "graphics/tile.h"
|
||||||
#include "../../graphics/sprite.h"
|
#include "graphics/sprite.h"
|
||||||
|
|
||||||
#include "../../utility/component.h"
|
#include "utility/component.h"
|
||||||
#include "../../utility/xmlloader.h"
|
#include "utility/xmlloader.h"
|
||||||
#include "../../utility/resourcemanager.h"
|
#include "utility/resourcemanager.h"
|
||||||
#include "../../utility/events.h"
|
#include "utility/events.h"
|
||||||
#include "../../utility/raycaster.h"
|
#include "utility/raycaster.h"
|
||||||
#include "../../utility/debugdraw.h"
|
#include "utility/debugdraw.h"
|
||||||
|
|
||||||
// Scene xml files, should contain a node called <player> that holds the sprite location
|
// Scene xml files, should contain a node called <player> that holds the sprite location
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../../../gameplay/weapons/bullet.h"
|
#include "gameplay/weapons/bullet.h"
|
||||||
#include "../../../utility/component.h"
|
#include "gameplay/physics.h"
|
||||||
#include "../../../gameplay/physics.h"
|
#include "utility/component.h"
|
||||||
|
|
||||||
void Bullet::addComponent(std::shared_ptr<Component> component)
|
void Bullet::addComponent(std::shared_ptr<Component> component)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "../../../gameplay/weapons/bulletmanager.h"
|
#include "gameplay/weapons/bulletmanager.h"
|
||||||
#include "../../../gameplay/weapons/bullet.h"
|
#include "gameplay/weapons/bullet.h"
|
||||||
#include "../../../utility/component.h"
|
#include "gameplay/physics.h"
|
||||||
#include "../../../gameplay/physics.h"
|
#include "utility/events.h"
|
||||||
#include "../../../utility/events.h"
|
#include "utility/component.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
#include "../../../gameplay/weapons/weapon.h"
|
#include "gameplay/weapons/weapon.h"
|
||||||
#include "../../../utility/resourcemanager.h"
|
#include "utility/resourcemanager.h"
|
||||||
#include "../../../gameplay/weapons/bulletmanager.h"
|
#include "gameplay/weapons/bulletmanager.h"
|
||||||
#include "../../../gameplay/weapons/bullet.h"
|
#include "gameplay/weapons/bullet.h"
|
||||||
#include "../../../gameplay/gameactor.h"
|
#include "gameplay/gameactor.h"
|
||||||
#include "../../../utility/component.h"
|
#include "utility/component.h"
|
||||||
#include "../../../utility/events.h"
|
#include "utility/events.h"
|
||||||
#include "../../../gameplay/physics.h"
|
#include "gameplay/physics.h"
|
||||||
#include <SDL_timer.h>
|
#include <SDL_timer.h>
|
||||||
|
|
||||||
#include "../../../utility/debugdraw.h"
|
#include "utility/debugdraw.h"
|
||||||
|
|
||||||
// TODO: Regular clean up, make this mess readable!
|
// TODO: Regular clean up, make this mess readable!
|
||||||
|
|
||||||
|
|
@ -52,37 +52,9 @@ void Weapon::shoot()
|
||||||
Uint32 currentTime = SDL_GetTicks();
|
Uint32 currentTime = SDL_GetTicks();
|
||||||
if (currentTime - lastFireTime >= fireSpeed)
|
if (currentTime - lastFireTime >= fireSpeed)
|
||||||
{
|
{
|
||||||
float rotation = glm::radians(wielder->getRotation());
|
// create bullet using this generated data
|
||||||
float mass = 0.1f;
|
BulletData b = genBulletData();
|
||||||
glm::vec2 facing = glm::vec2(
|
bulletManager->addBullet(createBullet(b));
|
||||||
cos(rotation + glm::radians(static_cast<float>(bulletSpread->genFloat()))),
|
|
||||||
sin(rotation + glm::radians(static_cast<float>(bulletSpread->genFloat())))
|
|
||||||
);
|
|
||||||
facing = glm::normalize(facing);
|
|
||||||
float sizeMod = bulletModifer->genFloat();
|
|
||||||
float speedMod = bulletModifer->genFloat();
|
|
||||||
float dropMod = bulletModifer->genFloat();
|
|
||||||
|
|
||||||
float radius = wielder->getScale().x + (weaponSize.x * 0.5) + weaponOffset.x;
|
|
||||||
|
|
||||||
glm::vec3 offset = glm::vec3(
|
|
||||||
// x offset from the wielder
|
|
||||||
wielder->getCenter().x + cos(rotation) * radius - sin(rotation) * weaponOffset.y,
|
|
||||||
// y offset from the wielder
|
|
||||||
wielder->getCenter().y + sin(rotation) * radius + cos(rotation) * weaponOffset.y,
|
|
||||||
0.0f
|
|
||||||
);
|
|
||||||
glm::vec3 origin = offset;
|
|
||||||
origin.x -= ((bulletSize.x) * sizeMod) * 0.5f;
|
|
||||||
origin.y -= ((bulletSize.y) * sizeMod) * 0.5f;
|
|
||||||
|
|
||||||
auto bullet = std::make_shared<Bullet>(wielder->getActorID(), bulletShader, origin, facing, bulletSpeed, bulletDrop, bulletSize);
|
|
||||||
bullet->addComponent(bulletSprite);
|
|
||||||
bullet->addPhysicsComponent(std::make_shared<PhysicsComponent>(PhysicsComponentFactory::makeBullet(wielder->getActorID(), origin, mass, bulletSize.x / 2)));
|
|
||||||
bullet->getPhysicsComponent()->rigidBody.velocity += bulletSpeed * glm::vec3(facing.x, facing.y, 0.f) / mass;
|
|
||||||
if (eventManager)
|
|
||||||
eventManager->notify(std::make_shared<BulletFiredEvent>(bullet));
|
|
||||||
bulletManager->addBullet(bullet);
|
|
||||||
lastFireTime = currentTime;
|
lastFireTime = currentTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -97,32 +69,10 @@ void Weapon::hookEventManager(const std::shared_ptr<EventManager>& eventManager)
|
||||||
void Weapon::update(float deltaTime)
|
void Weapon::update(float deltaTime)
|
||||||
{
|
{
|
||||||
Entity::update(deltaTime);
|
Entity::update(deltaTime);
|
||||||
|
// move the weapon into place as the wielder rotates and moves
|
||||||
if (wielder)
|
if (wielder)
|
||||||
{
|
adjustWeapon();
|
||||||
float rotation = glm::radians(wielder->getRotation());
|
|
||||||
|
|
||||||
glm::vec3 offset = glm::vec3(
|
|
||||||
cos(rotation) * ((wielder->getScale().x) - weaponSize.x * 0.5f),
|
|
||||||
sin(rotation) * ((wielder->getScale().y) - weaponSize.y * 0.5f),
|
|
||||||
0.0f
|
|
||||||
);
|
|
||||||
glm::vec3 origin = wielder->getCenter() + offset;
|
|
||||||
origin.x -= (weaponSize.x) * 0.5f;
|
|
||||||
origin.y -= (weaponSize.y) * 0.5f;
|
|
||||||
|
|
||||||
// Flip the texture if the weapon is facing upwards or downwards
|
|
||||||
Direction d = getDirectionFromRotation(glm::degrees(rotation));
|
|
||||||
if ((lastDir == Direction::Up || lastDir == Direction::Left) &&
|
|
||||||
(d == Direction::Down || d == Direction::Right) && !isFlipped())
|
|
||||||
flip();
|
|
||||||
if ((lastDir == Direction::Down || lastDir == Direction::Right) &&
|
|
||||||
(d == Direction::Up || d == Direction::Left) && isFlipped())
|
|
||||||
flip();
|
|
||||||
|
|
||||||
setRotation(wielder->getRotation() - 180);
|
|
||||||
setPosition(origin);
|
|
||||||
lastDir = getDirectionFromRotation(glm::degrees(rotation));
|
|
||||||
}
|
|
||||||
for (auto& component : components)
|
for (auto& component : components)
|
||||||
component->update();
|
component->update();
|
||||||
bulletManager->update(deltaTime);
|
bulletManager->update(deltaTime);
|
||||||
|
|
@ -138,3 +88,71 @@ void Weapon::render(const std::shared_ptr<Camera>& camera)
|
||||||
}
|
}
|
||||||
bulletManager->render(camera);
|
bulletManager->render(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Weapon::adjustWeapon()
|
||||||
|
{
|
||||||
|
float rotation = glm::radians(wielder->getRotation());
|
||||||
|
|
||||||
|
glm::vec3 offset = glm::vec3(
|
||||||
|
cos(rotation) * ((wielder->getScale().x) - weaponSize.x * 0.5f),
|
||||||
|
sin(rotation) * ((wielder->getScale().y) - weaponSize.y * 0.5f),
|
||||||
|
0.0f
|
||||||
|
);
|
||||||
|
glm::vec3 origin = wielder->getCenter() + offset;
|
||||||
|
origin.x -= (weaponSize.x) * 0.5f;
|
||||||
|
origin.y -= (weaponSize.y) * 0.5f;
|
||||||
|
|
||||||
|
// Flip the texture if the weapon is facing upwards or downwards
|
||||||
|
Direction d = getDirectionFromRotation(glm::degrees(rotation));
|
||||||
|
if ((lastDir == Direction::Up || lastDir == Direction::Left) &&
|
||||||
|
(d == Direction::Down || d == Direction::Right) && !isFlipped())
|
||||||
|
flip();
|
||||||
|
if ((lastDir == Direction::Down || lastDir == Direction::Right) &&
|
||||||
|
(d == Direction::Up || d == Direction::Left) && isFlipped())
|
||||||
|
flip();
|
||||||
|
|
||||||
|
setRotation(wielder->getRotation() - 180);
|
||||||
|
setPosition(origin);
|
||||||
|
lastDir = getDirectionFromRotation(glm::degrees(rotation));
|
||||||
|
}
|
||||||
|
|
||||||
|
Weapon::BulletData Weapon::genBulletData()
|
||||||
|
{
|
||||||
|
BulletData b;
|
||||||
|
float rotation = glm::radians(wielder->getRotation());
|
||||||
|
b.mass = 0.1f;
|
||||||
|
glm::vec2 facing = glm::vec2(
|
||||||
|
cos(rotation + glm::radians(static_cast<float>(bulletSpread->genFloat()))),
|
||||||
|
sin(rotation + glm::radians(static_cast<float>(bulletSpread->genFloat())))
|
||||||
|
);
|
||||||
|
b.direction = glm::normalize(facing);
|
||||||
|
b.sizeMod = bulletModifer->genFloat();
|
||||||
|
b.speedMod = bulletModifer->genFloat();
|
||||||
|
b.dropMod = bulletModifer->genFloat();
|
||||||
|
|
||||||
|
float radius = wielder->getScale().x + (weaponSize.x * 0.5) + weaponOffset.x;
|
||||||
|
|
||||||
|
b.origin = glm::vec3(
|
||||||
|
// x offset from the wielder
|
||||||
|
wielder->getCenter().x + cos(rotation) * radius - sin(rotation) * weaponOffset.y,
|
||||||
|
// y offset from the wielder
|
||||||
|
wielder->getCenter().y + sin(rotation) * radius + cos(rotation) * weaponOffset.y,
|
||||||
|
0.0f
|
||||||
|
);
|
||||||
|
b.origin.x -= ((bulletSize.x) * b.sizeMod) * 0.5f;
|
||||||
|
b.origin.y -= ((bulletSize.y) * b.sizeMod) * 0.5f;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Bullet> Weapon::createBullet(const Weapon::BulletData& data)
|
||||||
|
{
|
||||||
|
auto bullet = std::make_shared<Bullet>(wielder->getActorID(), bulletShader, data.origin, data.direction, bulletSpeed, bulletDrop, bulletSize);
|
||||||
|
bullet->addComponent(bulletSprite);
|
||||||
|
bullet->addPhysicsComponent(std::make_shared<PhysicsComponent>(PhysicsComponentFactory::makeBullet(wielder->getActorID(), data.origin, data.mass, bulletSize.x / 2)));
|
||||||
|
bullet->getPhysicsComponent()->rigidBody.velocity += bulletSpeed * glm::vec3(data.direction.x, data.direction.y, 0.f) / data.mass;
|
||||||
|
|
||||||
|
if (eventManager)
|
||||||
|
eventManager->notify(std::make_shared<BulletFiredEvent>(bullet));
|
||||||
|
return bullet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "../../graphics/instancedraw.h"
|
#include "graphics/instancedraw.h"
|
||||||
#include "../../graphics/texture.h"
|
#include "graphics/texture.h"
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../graphics/mesh.h"
|
#include "graphics/mesh.h"
|
||||||
|
|
||||||
Mesh::Mesh(const VertexList& vertexList, const IndexList& indexList) : indexSize(indexList.size())
|
Mesh::Mesh(const VertexList& vertexList, const IndexList& indexList) : indexSize(indexList.size())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../graphics/shader.h"
|
#include "graphics/shader.h"
|
||||||
|
|
||||||
Shader::Shader(const char* vertexPath, const char* fragmentPath)
|
Shader::Shader(const char* vertexPath, const char* fragmentPath)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "../../graphics/sprite.h"
|
#include "graphics/sprite.h"
|
||||||
#include "../../graphics/texture.h"
|
#include "graphics/texture.h"
|
||||||
#include "../../util.h"
|
#include "util.h"
|
||||||
#include "../../utility/events.h"
|
#include "utility/events.h"
|
||||||
|
|
||||||
SpriteStatic::SpriteStatic(const char* texturePath)
|
SpriteStatic::SpriteStatic(const char* texturePath)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "../../graphics/texture.h"
|
#include "graphics/texture.h"
|
||||||
#include "../../util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../../graphics/tile.h"
|
#include "graphics/tile.h"
|
||||||
#include "../../graphics/texture.h"
|
#include "graphics/texture.h"
|
||||||
#include "../../graphics/tiletype.h"
|
#include "graphics/tiletype.h"
|
||||||
|
|
||||||
TileSet::TileSet(const char* tileSetImage, float frameSize)
|
TileSet::TileSet(const char* tileSetImage, float frameSize)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// TODO: Fix circular dependency issues, mostly with input.h needing gameactor.h and command.h
|
// TODO: Fix circular dependency issues, mostly with input.h needing gameactor.h and command.h
|
||||||
#include "../gameplay/game.h"
|
#include "gameplay/game.h"
|
||||||
|
|
||||||
const float vertices[] = {
|
const float vertices[] = {
|
||||||
0.0f, 0.5f, 0.0f,
|
0.0f, 0.5f, 0.0f,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../util.h"
|
#include "util.h"
|
||||||
|
|
||||||
namespace UTIL
|
namespace UTIL
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "../../utility/command.h"
|
#include "utility/command.h"
|
||||||
#include "../../gameplay/gameactor.h"
|
#include "gameplay/gameactor.h"
|
||||||
|
|
||||||
//void LambdaCommand::execute(GameActor& actor) { func(actor); }
|
//void LambdaCommand::execute(GameActor& actor) { func(actor); }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../utility/debugdraw.h"
|
#include "utility/debugdraw.h"
|
||||||
|
|
||||||
Circle::Circle(const glm::vec3& position, float radius)
|
Circle::Circle(const glm::vec3& position, float radius)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../utility/ftfont.h"
|
#include "utility/ftfont.h"
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#include "../../utility/resourcemanager.h"
|
#include "utility/resourcemanager.h"
|
||||||
#include "../../utility/component.h"
|
#include "utility/component.h"
|
||||||
#include "../../graphics/sprite.h"
|
#include "graphics/sprite.h"
|
||||||
#include "../../graphics/tile.h"
|
#include "graphics/tile.h"
|
||||||
#include "../../utility/script.h"
|
#include "utility/script.h"
|
||||||
#include "../../graphics/tiletype.h"
|
#include "graphics/tiletype.h"
|
||||||
#include "../../graphics/shader.h"
|
#include "graphics/shader.h"
|
||||||
#include "../../gameplay/weapons/weapons.h"
|
#include "gameplay/weapons/weapons.h"
|
||||||
|
|
||||||
std::shared_ptr<Sprite> ResourceManager::loadSpriteAnimated(const std::string& path, float frameSize)
|
std::shared_ptr<Sprite> ResourceManager::loadSpriteAnimated(const std::string& path, float frameSize)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "../../utility/script.h"
|
#include "utility/script.h"
|
||||||
#include "../../gameplay/gameactor.h"
|
#include "gameplay/gameactor.h"
|
||||||
#include "../../gameplay/physics.h"
|
#include "gameplay/physics.h"
|
||||||
#include "../../gameplay/ai.h"
|
#include "gameplay/ai.h"
|
||||||
#include "../../utility/raycaster.h"
|
#include "utility/raycaster.h"
|
||||||
|
|
||||||
void Script::registerUserTypes()
|
void Script::registerUserTypes()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "../../utility/xmlloader.h"
|
#include "utility/xmlloader.h"
|
||||||
#include "../../graphics/tiletype.h"
|
#include "graphics/tiletype.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "../gameplay/mousestate.h"
|
#include "utility/mousestate.h"
|
||||||
|
|
||||||
class GameActor;
|
class GameActor;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef _H_COMPONENT_H
|
#ifndef _H_COMPONENT_H
|
||||||
#define _H_COMPONENT_H
|
#define _H_COMPONENT_H
|
||||||
|
|
||||||
#include "../graphics/mesh.h"
|
#include "graphics/mesh.h"
|
||||||
#include "../graphics/sprite.h"
|
#include "graphics/sprite.h"
|
||||||
#include "../graphics/shader.h"
|
#include "graphics/shader.h"
|
||||||
#include "../gameplay/ai.h"
|
#include "gameplay/ai.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
|
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "direction.h"
|
#include "utility/direction.h"
|
||||||
|
|
||||||
class Bullet;
|
class Bullet;
|
||||||
struct PhysicsComponent;
|
struct PhysicsComponent;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "debugdraw.h"
|
#include "utility/debugdraw.h"
|
||||||
|
|
||||||
class Raycaster {
|
class Raycaster {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "../utility/xmlloader.h"
|
#include "utility/xmlloader.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue