Pokitto-Raycasting/game.cpp

655 lines
28 KiB
C++
Raw Normal View History

2018-08-31 18:40:05 +02:00
/**
WIP raycasting demo for Pokitto.
2018-09-03 10:56:48 +02:00
Don't forget to compile with -O3!
2018-08-31 18:40:05 +02:00
author: Miloslav "drummyfish" Ciz
license: CC0
*/
2018-09-02 19:43:54 +02:00
//#define RAYCAST_TINY
2018-08-31 18:40:05 +02:00
#include <stdio.h>
#include "raycastlib.h"
#include "Pokitto.h"
2018-09-03 14:22:52 +02:00
#define SUBSAMPLE 2
2018-09-04 15:52:12 +02:00
#define SCREEN_WIDTH 110
#define SCREEN_HEIGHT 88
#define SUBSAMPLED_WIDTH (SCREEN_WIDTH / SUBSAMPLE)
#define SUBSAMPLED_HEIGHT (SCREEN_HEIGHT / SUBSAMPLE)
#define MIDDLE_ROW (SCREEN_HEIGHT / 2)
#define MIDDLE_COLUMN (SCREEN_WIDTH / 2)
#define SPRITES 6
2018-09-03 15:48:50 +02:00
Pokitto::Core p;
2018-09-04 15:52:12 +02:00
Unit zBuffer[SUBSAMPLED_WIDTH];
2018-09-03 14:22:52 +02:00
const unsigned char image[] =
{ 32, 32 // width, height
,0x12,0x12,0x12,0x12,0x12,0x12,0x00,0x09,0x00,0x12,0x12,0x12,0x12,0x12
,0x09,0x00,0x12,0x12,0x12,0x00,0x12,0x00,0x12,0x12,0x12,0x00,0x12,0x00
,0x12,0x12,0x09,0x00,0x65,0x5b,0x24,0x24,0x64,0x65,0x64,0x5b,0x09,0x64
,0x64,0x6d,0x6d,0x63,0x5b,0x00,0x24,0x64,0x64,0x64,0x64,0x64,0x6d,0x63
,0x64,0x65,0x6d,0x64,0x64,0x64,0x5b,0x00,0x65,0x5b,0x5b,0x5b,0x5b,0x5c
,0x52,0x09,0x00,0x64,0x5b,0x5b,0x5b,0x5b,0x11,0x00,0x64,0x64,0x52,0x64
,0x5b,0x63,0x5b,0x5b,0x5a,0x52,0x5b,0x5b,0x52,0x5b,0x12,0x09,0x6d,0x5b
,0x5b,0x5b,0x52,0x52,0x52,0x09,0x00,0x6d,0x64,0x52,0x5b,0x5a,0x08,0x00
,0x65,0x5b,0x5c,0x5b,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x52
,0x52,0x09,0x24,0x52,0x5b,0x52,0x09,0x5a,0x52,0x09,0x00,0x24,0x12,0x5a
,0x12,0x09,0x09,0x00,0x24,0x5b,0x5b,0x52,0x52,0x5b,0x5b,0x5b,0x52,0x5b
,0x5b,0x52,0x5b,0x5b,0x52,0x12,0x64,0x5b,0x5b,0x5a,0x11,0x5b,0x52,0x09
,0x00,0x5b,0x12,0x12,0x11,0x5b,0x09,0x00,0x64,0x5b,0x64,0x5b,0x5b,0x52
,0x5b,0x5b,0x5b,0x52,0x5b,0x5a,0x5b,0x5b,0x09,0x00,0x5b,0x5b,0x09,0x12
,0x12,0x51,0x5b,0x09,0x00,0x5b,0x12,0x09,0x12,0x11,0x09,0x12,0x64,0x64
,0x5b,0x5b,0x52,0x52,0x5b,0x52,0x5b,0x11,0x5a,0x5b,0x5b,0x52,0x09,0x12
,0x12,0x52,0x11,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x08,0x09,0x09,0x08
,0x08,0x00,0x5b,0x52,0x51,0x09,0x49,0x09,0x09,0x08,0x08,0x09,0x11,0x09
,0x09,0x09,0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00
,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x12,0x00,0x12,0x00,0x00
,0x00,0x09,0x00,0x12,0x12,0x00,0x00,0x00,0x64,0x64,0x64,0x5b,0x12,0x64
,0x6d,0x65,0x5b,0x5b,0x00,0x65,0x65,0x65,0x64,0x5b,0x5b,0x6d,0x6d,0x65
,0x64,0x64,0x64,0x5c,0x5b,0x00,0x6d,0x6d,0x6d,0x5b,0x6d,0x64,0x5b,0x64
,0x5b,0x52,0x00,0x6d,0x5b,0x5b,0x64,0x5a,0x00,0x64,0x5b,0x5b,0x64,0x5b
,0x5b,0x5b,0x5b,0x64,0x5b,0x5b,0x11,0x52,0x52,0x00,0x6d,0x64,0x12,0x5b
,0x5b,0x52,0x5b,0x52,0x5b,0x09,0x12,0x6d,0x5b,0x5b,0x5b,0x52,0x12,0x6d
,0x64,0x5b,0x5b,0x5b,0x52,0x52,0x52,0x5b,0x52,0x5b,0x5a,0x5b,0x09,0x00
,0x24,0x5a,0x5b,0x52,0x52,0x5b,0x12,0x52,0x5a,0x12,0x00,0x5c,0x52,0x5b
,0x09,0x52,0x09,0x6d,0x5b,0x52,0x5b,0x52,0x5b,0x5b,0x5b,0x52,0x52,0x52
,0x52,0x5b,0x09,0x00,0x64,0x5b,0x12,0x11,0x52,0x52,0x51,0x52,0x09,0x09
,0x00,0x65,0x5b,0x52,0x5b,0x09,0x00,0x64,0x5b,0x5b,0x5b,0x52,0x5b,0x52
,0x52,0x5b,0x5b,0x11,0x5b,0x52,0x09,0x12,0x64,0x5b,0x52,0x5b,0x12,0x5b
,0x12,0x5b,0x09,0x09,0x00,0x64,0x51,0x5b,0x52,0x08,0x09,0x64,0x5b,0x52
,0x5b,0x5b,0x52,0x52,0x11,0x52,0x51,0x5b,0x52,0x52,0x09,0x00,0x5b,0x5b
,0x5b,0x12,0x12,0x52,0x09,0x00,0x08,0x09,0x08,0x09,0x09,0x09,0x09,0x09
,0x00,0x5b,0x52,0x52,0x09,0x09,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x08
,0x09,0x08,0x5b,0x5b,0x52,0x09,0x09,0x09,0x00,0x09,0x00,0x00,0x09,0x00
,0x00,0x00,0x09,0x12,0x12,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x12
,0x09,0x00,0x00,0x08,0x09,0x00,0x00,0x00,0x09,0x08,0x08,0x09,0x6d,0x6d
,0x5b,0x24,0x64,0x24,0x1b,0x64,0x5b,0x5b,0x24,0x5a,0x00,0x65,0x5b,0x65
,0x64,0x5b,0x64,0x64,0x5b,0x00,0x5b,0x5b,0x24,0x5b,0x5a,0x5a,0x5a,0x5b
,0x11,0x00,0x6d,0x5b,0x5b,0x5a,0x5b,0x64,0x5b,0x12,0x11,0x52,0x5a,0x08
,0x12,0x6d,0x5b,0x5b,0x5b,0x5b,0x5a,0x64,0x09,0x00,0x5a,0x52,0x52,0x52
,0x12,0x11,0x09,0x5a,0x00,0x00,0x6d,0x5a,0x5b,0x5a,0x51,0x5b,0x12,0x63
,0x52,0x11,0x52,0x08,0x12,0x64,0x5b,0x5b,0x5b,0x52,0x64,0x64,0x09,0x00
,0x63,0x51,0x09,0x51,0x52,0x52,0x51,0x09,0x49,0x00,0x24,0x5b,0x5a,0x5b
,0x12,0x09,0x12,0x5b,0x09,0x5a,0x12,0x09,0x12,0x65,0x5b,0x5b,0x12,0x52
,0x5b,0x52,0x09,0x00,0x5a,0x09,0x12,0x09,0x12,0x09,0x09,0x51,0x09,0x00
,0x5b,0x5b,0x64,0x51,0x11,0x12,0x12,0x12,0x12,0x11,0x12,0x09,0x09,0x64
,0x5b,0x52,0x52,0x5b,0x52,0x09,0x08,0x00,0x23,0x52,0x09,0x09,0x09,0x12
,0x09,0x52,0x00,0x09,0x5b,0x5a,0x12,0x12,0x12,0x11,0x12,0x5b,0x09,0x12
,0x12,0x08,0x00,0x64,0x52,0x5b,0x5a,0x52,0x5b,0x5c,0x09,0x00,0x12,0x5a
,0x52,0x09,0x12,0x09,0x09,0x12,0x09,0x00,0x52,0x51,0x51,0x08,0x08,0x00
,0x09,0x09,0x08,0x08,0x08,0x09,0x00,0x5b,0x52,0x09,0x09,0x09,0x08,0x08
,0x12,0x09,0x00,0x09,0x08,0x09,0x08,0x09,0x09,0x08,0x00,0x00,0x12,0x12
,0x00,0x09,0x09,0x09,0x12,0x00,0x00,0x08,0x12,0x00,0x00,0x00,0x00,0x00
,0x12,0x00,0x00,0x00,0x00,0x12,0x12,0x00,0x00,0x00,0x00,0x09,0x09,0x00
,0x00,0x00,0x5b,0x64,0x64,0x25,0x64,0x64,0x5b,0x00,0x1b,0x1b,0x1b,0x5b
,0x5a,0x5b,0x64,0x63,0x24,0x1b,0x11,0x00,0x6d,0x6d,0x6d,0x6d,0x5b,0x64
,0x5b,0x00,0x5c,0x5b,0x6d,0x64,0x52,0x5b,0x5b,0x5b,0x5a,0x5b,0x11,0x00
,0x1b,0x52,0x12,0x5a,0x52,0x12,0x51,0x5a,0x52,0x52,0x09,0x00,0x24,0x64
,0x5b,0x52,0x5a,0x5b,0x12,0x00,0x64,0x5b,0x12,0x52,0x5b,0x52,0x52,0x52
,0x5b,0x52,0x09,0x00,0x23,0x52,0x5a,0x11,0x52,0x09,0x52,0x51,0x52,0x51
,0x49,0x00,0x6d,0x5b,0x11,0x11,0x52,0x52,0x09,0x00,0x6d,0x11,0x5b,0x5b
,0x12,0x5b,0x52,0x5b,0x12,0x52,0x11,0x00,0x1b,0x5b,0x49,0x51,0x09,0x11
,0x52,0x51,0x09,0x5a,0x08,0x00,0x24,0x52,0x5b,0x52,0x12,0x52,0x09,0x00
,0x1b,0x5b,0x52,0x5b,0x5b,0x52,0x11,0x52,0x12,0x12,0x09,0x09,0x5a,0x5a
,0x5a,0x51,0x52,0x09,0x52,0x51,0x52,0x52,0x09,0x00,0x64,0x64,0x64,0x5b
,0x5b,0x09,0x09,0x12,0x24,0x5b,0x5b,0x52,0x52,0x5b,0x09,0x11,0x09,0x12
,0x09,0x00,0x5b,0x09,0x52,0x5a,0x09,0x09,0x09,0x5a,0x52,0x09,0x00,0x00
,0x64,0x5b,0x64,0x52,0x5b,0x5b,0x08,0x12,0x64,0x5b,0x52,0x52,0x09,0x08
,0x09,0x09,0x09,0x08,0x09,0x00,0x11,0x09,0x09,0x09,0x09,0x09,0x00,0x08
,0x08,0x09,0x09,0x00,0x5b,0x52,0x52,0x09,0x09,0x09,0x09,0x12,0x08,0x08
,0x09,0x09
};
2018-09-03 15:14:39 +02:00
const unsigned char image2[] =
{ 32, 32 // width, height
,0xff,0xbf,0xff,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xff
,0xff,0xbf,0xbf,0xff,0xff,0xff,0xff,0xbf,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0xbf,0xff,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf
,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf
,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0x25,0xbf,0xbf,0xbf,0x77,0x76,0x77
,0x76,0x77,0x77,0x77,0x77,0x77,0x77,0xbf,0xbf,0x77,0x77,0xbf,0xbf,0xbf
,0x77,0x77,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0x77,0xbf,0x1c,0xbf,0xbf
,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x77,0x76,0x76,0xbf,0xbf,0x77
,0x76,0x77,0x77,0xb7,0x77,0x77,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0x77,0x77
,0xbf,0x24,0xbf,0xbf,0x77,0x76,0x76,0x76,0x76,0x76,0x76,0x77,0x77,0xb7
,0x77,0xbf,0xbf,0x77,0x76,0x77,0x77,0x77,0x77,0x77,0xbf,0xbf,0xbf,0xbf
,0xbf,0xbf,0xbf,0xbf,0xbf,0x1c,0xbf,0xbf,0x76,0x76,0x25,0x24,0x1c,0x1c
,0x24,0x24,0x25,0x25,0x25,0x24,0x24,0x25,0x25,0x24,0x24,0x25,0x25,0x24
,0x24,0x25,0x6d,0x6d,0x6e,0xbf,0xbf,0xbf,0xbf,0x1c,0xbf,0x76,0x76,0x76
,0x1c,0x1c,0x1c,0x24,0x24,0x25,0x25,0x65,0x25,0x25,0x6d,0x6d,0x6d,0x6d
,0x65,0x24,0x24,0x24,0x24,0x24,0x65,0x6d,0x76,0xbf,0xbf,0xb7,0xbf,0x1c
,0xbf,0x77,0x76,0x76,0x1c,0x1c,0x76,0x76,0x77,0x76,0x76,0x76,0x77,0x76
,0x76,0x77,0x76,0x76,0x77,0x77,0x76,0x76,0x77,0x77,0xbf,0xbf,0xbf,0xff
,0x77,0x77,0x77,0x1c,0xbf,0x76,0x76,0x76,0x1c,0x1c,0x76,0x76,0x76,0x76
,0x76,0x76,0x76,0x76,0x76,0x77,0x76,0x76,0x77,0x77,0x76,0x76,0x77,0xb7
,0xbf,0xbf,0xff,0xbf,0x76,0x76,0x76,0x1c,0xbf,0x76,0x6e,0x6e,0x1c,0x1c
,0x6e,0x76,0x76,0x76,0x76,0x6e,0x6e,0x76,0x76,0x76,0x76,0x76,0x76,0x76
,0x76,0x76,0x77,0x77,0x77,0xbf,0xff,0xbf,0x76,0x76,0x77,0x1c,0xbf,0x76
,0x76,0x76,0x1c,0x1c,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76
,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x77,0xbf,0xbf,0x76,0x77
,0x77,0x1c,0xbf,0x76,0x6e,0x76,0x1c,0x1c,0x6e,0x6e,0x76,0x76,0x76,0x76
,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x77,0x77,0x76
,0xbf,0xbf,0x76,0x77,0x77,0x1c,0xb7,0x6e,0x6e,0x6e,0x1c,0x1c,0x6e,0x6e
,0x6e,0x76,0x76,0x76,0x6e,0x76,0x76,0x76,0x76,0x76,0x76,0x6e,0x6e,0x76
,0x76,0x76,0x76,0x76,0xbf,0xbf,0x76,0x77,0x76,0x1c,0x77,0x6e,0x6e,0x6e
,0x1c,0x1c,0x6e,0x6e,0x6e,0x76,0x76,0x76,0x76,0x76,0x6e,0x6e,0x76,0x76
,0x76,0x6e,0x6e,0x76,0x76,0x76,0x76,0x76,0xbf,0xbf,0x76,0x76,0x76,0x1c
,0xbf,0x76,0x6e,0x76,0x24,0x24,0x6e,0x76,0x76,0x76,0x76,0x76,0x6e,0x6e
,0x6e,0x6e,0x6e,0x6d,0x6e,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0xbf,0xbf
,0x76,0x76,0x76,0x1c,0x77,0x76,0x76,0x76,0x25,0x25,0x76,0x76,0x76,0x76
,0x76,0x6e,0x6e,0x6e,0x6d,0x6e,0x6d,0x6d,0x6d,0x6e,0x6e,0x76,0x6e,0x6e
,0x76,0x6e,0xbf,0xbf,0x76,0x76,0x6e,0x1c,0x76,0x76,0x76,0x76,0x25,0x65
,0x76,0x77,0x77,0x76,0x76,0x6e,0x6e,0x6e,0x6e,0x6e,0x6d,0x6d,0x6e,0x6e
,0x6e,0x76,0x6e,0x76,0x76,0x76,0xbf,0xbf,0x6e,0x6e,0x6e,0x1c,0x76,0x6e
,0x6e,0x6e,0x24,0x25,0x76,0x77,0x77,0x76,0x76,0x76,0x6e,0x6e,0x6e,0x6e
,0x6e,0x6e,0x6e,0x76,0x76,0x76,0x76,0x6e,0x6e,0x6e,0xbf,0xbf,0x76,0x6e
,0x76,0x1c,0x6e,0x6d,0x6d,0x6d,0x1c,0x24,0x76,0x76,0x76,0x76,0x76,0x76
,0x76,0x76,0x76,0x6e,0x6d,0x6d,0x6e,0x6e,0x76,0x76,0x76,0x6e,0x6e,0x6e
,0xbf,0xbf,0x6e,0x76,0x76,0x24,0x6d,0x6d,0x6d,0x6d,0x1c,0x1c,0x6e,0x6e
,0x6e,0x6e,0x76,0x76,0x77,0x76,0x76,0x76,0x6e,0x6e,0x6d,0x6e,0x76,0x76
,0x6e,0x6e,0x6e,0x6e,0xbf,0xbf,0x6e,0x76,0x76,0x1c,0x6d,0x6d,0x6d,0x6d
,0x1c,0x1c,0x6d,0x6d,0x6d,0x6d,0x6e,0x6e,0x76,0x76,0x76,0x76,0x76,0x6e
,0x6e,0x6e,0x76,0x6e,0x6e,0x76,0x76,0x76,0xbf,0xbf,0x6e,0x6e,0x6e,0x1c
,0x6e,0x6d,0x6d,0x6d,0x1c,0x1c,0x6d,0x6d,0x6d,0x6d,0x6d,0x6d,0x6e,0x6e
,0x76,0x77,0x77,0x76,0x6e,0x6e,0x6e,0x6e,0x6e,0x6e,0x6e,0x6e,0xbf,0xbf
,0x6e,0x6e,0x6e,0x1c,0x6e,0x6d,0x6d,0x65,0x1c,0x24,0x6d,0x6d,0x6d,0x6d
,0x6d,0x6d,0x6d,0x6e,0x76,0x77,0x76,0x6e,0x6d,0x6d,0x6d,0x6d,0x6d,0x6d
,0x6d,0x6d,0xbf,0x77,0x6d,0x6d,0x6d,0x1c,0x6e,0x6d,0x6d,0x65,0x24,0x24
,0x6d,0x6d,0x6d,0x6d,0x6d,0x6d,0x6d,0x6e,0x76,0x76,0x76,0x6d,0x6d,0x6d
,0x6d,0x6d,0x65,0x6d,0x6d,0x6d,0xbf,0xbf,0x6e,0x6e,0x6d,0x1c,0x6e,0x6d
,0x6d,0x6d,0x24,0x24,0x6d,0x6d,0x6d,0x6d,0x65,0x65,0x6d,0x76,0x76,0x76
,0x6e,0x6d,0x6d,0x6d,0x6d,0x6d,0x6d,0x6d,0x6d,0x6d,0xbf,0xbf,0x6e,0x6e
,0x6d,0x1c,0x6e,0x6d,0x6d,0x6d,0x24,0x1c,0x6d,0x6d,0x6d,0x6d,0x6d,0x6e
,0x6e,0x76,0x76,0x6e,0x6d,0x65,0x6d,0x6d,0x6d,0x65,0x6d,0x6d,0x6d,0x6d
,0xbf,0xbf,0x6d,0x6d,0x6d,0x1c,0x6e,0x6d,0x6d,0x65,0x24,0x24,0x76,0x76
,0x76,0x77,0xbf,0xbf,0xbf,0xbf,0xbf,0x77,0x77,0x76,0x76,0x76,0x76,0x76
,0x76,0x77,0x77,0x77,0x77,0xbf,0x6d,0x6d,0x6d,0x1c,0x6e,0x6e,0x6d,0x65
,0x25,0x6d,0x77,0xb7,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0x77,0x76,0x77,0x77
,0x77,0x77,0x76,0x76,0x76,0x76,0x76,0x76,0xbf,0x77,0x65,0x65,0x65,0x1c
,0x76,0x6e,0x6d,0x6d,0x6d,0x6d,0x6d,0x6e,0x76,0x6e,0x6e,0x6d,0x6d,0x6d
,0x65,0x65,0x65,0x25,0x25,0x25,0x24,0x25,0x25,0x25,0x25,0x25,0x65,0x65
,0x6d,0x6d,0x6d,0x1c,0x76,0x6d,0x65,0x65,0x65,0x6d,0x6d,0x6e,0x6e,0x6d
,0x6d,0x65,0x65,0x6d,0x6d,0x6d,0x6d,0x6d,0x25,0x25,0x24,0x25,0x65,0x6d
,0x25,0x65,0x6d,0x6d,0x6d,0x6d,0x6d,0x1c,0x6e,0x6d,0x6d,0x6d,0x6d,0x6e
,0x6e,0x6e,0x6d,0x6d,0x6e,0x6e,0x76,0x76,0x76,0x6e,0x76,0x6e,0x76,0x6d
,0x6d,0x6d,0x6d,0x6d,0x25,0x65,0x6d,0x65,0x65,0x65,0x6d,0x1c,0x25,0x6d
,0x65,0x6d,0x6d,0x6d,0x6d,0x25,0x24,0x25,0x25,0x6d,0x6d,0x6e,0x6e,0x76
,0x6d,0x6e,0x6e,0x6d,0x24,0x24,0x24,0x24,0x24,0x1c,0x1c,0x1c,0x24,0x1c
,0x1c,0x1c
};
const unsigned char image3[] =
{ 32, 32 // width, height
,0x65,0x1d,0x1c,0x25,0x1d,0x1b,0x0a,0x0a,0x14,0x25,0x1d,0x0a,0x14,0x12
,0x09,0x14,0x66,0x6f,0x1b,0x13,0x1c,0x66,0x77,0x6e,0x6e,0x1d,0x25,0x66
,0x25,0x0a,0x1e,0x25,0x1d,0x14,0x1d,0x14,0x65,0x0a,0x14,0x15,0x14,0x02
,0x1c,0x0a,0x6f,0x6f,0x66,0x6f,0x6f,0x6f,0x25,0x0a,0x6e,0x77,0x7f,0x67
,0x67,0x66,0x66,0x6e,0x25,0x25,0x13,0x0a,0x01,0x13,0x1c,0x13,0x14,0x01
,0x0b,0x1d,0x5d,0x1d,0x66,0x66,0x6f,0x6f,0x6f,0x77,0x6f,0x6e,0x1d,0x01
,0x77,0x6f,0x67,0x6f,0x26,0x66,0x1c,0x25,0x5e,0x1d,0x1d,0x1c,0x1c,0x6e
,0x77,0x6e,0x2e,0x1d,0x14,0x0a,0x14,0x25,0x66,0x67,0x77,0x67,0x6e,0x77
,0x25,0x6e,0x1c,0x1c,0x6e,0x77,0x77,0x7f,0x67,0x66,0x6e,0x6e,0x1d,0x66
,0x14,0x1d,0x12,0x6e,0x67,0x6f,0x26,0x65,0x6e,0x01,0x14,0x1d,0x65,0x66
,0x6f,0x77,0x2f,0x2e,0x1c,0x25,0x1d,0x13,0x77,0x6f,0x77,0x6f,0x6f,0x6f
,0x66,0x1d,0x6e,0x14,0x65,0x1c,0x0a,0x66,0x6f,0x6f,0x77,0x1e,0x65,0x5d
,0x0a,0x09,0x6e,0x25,0x67,0x1d,0x6e,0x25,0x5d,0x0a,0x14,0x0a,0x6f,0x77
,0x77,0x77,0x77,0x6e,0x26,0x1d,0x25,0x25,0x66,0x25,0x01,0x6f,0x6f,0x77
,0x6d,0x6f,0x1d,0x6e,0x1d,0x13,0x1c,0x13,0x6e,0x77,0x26,0x1c,0x65,0x13
,0x01,0x6e,0x25,0x26,0x6f,0x6f,0x67,0x6f,0x66,0x6e,0x1c,0x66,0x66,0x1d
,0x13,0x77,0x77,0x6f,0x67,0x6e,0x66,0x5c,0x5d,0x1c,0x09,0x1c,0x13,0x13
,0x1c,0x0a,0x01,0x12,0x25,0x09,0x0a,0x6f,0x6e,0x6e,0x6f,0x6f,0x66,0x25
,0x25,0x6e,0x25,0x1c,0x14,0x77,0x67,0x77,0x6f,0x67,0x1d,0x25,0x1c,0x1d
,0x1c,0x24,0x0a,0x66,0x6f,0x65,0x66,0x6e,0x25,0x1d,0x1c,0x0b,0x5d,0x66
,0x1d,0x5d,0x25,0x13,0x66,0x1d,0x1d,0x14,0x6e,0x6f,0x77,0x77,0x25,0x66
,0x66,0x1d,0x6e,0x66,0x1d,0x14,0x09,0x77,0x66,0x6f,0x1e,0x6f,0x66,0x65
,0x1d,0x25,0x13,0x0a,0x6e,0x1d,0x1c,0x1d,0x1d,0x25,0x14,0x01,0x2e,0x66
,0x77,0x77,0x6f,0x66,0x1d,0x1e,0x1d,0x1d,0x14,0x25,0x13,0x6f,0x6f,0x6f
,0x6f,0x66,0x6e,0x25,0x1d,0x1c,0x14,0x01,0x14,0x0a,0x0a,0x14,0x09,0x09
,0x0a,0x1b,0x0b,0x66,0x66,0x1d,0x5e,0x65,0x66,0x26,0x65,0x1c,0x1c,0x1c
,0x12,0x6f,0x7f,0x6f,0x6f,0x6f,0x6f,0x66,0x66,0x25,0x1d,0x13,0x0a,0x25
,0x66,0x5e,0x1d,0x1c,0x14,0x0a,0x1c,0x13,0x13,0x1d,0x5d,0x14,0x14,0x1d
,0x5d,0x0b,0x0b,0x0b,0x1d,0x6f,0x6f,0x7f,0x6f,0x66,0x1d,0x66,0x1d,0x25
,0x1c,0x1d,0x01,0x26,0x6f,0x77,0x77,0x66,0x15,0x1d,0x1d,0x25,0x0a,0x01
,0x0b,0x1c,0x25,0x1b,0x1d,0x14,0x01,0x1d,0x66,0x77,0x7f,0x6f,0x77,0x65
,0x6f,0x6e,0x6e,0x25,0x1d,0x14,0x13,0x6f,0x7f,0x27,0x6f,0x77,0x65,0x65
,0x2e,0x0a,0x14,0x25,0x5d,0x25,0x14,0x14,0x0a,0x0b,0x1d,0x6e,0x6f,0x6f
,0x6f,0x77,0x6f,0x66,0x66,0x65,0x15,0x66,0x1d,0x65,0x01,0x6f,0x6f,0x7f
,0x66,0x6f,0x7f,0x6f,0x1d,0x01,0x77,0x67,0x6f,0x65,0x6e,0x25,0x01,0x65
,0x6e,0x77,0x66,0x66,0x6f,0x77,0x6f,0x6f,0x1d,0x25,0x26,0x1d,0x14,0x14
,0x25,0x6f,0x6f,0x77,0x6f,0x66,0x77,0x1d,0x13,0x6e,0x66,0x7f,0x6f,0x6e
,0x66,0x25,0x14,0x2d,0x77,0x7f,0x5e,0x77,0x6e,0x66,0x6e,0x66,0x1d,0x65
,0x25,0x1b,0x1d,0x02,0x66,0x7f,0x6f,0x7f,0x66,0x7f,0x66,0x66,0x0b,0x66
,0x6f,0x6f,0x26,0x66,0x25,0x1d,0x1c,0x09,0x66,0x77,0x6e,0x77,0x6e,0x6f
,0x6f,0x25,0x1d,0x6e,0x5e,0x25,0x0a,0x01,0x77,0x6f,0x66,0x67,0x66,0x77
,0x25,0x65,0x13,0x01,0x77,0x6f,0x1d,0x66,0x66,0x14,0x25,0x0a,0x1c,0x5e
,0x66,0x6f,0x66,0x6e,0x66,0x66,0x6e,0x1d,0x25,0x0a,0x09,0x1d,0x66,0x6f
,0x6f,0x66,0x66,0x1d,0x1d,0x6e,0x65,0x12,0x66,0x66,0x77,0x6e,0x5d,0x1d
,0x0a,0x09,0x1c,0x1c,0x25,0x6e,0x6f,0x6e,0x1d,0x25,0x1d,0x65,0x13,0x1d
,0x1c,0x1c,0x65,0x6f,0x77,0x67,0x6e,0x6e,0x1d,0x66,0x1d,0x02,0x1b,0x66
,0x66,0x66,0x66,0x14,0x01,0x14,0x6e,0x65,0x14,0x13,0x13,0x25,0x1d,0x0a
,0x0b,0x13,0x1d,0x6e,0x66,0x13,0x1c,0x77,0x6e,0x1d,0x65,0x1c,0x1d,0x1d
,0x1d,0x01,0x13,0x14,0x1c,0x1c,0x25,0x13,0x12,0x66,0x6f,0x6f,0x25,0x25
,0x13,0x14,0x0a,0x01,0x6e,0x65,0x77,0x67,0x77,0x66,0x0b,0x0a,0x66,0x1d
,0x66,0x1d,0x6e,0x14,0x13,0x1b,0x66,0x66,0x13,0x02,0x0a,0x01,0x1c,0x6f
,0x6f,0x7f,0x26,0x26,0x1d,0x01,0x66,0x6e,0x6f,0x6f,0x77,0x67,0x66,0x2e
,0x66,0x09,0x0a,0x13,0x65,0x1d,0x1c,0x0a,0x66,0x6e,0x77,0x6f,0x6f,0x1d
,0x6e,0x25,0x0b,0x66,0x77,0x6e,0x25,0x25,0x66,0x0a,0x6f,0x77,0x77,0x77
,0x66,0x6f,0x67,0x66,0x25,0x1d,0x1b,0x09,0x1c,0x0a,0x14,0x0a,0x6f,0x77
,0x6f,0x7f,0x6f,0x77,0x6f,0x6e,0x01,0x66,0x7f,0x6f,0x6f,0x66,0x1d,0x09
,0x66,0x77,0x7f,0x67,0x66,0x66,0x6e,0x77,0x66,0x6f,0x26,0x76,0x1d,0x25
,0x13,0x1b,0x6e,0x77,0x77,0x6f,0x6f,0x6e,0x6f,0x25,0x1c,0x1c,0x77,0x77
,0x1d,0x65,0x25,0x0a,0x2e,0x6f,0x6f,0x7f,0x6e,0x1d,0x1c,0x6e,0x66,0x6e
,0x1d,0x66,0x1d,0x66,0x65,0x12,0x65,0x77,0x6f,0x77,0x66,0x77,0x6e,0x25
,0x14,0x0a,0x5e,0x6f,0x77,0x66,0x66,0x0b,0x6e,0x6f,0x77,0x6f,0x6f,0x65
,0x65,0x1e,0x25,0x15,0x5e,0x24,0x65,0x1d,0x1d,0x1c,0x6f,0x77,0x6f,0x6f
,0x67,0x66,0x1d,0x25,0x25,0x01,0x6e,0x67,0x6f,0x66,0x65,0x14,0x6e,0x6e
,0x77,0x77,0x77,0x6e,0x66,0x25,0x6e,0x25,0x1d,0x1c,0x14,0x25,0x1c,0x0a
,0x77,0x77,0x6f,0x1d,0x66,0x25,0x13,0x1d,0x0b,0x0b,0x6f,0x6f,0x66,0x6e
,0x6e,0x1d,0x14,0x6e,0x66,0x6f,0x7f,0x67,0x66,0x25,0x66,0x1c,0x65,0x1b
,0x1c,0x13,0x0a,0x14,0x7f,0x6f,0x26,0x25,0x65,0x13,0x65,0x1c,0x1b,0x14
,0x67,0x6f,0x6e,0x66,0x1d,0x0a,0x13,0x14,0x66,0x6e,0x6e,0x6f,0x6d,0x6e
,0x1d,0x1d,0x13,0x13,0x25,0x0a,0x0a,0x6e,0x6f,0x6f,0x6e,0x1d,0x6e,0x5c
,0x5c,0x01,0x25,0x66,0x6f,0x66,0x66,0x6e,0x1d,0x14,0x12,0x1d,0x13,0x14
,0x12,0x6e,0x1c,0x0a,0x14,0x1d,0x0a,0x13,0x0a,0x1d,0x65,0x66,0x6f,0x6e
,0x1d,0x66,0x1c,0x1d,0x01,0x0a,0x14,0x1c,0x6f,0x25,0x1c,0x14,0x0a,0x13
,0x14,0x6e,0x5d,0x1c,0x13,0x13,0x09,0x13,0x0a,0x13,0x1d,0x1d,0x0a,0x14
,0x1d,0x25
};
2018-09-03 15:48:50 +02:00
const unsigned char sprite[] =
{ 32, 32 // width, height
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x76
,0xff,0xff,0x76,0x76,0xff,0x76,0x76,0xff,0x76,0x76,0x76,0x76,0x76,0x64
,0x76,0x76,0x76,0x64,0x76,0x64,0x09,0x09,0x00,0xff,0xff,0xff,0xff,0xff
,0x00,0x52,0x76,0xff,0xff,0x76,0x76,0xff,0x76,0x76,0x76,0x76,0x76,0x76
,0x76,0x64,0x76,0x76,0x76,0x76,0x76,0x76,0x64,0x64,0x09,0x09,0x00,0x00
,0xff,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0x76,0xff,0x76,0x76,0x76,0xff,0xff,0x76,0x64,0x76,0x52
,0x09,0x09,0x52,0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x52,0x52,0x52,0x52
,0x64,0x64,0x52,0x52,0x64,0x64,0x52,0x64,0x52,0x52,0x52,0x52,0x52,0xff
,0x76,0x76,0x64,0x09,0x09,0x09,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00
,0x64,0x64,0x52,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x52,0x64,0x52
,0x52,0x52,0x64,0xff,0x76,0x76,0x52,0x09,0x09,0x52,0x00,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0x00,0x52,0x64,0x64,0x64,0x64,0x64,0x52,0x64,0x52
,0x64,0x64,0x52,0x64,0x52,0x52,0xff,0x76,0x76,0x64,0x09,0x09,0x52,0x00
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x52,0x64,0x64,0x09
,0x09,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x76,0x76,0x52
,0x09,0x09,0x52,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00
,0x64,0x64,0x64,0x52,0x09,0x09,0x09,0x00,0xff,0xff,0xff,0xff,0x00,0x76
,0x76,0x76,0x64,0x09,0x09,0x52,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0x00,0x64,0x64,0x64,0x64,0x52,0x09,0x52,0x00,0xff,0xff
,0xff,0xff,0x00,0xff,0x76,0x76,0x52,0x52,0x09,0x52,0x00,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x64,0x64,0x52,0x52
,0x09,0x09,0x00,0xff,0xff,0x00,0x76,0x76,0x76,0x64,0x52,0x09,0x52,0x00
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64
,0x64,0x76,0x64,0x09,0x52,0x09,0x00,0xff,0xff,0x00,0x76,0x64,0x76,0x52
,0x09,0x52,0x52,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0x00,0x64,0x64,0x64,0x52,0x09,0x52,0x09,0x00,0x00,0x64
,0x64,0x76,0x64,0x52,0x52,0x09,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x64,0x64,0x76,0x52,0x52
,0x52,0x00,0x52,0x64,0x76,0x64,0x52,0x52,0x52,0x52,0x00,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64
,0x52,0x64,0x52,0x09,0x52,0x52,0x64,0x64,0x64,0x64,0x52,0x09,0x52,0x00
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0x00,0x64,0x64,0x52,0x76,0x52,0x52,0x52,0x64,0x64,0x64,0x52
,0x52,0x52,0x52,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x64,0x64,0x52,0x52,0x52
,0x52,0x64,0x64,0x52,0x52,0x52,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x52
,0x64,0x76,0x52,0x52,0x52,0x64,0x52,0x52,0x52,0x52,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0x00,0x64,0x52,0x76,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x00
,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x52,0x52,0x52,0x76,0x52,0x52,0x52
,0x09,0x52,0x52,0x00,0x00,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x64,0x52
,0x64,0x52,0x52,0x52,0x52,0x52,0x00,0x00,0xff,0xff,0xff,0x00,0x00,0x00
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00
,0x00,0x00,0x52,0x52,0x52,0x76,0x52,0x09,0x52,0x52,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00
,0x52,0x52,0x52,0x52,0x52,0x52,0x00,0x52,0x64,0x76,0x09,0x52,0x09,0x09
,0x00,0x00,0x00,0x09,0x00,0x09,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0x00,0x52,0x00,0x09,0x52,0x09,0x52,0x09,0x09,0x52,0x52,0x64
,0x64,0x52,0x52,0x09,0x00,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x00,0xff
,0xff,0xff,0xff,0xff,0xff,0x00,0x52,0x00,0x52,0x52,0x52,0x09,0x09,0x52
,0x09,0x09,0x64,0x64,0x76,0x52,0x09,0x00,0x09,0x09,0x00,0x09,0x00,0x00
,0x00,0x09,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x52,0x09,0x52,0x09,0x52
,0x09,0x52,0x09,0x09,0x09,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x00,0x00,0xff,0xff,0xff,0x00,0x76
,0x76,0x64,0x76,0x76,0x64,0x76,0x64,0x64,0x76,0x76,0x76,0x64,0x64,0x76
,0x64,0x64,0x52,0x64,0x64,0x52,0x52,0x64,0x52,0x64,0x52,0x00,0x00,0xff
,0xff,0xff,0x00,0x76,0x52,0x09,0x52,0x09,0x52,0x09,0x09,0x52,0x52,0x52
,0x09,0x09,0x09,0x09,0x52,0x09,0x52,0x09,0x09,0x09,0x52,0x09,0x09,0x52
,0x52,0x00,0x00,0xff,0xff,0xff,0x00,0x64,0x64,0x64,0x64,0x64,0x52,0x52
,0x64,0x64,0x64,0x52,0x64,0x52,0x52,0x52,0x52,0x64,0x52,0x52,0x52,0x52
,0x52,0x52,0x52,0x52,0x52,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
,0xff,0xff
};
inline uint8_t sampleImage(const unsigned char *image, Unit x, Unit y)
2018-09-03 14:22:52 +02:00
{
2018-09-04 15:52:12 +02:00
// TODO: optimize
x = wrap(x,UNITS_PER_SQUARE);
y = wrap(y,UNITS_PER_SQUARE);
int32_t index =
image[1] * ((image[1] * y) / UNITS_PER_SQUARE) + (image[0] * x) /
UNITS_PER_SQUARE;
2018-09-03 14:22:52 +02:00
return image[2 + index];
}
2018-09-03 10:56:48 +02:00
2018-09-04 15:52:12 +02:00
void drawSprite(const unsigned char *sprite, int16_t x, int16_t y, Unit depth, int16_t size)
2018-09-03 15:48:50 +02:00
{
// TODO: optimize
2018-09-04 11:42:05 +02:00
x -= size / 2;
y -= size / 2;
2018-09-03 15:48:50 +02:00
Unit step = UNITS_PER_SQUARE / size;
uint8_t c;
2018-09-04 15:52:12 +02:00
int16_t jTo = size - max(0,y + size - 88);
int16_t iTo = size - max(0,x + size - 110);
bool mask[SUBSAMPLED_WIDTH];
for (int i = 0; i < SUBSAMPLED_WIDTH; ++i)
mask[i] = zBuffer[i] > depth;
for (Unit j = max(-1 * y,0); j < jTo; ++j)
2018-09-03 15:48:50 +02:00
{
2018-09-04 15:52:12 +02:00
for (Unit i = max(-1 * x,0); i < iTo; ++i)
2018-09-03 15:48:50 +02:00
{
2018-09-04 16:08:14 +02:00
int16_t xPos = x + i;
if (!mask[xPos / SUBSAMPLE])
2018-09-04 15:52:12 +02:00
continue;
2018-09-03 15:48:50 +02:00
2018-09-04 15:52:12 +02:00
c = sampleImage(sprite,(i * UNITS_PER_SQUARE) / size,(j * UNITS_PER_SQUARE) / size);
2018-09-03 15:48:50 +02:00
if (c != 0xff)
2018-09-04 16:08:14 +02:00
p.display.drawPixel(xPos,y + j,c);
2018-09-03 15:48:50 +02:00
}
}
}
2018-09-03 10:56:48 +02:00
// r: 3 bits, g: 3 bits, b: 2 bits
inline uint8_t rgbToIndex(uint8_t r, uint8_t g, uint8_t b)
{
return (r & 0b00000111) | ((g & 0b00000111) << 3) | ((b & 0b00000011) << 6);
}
2018-09-03 15:14:39 +02:00
inline uint8_t addIntensity(uint8_t color, int intensity)
2018-09-03 14:31:29 +02:00
{
uint8_t r = color & 0b00000111;
uint8_t g = (color & 0b00111000) >> 3;
uint8_t b = (color & 0b11000000) >> 6;
2018-09-03 15:14:39 +02:00
if (intensity >= 0)
{
r += intensity;
r = r > 7 ? 7 : r;
2018-09-03 14:31:29 +02:00
2018-09-03 15:14:39 +02:00
g += intensity;
g = g > 7 ? 7 : g;
2018-09-03 14:31:29 +02:00
2018-09-03 15:14:39 +02:00
b += intensity / 2;
b = b > 3 ? 3 : b;
}
else
{
intensity *= -1;
r = (intensity > r) ? 0 : r - intensity;
g = (intensity > g) ? 0 : g - intensity;
2018-09-03 15:48:50 +02:00
intensity /= 2;
b = intensity > b ? 0 : b - intensity;
2018-09-03 15:14:39 +02:00
}
2018-09-03 14:31:29 +02:00
return rgbToIndex(r,g,b);
}
2018-08-31 18:40:05 +02:00
class Level
{
public:
int16_t getHeight(int16_t x, int16_t y)
{
if (x > 12 || y > 12)
2018-08-31 19:12:47 +02:00
return max(x,y) - 10;
2018-08-31 18:40:05 +02:00
2018-09-02 19:43:54 +02:00
if (y < 5 && y > 0)
{
return y > 2 ? x : -x;
}
2018-09-01 12:04:17 +02:00
2018-09-02 19:43:54 +02:00
return (x < 0 || y < 0 || x > 9 || y > 9) ? 4 : 0;
2018-08-31 18:40:05 +02:00
}
};
2018-09-04 15:52:12 +02:00
class Sprite
{
public:
Vector2D mPosition;
Unit mHeight;
};
2018-08-31 18:40:05 +02:00
class Character
{
public:
Camera mCamera;
Character()
{
2018-09-04 13:37:49 +02:00
mCamera.position.x = 2468;//UNITS_PER_SQUARE * 1;
mCamera.position.y = 6736;//UNITS_PER_SQUARE * 5;
mCamera.direction = -100;//200;
2018-08-31 18:40:05 +02:00
mCamera.fovAngle = UNITS_PER_SQUARE / 4;
2018-09-03 15:14:39 +02:00
mCamera.height = UNITS_PER_SQUARE / 2;
2018-09-03 10:56:48 +02:00
mCamera.resolution.x = 110 / SUBSAMPLE;
2018-08-31 18:40:05 +02:00
mCamera.resolution.y = 88;
}
};
Character player;
Level level;
2018-09-04 15:52:12 +02:00
Sprite sprites[SPRITES];
2018-08-31 18:40:05 +02:00
2018-09-01 09:07:27 +02:00
Unit heightFunc(int16_t x, int16_t y)
2018-08-31 18:40:05 +02:00
{
2018-09-02 19:43:54 +02:00
return level.getHeight(x,y) * UNITS_PER_SQUARE / 4;
2018-08-31 18:40:05 +02:00
}
2018-09-02 19:43:54 +02:00
inline void pixelFunc(PixelInfo pixel)
2018-08-31 18:40:05 +02:00
{
2018-09-04 15:52:12 +02:00
if (pixel.position.y == MIDDLE_ROW)
zBuffer[pixel.position.x] = pixel.depth;
2018-09-03 15:14:39 +02:00
uint8_t c;
2018-09-03 10:56:48 +02:00
2018-09-03 15:14:39 +02:00
Unit depth = pixel.depth - UNITS_PER_SQUARE;
2018-09-03 10:56:48 +02:00
2018-09-03 15:14:39 +02:00
if (depth < 0)
depth = 0;
2018-09-03 10:56:48 +02:00
2018-09-03 15:14:39 +02:00
int intensity = 7 - (depth * 7) / (UNITS_PER_SQUARE * 5);
2018-09-03 14:22:52 +02:00
if (intensity < 0)
intensity = 0;
2018-09-03 15:14:39 +02:00
if (pixel.isWall)
{
if ((pixel.hit.direction == 0 || pixel.hit.direction == 2))
intensity -= 2;
if (intensity < 0)
intensity = 0;
c = sampleImage(image2,pixel.hit.textureCoord,pixel.textureCoordY);
c = addIntensity(c,intensity - 3);
}
else
c = rgbToIndex(intensity/2,intensity,intensity/3);
2018-09-01 12:04:17 +02:00
2018-09-02 19:43:54 +02:00
uint8_t *buf = p.display.screenbuffer;
2018-09-01 12:04:17 +02:00
2018-09-03 10:56:48 +02:00
buf += pixel.position.x * SUBSAMPLE;
2018-09-02 19:43:54 +02:00
buf += pixel.position.y * p.display.width;
2018-09-03 10:56:48 +02:00
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)
*buf++ = c;
2018-09-02 19:43:54 +02:00
*buf = c;
2018-08-31 18:40:05 +02:00
}
2018-09-02 19:43:54 +02:00
unsigned short pal[256];
2018-08-31 18:40:05 +02:00
void draw()
{
RayConstraints c;
2018-09-02 20:25:17 +02:00
c.maxHits = 16;
c.maxSteps = 16;
2018-08-31 18:40:05 +02:00
render(player.mCamera,heightFunc,pixelFunc,c);
2018-09-03 15:48:50 +02:00
2018-09-04 16:08:14 +02:00
Unit previousDepth;
2018-09-04 15:52:12 +02:00
for (uint8_t i = 0; i < SPRITES; ++i)
{
PixelInfo pos = mapToScreen(sprites[i].mPosition,sprites[i].mHeight,player.mCamera);
if (pos.depth > 0)
drawSprite(sprite,pos.position.x * SUBSAMPLE,pos.position.y,
pos.depth,perspectiveScale(32,pos.depth));
2018-09-04 16:08:14 +02:00
if (i != 0 && pos.depth > previousDepth)
{
Sprite tmp = sprites[i];
sprites[i] = sprites[i - 1];
sprites[i - 1] = tmp;
}
previousDepth = pos.depth;
2018-09-04 15:52:12 +02:00
}
2018-08-31 18:40:05 +02:00
}
int main()
{
2018-09-04 15:52:12 +02:00
#define placeSprite(I,X,Y,Z)\
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;
placeSprite(0,5,7,0)
placeSprite(1,6,7,0)
placeSprite(2,5,8,0)
placeSprite(3,6,8,0)
placeSprite(4,-1,-2,1)
placeSprite(5,1,11,1)
#undef placeSprite
2018-08-31 18:40:05 +02:00
p.begin();
2018-09-02 19:43:54 +02:00
2018-09-03 15:14:39 +02:00
for (uint8_t r = 0; r < 8; ++r)
for (uint8_t g = 0; g < 8; ++g)
for (uint8_t b = 0; b < 4; ++b)
pal[rgbToIndex(r,g,b)] = p.display.RGBto565(36 * r, 36 * g, 85 * b);
2018-09-02 20:25:17 +02:00
2018-09-02 19:43:54 +02:00
p.display.load565Palette(&pal[0]); // load a palette the same way as any other palette in any other screen mode
2018-09-03 10:56:48 +02:00
p.display.persistence = 1;
2018-09-02 20:25:17 +02:00
p.setFrameRate(60);
2018-08-31 18:40:05 +02:00
p.display.setFont(fontTiny);
while (p.isRunning())
{
if (p.update())
{
draw();
2018-09-02 19:43:54 +02:00
const int16_t step = max(UNITS_PER_SQUARE / 10,1);
const int16_t step2 = max(UNITS_PER_SQUARE / 50,1);
2018-08-31 18:40:05 +02:00
Vector2D d = angleToDirection(player.mCamera.direction);
d.x = (d.x * step) / UNITS_PER_SQUARE;
d.y = (d.y * step) / UNITS_PER_SQUARE;
2018-09-02 19:43:54 +02:00
if (d.x == 0 && d.y == 0)
{
d.x = d.x > 0 ? step : -step;
d.y = d.y > 0 ? step : -step;
}
2018-09-04 15:52:12 +02:00
bool strafe = p.aBtn();
2018-08-31 18:40:05 +02:00
if (p.upBtn())
{
2018-09-04 15:52:12 +02:00
if (strafe)
player.mCamera.height += step;
else
{
player.mCamera.position.x += d.x;
player.mCamera.position.y += d.y;
}
2018-08-31 18:40:05 +02:00
}
else if (p.downBtn())
{
2018-09-04 15:52:12 +02:00
if (strafe)
player.mCamera.height -= step;
else
{
player.mCamera.position.x -= d.x;
player.mCamera.position.y -= d.y;
}
}
if (strafe)
{
d = angleToDirection(player.mCamera.direction + UNITS_PER_SQUARE / 4);
d.x = (d.x * step) / UNITS_PER_SQUARE;
d.y = (d.y * step) / UNITS_PER_SQUARE;
2018-08-31 18:40:05 +02:00
}
2018-09-04 15:52:12 +02:00
int addition = 0;
2018-08-31 18:40:05 +02:00
if (p.rightBtn())
2018-09-04 15:52:12 +02:00
addition = 1;
2018-08-31 18:40:05 +02:00
else if (p.leftBtn())
2018-09-04 15:52:12 +02:00
addition = -1;
2018-08-31 18:40:05 +02:00
2018-09-04 15:52:12 +02:00
if (strafe)
{
player.mCamera.position.x += addition * d.x;
player.mCamera.position.y += addition * d.y;
}
else
player.mCamera.direction += addition * step2;
2018-08-31 19:01:14 +02:00
2018-09-02 19:43:54 +02:00
player.mCamera.height =
max(heightFunc(player.mCamera.position.x / UNITS_PER_SQUARE,player.mCamera.position.y / UNITS_PER_SQUARE) + UNITS_PER_SQUARE / 2,player.mCamera.height);
2018-08-31 18:40:05 +02:00
}
}
return 0;
}