This commit is contained in:
Sylvain PILLOT 2023-05-11 22:37:22 +02:00
parent a5d6f818ab
commit 6a4d9d52a2
7 changed files with 22 additions and 279 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -110,8 +110,8 @@ void Level::Render( void )
else azrp_subimage_rgb16( i*16, j*16, map_level->tileset, xtile, ytile, 16, 16, DIMAGE_NONE | IMAGE_NOCLIP_INPUT );
#if(DEBUG_MODE)
if (textbacktile) Azur_draw_text( i*16, j*16, "%d", GetTileBackgroundINT( i, j ) );
if (textforetile) Azur_draw_text( i*16+8, j*16+8, "%d", GetTileForegroundINT( i, j ) );
if (textbacktile) azrp_draw_text( i*16, j*16, "%d", GetTileBackgroundINT( i, j ) );
if (textforetile) azrp_draw_text( i*16+8, j*16+8, "%d", GetTileForegroundINT( i, j ) );
#endif
}
}
@ -137,8 +137,8 @@ void Level::Render( void )
void Level::RenderSelected( uint8_t i, uint8_t j )
{
//azrp_image_p8( i*16, j*16, &img_selected, DIMAGE_NONE );
//Azur_draw_text( i*16+1, j*16+1, "B=%d", GetTileBackgroundINT( i, j ) );
//Azur_draw_text( i*16+1, j*16+1, "F=%d", GetTileForegroundINT( i, j ) );
//azrp_draw_text( i*16+1, j*16+1, "B=%d", GetTileBackgroundINT( i, j ) );
//azrp_draw_text( i*16+1, j*16+1, "F=%d", GetTileForegroundINT( i, j ) );
}

View File

@ -120,15 +120,15 @@ static void render( void )
// MyPlayer.Render();
#if(BIAS)
if (texttodraw>=1) Azur_draw_text(1,01, "FPS = %.0f", (float) (1000.0f / elapsedTime) );
if (texttodraw>=1) azrp_draw_text(1,01, "FPS = %.0f", (float) (1000.0f / elapsedTime) );
if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.3f ms", (float) time_update / 1000.0f );
if (texttodraw>=2) Azur_draw_text(1,41, "Render = %.3f ms", (float) time_render / 1000.0f );
if (texttodraw>=2) Azur_draw_text(1,51, ">Total = %.0f ms", (float) elapsedTime );
if (texttodraw>=2) azrp_draw_text(1,31, "Update = %.3f ms", (float) time_update / 1000.0f );
if (texttodraw>=2) azrp_draw_text(1,41, "Render = %.3f ms", (float) time_render / 1000.0f );
if (texttodraw>=2) azrp_draw_text(1,51, ">Total = %.0f ms", (float) elapsedTime );
if (texttodraw>=3) Azur_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory + extram_stats->used_memory);
if (texttodraw>=3) Azur_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory + extram_stats->free_memory);
if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory );
if (texttodraw>=3) azrp_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory + extram_stats->used_memory);
if (texttodraw>=3) azrp_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory + extram_stats->free_memory);
if (texttodraw>=3) azrp_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory );
#endif
}
@ -291,9 +291,9 @@ int main(void)
render();
Azur_draw_text(1,01, "FPS = %.0f", (float) (1000.0f / elapsedTime) );
azrp_draw_text(1,01, "FPS = %.0f", (float) (1000.0f / elapsedTime) );
//azrp_circle( 198, 112, 20, C_RED );
azrp_circle( 198, 112, 40, C_RED );
azrp_update();
}

View File

@ -1,257 +0,0 @@
#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 SPEEDWALK 6.0f
#define SPEEDRUN 12.0f
#define SPEEDSTATIC 0.0f
#define SPEEDJUMPWALK 4.0f
#define SPEEDJUMPRUN 12.0f
#define SPEEDJUMPSTATIC 8.0f
#define MAXFALLSPEED 20.0f
Player::Player( int16_t _x, int16_t _y )
{
this->x = _x;
this->y = _y;
this->vx = 0.0f;
this->vy = 0.0f;
this->ax = 0.0f;
this->ay = 1.0f;
this->width = 8;
this->height = 8;
this->xmin = (int) this->x - this->width;
this->xmax = (int) this->x + this->width;
this->ymin = (int) this->y - this->height;
this->ymax = (int) this->y + this->height;
last_tick = rtc_ticks();
}
Player::~Player()
{
}
void Player::Update( float dt )
{
float DeltaTime = dt / 100.0f ;
//this->vx += this->ax * DeltaTime; // horizontal acceleration not considered (yet)
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->x + this->vx * DeltaTime;
this->nexty = this->y + this->vy * DeltaTime;
bool testdestination = MyLevel.CanGo( this ); // true if we can go to the planed position
if (testdestination)
{
this->x = this->nextx;
this->y = this->nexty;
}
else if(this->action == JUMP)
{
this->vx = 0;
this->vy = 0;
this->action = FALL;
}
else
{
this->vx = 0;
this->vy = 0;
this->action = STATIC;
}
xmin = (int) x - width;
xmax = (int) x + width;
ymin = (int) y - height;
ymax = (int) y + height;
}
void Player::Render( void )
{
uint32_t temptick = rtc_ticks();
if (temptick-last_tick>=10)
{
last_tick = temptick;
framecounter++;
}
/*
if (action==RUN)
{
uint8_t frameinternal = framecounter % 8;
azrp_subimage_p8_effect(xmin, ymin, &img_running, frameinternal*16, 0, 16, 16, direction==RIGHT ? DIMAGE_NONE : IMAGE_HFLIP );
}
else if (action==WALK)
{
uint8_t frameinternal = framecounter % 7;
azrp_subimage_p8_effect(xmin, ymin, &img_walking, frameinternal*16, 0, 16, 16, direction==RIGHT ? DIMAGE_NONE : IMAGE_HFLIP );
}
else if (action==STATIC)
{
uint8_t frameinternal = framecounter % 8;
azrp_subimage_p8_effect(xmin, ymin, &img_static, frameinternal*16, 0, 16, 16, DIMAGE_NONE);
}
*/
azrp_image_p8_effect(xmin, ymin, &img_circle, DIMAGE_NONE);
}
/*
void Player::Walk_Left( float dt )
{
if ( this->action != JUMP && this->action != FALL )
{
this->vx -= 1.0f;
if ( this->vx <= SPEEDWALK*-1.0f )
this->vx = -1.0f*SPEEDWALK;
this->direction = LEFT;
this->action = WALK;
}
this->Update( dt );
}
void Player::Walk_Right( float dt )
{
if ( this->action != JUMP && this->action != FALL )
{
this->vx += 1.0f;
if ( this->vx >= SPEEDWALK )
this->vx = SPEEDWALK;
this->direction = RIGHT;
this->action = WALK;
}
this->Update( dt );
}
*/
void Player::Run_Left( float dt )
{
if ( this->action != JUMP && this->action != FALL )
{
this->vx -= 1.0f;
if ( this->vx <= -SPEEDRUN )
this->vx = -SPEEDRUN;
this->direction = LEFT;
this->action = RUN;
}
this->Update( dt );
}
void Player::Run_Right( float dt )
{
if ( this->action != JUMP && this->action != FALL )
{
this->vx += 1.0f;
if ( this->vx >= SPEEDRUN )
this->vx = SPEEDRUN;
this->direction = RIGHT;
this->action = RUN;
}
this->Update( dt );
}
void Player::Jump( float dt )
{
// check if we are already jumping or not
if (this->action != JUMP && this->action != FALL) // not in a jump or in a fall
{
/*
if ( this->action == WALK )
{
this->vy -= SPEEDJUMPWALK;
}
else
*/
if ( this->action == RUN )
{
this->vy -= SPEEDJUMPRUN;
}
else
{
this->vy -= SPEEDJUMPSTATIC;
}
}
else if ( this->action == FALL) // descending phase (FALL) of a jump, we can start a new small jump
{
this->vy -= SPEEDJUMPSTATIC;
}
else
{
}
this->action = JUMP;
this->Update( dt );
}
void Player::No_Order( float dt )
{
if (this->action == RUN || this->action == WALK)
{
this->action = BREAK;
this->vx *= 0.9;
if (ABS(this->vx) <= 0.2 )
{
this->vx = 0;
this->action = STATIC;
this->direction = STATIC;
}
}
this->Update( dt );
}

View File

@ -82,13 +82,13 @@ void Player::Render( void )
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" );
if (this->action==STATIC) azrp_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "S" );
else if (this->action==DRAFT) azrp_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "D" );
else if (this->action==WALK) azrp_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "W" );
else if (this->action==RUN) azrp_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "R" );
else if (this->action==JUMP) azrp_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "J" );
else if (this->action==FALL) azrp_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "F" );
else azrp_draw_text( (int) (this->currx*16.0f+4.0f), (int) (this->curry*16.0f+4.0f) , "X" );
#endif
}

View File

@ -7,7 +7,7 @@
#include <fxlibc/printf.h>
/* Render text with Azur images - quite bad, but I don't have time lol. */
void Azur_draw_text(int x, int y, char const *fmt, ...)
void azrp_draw_text(int x, int y, char const *fmt, ...)
{
char str[128];
va_list args;

View File

@ -1,7 +1,7 @@
#ifndef UTILITIES_H
#define UTILITIES_H
void Azur_draw_text(int x, int y, char const *fmt, ...);
void azrp_draw_text(int x, int y, char const *fmt, ...);
#define ABS(a) ( ( (a) >= 0 ) ? (a) : -(a) )