2023-03-19 01:37:14 +01:00
|
|
|
#include "entity.h"
|
2023-03-18 21:54:01 +01:00
|
|
|
#include "entityimpl.h"
|
2023-03-18 23:40:10 +01:00
|
|
|
#include "game.h"
|
2023-03-17 16:38:10 +01:00
|
|
|
#include "input.h"
|
2023-03-19 07:16:10 +01:00
|
|
|
#include "rotrect.h"
|
2023-03-17 17:00:47 +01:00
|
|
|
#include <math.h>
|
2023-03-17 10:51:17 +01:00
|
|
|
|
2023-03-26 09:26:47 +02:00
|
|
|
IMPL_INIT(player) {
|
|
|
|
this->width = 10;
|
|
|
|
this->height = 10;
|
|
|
|
this->player.scale_x = 1.0;
|
|
|
|
this->player.scale_y = 1.0;
|
|
|
|
this->player.dirx = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL(draw) {
|
|
|
|
LZY_DrawSetColor(BLACK);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-03-26 09:11:55 +02:00
|
|
|
IMPL(update) {
|
2023-03-17 16:38:10 +01:00
|
|
|
const int on_ground = entity_collide(this, g, 0, 1);
|
|
|
|
|
2023-03-17 17:00:47 +01:00
|
|
|
this->vel[0] = 2.0 * this->player.dirx;
|
2023-03-18 23:40:10 +01:00
|
|
|
this->vel[1] *= AIR_RESISTANCE;
|
|
|
|
this->vel[1] += GRAVITY;
|
2023-03-17 16:54:07 +01:00
|
|
|
this->player.scale_x += 0.1 * (1.0 - this->player.scale_x);
|
|
|
|
this->player.scale_y += 0.1 * (1.0 - this->player.scale_y);
|
|
|
|
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;
|
2023-03-17 16:38:10 +01:00
|
|
|
|
2023-03-20 18:58:42 +01:00
|
|
|
if (this->vel[1] >= 0.0 && on_ground) {
|
2023-03-19 07:16:10 +01:00
|
|
|
this->player.rot_speed = 0.0;
|
|
|
|
this->player.angle = 0.0;
|
2023-03-20 18:58:42 +01:00
|
|
|
} else {
|
2023-03-19 07:16:10 +01:00
|
|
|
this->player.angle += this->player.rot_speed;
|
|
|
|
this->player.rot_speed *= 0.95;
|
|
|
|
}
|
|
|
|
|
2023-03-17 16:38:10 +01:00
|
|
|
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;
|
2023-03-19 07:16:10 +01:00
|
|
|
this->player.rot_speed = 0.3 * this->player.dirx;
|
2023-03-17 16:38:10 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
this->vel[1] = -3.8;
|
2023-03-19 07:16:10 +01:00
|
|
|
this->player.rot_speed = 0.4 * this->player.dirx;
|
2023-03-17 16:38:10 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
this->vel[1] = -4.8;
|
2023-03-19 07:16:10 +01:00
|
|
|
this->player.rot_speed = 0.5 * this->player.dirx;
|
2023-03-17 16:38:10 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-09-24 12:15:34 +02:00
|
|
|
}/* else if (on_ground && input_down(K_X)) {
|
2023-03-19 06:01:50 +01:00
|
|
|
extern double tick;
|
2023-03-17 18:19:06 +01:00
|
|
|
this->vel[0] *= 3;
|
2023-03-19 06:01:50 +01:00
|
|
|
tick += 2.0;
|
2023-03-17 18:19:06 +01:00
|
|
|
this->player.scale_x *= 1.05;
|
2023-09-24 12:15:34 +02:00
|
|
|
}*/
|
2023-03-17 16:38:10 +01:00
|
|
|
|
2023-03-17 11:06:37 +01:00
|
|
|
entity_move(this, g);
|
2023-03-17 19:03:59 +01:00
|
|
|
if (this->vel[0] == 0.0 && this->vel[1] >= -0.0)
|
2023-03-17 17:00:47 +01:00
|
|
|
this->player.dirx *= -1;
|
2023-03-17 21:07:07 +01:00
|
|
|
|
2023-03-19 01:37:14 +01:00
|
|
|
if (this->bonk_ceiling ||
|
2023-03-23 16:16:22 +01:00
|
|
|
entity_place_meeting(this, g, entity_type("spike")) != NULL) {
|
2023-03-26 07:47:47 +02:00
|
|
|
const unsigned int deathpart = entity_type("deathpart");
|
2023-03-18 23:40:10 +01:00
|
|
|
int dy = this->pos[1] - 6;
|
|
|
|
for (int y = 0; y < 7; y++) {
|
|
|
|
int dx = this->pos[0] - 6;
|
|
|
|
for (int x = 0; x < 7; x++) {
|
2023-03-26 07:45:46 +02:00
|
|
|
entity_init(game_create_entity(g),
|
2023-03-26 07:47:47 +02:00
|
|
|
deathpart, dx, dy);
|
2023-03-18 23:40:10 +01:00
|
|
|
dx += 2;
|
|
|
|
}
|
|
|
|
dy += 2;
|
|
|
|
}
|
|
|
|
this->type = ET_NONE;
|
2023-03-19 05:52:04 +01:00
|
|
|
g->queue_restart_scene = 45;
|
2023-03-18 23:40:10 +01:00
|
|
|
}
|
2023-03-18 19:15:05 +01:00
|
|
|
|
2023-03-23 16:16:22 +01:00
|
|
|
if (entity_place_meeting(this, g, entity_type("exit")) != NULL)
|
2023-03-17 21:07:07 +01:00
|
|
|
g->queue_next_scene = true;
|
2023-03-26 09:11:55 +02:00
|
|
|
}
|