add reloading animation
parent
a1ad7f6af0
commit
71be55ee58
|
@ -91,7 +91,7 @@ add_executable(shooter
|
||||||
engine/network/UDPConnection.h
|
engine/network/UDPConnection.h
|
||||||
engine/network/UDPSocket.cpp
|
engine/network/UDPSocket.cpp
|
||||||
engine/network/UDPSocket.h
|
engine/network/UDPSocket.h
|
||||||
engine/SoundController.cpp engine/SoundController.h ShooterMsgType.h ShooterMsgType.cpp engine/animation/AAttractToPoint.h engine/animation/ARotateRelativePoint.h)
|
engine/SoundController.cpp engine/SoundController.h ShooterMsgType.h ShooterMsgType.cpp engine/animation/AAttractToPoint.h engine/animation/ARotateRelativePoint.h engine/animation/ARotateLeft.h)
|
||||||
|
|
||||||
if(APPLE OR UNIX)
|
if(APPLE OR UNIX)
|
||||||
include_directories(/usr/local/include)
|
include_directories(/usr/local/include)
|
||||||
|
|
14
Player.cpp
14
Player.cpp
|
@ -6,6 +6,9 @@
|
||||||
#include "engine/Screen.h"
|
#include "engine/Screen.h"
|
||||||
#include "engine/utils/Log.h"
|
#include "engine/utils/Log.h"
|
||||||
|
|
||||||
|
#include "engine/animation/Timeline.h"
|
||||||
|
#include "engine/animation/ARotateLeft.h"
|
||||||
|
|
||||||
Player::Player(ObjectNameTag name) : RigidBody(name) {
|
Player::Player(ObjectNameTag name) : RigidBody(name) {
|
||||||
loadObj(ShooterConsts::CUBE_OBJ, Vec3D{0.5, 1.9, 0.5});
|
loadObj(ShooterConsts::CUBE_OBJ, Vec3D{0.5, 1.9, 0.5});
|
||||||
setAcceleration(Vec3D{0, -ShooterConsts::GRAVITY, 0});
|
setAcceleration(Vec3D{0, -ShooterConsts::GRAVITY, 0});
|
||||||
|
@ -79,6 +82,15 @@ void Player::addWeapon(std::shared_ptr<Weapon> weapon) {
|
||||||
_weapons.back()->rotateRelativePoint(position() + Vec3D{0, 1.8, 0}, Vec3D{0, 1, 0}, angle().y());
|
_weapons.back()->rotateRelativePoint(position() + Vec3D{0, 1.8, 0}, Vec3D{0, 1, 0}, angle().y());
|
||||||
_weapons.back()->rotateRelativePoint(position() + Vec3D{0, 1.8, 0}, left(), headAngle());
|
_weapons.back()->rotateRelativePoint(position() + Vec3D{0, 1.8, 0}, left(), headAngle());
|
||||||
|
|
||||||
|
// add animation of reloading
|
||||||
|
_weapons.back()->setReloadCallBack([this]() {
|
||||||
|
Timeline::animate(AnimationListTag("reload_weapon"),
|
||||||
|
std::make_shared<ARotateLeft>(_weapons[_selectedWeapon],
|
||||||
|
2 * Consts::PI,
|
||||||
|
_weapons[_selectedWeapon]->reloadTime() / 2));
|
||||||
|
});
|
||||||
|
|
||||||
|
// add call back function to create fire traces
|
||||||
if (_addTraceCallBack != nullptr) {
|
if (_addTraceCallBack != nullptr) {
|
||||||
_weapons.back()->setAddTraceCallBack(_addTraceCallBack);
|
_weapons.back()->setAddTraceCallBack(_addTraceCallBack);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +122,7 @@ void Player::selectNextWeapon() {
|
||||||
if (_removeWeaponCallBack != nullptr) {
|
if (_removeWeaponCallBack != nullptr) {
|
||||||
_removeWeaponCallBack(_weapons[_selectedWeapon]);
|
_removeWeaponCallBack(_weapons[_selectedWeapon]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_selectedWeapon = (_selectedWeapon + 1) % _weapons.size();
|
_selectedWeapon = (_selectedWeapon + 1) % _weapons.size();
|
||||||
|
|
||||||
if (_addWeaponCallBack != nullptr) {
|
if (_addWeaponCallBack != nullptr) {
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
//
|
||||||
|
// Created by Иван Ильин on 01.11.2021.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SHOOTER_AROTATELEFT_H
|
||||||
|
#define SHOOTER_AROTATELEFT_H
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "Animation.h"
|
||||||
|
#include "../Object.h"
|
||||||
|
|
||||||
|
class ARotateLeft final : public Animation {
|
||||||
|
private:
|
||||||
|
const std::weak_ptr<Object> _object;
|
||||||
|
const double _rotationValue;
|
||||||
|
|
||||||
|
void update() override {
|
||||||
|
if (_object.expired()) {
|
||||||
|
stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_object.lock()->rotateLeft(_rotationValue * dprogress());
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
ARotateLeft(std::weak_ptr<Object> object, double r, double duration = 1, LoopOut looped = LoopOut::None,
|
||||||
|
InterpolationType interpolationType = InterpolationType::Bezier)
|
||||||
|
: Animation(duration, looped, interpolationType), _object(object), _rotationValue(r) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SHOOTER_AROTATELEFT_H
|
|
@ -208,6 +208,7 @@
|
||||||
<ClInclude Include="engine\animation\AWait.h" />
|
<ClInclude Include="engine\animation\AWait.h" />
|
||||||
<ClInclude Include="engine\animation\AAttractToPoint.h" />
|
<ClInclude Include="engine\animation\AAttractToPoint.h" />
|
||||||
<ClInclude Include="engine\animation\ARotateRelativePoint.h" />
|
<ClInclude Include="engine\animation\ARotateRelativePoint.h" />
|
||||||
|
<ClInclude Include="engine\animation\ARotateLeft.h" />
|
||||||
<ClInclude Include="engine\animation\Interpolation.h" />
|
<ClInclude Include="engine\animation\Interpolation.h" />
|
||||||
<ClInclude Include="engine\animation\Timeline.h" />
|
<ClInclude Include="engine\animation\Timeline.h" />
|
||||||
<ClInclude Include="engine\Camera.h" />
|
<ClInclude Include="engine\Camera.h" />
|
||||||
|
|
|
@ -221,6 +221,9 @@
|
||||||
<ClInclude Include="engine\animation\ARotateRelativePoint.h">
|
<ClInclude Include="engine\animation\ARotateRelativePoint.h">
|
||||||
<Filter>Файлы заголовков\engine\animation</Filter>
|
<Filter>Файлы заголовков\engine\animation</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="engine\animation\ARotateLeft.h">
|
||||||
|
<Filter>Файлы заголовков\engine\animation</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="weapon\Ak47.h">
|
<ClInclude Include="weapon\Ak47.h">
|
||||||
<Filter>Файлы заголовков\weapon</Filter>
|
<Filter>Файлы заголовков\weapon</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "Weapon.h"
|
#include "Weapon.h"
|
||||||
#include "../engine/ResourceManager.h"
|
#include "../engine/ResourceManager.h"
|
||||||
#include "../engine/utils/Log.h"
|
#include "../engine/utils/Log.h"
|
||||||
|
@ -70,6 +71,10 @@ void Weapon::reload() {
|
||||||
SoundController::playSound(SoundTag("reloadSound_" + name().str()), _reloadSound);
|
SoundController::playSound(SoundTag("reloadSound_" + name().str()), _reloadSound);
|
||||||
Log::log("Weapon::reload (" + std::to_string(_stockAmmo) + " : " + std::to_string(_clipAmmo) + ")");
|
Log::log("Weapon::reload (" + std::to_string(_stockAmmo) + " : " + std::to_string(_clipAmmo) + ")");
|
||||||
_lastReloadTime = Time::time();
|
_lastReloadTime = Time::time();
|
||||||
|
|
||||||
|
if(_reloadCallBack != nullptr) {
|
||||||
|
_reloadCallBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<ObjectNameTag, double>
|
std::map<ObjectNameTag, double>
|
||||||
|
|
|
@ -38,6 +38,7 @@ private:
|
||||||
double _lastReloadTime = std::numeric_limits<double>::min();
|
double _lastReloadTime = std::numeric_limits<double>::min();
|
||||||
|
|
||||||
std::function<void(const Vec3D &, const Vec3D &)> _addTraceCallBack;
|
std::function<void(const Vec3D &, const Vec3D &)> _addTraceCallBack;
|
||||||
|
std::function<void()> _reloadCallBack;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<ObjectNameTag, double>
|
std::map<ObjectNameTag, double>
|
||||||
|
@ -58,10 +59,13 @@ public:
|
||||||
const Vec3D &direction);
|
const Vec3D &direction);
|
||||||
|
|
||||||
void reload();
|
void reload();
|
||||||
|
[[nodiscard]] double reloadTime() const { return _reloadTime; }
|
||||||
|
|
||||||
[[nodiscard]] std::pair<double, double> balance() const { return std::make_pair(_clipAmmo, _stockAmmo); }
|
[[nodiscard]] std::pair<double, double> balance() const { return std::make_pair(_clipAmmo, _stockAmmo); }
|
||||||
|
|
||||||
void setAddTraceCallBack(std::function<void(Vec3D, Vec3D)> add) { _addTraceCallBack = std::move(add); }
|
void setAddTraceCallBack(std::function<void(Vec3D, Vec3D)> add) { _addTraceCallBack = std::move(add); }
|
||||||
|
void setReloadCallBack(std::function<void()> reload) { _reloadCallBack = std::move(reload); }
|
||||||
|
|
||||||
|
|
||||||
void addAmmo(int ammoAdd) { _stockAmmo += ammoAdd; }
|
void addAmmo(int ammoAdd) { _stockAmmo += ammoAdd; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue