mirror of
https://gitlab.com/drummyfish/anarch.git
synced 2024-11-23 17:32:16 -05:00
Update tests
This commit is contained in:
parent
84bc75df12
commit
ea43c8ee7a
81
main_test.c
81
main_test.c
@ -16,14 +16,24 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define SFG_SCREEN_RESOLUTION_X 67
|
||||
#define SFG_SCREEN_RESOLUTION_Y 31
|
||||
#define SFG_BACKGROUND_BLUR 1
|
||||
#define SFG_DITHERED_SHADOW 1
|
||||
#define SFG_FPS 30
|
||||
|
||||
#include "game.h"
|
||||
#include "sounds.h"
|
||||
|
||||
uint8_t screen[SFG_SCREEN_RESOLUTION_X * SFG_SCREEN_RESOLUTION_Y];
|
||||
uint8_t keys[SFG_KEY_COUNT];
|
||||
|
||||
uint32_t time = 0;
|
||||
|
||||
int8_t SFG_keyPressed(uint8_t key)
|
||||
{
|
||||
return 0;
|
||||
return keys[key];
|
||||
}
|
||||
|
||||
void SFG_getMouseOffset(int16_t *x, int16_t *y)
|
||||
@ -41,6 +51,7 @@ void SFG_sleepMs(uint16_t timeMs)
|
||||
|
||||
static inline void SFG_setPixel(uint16_t x, uint16_t y, uint8_t colorIndex)
|
||||
{
|
||||
screen[y * SFG_SCREEN_RESOLUTION_X + x] = colorIndex;
|
||||
}
|
||||
|
||||
void SFG_playSound(uint8_t soundIndex, uint8_t volume)
|
||||
@ -68,6 +79,24 @@ void printTestHeading(const char *text)
|
||||
printf("\n~~~~~ testing: %s ~~~~~\n\n",text);
|
||||
}
|
||||
|
||||
const char colors[8] = " .,-;imX";
|
||||
|
||||
void printScreen()
|
||||
{
|
||||
const char *c = screen;
|
||||
|
||||
for (uint8_t y = 0; y < SFG_SCREEN_RESOLUTION_Y; ++y)
|
||||
{
|
||||
for (uint8_t x = 0; x < SFG_SCREEN_RESOLUTION_X; ++x)
|
||||
{
|
||||
putchar(*c != 7 ? colors[(*c) % 8] : '@');
|
||||
++c;
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("===== TESTING ANARCH =====\n");
|
||||
@ -80,9 +109,9 @@ int main(void)
|
||||
|
||||
ASSERT("frame == 0",SFG_game.frame == 0);
|
||||
|
||||
{
|
||||
printTestHeading("music and sounds");
|
||||
|
||||
{
|
||||
static const expectedSamples[] = { 1, 0, 0, 0, 0, 0, 255, 251, 80, 240, 240, 10, 0, 6, 4, 0 };
|
||||
|
||||
uint16_t pos = 0;
|
||||
@ -97,9 +126,55 @@ int main(void)
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT("sfx sample",SFG_GET_SFX_SAMPLE(0,0) == 128);
|
||||
ASSERT("sfx sample",SFG_GET_SFX_SAMPLE(1,200) == 112);
|
||||
ASSERT("sfx sample",SFG_GET_SFX_SAMPLE(3,512) == 112);
|
||||
ASSERT("sfx sample",SFG_GET_SFX_SAMPLE(4,1000) == 128);
|
||||
}
|
||||
|
||||
puts("DONE\neverything seems OK");
|
||||
{
|
||||
printTestHeading("levels");
|
||||
|
||||
SFG_TileDefinition t;
|
||||
uint8_t p;
|
||||
|
||||
t = SFG_getMapTile(&SFG_level1,10,8,&p);
|
||||
ASSERT("level1 tile",SFG_TILE_FLOOR_HEIGHT(t) == 14 && SFG_TILE_CEILING_HEIGHT(t) == 0 && SFG_TILE_FLOOR_TEXTURE(t) == 4 && p == 0);
|
||||
|
||||
t = SFG_getMapTile(&SFG_level3,9,20,&p);
|
||||
ASSERT("level3 tile",SFG_TILE_FLOOR_HEIGHT(t) == 17 && SFG_TILE_CEILING_HEIGHT(t) == 13 && SFG_TILE_FLOOR_TEXTURE(t) == 0 && p == 128);
|
||||
|
||||
t = SFG_getMapTile(&SFG_level5,-9,0,&p);
|
||||
ASSERT("outside tile",SFG_TILE_FLOOR_HEIGHT(t) == 31 && SFG_TILE_CEILING_HEIGHT(t) == 0 && SFG_TILE_FLOOR_TEXTURE(t) == 7 && p == 0);
|
||||
}
|
||||
|
||||
{
|
||||
printTestHeading("gameplay");
|
||||
|
||||
for (uint8_t i = 0; i < SFG_KEY_COUNT; ++i)
|
||||
keys[i] = 0;
|
||||
|
||||
#define STEP(ms) { printf("(fr %d, step %d ms) ",SFG_game.frame,ms); time += ms; SFG_mainLoopBody(); }
|
||||
|
||||
#define PRESS(k) { printf("(press %d) ",k); keys[k] = 1; }
|
||||
#define RELEASE(k) { printf("(release %d) ",k); keys[k] = 0; }
|
||||
|
||||
STEP(10)
|
||||
STEP(100)
|
||||
PRESS(SFG_KEY_DOWN);
|
||||
STEP(1000)
|
||||
// RELEASE(SFG_KEY_A);
|
||||
// STEP(5000)
|
||||
|
||||
printScreen();
|
||||
|
||||
#undef PRESS
|
||||
#undef RELEASE
|
||||
#undef STEP
|
||||
}
|
||||
|
||||
puts("======================================\n\nDone.\nEverything seems OK.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user