#include <acknex.h>
#include <default.c>
#define tw 8
#define th 8
#define sw 80
#define sh 60
BMAP* screen; // buffer image
COLOR screencolor; // buffer background colour
int map[sw][sh]; // map
BMAP* tiles[4]; // tile type images
int tile_vis[4] = { 0, 1, 1, 1 }; // tile type visibility flags
int tile_color[4] = { 0x000000, 0xFFFFFF, 0xAAAAAA, 0x777777 }; // tile type colours
void res_init()
{
int i, j, k;
COLOR c;
for (i = 0; i < 4; i++) // create color images
{
tiles[i] = bmap_createblack(tw, th, 32);
k = tile_color[i];
c.red = (k >> 16) & 0xFF;
c.green = (k >> 8) & 0xFF;
c.blue = k & 0xFF;
bmap_fill(tiles[i], c, 100);
}
for (i = 0; i < sw; i++) // generate some terrain
{
k = random(sh >> 2) >> 0; for (j = 0; j < k; j++) map[i][j] = 0;
k += random(sh >> 2) >> 0; for (; j < k; j++) map[i][j] = 3;
k += random(sh >> 2) >> 0; for (; j < k; j++) map[i][j] = 2;
for (; j < sh; j++) map[i][j] = 1;
}
screen = bmap_createblack(tw * sw, th * sh, 24);
vec_set(screencolor, vector(40, 40, 40));
}
void main()
{
wait(1); // must-wait - some bitmap functions cant be used at first frame
res_init(); // initialize things
while (1) // main loop.
{
bmap_fill(screen, screencolor, 1); // clear screen with colour
int i, j, k; // counters and temp. var
VECTOR v; // temp vector
for (j = 0; j < sh; j++)
for (i = 0; i < sw; i++)
{
k = map[i][j]; // obtain tile index at coordinates
if (!tile_vis[k]) continue;
v.x = i * tw; v.y = j * th; // move vector
bmap_blit(screen, tiles[k], v, NULL); // draw tile image to buffer
}
draw_quad(screen, vector(320, 0, 0), 0, 0, 0, 0, 100, 0); // draw buffer to engine window
wait(1); // if you'll put 2 there, you'll be able to see the horror of screen flickering :)
}
}