Move more stuff to general
This commit is contained in:
parent
0f4882f18e
commit
3457570fb6
2 changed files with 91 additions and 54 deletions
67
demo1.cpp
67
demo1.cpp
|
@ -9,15 +9,18 @@
|
||||||
|
|
||||||
#include "general.hpp"
|
#include "general.hpp"
|
||||||
|
|
||||||
#define SPRITES 3
|
|
||||||
#define SPRITE_MAX_DISTANCE 5 * UNITS_PER_SQUARE
|
|
||||||
|
|
||||||
#define SUBSAMPLE 2
|
#define SUBSAMPLE 2
|
||||||
#define SUBSAMPLED_WIDTH (SCREEN_WIDTH / SUBSAMPLE)
|
#define SUBSAMPLED_WIDTH (SCREEN_WIDTH / SUBSAMPLE)
|
||||||
|
|
||||||
#define LEVEL_X_RES 29
|
#define LEVEL_X_RES 29
|
||||||
#define LEVEL_Y_RES 21
|
#define LEVEL_Y_RES 21
|
||||||
|
|
||||||
|
Player player;
|
||||||
|
|
||||||
|
#define SPRITES 3
|
||||||
|
#define SPRITE_MAX_DISTANCE 5 * UNITS_PER_SQUARE
|
||||||
|
Sprite sprites[SPRITES];
|
||||||
|
|
||||||
const unsigned char levelTexture[] =
|
const unsigned char levelTexture[] =
|
||||||
{
|
{
|
||||||
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 0, 3, 3, 2, 2, 2, 2,
|
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 0, 3, 3, 2, 2, 2, 2,
|
||||||
|
@ -563,36 +566,6 @@ const unsigned char sprite2[] =
|
||||||
|
|
||||||
const unsigned char *textures[] = {texture1, texture2, texture3, texture4};
|
const unsigned char *textures[] = {texture1, texture2, texture3, texture4};
|
||||||
|
|
||||||
class Sprite
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
const unsigned char *mImage;
|
|
||||||
Vector2D mPosition;
|
|
||||||
Unit mHeight;
|
|
||||||
Unit mPixelSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Character
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Camera mCamera;
|
|
||||||
Unit mVericalSpeed;
|
|
||||||
|
|
||||||
Character()
|
|
||||||
{
|
|
||||||
mCamera.position.x = 23295;//UNITS_PER_SQUARE * 1;
|
|
||||||
mCamera.position.y = 14593;//UNITS_PER_SQUARE * 5;
|
|
||||||
mCamera.direction = -3350;//200;
|
|
||||||
mCamera.height = UNITS_PER_SQUARE * 3;
|
|
||||||
mCamera.resolution.x = 110 / SUBSAMPLE;
|
|
||||||
mCamera.resolution.y = 88;
|
|
||||||
mCamera.shear = 0;
|
|
||||||
mVericalSpeed = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Character player;
|
|
||||||
Sprite sprites[SPRITES];
|
|
||||||
|
|
||||||
Unit textureAt(int16_t x, int16_t y)
|
Unit textureAt(int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
|
@ -663,8 +636,6 @@ inline void pixelFunc(PixelInfo pixel)
|
||||||
*buf = c;
|
*buf = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short pal[256];
|
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
RayConstraints c;
|
RayConstraints c;
|
||||||
|
@ -712,29 +683,17 @@ pokitto.display.print(player.mCamera.direction);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#define placeSprite(S,I,X,Y,Z,P)\
|
|
||||||
sprites[I].mImage = S;\
|
|
||||||
sprites[I].mPosition.x = X * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2;\
|
|
||||||
sprites[I].mPosition.y = Y * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2;\
|
|
||||||
sprites[I].mHeight = Z * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2;\
|
|
||||||
sprites[I].mPixelSize = P;
|
|
||||||
|
|
||||||
placeSprite(sprite1,0,10,5,1,100)
|
|
||||||
placeSprite(sprite1,1,14,5,1,100)
|
|
||||||
placeSprite(sprite2,2,15,19,1,200)
|
|
||||||
|
|
||||||
#undef placeSprite
|
|
||||||
|
|
||||||
pokitto.begin();
|
pokitto.begin();
|
||||||
|
initPalette();
|
||||||
|
|
||||||
for (uint8_t r = 0; r < 8; ++r)
|
player.setPositionSquare(4,5);
|
||||||
for (uint8_t g = 0; g < 8; ++g)
|
|
||||||
for (uint8_t b = 0; b < 4; ++b)
|
sprites[0] = Sprite(sprite1,10,5,1,100);
|
||||||
pal[rgbToIndex(r,g,b)] = pokitto.display.RGBto565(36 * r, 36 * g, 85 * b);
|
sprites[1] = Sprite(sprite1,14,5,1,100);
|
||||||
|
sprites[2] = Sprite(sprite1,15,19,1,100);
|
||||||
|
|
||||||
pokitto.display.load565Palette(&pal[0]); // load a palette the same way as any other palette in any other screen mode
|
|
||||||
pokitto.display.persistence = 1;
|
pokitto.display.persistence = 1;
|
||||||
pokitto.setFrameRate(30);
|
pokitto.setFrameRate(FPS);
|
||||||
pokitto.display.setFont(fontTiny);
|
pokitto.display.setFont(fontTiny);
|
||||||
|
|
||||||
while (pokitto.isRunning())
|
while (pokitto.isRunning())
|
||||||
|
|
78
general.hpp
78
general.hpp
|
@ -17,6 +17,10 @@
|
||||||
|
|
||||||
Pokitto::Core pokitto;
|
Pokitto::Core pokitto;
|
||||||
|
|
||||||
|
#ifndef FPS
|
||||||
|
#define FPS 30
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SCREEN_WIDTH 110
|
#define SCREEN_WIDTH 110
|
||||||
#define SCREEN_HEIGHT 88
|
#define SCREEN_HEIGHT 88
|
||||||
|
|
||||||
|
@ -33,6 +37,8 @@ Pokitto::Core pokitto;
|
||||||
|
|
||||||
Unit zBuffer[SUBSAMPLED_WIDTH]; ///< 1D z-buffer for visibility determination.
|
Unit zBuffer[SUBSAMPLED_WIDTH]; ///< 1D z-buffer for visibility determination.
|
||||||
|
|
||||||
|
unsigned short palette[256];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gets (the index of) color by specified RGB components.
|
Gets (the index of) color by specified RGB components.
|
||||||
|
|
||||||
|
@ -46,6 +52,20 @@ inline uint8_t rgbToIndex(uint8_t r, uint8_t g, uint8_t b)
|
||||||
return (r & 0b00000111) | ((g & 0b00000111) << 3) | ((b & 0b00000011) << 6);
|
return (r & 0b00000111) | ((g & 0b00000111) << 3) | ((b & 0b00000011) << 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Inits and loads a general 256 color palette.
|
||||||
|
*/
|
||||||
|
void initPalette()
|
||||||
|
{
|
||||||
|
for (uint8_t r = 0; r < 8; ++r)
|
||||||
|
for (uint8_t g = 0; g < 8; ++g)
|
||||||
|
for (uint8_t b = 0; b < 4; ++b)
|
||||||
|
palette[rgbToIndex(r,g,b)] =
|
||||||
|
pokitto.display.RGBto565(36 * r, 36 * g, 85 * b);
|
||||||
|
|
||||||
|
pokitto.display.load565Palette(palette);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Adds given intensity to a color.
|
Adds given intensity to a color.
|
||||||
|
|
||||||
|
@ -131,4 +151,62 @@ void inline drawSprite(const unsigned char *sprite, int16_t x, int16_t y, Unit d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Player
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera mCamera;
|
||||||
|
Unit mVericalSpeed;
|
||||||
|
|
||||||
|
Player()
|
||||||
|
{
|
||||||
|
mCamera.position.x = 0;
|
||||||
|
mCamera.position.y = 0;
|
||||||
|
mCamera.direction = 0;
|
||||||
|
mCamera.height = UNITS_PER_SQUARE * 3;
|
||||||
|
mCamera.resolution.x = SCREEN_WIDTH / SUBSAMPLE;
|
||||||
|
mCamera.resolution.y = SCREEN_HEIGHT;
|
||||||
|
mCamera.shear = 0;
|
||||||
|
mVericalSpeed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPosition(Unit x, Unit y)
|
||||||
|
{
|
||||||
|
mCamera.position.x = x;
|
||||||
|
mCamera.position.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPositionSquare(int16_t squareX, int16_t squareY)
|
||||||
|
{
|
||||||
|
setPosition(
|
||||||
|
squareX * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2,
|
||||||
|
squareY * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Sprite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Sprite(const unsigned char *image, int16_t squareX, int16_t squareY, Unit z,
|
||||||
|
Unit pixelSize):
|
||||||
|
mImage(image),
|
||||||
|
mPixelSize(pixelSize)
|
||||||
|
{
|
||||||
|
mPosition.x = squareX * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2;
|
||||||
|
mPosition.y = squareY * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2;
|
||||||
|
mHeight = z * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sprite():
|
||||||
|
mImage(0), mHeight(0), mPixelSize(1)
|
||||||
|
{
|
||||||
|
mPosition.x = 0;
|
||||||
|
mPosition.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unsigned char *mImage;
|
||||||
|
Vector2D mPosition;
|
||||||
|
Unit mHeight;
|
||||||
|
Unit mPixelSize;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue