Skip to content

Commit

Permalink
mario fixed kinda
Browse files Browse the repository at this point in the history
  • Loading branch information
borbrudar committed Sep 21, 2021
1 parent e94f40f commit 7789e0a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
File renamed without changes
4 changes: 2 additions & 2 deletions src/include/Enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> etype, bool onScr = 0);
bool update(std::vector<int> etype, bool onScr, float delta);
void off(float offX);
void boxUpdate();

Expand All @@ -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;
};
6 changes: 3 additions & 3 deletions src/include/Mario.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class Mario {

Manimation box;
std::vector<RectangleShape> 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
Clock opc;
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
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/src/Enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> etype, bool onScr)
bool Enemy::update(std::vector<int> etype, bool onScr, float delta)
{
onScreen = onScr;

Expand All @@ -49,11 +49,11 @@ bool Enemy::update(std::vector<int> 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) {
Expand Down
8 changes: 4 additions & 4 deletions src/src/Mario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ bool Mario::update(bool left, bool right, bool up, bool col, std::vector<int> 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;

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;
Expand Down Expand Up @@ -166,7 +166,7 @@ bool Mario::update(bool left, bool right, bool up, bool col, std::vector<int> ty
jumping = 0;
gtimer = 0;
}
else pos.y -= jump;
else pos.y -= jump * delta;

}
else gclock.restart();
Expand Down
6 changes: 3 additions & 3 deletions src/src/Super_Mario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7789e0a

Please sign in to comment.