Very basic attack system.

master
Zed A. Shaw 4 weeks ago
parent 6bca6d021e
commit abd843d5ec
  1. 4
      assets/enemies.json
  2. 36
      gui.cpp
  3. 5
      gui.hpp
  4. 1
      systems.cpp
  5. 5
      worldbuilder.cpp

@ -17,7 +17,7 @@
"foreground": [131, 213, 238],
"background": [30, 20, 75]
},
{"_type": "Combat", "hp": 200, "damage": 15, "dead": false},
{"_type": "Combat", "hp": 20, "damage": 1, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": false},
{"_type": "LightSource", "strength": 70, "radius": 2},
{"_type": "EnemyConfig", "hearing_distance": 5},
@ -30,7 +30,7 @@
"foreground": [205, 164, 246],
"background": [30, 20, 75]
},
{"_type": "Combat", "hp": 100, "damage": 50, "dead": false},
{"_type": "Combat", "hp": 50, "damage": 10, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": false},
{"_type": "EnemyConfig", "hearing_distance": 10},
{"_type": "Sprite", "name": "evil_eye"}

@ -94,6 +94,7 @@ namespace gui {
switch($state) {
FSM_STATE(State, START, ev);
FSM_STATE(State, MOVING, ev);
FSM_STATE(State, ATTACKING, ev);
FSM_STATE(State, MAPPING, ev);
FSM_STATE(State, ROTATING, ev);
FSM_STATE(State, IDLE, ev);
@ -141,6 +142,18 @@ namespace gui {
}
}
void FSM::ATTACKING(Event ev) {
fmt::println("ATTACKING! {}", $rotation);
switch(ev) {
case Event::ATTACK:
run_systems();
$rotation = $rotation < 0.0f ? 0.0f : -33.0f;
break;
default:
state(State::IDLE);
}
}
void FSM::ROTATING(Event ) {
if($camera.play_rotate($rayview)) {
state(State::IDLE);
@ -149,6 +162,7 @@ namespace gui {
void FSM::IDLE(Event ev) {
using FU = Event;
$rotation = -10.0f;
switch(ev) {
case FU::QUIT:
@ -178,6 +192,11 @@ namespace gui {
case FU::MAP_OPEN:
state(State::MAPPING);
break;
case FU::ATTACK:
fmt::println("ATTACK IN IDLE!");
draw_weapon();
state(State::ATTACKING);
break;
case FU::CLOSE:
dbc::log("Nothing to close.");
break;
@ -229,6 +248,10 @@ namespace gui {
case KEY::A:
event(Event::MOVE_LEFT);
break;
case KEY::Space:
$rotation = 0;
event(Event::ATTACK);
break;
case KEY::R:
$stats.reset();
break;
@ -258,8 +281,12 @@ namespace gui {
rect.setFillColor({50, 50, 50});
$window.draw(rect);
auto player = $level.world->get_the<Player>();
auto player_combat = $level.world->get<Combat>(player.entity);
$text.setString(
fmt::format("FPS\n"
"HP: {}\n"
"mean:{:>8.5}\n"
"sdev: {:>8.5}\n"
"min: {:>8.5}\n"
@ -270,7 +297,7 @@ namespace gui {
"Debug? {}\n\n"
"dir: {:>2.02},{:>2.02}\n"
"pos: {:>2.02},{:>2.02}\n\n",
$stats.mean(), $stats.stddev(), $stats.min,
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
$stats.max, $stats.n, VSYNC,
FRAME_LIMIT, DEBUG_BUILD, $rayview.$dir_x,
$rayview.$dir_y, $rayview.$pos_x, $rayview.$pos_y));
@ -294,16 +321,11 @@ namespace gui {
$stats.sample(1/elapsed.count());
draw_gui();
// draw_weapon();
draw_weapon();
$window.display();
}
void FSM::mouse() {
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
$rotation = -30.0f;
} else {
$rotation = -10.0f;
}
}
void FSM::generate_map() {

@ -28,6 +28,7 @@ namespace gui {
enum class State {
START,
MOVING,
ATTACKING,
MAPPING,
ROTATING,
IDLE,
@ -45,12 +46,13 @@ namespace gui {
CLOSE,
ROTATE_LEFT,
ROTATE_RIGHT,
ATTACK,
QUIT
};
class FSM : public DeadSimpleFSM<State, Event> {
public:
float $rotation = -30.0f;
float $rotation = -10.0f;
Point $player{0,0};
LevelManager $levels;
sf::RenderWindow $window;
@ -70,6 +72,7 @@ namespace gui {
void START(Event );
void MOVING(Event );
void ATTACKING(Event );
void MAPPING(Event);
void ROTATING(Event );
void IDLE(Event ev);

@ -115,6 +115,7 @@ void System::death(GameLevel &level) {
world.query<Position, Combat>([&](const auto &ent, auto &position, auto &combat) {
// bring out yer dead
if(combat.hp <= 0 && !combat.dead) {
fmt::println("DIE! entity {} died", ent);
combat.dead = true;
// take them out of collision map
collider.remove(position.location);

@ -235,7 +235,10 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config
int rand_entity = Random::uniform<int>(0, keys.size() - 1);
std::string key = keys[rand_entity];
// BUG: this may crash if PLAYER_TILE isn't first
if(key == "PLAYER_TITLE") key = keys[rand_entity + 1];
if(key == "PLAYER_TITLE") {
key = keys[rand_entity + 1];
fmt::println("SKIPPING PLAYER and using {} instead", key);
}
auto entity_data = entity_db[key];
// pass that to the config as it'll be a generic json

Loading…
Cancel
Save