#include "parameters.h" #include "player.h" #include #include #include "level.h" #include "utilities.h" #include /* 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 #define MAXRUNSPEED 10.0f Player::Player( int16_t _x, int16_t _y ) { this->currx = libnum::num(_x); // initial position this->curry = libnum::num(_y); this->vx = libnum::num(0.0f); // initial velocity this->vy = libnum::num(0.0f); 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); this->tileX = (int) this->currx / 16; this->tileY = (int) this->curry / 16; last_tick = rtc_ticks(); } Player::~Player() { } void Player::Update( float dt ) { libnum::num DeltaTime = libnum::num( dt / 100.0f ) ; this->vy += this->ay * DeltaTime; this->vx += this->ax * DeltaTime; if (this->vx >= MAXRUNSPEED) this->vx = MAXRUNSPEED; if (this->vy >= MAXFALLSPEED) this->vy = MAXFALLSPEED; this->nextx = this->currx + this->vx * DeltaTime; this->nexty = this->curry + this->vy * DeltaTime; this->currx = this->nextx; this->curry = this->nexty; this->tileX = ((int) this->currx) / 16; this->tileY = ((int) this->curry) / 16; MyLevel.UpdateBorders( ); } 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); } void Player::Left( float dt ) { this->vx += LEFT; } void Player::Right( float dt ) { this->vx += RIGHT; } void Player::Up( float dt ) { this->vy += TOP; } void Player::Down( float dt ) { this->vy += BOTTOM; } void Player::Jump( float dt ) { this->vy -= SPEEDJUMP; } void Player::Nothing( float dt ) { this->vx *= libnum::num(0.95); this->vy *= libnum::num(0.95); }