Skip to content

Commit 1c2d2a7

Browse files
committed
updating player movement
1 parent 143ef0b commit 1c2d2a7

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

orBit Project/Motor2D/j1Player.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,8 @@ bool j1Player::Update(float dt)
122122
first_move = true;
123123
}
124124

125-
float auxpos = position.x;
126-
127-
position.x -= playerinfo.initialVx*dt;
128-
129-
if (-(position.x - auxpos) > dt/10.0f )
130-
{
131-
if (entitystate != JUMPING && entitystate != FALLING && !must_fall)
132-
position.x += 0.49f;
133-
}
134-
125+
position.x = (position.x - playerinfo.initialVx*dt);
126+
135127
going_left = true;
136128
going_right = false;
137129
CurrentAnimation = playerinfo.runLeft;
@@ -146,18 +138,8 @@ bool j1Player::Update(float dt)
146138
first_move = true;
147139
}
148140

149-
float auxpos = position.x;
150-
151-
/*Velocity.x = playerinfo.initialVx;
152-
position.x = position.x + ceil((Velocity.x)*dt);*/
153-
154-
position.x += ceilf(playerinfo.initialVx*dt);
155-
156-
if ((position.x - auxpos) > (dt * 200.0f))
157-
{
158-
position.x -= 0.9f;
159-
}
160-
141+
position.x = (position.x + playerinfo.initialVx*dt);
142+
161143
going_right = true;
162144
going_left = false;
163145
CurrentAnimation = playerinfo.runRight;
@@ -366,13 +348,13 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
366348

367349
if (c1->rect.x + c1->rect.w >= c2->rect.x && c1->rect.x + c1->rect.w <= c2->rect.x + 2)
368350
{
369-
Velocity.x = 0.0f;
351+
//Velocity.x = 0.0f;
370352
c1->rect.x = c2->rect.x - c1->rect.w - colliding_offset;
371353
}
372354

373355
if (c1->rect.x >= c2->rect.x + c2->rect.w - 2 && c1->rect.x <= c2->rect.x + c2->rect.w)
374356
{
375-
Velocity.x = 0.0f;
357+
//Velocity.x = 0.0f;
376358
c1->rect.x = c2->rect.x + c2->rect.w + colliding_offset;
377359
}
378360

@@ -401,7 +383,7 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
401383
{
402384
c1->rect.y = c2->rect.y - c1->rect.h;
403385
}
404-
Velocity.y = 0.0f;
386+
//Velocity.y = 0.0f;
405387
entitystate = IDLE;
406388
colliding_floor = true;
407389
double_jump = true;
@@ -430,7 +412,7 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
430412

431413
if (c1->rect.x + c1->rect.w >= c2->rect.x && c1->rect.x + c1->rect.w <= c2->rect.x + 4)
432414
{
433-
Velocity.x = 0.0f;
415+
//Velocity.x = 0.0f;
434416
if (entitystate != JUMPING)
435417
c1->rect.y = aux;
436418
c1->rect.x = c2->rect.x - c1->rect.w - colliding_offset;
@@ -459,7 +441,7 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
459441

460442
if (c1->rect.x >= c2->rect.x + c2->rect.w - 4 && c1->rect.x <= c2->rect.x + c2->rect.w)
461443
{
462-
Velocity.x = 0.0f;
444+
//Velocity.x = 0.0f;
463445
if (entitystate != JUMPING)
464446
c1->rect.y = aux;
465447
c1->rect.x = c2->rect.x + c2->rect.w + colliding_offset;
@@ -486,7 +468,7 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
486468

487469
else if (c2->type == COLLIDER_SPIKES || c2->type == COLLIDER_ENEMY_SLIME || c2->type == COLLIDER_ENEMY_BAT)
488470
{
489-
Velocity.x = 0.0f;
471+
//Velocity.x = 0.0f;
490472

491473
must_fall = false;
492474
double_jump = false;
@@ -522,13 +504,13 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
522504

523505
if (c1->rect.x + c1->rect.w >= c2->rect.x && c1->rect.x + c1->rect.w <= c2->rect.x + 4)
524506
{
525-
Velocity.x = 0.0f;
507+
//Velocity.x = 0.0f;
526508
c1->rect.x = c2->rect.x - c1->rect.w - colliding_offset;
527509
}
528510

529511
if (c1->rect.x >= c2->rect.x + c2->rect.w - 4 && c1->rect.x <= c2->rect.x + c2->rect.w)
530512
{
531-
Velocity.x = 0.0f;
513+
//Velocity.x = 0.0f;
532514
c1->rect.x = c2->rect.x + c2->rect.w + colliding_offset;
533515
}
534516

@@ -537,7 +519,7 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
537519

538520
if (entitystate != JUMPING)
539521
{
540-
Velocity.y = 0.0f;
522+
//Velocity.y = 0.0f;
541523
entitystate = IDLE;
542524

543525
}
@@ -556,7 +538,7 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
556538

557539
if (entitystate != JUMPING)
558540
{
559-
Velocity.y = 0.0f;
541+
//Velocity.y = 0.0f;
560542
entitystate = IDLE;
561543
colliding_floor = true;
562544
}
@@ -576,7 +558,7 @@ void j1Player::OnCollision(Collider * c1, Collider * c2)
576558
if (c1->rect.y <= c2->rect.y + c2->rect.h && c1->rect.y >= c2->rect.y + c2->rect.h - 6)
577559
{
578560
c1->rect.y = c2->rect.y + c2->rect.h + colliding_offset;
579-
Velocity.y = 0.0f;
561+
//Velocity.y = 0.0f;
580562
entitystate = FALLING;
581563
double_jump = false;
582564
must_fall = true;

0 commit comments

Comments
 (0)