Shmup/src/background.cpp

97 lines
2.1 KiB
C++

#include "config.h"
#include "background.h"
#include <azur/azur.h>
#include <azur/gint/render.h>
#include <cstdint>
#include <stdlib.h>
extern struct Map map_Level2;
Background::Background( )
{
}
Background::~Background( )
{
}
void Background::Render( void )
{
int x0 = (int) xlevel;
int xshifttile = (int) (16*xlevel.frac());
int y0 = (int) ylevel;
int yshifttile = (int) (16*ylevel.frac());
for(int u=0; u<map_Level2.nblayers;u++)
for(int i=0; i<=25; i++)
{
for(int j=0; j<=14; j++)
{
uint16_t index = (j+y0) * map_Level2.w + (x0+i) % map_Level2.w;
uint16_t currentTile = map_Level2.layers[u][ index ];
if (currentTile!=0)
{
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 );
}
}
}
/* int x0 = (int) xlevel;
int shifttile = (int) (16*xlevel.frac());
uint16_t tilemap[25*14]={0};
for(int u=0; u<map_Level2.nblayers;u++)
{
for(int j=0; j<14; j++)
{
for(int i=0; i<=25; i++)
{
uint16_t index = j * map_Level2.w + (x0+i) % map_Level2.w;
tilemap[25*j+i]= cmap_Level2.layers[u][ index ];
}
}
azrp_tilesmap( shifttile, tilemap, map_Level2.tileset, map_Level2.tileset_size);
}
*/
}
void Background::Update( float dt )
{
libnum::num a = libnum::num( dt / 90000.0f); //18000.0f );
xlevel += a;
}
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;
}