anarch/levels.h

226 lines
6.8 KiB
C
Raw Normal View History

2019-10-03 18:04:14 -04:00
/**
@file levels.h
This file contains game levels and related code.
by Miloslav Ciz (drummyfish), 2019
Released under CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/)
plus a waiver of all other intellectual property. The goal of this work is
be and remain completely in the public domain forever, available for any use
whatsoever.
*/
2019-09-25 09:51:19 -04:00
#ifndef _SFG_LEVELS_H
#define _SFG_LEVELS_H
#define SFG_MAP_SIZE 64
#define SFG_TILE_DICTIONARY_SIZE 64
typedef uint16_t SFG_TileDefinition;
/**<
Defines a single game map tile. The format is following:
MSB aaabbbbb cccddddd LSB
2019-10-08 07:46:12 -04:00
aaa: ceiling texture index (from texture available on the map), 111
means completely transparent texture
bbbbb: ceiling height (1111 meaning no ceiling) ABOVE the floor
ccc: floor texture index, 111 means completely transparent texture
ddddd: floor height
2019-09-25 09:51:19 -04:00
*/
2019-09-25 20:40:35 -04:00
#define SFG_TILE_CEILING_MAX_HEIGHT 31
#define SFG_TILE_TEXTURE_TRANSPARENT 7
2019-09-25 09:51:19 -04:00
typedef SFG_TileDefinition SFG_TileDictionary[SFG_TILE_DICTIONARY_SIZE];
/// helper macros for SFG_TileDefinition
#define SFG_TD(floorH, ceilH, floorT, ceilT)\
((floorH & 0x001f) |\
((floorT & 0x0007) << 5) |\
((ceilH & 0x001f) << 8) |\
((ceilT & 0x0007) << 13))
#define SFG_TILE_FLOOR_HEIGHT(tile) (tile & 0x1f)
2019-09-25 14:14:45 -04:00
#define SFG_TILE_FLOOR_TEXTURE(tile) ((tile & 0xe0) >> 5)
2019-09-25 20:40:35 -04:00
#define SFG_TILE_CEILING_HEIGHT(tile) ((tile & 0x1f00) >> 8)
2019-09-26 15:15:07 -04:00
#define SFG_TILE_CEILING_TEXTURE(tile) ((tile & 0xe000) >> 13)
2019-09-25 09:51:19 -04:00
2019-09-25 20:40:35 -04:00
#define SFG_OUTSIDE_TILE SFG_TD(63,0,7,7)
2019-09-25 19:34:57 -04:00
2020-09-23 08:01:25 -04:00
/**
2019-09-25 09:51:19 -04:00
Game map represented as a 2D array. Array item has this format:
MSB aabbbbbb LSB
aa: type of square, possible values:
00: normal
2019-09-26 20:03:28 -04:00
01: moving floor (elevator), moves from floor height to ceililing height
(there is no ceiling above)
2019-09-25 09:51:19 -04:00
10: moving ceiling, moves from ceiling height to floor height
11: door
bbbbbb: index into tile dictionary
*/
2020-09-23 08:01:25 -04:00
typedef uint8_t SFG_MapArray[SFG_MAP_SIZE * SFG_MAP_SIZE];
2019-09-25 09:51:19 -04:00
2019-09-27 13:04:49 -04:00
#define SFG_TILE_PROPERTY_MASK 0xc0
2019-09-26 21:34:49 -04:00
#define SFG_TILE_PROPERTY_NORMAL 0x00
#define SFG_TILE_PROPERTY_ELEVATOR 0x40
#define SFG_TILE_PROPERTY_SQUEEZER 0x80
#define SFG_TILE_PROPERTY_DOOR 0xc0
2019-10-05 14:09:27 -04:00
/**
Serves to place elements (items, enemies etc.) into the game level.
*/
typedef struct
{
2019-10-25 18:50:22 -04:00
uint8_t type;
2019-10-05 14:09:27 -04:00
uint8_t coords[2];
} SFG_LevelElement;
#define SFG_MAX_LEVEL_ELEMENTS 128
/*
Definitions of level element type. These values must leave the highest bit
unused because that will be used by the game engine, so the values must be
lower than 128.
*/
2020-03-28 15:48:16 -04:00
#define SFG_LEVEL_ELEMENT_NONE 0
2019-10-18 11:41:55 -04:00
#define SFG_LEVEL_ELEMENT_BARREL 0x01
2019-10-23 14:17:12 -04:00
#define SFG_LEVEL_ELEMENT_HEALTH 0x02
2020-01-06 10:43:29 -05:00
#define SFG_LEVEL_ELEMENT_BULLETS 0x03
2020-01-12 10:26:58 -05:00
#define SFG_LEVEL_ELEMENT_ROCKETS 0x04
#define SFG_LEVEL_ELEMENT_PLASMA 0x05
2020-02-05 11:22:02 -05:00
#define SFG_LEVEL_ELEMENT_TREE 0x06
2020-02-08 16:56:22 -05:00
#define SFG_LEVEL_ELEMENT_FINISH 0x07
2020-02-09 09:03:15 -05:00
#define SFG_LEVEL_ELEMENT_TELEPORT 0x08
2020-02-22 09:17:22 -05:00
#define SFG_LEVEL_ELEMENT_TERMINAL 0x09
2020-02-24 06:53:49 -05:00
#define SFG_LEVEL_ELEMENT_COLUMN 0x0a
2020-03-01 08:37:54 -05:00
#define SFG_LEVEL_ELEMENT_RUIN 0x0b
2020-03-22 12:52:23 -04:00
#define SFG_LEVEL_ELEMENT_LAMP 0x0c
#define SFG_LEVEL_ELEMENT_CARD0 0x0d ///< Access card, unlocks doors with lock.
#define SFG_LEVEL_ELEMENT_CARD1 0x0e
#define SFG_LEVEL_ELEMENT_CARD2 0x0f
#define SFG_LEVEL_ELEMENT_LOCK0 0x10 /**< Special level element that must be
2020-02-08 15:41:05 -05:00
placed on a tile with door. This door is
then unlocked by taking the corresponding
access card. */
2020-03-22 12:52:23 -04:00
#define SFG_LEVEL_ELEMENT_LOCK1 0x11
#define SFG_LEVEL_ELEMENT_LOCK2 0x12
#define SFG_LEVEL_ELEMENT_BLOCKER 0x13 ///< Invisible wall.
2019-10-23 14:17:12 -04:00
2020-03-28 15:48:16 -04:00
#define SFG_LEVEL_ELEMENT_MONSTER_SPIDER 0x20
#define SFG_LEVEL_ELEMENT_MONSTER_DESTROYER 0x21
#define SFG_LEVEL_ELEMENT_MONSTER_WARRIOR 0x22
#define SFG_LEVEL_ELEMENT_MONSTER_PLASMABOT 0x23
#define SFG_LEVEL_ELEMENT_MONSTER_ENDER 0x24
#define SFG_LEVEL_ELEMENT_MONSTER_TURRET 0x25
#define SFG_LEVEL_ELEMENT_MONSTER_EXPLODER 0x26
2019-10-05 14:09:27 -04:00
2019-12-30 18:35:35 -05:00
#define SFG_MONSTERS_TOTAL 7
#define SFG_MONSTER_TYPE_TO_INDEX(monsterType) \
2020-03-28 15:48:16 -04:00
((monsterType) - SFG_LEVEL_ELEMENT_MONSTER_SPIDER)
#define SFG_MONSTER_INDEX_TO_TYPE(monsterIndex) \
((monsterIndex) + SFG_LEVEL_ELEMENT_MONSTER_SPIDER)
2019-12-30 18:35:35 -05:00
2020-03-28 15:48:16 -04:00
#define SFG_LEVEL_ELEMENT_TYPE_IS_MOSTER(t) \
((t) >= SFG_LEVEL_ELEMENT_MONSTER_SPIDER)
2019-12-27 11:17:14 -05:00
2019-09-25 09:51:19 -04:00
typedef struct
{
SFG_MapArray mapArray;
2019-09-26 15:15:07 -04:00
SFG_TileDictionary tileDictionary;
uint8_t textureIndices[7]; /**< Says which textures are used on the map. There
can be at most 7 because of 3bit indexing (one
value is reserved for special transparent
texture). */
2019-09-27 13:04:49 -04:00
uint8_t doorTextureIndex; /**< Index (global, NOT from textureIndices) of a
texture used for door. */
2019-09-29 14:26:53 -04:00
uint8_t floorColor;
uint8_t ceilingColor;
2020-01-05 18:00:44 -05:00
uint8_t playerStart[3]; /**< Player starting location: square X, square Y,
direction (fourths of RCL_Unit). */
2020-01-02 18:34:50 -05:00
uint8_t backgroundImage; /** Index of level background image. */
2019-10-05 14:09:27 -04:00
SFG_LevelElement elements[SFG_MAX_LEVEL_ELEMENTS];
2019-09-25 09:51:19 -04:00
} SFG_Level;
2019-09-25 21:21:20 -04:00
static inline SFG_TileDefinition SFG_getMapTile
(
2019-09-29 03:50:58 -04:00
const SFG_Level *level,
2019-09-25 21:21:20 -04:00
int16_t x,
2019-09-26 21:34:49 -04:00
int16_t y,
uint8_t *properties
2019-09-25 21:21:20 -04:00
)
2019-09-25 09:51:19 -04:00
{
if (x < 0 || x >= SFG_MAP_SIZE || y < 0 || y >= SFG_MAP_SIZE)
2019-09-26 21:34:49 -04:00
{
*properties = SFG_TILE_PROPERTY_NORMAL;
2019-09-25 19:34:57 -04:00
return SFG_OUTSIDE_TILE;
2019-09-26 21:34:49 -04:00
}
2019-09-25 09:51:19 -04:00
2019-09-29 03:50:58 -04:00
uint8_t tile = level->mapArray[y * SFG_MAP_SIZE + x];
2019-09-25 09:51:19 -04:00
2019-09-26 21:34:49 -04:00
*properties = tile & 0xc0;
2019-09-29 03:50:58 -04:00
return level->tileDictionary[tile & 0x3f];
2019-09-25 09:51:19 -04:00
}
2020-02-13 02:23:44 -05:00
#define SFG_NUMBER_OF_LEVELS 10
2020-02-12 10:52:18 -05:00
2020-09-24 09:40:01 -04:00
/*
NOTE: Initially the levels were stored sequentially in one big array, but that
caused some issues with Arduino's PROGMEM, so now we store each level in a
separate variable and eventually create an array of pointers to these.
*/
SFG_PROGRAM_MEMORY SFG_Level SFG_level0 =
2020-09-26 09:35:09 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
;
2020-09-24 09:40:01 -04:00
SFG_PROGRAM_MEMORY SFG_Level SFG_level1 =
2020-09-26 09:35:09 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
;
2020-09-24 09:40:01 -04:00
SFG_PROGRAM_MEMORY SFG_Level SFG_level2 =
2020-09-26 09:35:09 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
;
2020-09-24 09:40:01 -04:00
SFG_PROGRAM_MEMORY SFG_Level SFG_level3 =
2020-09-26 09:35:09 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
;
2020-09-24 09:40:01 -04:00
SFG_PROGRAM_MEMORY SFG_Level SFG_level4 =
2020-09-26 09:35:09 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
;
2020-09-24 09:40:01 -04:00
SFG_PROGRAM_MEMORY SFG_Level SFG_level5 =
2020-09-14 10:40:26 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
2020-09-24 09:40:01 -04:00
;
SFG_PROGRAM_MEMORY SFG_Level SFG_level6 =
2020-09-14 10:40:26 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
2020-09-24 09:40:01 -04:00
;
SFG_PROGRAM_MEMORY SFG_Level SFG_level7 =
2020-09-14 10:40:26 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
2020-09-24 09:40:01 -04:00
;
SFG_PROGRAM_MEMORY SFG_Level SFG_level8 =
2020-09-14 10:40:26 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
2020-09-24 09:40:01 -04:00
;
SFG_PROGRAM_MEMORY SFG_Level SFG_level9 =
2020-09-14 10:40:26 -04:00
#include "/home/tastyfish/git/anarch/assets/tmp.txt"
2020-09-24 09:40:01 -04:00
;
static const SFG_Level * SFG_levels[SFG_NUMBER_OF_LEVELS] =
{
&SFG_level0, &SFG_level1, &SFG_level2, &SFG_level3, &SFG_level4, &SFG_level5,
&SFG_level6, &SFG_level7, &SFG_level8, &SFG_level9
2019-09-25 09:51:19 -04:00
};
#endif // guard
2019-09-26 11:13:18 -04:00