1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
|
/*
Overgod
Copyright (C) 2005 Linley Henzell
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation; either version 2 of the Licence, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GPL version 2 is included in this distribution in a file called
LICENCE.TXT. Use any text editor or the TYPE command to read it.
You should be able to reach me by sending an email to
l_henzell@yahoo.com.au.
File: Main.c
History:
11/9/2005 - Version 1.0 finalised
This file contains:
- main()
- various initialisation functions
- miscellaneous stuff
*/
/*
Your guide to source files:
(for more information visit the files themselves)
actor.c
- functions for dealing with actors (ie players' ships)
bullet.c
- creation, movement and collision of bullets
cloud.c
- clouds - ie non-bullet special effects
cmds.c
- makes actors implement commands issued in input.c
displ_in.c
- initialises the display and loads bitmaps
display.c
- shows things on the screen
eclass.c
- big struct containing enemy data
enemy.c
- horrible code for all enemies
game.c
- the game loop and a few special functions
input.c
- takes keyboard input
levels.c
- initialises and manages the levels, enemy spawning etc
light.c
- like cloud.c but for lights
main.c
- this file
menu.c
- the front-end interface
palette.c
- the palette and transparency functions
pickup.c
- pickups are symbols/repair/weapons
score.c
- deals with scoring
sound.c
- initialises and plays sounds
stuff.c
- small, very generic functions (like grand)
tile.c
- generates the background graphics, which are displayed in display.c
Most .h files just contain function definitions. But some are special:
config.h
- structs, enums and #defines
globvar.h
- extern declarations of global variables
sound.h
- the WAV_xxx sound enum
palette.h
- the COLOUR_xxx and TRANS_xxx enums
display.h
- all the graphics enums
*/
#include "allegro.h"
//#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
//#include <pc.h>
#include <math.h>
#include "config.h"
#include "palette.h"
#include "displ_in.h"
#include "display.h"
#include "cmds.h"
#include "input.h"
#include "actor.h"
//#include "stars.h"
#include "bullet.h"
#include "cloud.h"
//#include "ships.h"
#include "enemy.h"
#include "levels.h"
#include "menu.h"
#include "sound.h"
#include "stuff.h"
// Global variables:
struct gamestruct game;
struct playerstruct player [NO_PLAYERS];
struct actorstruct actor [NO_ACTORS];
struct bulletstruct bullet [NO_BULLETS];
struct cloudstruct cloud [NO_CLOUDS];
struct starstruct star [NO_STARS];
struct arenastruct arena;
struct enemystruct enemy [NO_ENEMIES];
unsigned char counter;
struct pickupstruct pickup [NO_PICKUPS];
// --- end global variables
// timer interupt functions and variables:
void framecount(void);
volatile int framecounter;
volatile int frames_per_second;
volatile int inputcounter = 0;
volatile int inputs_per_second = 0;
volatile int turncounter = 0;
volatile int turns_per_second = 0;
void tickover(void);
volatile unsigned char ticked;
//volatile unsigned char tick_counter;
int slacktime;
// --- end timer interupt
extern int grid_offset_x_2p_finetune;
// init functions
void init_at_startup(void);
void begin_game(void);
// --- end init functions
void game_loop(void);
struct optionstruct options;
void framecount(void)
{
frames_per_second = framecounter;
framecounter = 0;
// turns_per_second = turncounter;
// turncounter = 0;
// inputs_per_second = inputcounter;
// inputcounter = 0;
// arena.time_left --;
}
END_OF_FUNCTION (framecount);
void tickover(void)
{
ticked ++;
// tick_counter++; // assumes it'll wrap at 256
}
END_OF_FUNCTION (tickover);
int main(void)
{
int allint = allegro_init();
if (allint == -1)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Failed to initialise Allegro! This isn't going to work, sorry.");
exit(1);
}
install_keyboard();
install_timer();
three_finger_flag = 0;
key_led_flag = 0;
init_at_startup();
menu_loop();
return 0;
}
END_OF_MAIN();
void init_at_startup(void)
{
LOCK_FUNCTION (framecount);
LOCK_FUNCTION (tickover);
LOCK_VARIABLE (ticked);
// LOCK_VARIABLE (tick_counter);
LOCK_VARIABLE (frames_per_second);
LOCK_VARIABLE (framecounter);
LOCK_VARIABLE (turns_per_second);
LOCK_VARIABLE (turncounter);
// LOCK_VARIABLE (inputs_per_second);
// LOCK_VARIABLE (inputcounter);
install_int (framecount, 1000);
install_int (tickover, 30);
set_color_depth(8);
char *home, config_file[4096];
home = getenv("HOME");
if(!home)
home = ".";
snprintf(config_file, 4095, "%s/.overgod.cfg", home);
config_file[4095] = '\0';
set_config_file(config_file);
options.resolution = get_config_int("Options", "Resolution", 0);
int randseed = get_config_int("Misc", "Seed", 0);
srand(randseed);
int windowed = GFX_AUTODETECT_FULLSCREEN;
switch(options.resolution)
{
// case 640:
case 0:
graphics_mode = GMODE_640_480;
break;
case 1:
graphics_mode = GMODE_800_600;
break;
case 2:
graphics_mode = GMODE_640_480;
windowed = GFX_AUTODETECT_WINDOWED;
break;
case 3:
graphics_mode = GMODE_800_600;
windowed = GFX_AUTODETECT_WINDOWED;
break;
/* case 1024:
graphics_mode = GMODE_1024_768;
break;*/
}
scr_x = 640;
scr_y = 480;
tp_window_width = 315;
grid_offset_x_1p = 0;//35000;
grid_offset_x_2p = -3;//32000;
// grid_offset_x_2p = 32000 + 850000;
grid_offset_x_2p_finetune = -13;
grid_offset_y = 0;
special_600_y = 0;
text_offset_x_1p = 0;
text_offset_x_2p = 0;
text_offset_x = 0;
text_offset_y = 0;
grid_finetune_x_1p = 0;
grid_finetune_y = 0;
visible_grids_y = 15;
switch(graphics_mode)
{
case GMODE_800_600:
scr_x = 800;
scr_y = 600;
tp_window_width = 395;
grid_offset_x_1p = 3;//5000;
grid_offset_x_2p = -3;//8000;//-2000;
grid_finetune_x_1p = 31;
grid_finetune_x_2p = 10;
grid_offset_x_2p_finetune = -22;
grid_finetune_y = -90;
grid_offset_y = -10000;
special_600_y = -5;
text_offset_y = 60;
text_offset_x = 80;
visible_grids_y = 60;
special_600_y = 2;
break;
/* case GMODE_1024_768:
scr_x = 1024;
scr_y = 768;
tp_window_width = 507;
grid_offset_x_1p = 43000;
grid_offset_x_2p = 2000;
grid_offset_y = 6000;
special_600_y = 0;
text_offset_y = 144;
text_offset_x = 192;
break;
not working
*/
}
if (set_gfx_mode(windowed, scr_x, scr_y, 0, 0) != 0)
// if (set_gfx_mode(GFX_DIRECTX_FULLSCREEN, scr_x, scr_y, 0, 0) != 0)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Unable to set %ix%i display mode\n%s\n", scr_x, scr_y, allegro_error);
exit(1);
}
init_trig(); // can't use any integer trig before this!
init_palette();
init_display();
init_menus_once_only();
init_sound(); // must come after init_menus_once_only, as that's where
// options.sound_enabled is set.
}
|