2023-08-14 14:22:53 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2023-01-26 22:35:33 +01:00
|
|
|
#include "background.h"
|
|
|
|
#include <azur/azur.h>
|
|
|
|
#include <azur/gint/render.h>
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-31 23:07:32 +01:00
|
|
|
extern struct Map map_Level2;
|
2023-01-26 22:35:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
Background::Background( )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Background::~Background( )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Background::Render( void )
|
|
|
|
{
|
2023-01-31 23:07:32 +01:00
|
|
|
int x0 = (int) xlevel;
|
|
|
|
int xshifttile = (int) (16*xlevel.frac());
|
|
|
|
int y0 = (int) ylevel;
|
|
|
|
int yshifttile = (int) (16*ylevel.frac());
|
2023-01-26 22:35:33 +01:00
|
|
|
|
2023-01-31 23:07:32 +01:00
|
|
|
for(int u=0; u<map_Level2.nblayers;u++)
|
2023-01-29 19:55:11 +01:00
|
|
|
for(int i=0; i<=25; i++)
|
2023-01-26 22:35:33 +01:00
|
|
|
{
|
2023-01-31 23:07:32 +01:00
|
|
|
for(int j=0; j<=14; j++)
|
2023-01-26 22:35:33 +01:00
|
|
|
{
|
2023-01-31 23:07:32 +01:00
|
|
|
uint16_t index = (j+y0) * map_Level2.w + (x0+i) % map_Level2.w;
|
|
|
|
uint16_t currentTile = map_Level2.layers[u][ index ];
|
2023-01-29 19:55:11 +01:00
|
|
|
if (currentTile!=0)
|
|
|
|
{
|
2023-01-31 23:07:32 +01:00
|
|
|
uint16_t xtile = ((currentTile % map_Level2.tileset_size)-1) * 16;
|
|
|
|
uint16_t ytile = (currentTile / map_Level2.tileset_size) * 16;
|
|
|
|
azrp_subimage_p8( i*16-xshifttile, j*16-yshifttile, map_Level2.tileset, xtile, ytile, 16, 16, DIMAGE_NONE );
|
2023-01-29 19:55:11 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-26 22:35:33 +01:00
|
|
|
}
|
|
|
|
|
2023-01-31 23:07:32 +01:00
|
|
|
|
|
|
|
/* int x0 = (int) xlevel;
|
2023-01-30 22:31:33 +01:00
|
|
|
int shifttile = (int) (16*xlevel.frac());
|
2023-01-26 22:35:33 +01:00
|
|
|
|
2023-01-30 22:31:33 +01:00
|
|
|
uint16_t tilemap[25*14]={0};
|
|
|
|
|
2023-01-31 23:07:32 +01:00
|
|
|
for(int u=0; u<map_Level2.nblayers;u++)
|
2023-01-30 22:31:33 +01:00
|
|
|
{
|
|
|
|
for(int j=0; j<14; j++)
|
|
|
|
{
|
|
|
|
for(int i=0; i<=25; i++)
|
|
|
|
{
|
2023-01-31 23:07:32 +01:00
|
|
|
uint16_t index = j * map_Level2.w + (x0+i) % map_Level2.w;
|
|
|
|
tilemap[25*j+i]= cmap_Level2.layers[u][ index ];
|
2023-01-30 22:31:33 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-31 23:07:32 +01:00
|
|
|
azrp_tilesmap( shifttile, tilemap, map_Level2.tileset, map_Level2.tileset_size);
|
2023-01-30 22:31:33 +01:00
|
|
|
}
|
2023-01-31 23:07:32 +01:00
|
|
|
*/
|
2023-01-26 22:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Background::Update( float dt )
|
|
|
|
{
|
2023-01-29 19:55:11 +01:00
|
|
|
libnum::num a = libnum::num( dt / 90000.0f); //18000.0f );
|
2023-01-27 22:52:13 +01:00
|
|
|
xlevel += a;
|
2023-01-31 23:07:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Background::IncXCoordinate( libnum::num x )
|
|
|
|
{
|
|
|
|
xlevel += x ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Background::IncYCoordinate( libnum::num y )
|
|
|
|
{
|
|
|
|
ylevel += y ;
|
|
|
|
if (ylevel<0) ylevel=libnum::num(0);
|
|
|
|
if (ylevel>map_Level2.h-14) ylevel=libnum::num(map_Level2.h-14);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Background::GetXCoordinate( void )
|
|
|
|
{
|
|
|
|
return (int) xlevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Background::GetYCoordinate( void )
|
|
|
|
{
|
|
|
|
return (int) ylevel;
|
2023-01-26 22:35:33 +01:00
|
|
|
}
|