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

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

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

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