2023-05-07 22:05:25 +02:00
|
|
|
|
|
|
|
#include "parameters.h"
|
|
|
|
|
2023-04-21 20:27:02 +02:00
|
|
|
#include "player.h"
|
|
|
|
#include <num/num.h>
|
|
|
|
#include <gint/rtc.h>
|
2023-04-22 12:50:03 +02:00
|
|
|
#include "level.h"
|
2023-04-22 22:01:03 +02:00
|
|
|
#include "utilities.h"
|
2023-04-21 20:27:02 +02:00
|
|
|
|
2023-05-16 16:11:39 +02:00
|
|
|
#include <num/num.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-21 20:27:02 +02:00
|
|
|
/*
|
|
|
|
extern bopti_image_t img_walking;
|
|
|
|
extern bopti_image_t img_running;
|
|
|
|
extern bopti_image_t img_static;
|
|
|
|
*/
|
|
|
|
|
2023-04-22 12:50:03 +02:00
|
|
|
extern bopti_image_t img_circle;
|
2023-04-21 20:27:02 +02:00
|
|
|
static uint32_t framecounter = 0;
|
2023-04-22 12:50:03 +02:00
|
|
|
extern Level MyLevel;
|
|
|
|
|
|
|
|
|
2023-05-03 22:50:46 +02:00
|
|
|
#define SPEEDRUN 9.0f
|
|
|
|
#define SPEEDJUMP 9.0f
|
2023-04-22 22:01:03 +02:00
|
|
|
#define MAXFALLSPEED 15.0f
|
2023-05-16 16:11:39 +02:00
|
|
|
#define MAXRUNSPEED 10.0f
|
2023-04-21 20:27:02 +02:00
|
|
|
|
|
|
|
Player::Player( int16_t _x, int16_t _y )
|
|
|
|
{
|
2023-05-16 16:11:39 +02:00
|
|
|
this->currx = libnum::num(_x); // initial position
|
|
|
|
this->curry = libnum::num(_y);
|
2023-04-21 20:27:02 +02:00
|
|
|
|
2023-05-16 16:11:39 +02:00
|
|
|
this->vx = libnum::num(0.0f); // initial velocity
|
|
|
|
this->vy = libnum::num(0.0f);
|
2023-04-21 20:27:02 +02:00
|
|
|
|
2023-05-16 16:11:39 +02:00
|
|
|
this->ax = libnum::num(0.0f); // initial acceleration (ie. gravity chosen at 1 unit - be careful of the sign, y axis oriented to the bottom )
|
|
|
|
this->ay = libnum::num(0.0f);
|
2023-04-22 12:50:03 +02:00
|
|
|
|
2023-05-16 16:11:39 +02:00
|
|
|
this->tileX = (int) this->currx / 16;
|
|
|
|
this->tileY = (int) this->curry / 16;
|
2023-04-22 12:50:03 +02:00
|
|
|
|
2023-04-21 20:27:02 +02:00
|
|
|
last_tick = rtc_ticks();
|
|
|
|
}
|
|
|
|
|
2023-04-22 22:01:03 +02:00
|
|
|
|
2023-04-21 20:27:02 +02:00
|
|
|
Player::~Player()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-04-22 12:50:03 +02:00
|
|
|
|
|
|
|
void Player::Update( float dt )
|
2023-04-21 20:27:02 +02:00
|
|
|
{
|
2023-05-16 16:11:39 +02:00
|
|
|
libnum::num DeltaTime = libnum::num( dt / 100.0f ) ;
|
2023-05-03 22:50:46 +02:00
|
|
|
|
2023-04-22 12:50:03 +02:00
|
|
|
this->vy += this->ay * DeltaTime;
|
2023-05-16 16:11:39 +02:00
|
|
|
this->vx += this->ax * DeltaTime;
|
|
|
|
if (this->vx >= MAXRUNSPEED) this->vx = MAXRUNSPEED;
|
2023-04-22 12:50:03 +02:00
|
|
|
if (this->vy >= MAXFALLSPEED) this->vy = MAXFALLSPEED;
|
|
|
|
|
2023-05-03 22:50:46 +02:00
|
|
|
this->nextx = this->currx + this->vx * DeltaTime;
|
|
|
|
this->nexty = this->curry + this->vy * DeltaTime;
|
2023-04-21 20:27:02 +02:00
|
|
|
|
2023-05-16 16:11:39 +02:00
|
|
|
this->currx = this->nextx;
|
|
|
|
this->curry = this->nexty;
|
|
|
|
|
|
|
|
this->tileX = ((int) this->currx) / 16;
|
|
|
|
this->tileY = ((int) this->curry) / 16;
|
|
|
|
|
|
|
|
MyLevel.UpdateBorders( );
|
2023-04-21 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2023-04-22 22:01:03 +02:00
|
|
|
|
2023-04-21 20:27:02 +02:00
|
|
|
void Player::Render( void )
|
|
|
|
{
|
|
|
|
uint32_t temptick = rtc_ticks();
|
|
|
|
if (temptick-last_tick>=10)
|
|
|
|
{
|
|
|
|
last_tick = temptick;
|
|
|
|
framecounter++;
|
|
|
|
}
|
|
|
|
|
2023-05-03 22:50:46 +02:00
|
|
|
azrp_image_p8_effect((int) (this->currx*16.0f), (int) (this->curry*16.0f), &img_circle, DIMAGE_NONE);
|
2023-04-21 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2023-04-22 22:01:03 +02:00
|
|
|
|
2023-05-03 22:50:46 +02:00
|
|
|
void Player::Left( float dt )
|
|
|
|
{
|
|
|
|
this->vx += LEFT;
|
2023-04-21 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2023-04-22 22:01:03 +02:00
|
|
|
|
2023-05-03 22:50:46 +02:00
|
|
|
void Player::Right( float dt )
|
2023-04-21 20:27:02 +02:00
|
|
|
{
|
2023-05-03 22:50:46 +02:00
|
|
|
this->vx += RIGHT;
|
2023-05-16 16:11:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Up( float dt )
|
|
|
|
{
|
|
|
|
this->vy += TOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Player::Down( float dt )
|
|
|
|
{
|
|
|
|
this->vy += BOTTOM;
|
2023-04-21 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2023-04-22 22:01:03 +02:00
|
|
|
|
2023-04-21 20:27:02 +02:00
|
|
|
void Player::Jump( float dt )
|
|
|
|
{
|
2023-05-03 22:50:46 +02:00
|
|
|
this->vy -= SPEEDJUMP;
|
2023-04-21 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2023-04-22 22:01:03 +02:00
|
|
|
|
2023-05-03 22:50:46 +02:00
|
|
|
void Player::Nothing( float dt )
|
2023-04-21 20:27:02 +02:00
|
|
|
{
|
2023-05-16 16:11:39 +02:00
|
|
|
this->vx *= libnum::num(0.95);
|
|
|
|
this->vy *= libnum::num(0.95);
|
2023-04-21 20:27:02 +02:00
|
|
|
}
|
2023-05-16 16:11:39 +02:00
|
|
|
|