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

Last change on this file since 682 was 682, checked in by Sam Hocevar, 9 years ago

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

  • Property svn:keywords set to Id
File size: 4.3 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, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#ifndef __GAME_HPP_
12#define __GAME_HPP_
13
14#include "loader2.h"
15
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{
65public:
66    Game(int argc, char **argv);
67    ~Game();
68
69private:
70  JCFont *fnt;
71  bool finished;
72  int bg_top,fg_top;                         // in the fg/bg window which tile is at the top?
73  int bright_color,med_color,dark_color,     // for boundaries and windows, etc
74      morph_bright_color,morph_med_color,morph_dark_color;
75
76  int32_t last_time,fps;
77  char mapname[100],command[200],help_text[200];
78  int refresh,mousex,mousey,help_text_frames;
79  int has_joystick,no_delay;
80
81
82  Jwindow *top_menu,*joy_win,*last_input;
83  JCFont *game_font;
84  uint8_t keymap[512/8];
85
86public :
87  int key_down(int key) { return keymap[key/8]&(1<<(key%8)); }
88  void set_key_down(int key, int x) { if (x) keymap[key/8]|=(1<<(key%8)); else keymap[key/8]&=~(1<<(key%8)); }
89  void reset_keymap() { memset(keymap,0,sizeof(keymap)); }
90
91  int nplayers;
92  view *first_view,*old_view;
93  int state,zoom;
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    ivec2 GetFgTile(ivec2 pos);
110    ivec2 GetBgTile(ivec2 pos);
111  void toggle_delay();
112  void set_delay(int on) { no_delay=!on; }
113  void pan(int xv, int yv);
114
115    ivec2 MouseToGame(ivec2 pos, view *v = NULL);
116    ivec2 GameToMouse(ivec2 pos, view *v);
117    view *GetView(ivec2 pos);
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 PutFg(ivec2 pos, int type);
128    void PutBg(ivec2 pos, int type);
129  void draw_map(view *v, int interpolate=0);
130  void dev_scroll();
131
132  int in_area(Event &ev, int x1, int y1, int x2, int y2);
133  void load_level(char const *name);
134  void set_level(level *nl);
135  void show_time();
136    tile_type GetMapBg(ivec2 pos) { return current_level->GetBg(pos); }
137    tile_type GetMapFg(ivec2 pos) { return current_level->GetFg(pos); }
138  void end_session();
139  void need_refresh() { refresh=1; }       // for development mode only
140  palette *current_palette() { return pal; }
141
142  void update_screen();
143  void get_input();
144  void do_intro();
145  void joy_calb(Event &ev);
146  void menu_select(Event &ev2);
147  int can_morph_into(int type);
148  void morph_into(int type);
149  void set_state(int new_state);
150  int game_over();
151  void grow_views(int amount);
152  void play_sound(int id, int vol, int32_t x, int32_t y);
153  void request_level_load(char *name);
154  void request_end();
155};
156
157extern int playing_state(int state);
158#endif
159
160
Note: See TracBrowser for help on using the repository browser.