bounce on walls

This commit is contained in:
kdx 2023-03-17 17:00:47 +01:00
parent 066760bd7a
commit 4d17f417eb
4 changed files with 8 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 68 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 500 B

After

Width:  |  Height:  |  Size: 68 B

View File

@ -5,13 +5,14 @@
#include "cfg.h"
#include "input.h"
#include <string.h>
#include <math.h>
static void
player_update(Entity *this, Game *g)
{
const int on_ground = entity_collide(this, g, 0, 1);
this->vel[0] = 2.0;
this->vel[0] = 2.0 * this->player.dirx;
this->vel[1] *= 0.99;
this->vel[1] += 0.2;
this->player.scale_x += 0.1 * (1.0 - this->player.scale_x);
@ -42,6 +43,8 @@ player_update(Entity *this, Game *g)
}
entity_move(this, g);
if (this->vel[0] == 0.0)
this->player.dirx *= -1;
}
static void
@ -74,4 +77,5 @@ player_init(Entity *this)
this->height = 12;
this->player.scale_x = 1.0;
this->player.scale_y = 1.0;
this->player.dirx = 1;
}

View File

@ -1,8 +1,9 @@
#pragma once
typedef struct {
float scale_x;
float scale_y;
double scale_x;
double scale_y;
int dirx;
} Player;
struct Entity;