1 // ------------------------------------------------------------------
3 // ------------------------------------------------------------------
4 // This handles the tile map for the ball game
5 // ------------------------------------------------------------------
6 // By Kronoman - In loving memory of my father
7 // Copyright (c) 2003, Kronoman
8 // ------------------------------------------------------------------
15 #include "cwdata.h" // For data handling/loading of tile data
17 // square map size (fixed, sorry ; also, don't get this > 256 because I use chars to determine numbers :P)
20 // sprite size of each tile
24 // map layers (currently, leave this at 2)
27 // ============================================================================
28 // This is a single tile class (defines different kinds of tiles,
29 // each one of this is 1 tile class)
30 // ============================================================================
36 void draw(BITMAP
*bmp
, int x
, int y
, bool draw_grid
, int layer
); // draws the tile on bmp at x,y (pixel coordinates)
38 void load_from_config(int nt
, CWDatafile
*data
); // this loads the tile 'nt' (1.255) from a previously set config
39 void save_to_config(int nt
); // this saves parameters to a previously set config *FILE* (not memory pointer)
42 BITMAP
*spr
; // sprite
43 char spr_name
[512]; // this is to keep sprite name, is just to let the thing save itself when needed (as in a map editor)
45 SAMPLE
*sound
; // sound ; will be played *only* if: a) is a prize and is pickup ; b) is a wall and ball bounces
46 char sound_name
[512]; // this is to keep sound name, is just to let the thing save itself when needed (as in a map editor)
49 bool exit_level
; // this kind of tile is exit level (default = false)
50 bool solid
; // this is totally solid -> IS a WALL? (the ball bounces against it, check bounce factor) (default = false)
51 float bounce_factor
; // a value _positive_ that is 'bounce factor', when solid = true, (default = 0.9)
52 float adx
, ady
,adz
; // when the ball goes over this tile, this is _added_ to the dx,dy,dz values of the ball (default = 0.0)
53 float mdx
, mdy
,mdz
; // when the ball goes over this tile, this is _multiplied_ to the dx,dy,dz values of the ball (default = 1.0)
55 // prize propertys, this are for when the tile belongs to 'prize' layer
56 int score
; // score on pickup
57 bool indispensable
; // we must pickup it to pass the level
58 bool is_a_prize
; // this tile is a 'prize' or just a decoration tile
61 // ============================================================================
62 // This handles a tile map
63 // ============================================================================
70 bool get_tile_walkable(int x
, int y
, int layer
); // this serves for validation purposes (for the ball), will return true if the tile is walkable, false otherwise (outside map counts as non walkable)
72 int get_tile_type(int x
, int y
, int layer
); // this returns the tile type (1..255), or -1 if outside map, or 0 if empty (if empty, or outside map, ball should fall free to death)
74 void set_tile_type(int x
, int y
, int layer
, int value
); // this sets the tile type at x,y (0..255) x,y are coordinates of the matrix
76 bool load_map_from_file(const char *filename
); // load tile map from file, return true if FAILS, false otherwise
77 bool save_map_to_file(const char *filename
); // save tile map to file, return true if FAILS, false otherwise
79 bool load_tile_set_from_file(char *filename
); // loads a tile set from a DATAFILE (filename is the name of the datafile), return true if FAILS, false otherwise
80 bool save_tile_set_config_to_file(char *filename
); // saves the tile set configuration to a text file (not the bitmaps!)
82 void empty_the_map(); // resets all map to 0s
84 void draw_map(BITMAP
*bmp
, int ix
, int iy
, int iw
, int ih
, int layer
, bool draw_grid
); // draws a zone of the map, coordinates in pixels
86 void free_memory(); // releases the memory, auto called on destructor
88 void update_logic(); // updates the logic of the map (animations, time remaining, etc)
90 // -- data, all public for faster access --
91 int tile_map
[TMAP_SIZE
][TMAP_SIZE
][MAP_LAYERS
]; // tile map loaded, is divided in layers, 0 = floor, 1 = prizes, DON'T USE MORE (is like this for future ampliation only)
93 CTileClass tile_set
[256]; // tile class loaded (each tilem[][] is a index in this array) ; NOTE: 0 is reserved for empty tile index!!!, so this goes 1..255 for valid tiles
95 CWDatafile tile_set_data
; // this is the data loaded from file (has the sprites, etc of the tile_set array)
97 int background_index
; // ID index of background, ranges from 0...255
98 int music_index
; // ID index of the music, ranges from 0..255
100 int prize_map_indispensable
; // ammount of indispensable items on map (if > 0, you can't leave the map)
101 int time_m
; // minutes (0..255) left to try to collect items and reach exit
102 int time_s
; // seconds (0..59) left to try to collect items and reach exit
103 int timer_tick_rate
; // set this to measure timer tick rate, otherwise, the time will run wild (ex: if update logic is called 30 times by second, then set this to 30)
104 int curr_tick
; // internal current tick measurer, when reaches 0, time_s --;
106 int sxp
, syp
; // starting position for the player (is the first 2 bytes of the map file, 0..255, 0..255)