Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs #82

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extern/EwECS
Submodule EwECS updated 1 files
+9 −3 src/World.cpp
1 change: 1 addition & 0 deletions src/client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ int main(int ac, char **av)
world.runSystems();
eventManager->keepEventsAndClear<RType::ClientGameEvent>();
world.calcDeltaTime();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
GlassAlo marked this conversation as resolved.
Show resolved Hide resolved
}

// Quit server properly
Expand Down
1 change: 1 addition & 0 deletions src/client/systems/bot/System+TriggerBotDeath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace ECS {
} else if (!isAlive.isAlive && isAlive.timeToDie == 0) {
sprite.path = EXPLOSION_ASSET;
sprite.texture = nullptr;
type.isBot = true;
type.isPlayer = false;
for (size_t i = 0; i < sprite.rect.size(); i++) {
sprite.rect[i].height = EXPLOSION_TEX_HEIGHT;
Expand Down
1 change: 1 addition & 0 deletions src/client/systems/player/System+MovePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace ECS {
auto &pos = aPos[i].value();
auto &speed = aSpeed[i].value().speed;
RType::Client::MovePayload payload {0, 0};

for (auto &event : keyboardEvent) {
if (keyMap.find(event._keyId) == keyMap.end() || !aIsAlive[i].has_value() || !aPos[i].has_value()
|| !aSpeed[i].has_value() || !aIsAlive[i].value().isAlive) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/systems/player/System+TriggerPlayerShoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ECS {
continue;
}
for (auto &event : keyboardEvent) {
if (event._keyId == Event::KeyIdentifier::SPACE) {
if (event._keyId == Event::KeyIdentifier::SPACE && event._state == Event::KeyState::PRESSED) {
int playerOnlineId = aType[i].value().onlineId.value_or(-1);

if (playerOnlineId == -1) {
Expand Down
3 changes: 2 additions & 1 deletion src/rtype/Values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const constexpr float ENEMY_SPEED = 200;
const constexpr int ENEMY_TEX_WIDTH = 33;
const constexpr int ENEMY_TEX_HEIGHT = 33;
static const std::string ENEMY_ASSET = "assets/sprites/r-typesheet5.png";
const constexpr int PROBABILTY_SHOOT_ENEMY = 200000;
const constexpr int PROBABILTY_SHOOT_ENEMY = 100;
const constexpr int ENEMY_SPAWN_INTERVAL = 5; // in seconds

//------------------ BACKGROUND ------------------//
Expand All @@ -33,6 +33,7 @@ const constexpr float PLAYER_SPEED = 10;
const constexpr int PLAYER_TEX_WIDTH = 33;
const constexpr int PLAYER_TEX_HEIGHT = 17;
const constexpr int MAX_NUMBER_PLAYER = 4;
const constexpr float DELTA = 5.F;

//------------------ BULLET (for players) ------------------//
static const std::string BULLET_ASSET = "assets/sprites/r-typesheet2.png";
Expand Down
2 changes: 2 additions & 0 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <thread>
#include "Components.hpp"
#include "EwECS/Asset/AssetManager.hpp"
#include "EwECS/Event/EventManager.hpp"
Expand Down Expand Up @@ -97,6 +98,7 @@ int main(int ac, char **av)
world.runSystems();
eventManager->keepEventsAndClear<RType::ServerGameEvent>();
world.calcDeltaTime();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}

ECS::Network::ServerHandler::getInstance().stop();
Expand Down
7 changes: 3 additions & 4 deletions src/server/systems/player/System+MovePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace ECS {
{
ECS::Event::EventManager *eventManager = ECS::Event::EventManager::getInstance();
ECS::Network::ServerHandler &server = ECS::Network::ServerHandler::getInstance();
Core::World &world = Core::World::getInstance();
auto &events = eventManager->getEventsByType<RType::ServerGameEvent>();
const auto size = events.size();
std::vector<size_t> toRemove;
Expand Down Expand Up @@ -60,10 +59,10 @@ namespace ECS {
float speed = aSpeed[entityId].value().speed;
auto &pos = aPos[entityId].value();

auto deltaTime = world.getDeltaTime() * 10000;
auto delta = DELTA;

pos.x += payload.moveX * speed * deltaTime;
pos.y -= payload.moveY * speed * deltaTime;
pos.x += payload.moveX * speed / delta;
pos.y -= payload.moveY * speed / delta;

if (pos.x < 0) {
pos.x = 0;
Expand Down
Loading