Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
Add dashing as a mechanic
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvh committed Jul 11, 2018
1 parent 4241ad0 commit 2daf8b5
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 141 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ Additional developer insight and blog can be found at

![Our Dinosaur Warrior][raptr-idle]

## Installing and Running v0.1-alpha.5
## Installing and Running v0.1-alpha.6

It's pretty dang simple under 64-bit Windows right now.

1. [Download the 0.1-alpha.5 Windows 64-bit Release](https://github.com/justinvh/raptr/releases/download/v0.1-alpha.5/raptr-0.1.0-alpha.5-Release-win64.zip)
1. [Download the 0.1-alpha.6 Windows 64-bit Release](https://github.com/justinvh/raptr/releases/download/v0.1-alpha.6/raptr-0.1.0-alpha.6-Release-win64.zip)
2. Extract that anywhere your heart desires.
3. Plug in a 360, GameCube, or Steam controller.
4. Go into the bin/ folder and run `raptr-client.exe`
5. Realize how much of an alpha this is :)

If you get a complaint about redistributables missing, then try downloading the [Visual C++ Redistributable for Visual Studio 2017 - x64](https://aka.ms/vs/15/release/vc_redist.x64.exe)

## Current State: v0.1-alpha.5
## Current State: v0.1-alpha.6

![Feature Mash][raptr-0.1-alpha.5]
![Feature Mash][raptr-0.1-alpha.6]

## Features with some Hyperbole

Expand All @@ -39,7 +39,7 @@ If you get a complaint about redistributables missing, then try downloading the

## Building and Running Raptr with CMake

1. [Download the 7-zip archive of Raptr's dependencies from here](https://github.com/justinvh/raptr/releases/download/v0.1-alpha.5/vcpkg-export-20180710-003830.7z)
1. [Download the 7-zip archive of Raptr's dependencies from here](https://github.com/justinvh/raptr/releases/download/v0.1-alpha.6/vcpkg-export-20180710-003830.7z)

```
$ git clone https://github.com/justinvh/raptr.git raptr
Expand Down Expand Up @@ -137,7 +137,11 @@ To be added

## Other Screenshots ([View the Album](https://imgur.com/a/pnREFi5))

7/8/2018 - Parallax backgrounds and foregrounds, oh my.
7/10/2018 - Multiplayer + parallax

![Feature Mash][raptr-0.1-alpha.5]

7/9/2018 - Parallax backgrounds and foregrounds, oh my.

![Feature Mash][raptr-0.1-alpha.4]

Expand Down Expand Up @@ -174,3 +178,4 @@ To be added
[raptr-0.1-alpha.3]: https://i.imgur.com/szO854w.gif
[raptr-0.1-alpha.4]: https://i.imgur.com/DQ5CTNO.gif
[raptr-0.1-alpha.5]: https://i.imgur.com/p71vkhy.gif
[raptr-0.1-alpha.6]: https://i.imgur.com/VCSDNqM.gif
21 changes: 9 additions & 12 deletions engine/include/raptr/game/character.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#include <cstdint>
#include <raptr/game/entity.hpp>
#include <raptr/common/filesystem.hpp>
#include <raptr/input/controller.hpp>

namespace raptr {

class Game;
class Sprite;
class Controller;
class Renderer;
class Filesystem;
struct ControllerState;

/*!
A character is a subclass of an entity that is intended to be controlled.
Expand Down Expand Up @@ -132,6 +131,12 @@ class Character : public Entity {
//! How long the character has been jumping
int64_t jump_time_us;

int64_t dash_length_us;

int64_t dash_time_us;

int32_t dash_speed;

//! Current jump count
uint32_t jump_count;

Expand All @@ -150,17 +155,9 @@ class Character : public Entity {
//! The initial velocity (v(0)) for computing how high the character will jump
int32_t jump_vel;

//! Dashing is a multiplier of 1.25
bool dashing;

//! Dash multiplier
double dash_scale;

int64_t dash_check_timer;

int32_t dash_move_check;

int32_t bunny_hop_count;

ControllerState last_controller_state;
};

} // namespace raptr
32 changes: 12 additions & 20 deletions engine/include/raptr/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Game : public std::enable_shared_from_this<Game>, public Serializable {
template <class T>
void add_event(T* event)
{
engine_events.push_back(EngineEvent::create<T>(event));
engine_events_buffers[engine_event_index].push_back(EngineEvent::create<T>(event));
}

void dispatch_event(const std::shared_ptr<EngineEvent>& event);
Expand All @@ -88,29 +88,19 @@ class Game : public std::enable_shared_from_this<Game>, public Serializable {
Spawn an entity to the world
*/
void spawn_staticmesh(const std::string& path,
StaticMeshSpawnEvent::Callback callback = [](auto&a) {})
{
StaticMeshSpawnEvent* event = new StaticMeshSpawnEvent();
auto g = xg::newGuid();
event->guid = g.bytes();
event->path = path;
event->callback = callback;
this->add_event<StaticMeshSpawnEvent>(event);
}
StaticMeshSpawnEvent::Callback callback = [](auto&a) {});


/*!
Spawn an entity to the world
*/
void spawn_character(const std::string& path,
CharacterSpawnEvent::Callback callback = [](auto&a) {})
{
CharacterSpawnEvent* event = new CharacterSpawnEvent();
auto g = xg::newGuid();
event->guid = g.bytes();
event->path = "characters/" + path + ".toml";
event->callback = callback;
this->add_event<CharacterSpawnEvent>(event);
}
CharacterSpawnEvent::Callback callback = [](auto&a) {});

/*
*/
void spawn_player(int32_t controller_id,
CharacterSpawnEvent::Callback callback = [](auto&a) {});

/*!
Run the game and manage maintaining a healthy FPS
Expand Down Expand Up @@ -187,6 +177,7 @@ class Game : public std::enable_shared_from_this<Game>, public Serializable {

//! A mapping of controller device ID to controller instances
std::map<int32_t, std::shared_ptr<Controller>> controllers;
std::map<int32_t, std::vector<std::shared_ptr<Character>>> controller_to_character;

//! A list of all loaded entities in the game
std::vector<std::shared_ptr<Entity>> entities;
Expand All @@ -213,7 +204,8 @@ class Game : public std::enable_shared_from_this<Game>, public Serializable {

int64_t frame_last_time;

std::vector<std::shared_ptr<EngineEvent>> engine_events;
int32_t engine_event_index = 0;
std::vector<std::shared_ptr<EngineEvent>> engine_events_buffers[2];

public:
//! If set, then all initialization has happened successfully
Expand Down
95 changes: 46 additions & 49 deletions engine/src/game/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ std::shared_ptr<Character> Character::from_toml(const FileInfo& toml_path)
"character.jumps_allowed",
"character.jump_perfect_scale",
"character.fast_fall_scale",
"character.dash_scale",
"character.dash_speed",
"character.dash_length_ms",
"sprite.path",
"sprite.scale"
};
Expand Down Expand Up @@ -103,8 +104,9 @@ std::shared_ptr<Character> Character::from_toml(const FileInfo& toml_path)
character->sprite->x = 0;
character->sprite->y = 0;
character->jump_count = 0;
character->dash_scale = dict["character.dash_scale"]->as<double>();
character->dash_check_timer = 0;
character->dash_speed = dict["character.dash_speed"]->as<int32_t>();
character->dash_length_us = dict["character.dash_length_ms"]->as<int32_t>() * 1e3;
character->dash_time_us = 0;

character->do_pixel_collision_test = false;
if (character->sprite->has_animation("Collision")) {
Expand Down Expand Up @@ -138,21 +140,33 @@ void Character::think(std::shared_ptr<Game>& game)
jump_time_us += delta_us;
}

bool in_dash = false;
if (dash_time_us > 0) {
in_dash = true;
dash_time_us += delta_us;
}

if (dash_time_us > dash_length_us) {
in_dash = false;
dash_time_us = 0;
this->on_left_joy(this->last_controller_state);
}

acc.y = game->gravity;

// External forces, like gravity
Rect fall_check = this->want_position_y(delta_us)[0];
fall_check.y += 0.1;

auto intersected_entity = game->intersect_world(this, fall_check);
if (!intersected_entity) {
if (!intersected_entity && !in_dash) {
if (fast_fall) {
vel.y += fast_fall_scale * game->gravity * delta_us / 1e6;
} else {
vel.y += game->gravity * delta_us / 1e6;
}
falling = true;
} else {
} else if (!in_dash) {
if (falling) {
jump_count = 0;
jump_time_us = 0;
Expand All @@ -163,7 +177,9 @@ void Character::think(std::shared_ptr<Game>& game)
vel.x = 0;
}

if (vel.x > walk_speed) {
if (in_dash) {
sprite->set_animation("Dash");
} else if (vel.x > walk_speed) {
sprite->set_animation("Run");
} else if (vel.x > 0) {
sprite->set_animation("Walk");
Expand Down Expand Up @@ -208,6 +224,8 @@ void Character::think(std::shared_ptr<Game>& game)
pos.x = want_x.x;
} else {
vel.x = 0;
dash_time_us = 0;
sprite->set_animation("Idle");
}

int32_t steps_y = static_cast<int32_t>((std::abs(pos.y - want_y.y) / 4) + 1);
Expand Down Expand Up @@ -269,62 +287,33 @@ void Character::stop()
moving = false;
auto& vel = this->velocity();
vel.x = 0.0;
dash_time_us = 0;
if (!falling) {
sprite->set_animation("Idle");
}
}

bool Character::on_left_joy(const ControllerState& state)
{
this->last_controller_state = state;
auto& vel = this->velocity();
float mag_x = std::fabs(state.x);
int64_t dash_delta_ms = static_cast<int64_t>((clock::ticks() - dash_check_timer) / 1e3);

// Turn around boosted dash
if (!dashing) {
bool can_dash = dash_delta_ms < 250;
if (state.x < -0.95) {
if (dash_move_check == 1 && can_dash) {
dashing = true;
} else if (dash_move_check != -1) {
dash_move_check = -1;
dash_check_timer = clock::ticks();
}
} else if (state.x > 0.95) {
if (dash_move_check == -1 && can_dash) {
dashing = true;
} else if (dash_move_check != 1) {
dash_move_check = 1;
dash_check_timer = clock::ticks();
}
if (dash_time_us > 0) {
if (mag_x < 0.01f && !falling) {
this->stop();

}
return false;
}

if (mag_x < 0.95) {
dashing = false;
}

// Turn around boosted dash
if (mag_x < 0.01f) {
this->stop();

if (dash_delta_ms > 250) {
dash_move_check = 0;
}

} else if (mag_x < 0.75f) {
this->walk(state.x);
} else if (mag_x >= 0.75f) {
if (dashing) {
float new_x = 0.0f;
if (state.x < 0.0f) {
new_x = static_cast<float>(-dash_scale);
} else {
new_x = static_cast<float>(dash_scale);
}
this->run(new_x);
} else {
this->run(state.x);
}
this->run(state.x);
}

if (falling && state.y > 0.5) {
Expand Down Expand Up @@ -352,6 +341,19 @@ bool Character::on_button_down(const ControllerState& state)
sprite->set_animation("Jump");
++jump_count;
}

if (state.button == Button::x && dash_time_us == 0 && jump_count < jumps_allowed) {
sprite->set_animation("Dash");
dash_time_us = 1;
if (sprite->flip_x) {
vel.x += dash_speed;
} else {
vel.x -= dash_speed;
}


vel.y = 0;
}
return false;
}

Expand Down Expand Up @@ -415,11 +417,6 @@ void Character::serialize(std::vector<NetField>& list)
CNF(walk_speed),
CNF(run_speed),
CNF(jump_vel),
CNF(dashing),
CNF(dashing),
CNF(dash_scale),
CNF(dash_check_timer),
CNF(dash_move_check),
CNF(bunny_hop_count)
};

Expand Down
Loading

0 comments on commit 2daf8b5

Please sign in to comment.