spinny player

This commit is contained in:
kdx 2023-03-19 06:16:10 +00:00
parent 2dad06ba4c
commit 9a75800f10
3 changed files with 22 additions and 14 deletions

View File

@ -1,13 +1,14 @@
#include "entityimpl.h"
#include "rotrect.h"
IMPL_UPDATE() {
} IMPL_END
IMPL_DRAW() {
LZY_DrawSetColor(BLACK);
LZY_DrawRect(this->pos[0] - this->width / 2,
this->pos[1] - this->height / 2,
this->width, this->height);
rotrect(this->pos[0] - this->width / 2.0,
this->pos[1] - this->height / 2.0,
this->width, this->height, 0.2);
} IMPL_END
IMPL_INIT(exit) {

View File

@ -3,6 +3,7 @@
#include "entityimpl.h"
#include "game.h"
#include "input.h"
#include "rotrect.h"
#include <math.h>
IMPL_UPDATE() {
@ -16,24 +17,31 @@ IMPL_UPDATE() {
if (fabs(this->player.scale_x - 1.0) < 0.05) this->player.scale_x = 1.01;
if (fabs(this->player.scale_y - 1.0) < 0.05) this->player.scale_y = 1.01;
if (on_ground) {
this->player.rot_speed = 0.0;
this->player.angle = 0.0;
} else {
this->player.angle += this->player.rot_speed;
this->player.rot_speed *= 0.95;
}
if (on_ground && input_pressed(K_O)) {
const int diry = input_down(K_UP) - input_down(K_DOWN);
switch (diry) {
case -1:
this->vel[1] = -2.8;
this->player.scale_y = 1.40;
this->player.rot_speed = 0.3 * this->player.dirx;
break;
default:
case 0:
this->vel[1] = -3.8;
this->player.scale_y = 1.60;
this->player.rot_speed = 0.4 * this->player.dirx;
break;
case 1:
this->vel[1] = -4.8;
this->player.scale_y = 2.0;
this->player.rot_speed = 0.5 * this->player.dirx;
break;
}
this->player.scale_x = 1.0 / this->player.scale_y;
} else if (on_ground && input_down(K_X)) {
extern double tick;
this->vel[0] *= 3;
@ -66,13 +74,10 @@ IMPL_UPDATE() {
IMPL_DRAW() {
LZY_DrawSetColor(BLACK);
int width = (int)(this->width / 2 + 1) * this->player.scale_x;
int height = (int)(this->height / 2 + 1) * this->player.scale_y;
width *= 2;
height *= 2;
LZY_DrawRect(this->pos[0] - width / 2,
this->pos[1] - height / 2,
width, height);
const double width = this->width * this->player.scale_x + 2;
const double height = this->height * this->player.scale_y + 2;
rotrect(this->pos[0] - 1, this->pos[1] - 1,
width, height, this->player.angle);
} IMPL_END
IMPL_INIT(player) {

View File

@ -6,6 +6,8 @@
typedef struct {
double scale_x;
double scale_y;
double rot_speed;
double angle;
int dirx;
} Player;