Draw sky strip
This commit is contained in:
parent
d7194d9183
commit
6e068eff2b
2 changed files with 97 additions and 58 deletions
77
game.h
77
game.h
|
@ -7,9 +7,6 @@
|
||||||
#ifndef _LCR_GAME_H
|
#ifndef _LCR_GAME_H
|
||||||
#define _LCR_GAME_H
|
#define _LCR_GAME_H
|
||||||
|
|
||||||
#include "map.h"
|
|
||||||
#include "assets.h"
|
|
||||||
|
|
||||||
#define LCR_KEY_UP 0x00
|
#define LCR_KEY_UP 0x00
|
||||||
#define LCR_KEY_RIGHT 0x01
|
#define LCR_KEY_RIGHT 0x01
|
||||||
#define LCR_KEY_DOWN 0x02
|
#define LCR_KEY_DOWN 0x02
|
||||||
|
@ -70,13 +67,24 @@ uint8_t LCR_gameStep(uint32_t timeMs);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
|
||||||
|
uint_fast16_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Internal pixel drawing function that checks for out-of-screen coordinates. Use
|
||||||
|
this if the pixel can potentially lie of screen (however if you know it won't,
|
||||||
|
use the normal unsafe function in sake of performance).
|
||||||
|
*/
|
||||||
|
static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y,
|
||||||
|
uint_fast16_t color);
|
||||||
|
|
||||||
|
#include "map.h"
|
||||||
|
#include "assets.h"
|
||||||
|
#include "renderer.h"
|
||||||
|
|
||||||
uint8_t _LCR_keyStates[LCR_KEYS_TOTAL]; /**< Assures unchanging key states
|
uint8_t _LCR_keyStates[LCR_KEYS_TOTAL]; /**< Assures unchanging key states
|
||||||
during a single frame. */
|
during a single frame. */
|
||||||
|
|
||||||
/**
|
|
||||||
Internal pixel drawing function that takes into account things like subdivided
|
|
||||||
resolution etc. This function does not check for out-of-screen coordinates!
|
|
||||||
*/
|
|
||||||
void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
|
void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
|
||||||
uint_fast16_t color)
|
uint_fast16_t color)
|
||||||
{
|
{
|
||||||
|
@ -94,11 +102,6 @@ void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Internal pixel drawing function that checks for out-of-screen coordinates. Use
|
|
||||||
this if the pixel can potentially lie of screen (however if you know it won't,
|
|
||||||
use the normal unsafe function in sake of performance).
|
|
||||||
*/
|
|
||||||
static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y,
|
static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y,
|
||||||
uint_fast16_t color)
|
uint_fast16_t color)
|
||||||
{
|
{
|
||||||
|
@ -116,51 +119,6 @@ void LCR_gameEnd(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCR_drawSkyStrip(int verticalOffset, uint8_t horizontalOffset)
|
|
||||||
{
|
|
||||||
#if LCR_SETTING_SKY_SIZE != 0
|
|
||||||
verticalOffset -= (LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE) / 2;
|
|
||||||
|
|
||||||
int finalY = verticalOffset + LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE;
|
|
||||||
|
|
||||||
finalY = (finalY / LCR_SETTING_SKY_SIZE) * LCR_SETTING_SKY_SIZE;
|
|
||||||
|
|
||||||
if (finalY >= LCR_EFFECTIVE_RESOLUTION_Y)
|
|
||||||
finalY = LCR_EFFECTIVE_RESOLUTION_Y - 1;
|
|
||||||
|
|
||||||
const uint16_t *skyLine = LCR_skyImages + 256;
|
|
||||||
|
|
||||||
if (verticalOffset < 0)
|
|
||||||
{
|
|
||||||
skyLine += (-1 * verticalOffset / LCR_SETTING_SKY_SIZE) * (LCR_SKY_IMAGE_SIZE / 2);
|
|
||||||
verticalOffset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (verticalOffset < finalY)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i)
|
|
||||||
{
|
|
||||||
// TODO: check z-buffer
|
|
||||||
|
|
||||||
int offsetX = (i / LCR_SETTING_SKY_SIZE + horizontalOffset)
|
|
||||||
% LCR_SKY_IMAGE_SIZE;
|
|
||||||
|
|
||||||
uint16_t pixel = *(skyLine + offsetX / 2);
|
|
||||||
|
|
||||||
pixel = offsetX % 2 ? (pixel >> 8) : (pixel & 0x00ff);
|
|
||||||
|
|
||||||
LCR_drawPixelUnsafe(i,verticalOffset,LCR_skyImages[pixel]);
|
|
||||||
}
|
|
||||||
|
|
||||||
verticalOffset++;
|
|
||||||
|
|
||||||
if (verticalOffset % LCR_SETTING_SKY_SIZE == 0)
|
|
||||||
skyLine += LCR_SKY_IMAGE_SIZE / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int aaa = 0;
|
int aaa = 0;
|
||||||
|
|
||||||
uint8_t LCR_gameStep(uint32_t time)
|
uint8_t LCR_gameStep(uint32_t time)
|
||||||
|
@ -173,7 +131,10 @@ for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i)
|
||||||
for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
|
for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
|
||||||
_LCR_keyStates[i] = LCR_keyPressed(i);
|
_LCR_keyStates[i] = LCR_keyPressed(i);
|
||||||
|
|
||||||
LCR_drawSkyStrip(200 + aaa / 10,aaa / 30);
|
|
||||||
|
|
||||||
|
LCR_drawBackground(200 + aaa / 10);
|
||||||
|
LCR_drawSkyStrip(200 + aaa / 10,aaa / 30);
|
||||||
|
|
||||||
|
|
||||||
aaa = (aaa + 1) % 10000;
|
aaa = (aaa + 1) % 10000;
|
||||||
|
|
78
renderer.h
Normal file
78
renderer.h
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#ifndef _LCR_RENDERER_H
|
||||||
|
#define _LCR_RENDERER_H
|
||||||
|
|
||||||
|
struct LCR_Renderer
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
};
|
||||||
|
|
||||||
|
void LCR_drawBackground(int verticalOffset)
|
||||||
|
{
|
||||||
|
uint16_t color = LCR_skyImages[LCR_skyImages[256] & 0x00ff] ; // TODO
|
||||||
|
int limit = verticalOffset - LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE / 2;
|
||||||
|
|
||||||
|
if (limit >= LCR_EFFECTIVE_RESOLUTION_Y)
|
||||||
|
limit = LCR_EFFECTIVE_RESOLUTION_Y - 1;
|
||||||
|
|
||||||
|
for (int y = 0; y <= limit; ++y)
|
||||||
|
for (int x = 0; x < LCR_EFFECTIVE_RESOLUTION_X; ++x)
|
||||||
|
LCR_drawPixelUnsafe(x,y,color);
|
||||||
|
|
||||||
|
color = LCR_skyImages[LCR_skyImages[255 + (128 * 128) / 2] >> 8]; // TODO
|
||||||
|
limit = verticalOffset + LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE / 2 -
|
||||||
|
LCR_SETTING_SKY_SIZE;
|
||||||
|
|
||||||
|
if (limit < 0)
|
||||||
|
limit = 0;
|
||||||
|
|
||||||
|
for (int y = LCR_EFFECTIVE_RESOLUTION_Y - 1; y >= limit; --y)
|
||||||
|
for (int x = 0; x < LCR_EFFECTIVE_RESOLUTION_X; ++x)
|
||||||
|
LCR_drawPixelUnsafe(x,y,color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LCR_drawSkyStrip(int verticalOffset, uint8_t horizontalOffset)
|
||||||
|
{
|
||||||
|
#if LCR_SETTING_SKY_SIZE != 0
|
||||||
|
verticalOffset -= (LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE) / 2;
|
||||||
|
|
||||||
|
int finalY = verticalOffset + LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE;
|
||||||
|
|
||||||
|
finalY = (finalY / LCR_SETTING_SKY_SIZE) * LCR_SETTING_SKY_SIZE;
|
||||||
|
|
||||||
|
if (finalY >= LCR_EFFECTIVE_RESOLUTION_Y)
|
||||||
|
finalY = LCR_EFFECTIVE_RESOLUTION_Y - 1;
|
||||||
|
|
||||||
|
const uint16_t *skyLine = LCR_skyImages + 256;
|
||||||
|
|
||||||
|
if (verticalOffset < 0)
|
||||||
|
{
|
||||||
|
skyLine += (-1 * verticalOffset / LCR_SETTING_SKY_SIZE) * (LCR_SKY_IMAGE_SIZE / 2);
|
||||||
|
verticalOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (verticalOffset < finalY)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i)
|
||||||
|
{
|
||||||
|
// TODO: check z-buffer
|
||||||
|
|
||||||
|
int offsetX = (i / LCR_SETTING_SKY_SIZE + horizontalOffset)
|
||||||
|
% LCR_SKY_IMAGE_SIZE;
|
||||||
|
|
||||||
|
uint16_t pixel = *(skyLine + offsetX / 2);
|
||||||
|
|
||||||
|
pixel = offsetX % 2 ? (pixel >> 8) : (pixel & 0x00ff);
|
||||||
|
|
||||||
|
LCR_drawPixelUnsafe(i,verticalOffset,LCR_skyImages[pixel]);
|
||||||
|
}
|
||||||
|
|
||||||
|
verticalOffset++;
|
||||||
|
|
||||||
|
if (verticalOffset % LCR_SETTING_SKY_SIZE == 0)
|
||||||
|
skyLine += LCR_SKY_IMAGE_SIZE / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // guard
|
Loading…
Reference in a new issue