From 7789e0a9cc10b2a09be67ea014defd5acd34772c Mon Sep 17 00:00:00 2001 From: Bor Brudar Date: Tue, 21 Sep 2021 23:07:28 +0200 Subject: [PATCH] mario fixed kinda --- res/mario/{hill.PNG => hill.png} | Bin src/include/Enemy.h | 4 ++-- src/include/Mario.h | 6 +++--- src/src/Enemy.cpp | 6 +++--- src/src/Mario.cpp | 8 ++++---- src/src/Super_Mario.cpp | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) rename res/mario/{hill.PNG => hill.png} (100%) diff --git a/res/mario/hill.PNG b/res/mario/hill.png similarity index 100% rename from res/mario/hill.PNG rename to res/mario/hill.png diff --git a/src/include/Enemy.h b/src/include/Enemy.h index d35e8ba..4b2b445 100644 --- a/src/include/Enemy.h +++ b/src/include/Enemy.h @@ -10,7 +10,7 @@ class Enemy { Enemy(Vector2f pos, Vector2f size,Vector2f tSize, Texture &t1, int type = 0); void setup(Vector2f pos, Vector2f size, Vector2f tSize, Texture &t1, int type = 0); void draw(RenderWindow& window); - bool update(std::vector etype, bool onScr = 0); + bool update(std::vector etype, bool onScr, float delta); void off(float offX); void boxUpdate(); @@ -27,7 +27,7 @@ class Enemy { float dtime = 0, dtimer = 0, ddelay = 0.7f; RectangleShape death; - float speed = 0.4f, gravity = 1.5f; + float speed = 100.f, gravity = 450.f; bool groundTouch = 0, deathSet = 0; float offX = 0.f; }; \ No newline at end of file diff --git a/src/include/Mario.h b/src/include/Mario.h index 68ce745..fd7819b 100644 --- a/src/include/Mario.h +++ b/src/include/Mario.h @@ -17,7 +17,7 @@ class Mario { Manimation box; std::vector mariobox; - float mariosp = 1.f, sprintsp = 1.6f; + float mariosp = 200.f, sprintsp = 1.6f; bool showHitbox = 0, big = 0, shiny = 0, canShoot = 0, prevDir = 1, alive = 1, op = 0, groundTouch = 0; private: //op clock @@ -25,7 +25,7 @@ class Mario { float opt = 0.f, optr = 0.f, opd = 3.5f; //physics Vector2f pos, prevPos; - float gravity = 2.2f, jump = gravity; + float gravity = 400.f, jump = gravity; bool jumping = 0, canLeft = 1, canRight = 1, checkBig = 0, checkShiny = 0; //shooting clock @@ -34,7 +34,7 @@ class Mario { //jumping clock Clock gclock, jdclock; - float gtime = 0.f, gtimer = 0.f, gdelay = 0.4f, minDelay = 0.25f; + float gtime = 0.f, gtimer = 0.f, gdelay = 0.3f, minDelay = 0.12f; float jdtime = 0.f, jdtimer = 0.f, jddelay = 0.2f; bool noDelay = 1; diff --git a/src/src/Enemy.cpp b/src/src/Enemy.cpp index d8173b3..0f0d47d 100644 --- a/src/src/Enemy.cpp +++ b/src/src/Enemy.cpp @@ -39,7 +39,7 @@ void Enemy::draw(RenderWindow& window) if(showHitbox) for (int i = 0; i < enemybox.size(); i++) window.draw(enemybox[i]); } -bool Enemy::update(std::vector etype, bool onScr) +bool Enemy::update(std::vector etype, bool onScr, float delta) { onScreen = onScr; @@ -49,11 +49,11 @@ bool Enemy::update(std::vector etype, bool onScr) if (etype[2] == 1) { speed = -speed; pos.x = prevPos.x; } else if (etype[3] == 1) { speed = -speed; pos.x = prevPos.x; }; //fall - if (!groundTouch) pos.y += gravity; + if (!groundTouch) pos.y += gravity * delta; //hybrid if (alive) { - if (onScreen) pos.x -= speed; + if (onScreen) pos.x -= speed * delta; dclock.restart(); } else if (type == 0) { diff --git a/src/src/Mario.cpp b/src/src/Mario.cpp index 98a0e52..16215b5 100644 --- a/src/src/Mario.cpp +++ b/src/src/Mario.cpp @@ -118,10 +118,10 @@ bool Mario::update(bool left, bool right, bool up, bool col, std::vector ty //left/right movement if (pos.x <= (scrWidth / 2) || left) { if (left && canLeft) { - if (sprint) pos.x -= mariosp * sprintsp; else pos.x -= mariosp; + pos.x -= mariosp * delta; } else if (right && canRight) { - if (sprint) pos.x += mariosp * sprintsp; else pos.x += mariosp; + pos.x += mariosp * delta; } } else if (right && canRight) ret = 1; @@ -129,7 +129,7 @@ bool Mario::update(bool left, bool right, bool up, bool col, std::vector ty if (pos.x < 0) pos.x = 0; //fall - if (!jumping && !groundTouch) pos.y += gravity; + if (!jumping && !groundTouch) pos.y += gravity * delta; //kill if falls if (pos.y + box.animation.getSize().y > scrHeight) alive = 0; @@ -166,7 +166,7 @@ bool Mario::update(bool left, bool right, bool up, bool col, std::vector ty jumping = 0; gtimer = 0; } - else pos.y -= jump; + else pos.y -= jump * delta; } else gclock.restart(); diff --git a/src/src/Super_Mario.cpp b/src/src/Super_Mario.cpp index 47cd45a..ae81087 100644 --- a/src/src/Super_Mario.cpp +++ b/src/src/Super_Mario.cpp @@ -291,7 +291,7 @@ void Super_Mario::update(Mouse& mouse, RenderWindow& window, state& gameState, E //is on screen if (enemies[j].anim.animation.getPosition().x < scrWidth) onsc = 1; //update - if (enemies[j].update(etype, onsc)) { + if (enemies[j].update(etype, onsc, delta)) { enemies.erase(enemies.begin() + j); break; } @@ -432,8 +432,8 @@ void Super_Mario::update(Mouse& mouse, RenderWindow& window, state& gameState, E } //offset everything if necessary - if (mario.update(left, right, up, col, type, sprint) == 1) { - if (sprint) offX -= mario.mariosp * mario.sprintsp; else offX -= mario.mariosp; + if (mario.update(left, right, up, col, type, delta, sprint) == 1) { + offX -= mario.mariosp * delta; //update world if (sprint) tx += mario.mariosp * mario.sprintsp; else tx += mario.mariosp;