Shmup/src/shmup/background.cpp

104 lines
2.3 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_Level1;
extern struct Map map_Level2;
Map *map_Level;
Background::Background( )
{
map_Level = &map_Level1;
speed = libnum::num(1.0);
}
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_Level->nblayers;u++)
for(int i=0; i<=25; i++)
{
for(int j=0; j<=14; j++)
{
uint16_t index = (j+y0) * map_Level->w + (x0+i) % map_Level->w;
uint16_t currentTile = map_Level->layers[u][ index ];
if (currentTile!=0)
{
uint16_t xtile = ((currentTile % map_Level->tileset_size)-1) * 16;
uint16_t ytile = (currentTile / map_Level->tileset_size) * 16;
azrp_subimage_p8( i*16-xshifttile, j*16-yshifttile, map_Level->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_Level->nblayers;u++)
{
for(int j=0; j<14; j++)
{
for(int i=0; i<=25; i++)
{
uint16_t index = j * map_Level->w + (x0+i) % map_Level->w;
tilemap[25*j+i]= cmap_Level->layers[u][ index ];
}
}
azrp_tilesmap( shifttile, tilemap, map_Level->tileset, map_Level->tileset_size);
}
*/
}
void Background::Update( float dt )
{
libnum::num a = libnum::num( dt / 90000.0f); //18000.0f );
xlevel += speed*a;
}
void Background::SetSpeed(libnum::num s)
{
speed = s;
}
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_Level->h-14) ylevel=libnum::num(map_Level->h-14);
}
int Background::GetXCoordinate( void )
{
return (int) xlevel;
}
int Background::GetYCoordinate( void )
{
return (int) ylevel;
}