source: abuse/trunk/src/game.h @ 494

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#ifndef __GAME_HPP_
12#define __GAME_HPP_
13
14#include "loader2.h"
15
16#include "macs.h"
17#include "image.h"
18#include "video.h"
19#include "event.h"
20#include "fonts.h"
21#include "items.h"
22#include "jwindow.h"
23#include "filter.h"
24#include "level.h"
25#include "cache.h"
26#include "director.h"
27#include "view.h"
28#include "id.h"
29
30#define MAPFW                100
31#define MAPFH                100
32#define MAPBW                100
33#define MAPBH                100
34
35#define RUN_STATE 0
36#define PAUSE_STATE 1
37#define HELP_STATE 2
38#define INTRO_START_STATE 3
39#define INTRO_MORPH_STATE 4
40#define JOY_CALB_STATE    5
41#define MENU_STATE        6
42#define SCENE_STATE       7
43#define START_STATE       8
44#define BLACK 0
45
46/* Cleaned-up externs */
47extern WindowManager *wm;
48
49
50#define tile_type unsigned short
51class Game;
52extern Game *the_game;
53extern int dev;
54extern int morph_sel_frame_color;
55
56extern char **start_argv;
57extern int start_argc;
58extern int32_t current_vxadd,current_vyadd;
59extern int frame_panic,massive_frame_panic;
60extern int demo_start,idle_ticks;
61
62extern FILE *open_FILE(char const *filename, char const *mode);
63
64class Game
65{
66private:
67  JCFont *fnt;
68  bool finished;
69  int bg_top,fg_top;                         // in the fg/bg window which tile is at the top?
70  int bright_color,med_color,dark_color,     // for boundaries and windows, etc
71      morph_bright_color,morph_med_color,morph_dark_color;
72
73  int32_t last_time,fps;
74  char mapname[100],command[200],help_text[200];
75  int refresh,mousex,mousey,help_text_frames;
76  int has_joystick,no_delay;
77
78
79  Jwindow *top_menu,*joy_win,*last_input;
80  JCFont *game_font;
81  uint8_t keymap[512/8];
82
83public :
84  int key_down(int key) { return keymap[key/8]&(1<<(key%8)); }
85  void set_key_down(int key, int x) { if (x) keymap[key/8]|=(1<<(key%8)); else keymap[key/8]&=~(1<<(key%8)); }
86  void reset_keymap() { memset(keymap,0,sizeof(keymap)); }
87
88  int nplayers;
89  view *first_view,*old_view;
90  int state,zoom;
91
92  Game(int argc, char **argv);
93  ~Game();
94
95  void step();
96  void show_help(char const *st);
97  void draw_value(image *screen, int x, int y, int w, int h, int val, int max);
98  unsigned char get_color(int x) { return x; }
99  int done();
100  void draw(int scene_mode=0);
101
102  backtile *get_bg(int x) { if (x<0 || x>=nbacktiles || backtiles[x]<0)
103                           return cache.backt(backtiles[BLACK]);
104                           else return cache.backt(backtiles[x]); }
105  foretile *get_fg(int x) { if (x<0 || x>=nforetiles || foretiles[x]<0)
106                           return cache.foret(foretiles[BLACK]); else
107               return cache.foret(foretiles[x]); }
108
109  void ftile_on(int screenx, int screeny, int32_t &x, int32_t &y);
110  void btile_on(int screenx, int screeny, int32_t &x, int32_t &y);
111  void toggle_delay();
112  void set_delay(int on) { no_delay=!on; }
113  void pan(int xv, int yv);
114
115  void mouse_to_game(int32_t x, int32_t y, int32_t &gamex, int32_t &gamey, view *v=NULL);
116  void game_to_mouse(int32_t gamex, int32_t gamey, view *which, int32_t &x, int32_t &y);
117  view *view_in(int mousex, int mousey);
118
119  int calc_speed();
120  int ftile_width()  { return f_wid; }
121  int ftile_height() { return f_hi; }
122
123  int btile_width()  { return b_wid; }
124  int btile_height() { return b_hi; }
125
126
127  void put_fg(int x, int y, int type);
128  void put_bg(int x, int y, int type);
129  void draw_map(view *v, int interpolate=0);
130  void dev_scroll();
131  void put_block_fg(int x, int y, trans_image *im);
132  void put_block_bg(int x, int y, image *im);
133
134
135  int in_area(event &ev, int x1, int y1, int x2, int y2);
136  void load_level(char const *name);
137  void set_level(level *nl);
138  void show_time();
139  tile_type get_map_bg(int x, int y) { return current_level->get_bg(x,y); }
140  tile_type get_map_fg(int x, int y) { return current_level->get_fg(x,y); }
141  void end_session();
142  void need_refresh() { refresh=1; }       // for development mode only
143  palette *current_palette() { return pal; }
144
145  void update_screen();
146  void get_input();
147  void do_intro();
148  void joy_calb(event &ev);
149  void menu_select(event &ev2);
150  int can_morph_into(int type);
151  void morph_into(int type);
152  void set_state(int new_state);
153  int game_over();
154  void grow_views(int amount);
155  void play_sound(int id, int vol, int32_t x, int32_t y);
156  void request_level_load(char *name);
157  void request_end();
158} ;
159
160extern int playing_state(int state);
161#endif
162
163
Note: See TracBrowser for help on using the repository browser.