home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
game
/
moonrocks.lha
/
MoonRocks
/
game.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-14
|
34KB
|
1,270 lines
/*
* MOON ROCKS by Alan Bland. This is an example game using the
* GameSmith Development System. You are free to use portions of
* this source code for any purpose whatsoever. This isn't
* necessarily the best way to use GDS for this type of game,
* but it shows usage of many of the components of GDS (anims,
* anim complexes, sounds, scrolling background, multiple viewports,
* RastPort usage, background collision detection).
*
* This game won't work on an OCS Amiga because of the large
* scrolling superbitmap. It may also require 1 meg of chip ram.
*
* The elvis animation is based on the "tiny elvis" public domain
* screen hack for Microsoft Windows. I changed it around quite
* a bit to reduce the color palette and to make different dancing
* motions from the original.
*
* Call CYBERMIGA BBS at 1-303-939-9923. Lots of Amiga files!
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <math.h>
#include <intuition/intuition.h>
#include <exec/memory.h>
#include <exec/types.h>
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include "GameSmith:GameSmith.h"
#include "GameSmith:include/libraries/libptrs.h"
#include "GameSmith:include/proto/all_regargs.h"
/* header file for anim complexes */
#include "lc.h"
#include "rs.h"
#define DDEPTH 3
#define NUM_COLORS 8
#define VP2_HEIGHT 19
#define VP2_DEPTH 3
#define VP2_NUM_COLORS 8
#define DWIDTH 320
#define DHEIGHT (200-VP2_HEIGHT-3)
#define DISP_MODE 0
#define X_SCROLLPOS (DWIDTH/3)
#define Y_SCROLLTOP (DHEIGHT/4)
#define Y_SCROLLBOT (DHEIGHT/2)
/* this defines the vertical position below which the spacecraft
* can collide with background objects. see main loop comments.
*/
#define GROUND_THRESHOLD (bmheight-52)
/* this is how close (pixels) we must land to the target to win the game */
#define CLOSE_ENOUGH 250
#define MAX_FUEL 3000
#define LOW_FUEL 300
/* physical constants */
#define MAX_ALTITUDE 70000.0
#define MAX_RANGE 50000.0
#define GRAVITY 5.0
#define THRUST 10.0
#define SAFE_SPEED 200.0
/* To be strictly accurate, I think this should be 60 for NTSC, 50 for PAL */
#define TICKS_PER_SEC 60
/* joystick responsiveness - set to 0 for fastest */
#define JOY_INTERVAL 3
/* how often to animate the rock star */
#define DANCE_DELAY 5
unsigned char time_to_dance;
short dance_time;
unsigned char rockstar_visible; /* is he visible? */
unsigned long rockstar_time; /* next time that he changes animation */
unsigned char allow_rockstar; /* allow him to materialize */
/*
* The VP2 bitmap has several different control panel images which we
* scroll into view as necessary. The top image is the normal panel.
* These constants define the scroll offset for each image.
*/
#define VP_PAUSED VP2_HEIGHT
#define VP_NOWHERE (VP2_HEIGHT*2)
#define VP_VISIBLE (VP2_HEIGHT*3)
#define VP_CRASHED (VP2_HEIGHT*4)
#define VP_SUCCESS (VP2_HEIGHT*5)
unsigned long lunar_cmap[NUM_COLORS];
unsigned long vp2_cmap[VP2_NUM_COLORS];
/* need a copper list to turn off sprites */
unsigned short copper_list[] = {
UC_WAIT, 0, 0, UC_NOSPRITES, UC_END
};
struct copper_struct copper =
{
copper_list,
NULL,
NULL
};
/*
* vp is the viewport for the main viewing area.
* vp2 is the control panel at the bottom of the screen.
*/
struct gs_viewport vp2 = {
NULL, /* ptr to next viewport */
vp2_cmap, /* ptr to color table */
VP2_NUM_COLORS, /* number of colors in table */
&copper, /* ptr to user copper list */
VP2_HEIGHT,DWIDTH,VP2_DEPTH, /* height, width, depth */
0,0, /* bmheight, bmwidth */
DHEIGHT+2,0, /* top & left viewport offsets */
0,0, /* X & Y bitmap offsets */
0, /* flags */
NULL,NULL, /* 2.xx & above compatibility stuff */
NULL,NULL, /* bitmap pointers */
NULL, /* future expansion */
0,0,0,0 /* display clip (use nominal) */
};
struct gs_viewport vp = {
&vp2, /* ptr to next viewport */
lunar_cmap, /* ptr to color table */
NUM_COLORS, /* number of colors in table */
NULL, /* ptr to user copper list */
DHEIGHT,DWIDTH,DDEPTH, /* height, width, depth */
0,0, /* bmheight, bmwidth */
0,0, /* top & left viewport offsets */
0,0, /* X & Y bitmap offsets */
0, /* flags */
NULL,NULL, /* 2.xx & above compatibility stuff */
NULL,NULL, /* bitmap pointers */
NULL, /* future expansion */
0,0,0,0 /* display clip (use nominal) */
};
struct display_struct lunar_display = {
NULL, /* ptr to previous display view */
NULL,NULL, /* 2.xx & above compatibility stuff */
0,0, /* X and Y display offsets (1.3 style) */
DISP_MODE, /* display mode ID */
GSV_DOUBLE|GSV_SCROLLABLE, /* flags (double buffered, scrollable) */
&vp, /* ptr to 1st viewport */
NULL /* future expansion */
};
struct anim_cplx *lem; /* the spacecraft anim complex */
struct anim_cplx *rockstar; /* the rock star anim complex */
struct display_struct *display; /* points at lunar_display if it got created ok */
struct Interrupt *scroller=NULL; /* interrupt handler for smooth scrolling */
int dlist=-1; /* display list used with anim system */
int bmwidth;
int bmheight;
struct RastPort rp; /* RastPort for writing text to the control panel */
struct BitMap *cp_bitmaps[2]; /* need to double-buffer bitmaps for RastPort */
struct TextAttr sysfont = { /* control panel will be topaz.8 */
"topaz.font", 8, 0, 0
};
struct TextFont *myfont;
short elapsed_mins;
short elapsed_secs;
short elapsed_ticks;
/*
* The MED module uses channels 0 and 1. Sound effects are on 2 and 3
* except for the PING sound, which is only played without music so it's
* on one of the music channels.
*/
#include "libproto.h"
struct MMD0 *tune;
struct Library *MEDPlayerBase;
/*
* structures and channel assignments for each sound.
*/
#define THRUST_CHANNEL CHANNEL2
#define WHOOP_CHANNEL CHANNEL3
#define PING_CHANNEL CHANNEL1
#define FILL_CHANNEL CHANNEL3
#define KABOOM_CHANNEL CHANNEL2
#define LANDED_CHANNEL CHANNEL3
struct sound_struct thrust;
struct sound_struct whoop;
struct sound_struct kaboom;
struct sound_struct landed;
struct sound_struct ping;
struct sound_struct fill;
/* the "lc" anim complex contains zillions of short anims showing the
spacecraft at various rotation angles (increments of 15 degrees),
with and without flames. the "lc_flame" array lists the anims with
flames in clockwise rotation order. "lc_noflame" lists the anims
without flames. */
#define LC_ANIM_COUNT 24
short lc_flame[LC_ANIM_COUNT] = {
FLAME00, FLAME15, FLAME30, FLAME45, FLAME60, FLAME75,
FLAME90, FLAME105, FLAME120, FLAME135, FLAME150, FLAME165,
FLAME180, FLAME195, FLAME210, FLAME225, FLAME240, FLAME255,
FLAME270, FLAME285, FLAME300, FLAME315, FLAME330, FLAME345
};
short lc_noflame[LC_ANIM_COUNT] = {
LEM00, LEM15, LEM30, LEM45, LEM60, LEM75,
LEM90, LEM105, LEM120, LEM135, LEM150, LEM165,
LEM180, LEM195, LEM210, LEM225, LEM240, LEM255,
LEM270, LEM285, LEM300, LEM315, LEM330, LEM345
};
/* sines and cosines are pre-computed for each 15 degree rotational
position. this makes the game fast enough to run on an old
68000 Amiga without a math chip. */
double sinval[LC_ANIM_COUNT] = {
-1.000000, -0.966168, -0.866519, -0.707840, -0.500941, -0.259916,
0.000000, 0.258771, 0.499914, 0.707002, 0.865927, 0.965862,
1.000000, 0.966015, 0.866223, 0.707421, 0.500428, 0.259344,
0.000593, -0.258199, -0.499401, -0.706583, -0.865630, -0.965708
};
double cosval[LC_ANIM_COUNT] = {
-0.000889, 0.257913, 0.499144, 0.706373, 0.865482, 0.965631,
1.000000, 0.965939, 0.866075, 0.707212, 0.500171, 0.259058,
0.000296, -0.258485, -0.499658, -0.706792, -0.865778, -0.965785,
-1.000000, -0.966092, -0.866371, -0.707630, -0.500684, -0.259630
};
/* The "craft" structure defines the current physical attributes of
the spacecraft. */
struct {
int fuel; /* fuel remaining */
int index; /* array index into lc_flame/lc_noflame which indicates
the current rotation of the spac