NppClone/src/player.cpp

124 lines
2.9 KiB
C++

#include "parameters.h"
#include "player.h"
#include <num/num.h>
#include <gint/rtc.h>
#include "level.h"
#include "utilities.h"
/*
extern bopti_image_t img_walking;
extern bopti_image_t img_running;
extern bopti_image_t img_static;
*/
extern bopti_image_t img_circle;
static uint32_t framecounter = 0;
extern Level MyLevel;
#define SPEEDRUN 9.0f
#define SPEEDJUMP 9.0f
#define MAXFALLSPEED 15.0f
Player::Player( int16_t _x, int16_t _y )
{
this->currx = _x; // initial position
this->curry = _y;
this->vx = 0.0f; // initial velocity
this->vy = 0.0f;
this->ax = 0.0f; // initial acceleration (ie. gravity chosen at 1 unit - be careful of the sign, y axis oriented to the bottom )
this->ay = 1.0f;
this->width = 8;
this->height = 8;
last_tick = rtc_ticks();
this->action = STATIC;
this->direction = STATIC;
}
Player::~Player()
{
}
void Player::Update( float dt )
{
float DeltaTime = dt / 100.0f ;
this->vy += this->ay * DeltaTime;
if (this->vy >= MAXFALLSPEED) this->vy = MAXFALLSPEED;
// we were jumping and are reaching the top of the curve or even starting falling
if (this->action == JUMP && this->vy >= 0)
{
this->action = FALL;
}
this->nextx = this->currx + this->vx * DeltaTime;
this->nexty = this->curry + this->vy * DeltaTime;
}
void Player::Render( void )
{
uint32_t temptick = rtc_ticks();
if (temptick-last_tick>=10)
{
last_tick = temptick;
framecounter++;
}
azrp_image_p8_effect((int) (this->currx*16.0f), (int) (this->curry*16.0f), &img_circle, DIMAGE_NONE);
#if(DEBUG_MODE)
if (this->action==STATIC) Azur_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "S" );
else if (this->action==DRAFT) Azur_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "D" );
else if (this->action==WALK) Azur_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "W" );
else if (this->action==RUN) Azur_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "R" );
else if (this->action==JUMP) Azur_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "J" );
else if (this->action==FALL) Azur_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "F" );
else Azur_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "X" );
#endif
}
void Player::Left( float dt )
{
this->vx += LEFT;
this->direction = LEFT;
this->action = RUN;
}
void Player::Right( float dt )
{
this->vx += RIGHT;
this->direction = RIGHT;
this->action = RUN;
}
void Player::Jump( float dt )
{
this->vy -= SPEEDJUMP;
this->action = JUMP;
}
void Player::Nothing( float dt )
{
this->vx *= 0.98;
}