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

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

game: refactor the GetFg? methods to use vec2i.

  • Property svn:keywords set to Id
File size: 4.3 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This software was released into the Public Domain. As with most public
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[2]11#ifndef __GAME_HPP_
12#define __GAME_HPP_
13
[481]14#include "loader2.h"
[2]15
[481]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"
[2]28
[124]29#define MAPFW                100
30#define MAPFH                100
31#define MAPBW                100
32#define MAPBH                100
[2]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
[88]45/* Cleaned-up externs */
[120]46extern WindowManager *wm;
[88]47
48
[2]49#define tile_type unsigned short
[127]50class Game;
51extern Game *the_game;
[2]52extern int dev;
53extern int morph_sel_frame_color;
54
55extern char **start_argv;
56extern int start_argc;
[16]57extern int32_t current_vxadd,current_vyadd;
[2]58extern int frame_panic,massive_frame_panic;
59extern int demo_start,idle_ticks;
60
[39]61extern FILE *open_FILE(char const *filename, char const *mode);
62
[127]63class Game
[2]64{
[657]65public:
66    Game(int argc, char **argv);
67    ~Game();
68
[127]69private:
[2]70  JCFont *fnt;
[127]71  bool finished;
[2]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
[16]76  int32_t last_time,fps;
[2]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
[120]82  Jwindow *top_menu,*joy_win,*last_input;
[2]83  JCFont *game_font;
[17]84  uint8_t keymap[512/8];
[2]85
[124]86public :
[2]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();
[39]96  void show_help(char const *st);
[2]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
[124]102  backtile *get_bg(int x) { if (x<0 || x>=nbacktiles || backtiles[x]<0)
103                           return cache.backt(backtiles[BLACK]);
[123]104                           else return cache.backt(backtiles[x]); }
[124]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]); }
[2]108
[657]109    vec2i GetFgTile(vec2i pos);
110    vec2i GetBgTile(vec2i pos);
[2]111  void toggle_delay();
112  void set_delay(int on) { no_delay=!on; }
113  void pan(int xv, int yv);
114
[657]115    vec2i MouseToGame(vec2i pos, view *v = NULL);
116    vec2i GameToMouse(vec2i pos, view *v);
117    view *GetView(vec2i pos);
[2]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
[666]127    void PutFg(vec2i pos, int type);
128    void PutBg(vec2i pos, int type);
[2]129  void draw_map(view *v, int interpolate=0);
130  void dev_scroll();
131
[643]132  int in_area(Event &ev, int x1, int y1, int x2, int y2);
[39]133  void load_level(char const *name);
[2]134  void set_level(level *nl);
135  void show_time();
[666]136    tile_type GetMapBg(vec2i pos) { return current_level->GetBg(pos); }
137    tile_type GetMapFg(vec2i pos) { return current_level->GetFg(pos); }
[2]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();
[643]145  void joy_calb(Event &ev);
146  void menu_select(Event &ev2);
[2]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);
[16]152  void play_sound(int id, int vol, int32_t x, int32_t y);
[2]153  void request_level_load(char *name);
154  void request_end();
[666]155};
[2]156
157extern int playing_state(int state);
158#endif
159
160
Note: See TracBrowser for help on using the repository browser.