//------------------------------------------------------------------------------ // File: gfx.c // Author: George Bain // Date: May 14, 1997 // Description: Graphic and game related routines // Copyright (C) 1997 George Bain, All Rights Reserved //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // I N C L U D E S //------------------------------------------------------------------------------ #include // standard Sony library #include "gfx.h" //------------------------------------------------------------------------------ // G L O B A L S //------------------------------------------------------------------------------ int cos_look[SCREEN_WIDTH]; //------------------------------------------------------------------------------ // Function: InitSprite() // Description: Initialize members of sprite // Parameters: Lots..read comments below // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void InitSprite( object_ptr object, unsigned long attribute, short x, short y, unsigned short w, unsigned short h, unsigned short tpage, unsigned char u, unsigned char v, short cx, short cy, unsigned char r, unsigned char g, unsigned char b, short mx, short my, short scalex, short scaley, long rotate ) { int count; // init GsSPRITE object->sprite.attribute = attribute; // 32-bit attributes object->sprite.x = x; // x display position object->sprite.y = y; // y display position object->sprite.w = w; // width of sprite object->sprite.h = h; // height of sprite object->sprite.tpage = tpage; // sprite pattern texture page number object->sprite.u = u; // sprite pattern in-page x offset object->sprite.v = v; // sprite pattern in-page y offset object->sprite.cx = cx; // CLUT address object->sprite.cy = cy; // CLUT address object->sprite.r = r; // red brightness ( 127 is normal ) object->sprite.g = g; // green brightness object->sprite.b = b; // blue brightness object->sprite.mx = mx; // rotation/expansion central coordinates object->sprite.my = my; // rotation/expansion central coordinates object->sprite.scalex = scalex; // x direction scaling values object->sprite.scaley = scaley; // y direction scaling values object->sprite.rotate = rotate; // rotation angle( Units:4096= 1 degree ) // init object object->dir= 0; // direction of the object object->anim_clock= 0; // animation clock object->anim_speed= 0; // animation speed object->curr_frame= 0; // current frame being displayed object->num_frames= 0; // total number of frames object->state= 0; // state of the object object->motion_speed= 0; // motion speed }// end InitSprite //------------------------------------------------------------------------------ // Function: InitParticle() // Description: Initialize the particle // Parameters: Lots..read the comments below // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void InitParticle( particle_ptr particle, short x, short y, u_short w, u_short h, unsigned char r, unsigned char g, unsigned char b, int xv, int yv, int state, int tag, int counter) { // init GSBOXF particle->rect.attribute = 0x00000000; particle->rect.x = x; // x position of particle particle->rect.y = y; // y position of particle particle->rect.w = w; // width of particle particle->rect.h = h; // height of particle particle->rect.r = r; // r color value particle->rect.g = g; // g color value particle->rect.b = b; // b color value // init paritcle particle->xv = xv; // x velocity of particle particle->yv = yv; // y velocity of particle particle->state = state; // the state of the particle particle->tag = tag; // who's particle particle->counter = counter; // a counter }// end InitParticle //------------------------------------------------------------------------------ // Function: GetFrame() // Description: Gets a frame from a picture image // Parameters: Lots..read the comments below // Returns: void // Notes: This needs improvement //------------------------------------------------------------------------------ void GetFrame( object_ptr sprite, short sprite_w, short sprite_h, short grab_x, short grab_y, int sprite_frame ) { sprite->sprite.u = grab_x; // sprite pattern in-page x offset sprite->sprite.v = grab_y; // sprite pattern in-page y offset sprite->sprite.w = sprite_w; // width of sprite sprite->sprite.h = sprite_h; // height of sprite sprite->curr_frame = sprite_frame; // animation frame }// end GetFrame //------------------------------------------------------------------------------ // Function: RandLocation() // Description: Get a random y location for the enemy path // Parameters: none // Returns: int // Notes: N/A //------------------------------------------------------------------------------ short RandLocation( void ) { short loc_y = 0; loc_y = rand()%200; if( loc_y < 10 ) loc_y = 20; else if( loc_y > 165 ) loc_y = 165; return loc_y; }// end RandLocation //------------------------------------------------------------------------------ // Function: CreateLookup() // Description: Creat cosine lookup table // Parameters: none // Returns: none // Notes: N/A //------------------------------------------------------------------------------ void CreateLookup( void ) { int index; for( index=0; index<320; index++ ) cos_look[index]= (int)(2*cos(3.14*5*(float)index/180)); }// end CreateLookup //------------------------------------------------------------------------------ // Function: GetBoundingBox() // Description: Calculate the bounding box of the sprite and missile // Parameters: particle_ptr missile: the current missile // object_ptr sprite: the current sprite // Returns: int // Notes: N/A //------------------------------------------------------------------------------ int MissileCollision( particle_ptr missile, object_ptr sprite) { if( missile->rect.x > (sprite->sprite.x + sprite->sprite.w-1) || sprite->sprite.x > (missile->rect.x + missile->rect.w-1) || missile->rect.y > (sprite->sprite.y + sprite->sprite.h-1) || sprite->sprite.y > (missile->rect.y + missile->rect.h-1) ) { return(0); // NO HIT } else { return(1); // HIT } }// end MissileCollision //------------------------------------------------------------------------------ // Function: SpriteCollision() // Description: Calculate the bounding box of two sprites // Parameters: object_ptr sprite: first sprite // object_ptr sprite_two: second sprite // Returns: int // Notes: N/A //------------------------------------------------------------------------------ int SpriteCollision( object_ptr sprite, object_ptr sprite_two) { if( sprite->sprite.x > (sprite_two->sprite.x + sprite_two->sprite.w-1) || sprite_two->sprite.x > (sprite->sprite.x + sprite->sprite.w-1) || sprite->sprite.y > (sprite_two->sprite.y + sprite_two->sprite.h-1) || sprite_two->sprite.y > (sprite->sprite.y + sprite->sprite.h-1) ) { return(0); // NO HIT } else { return(1); // HIT } }// end SpriteCollision //-----------------------------------EOF----------------------------------------