Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
MoofWars/TEnemySprite.cp
/* |
File: TEnemySprite.cp |
Contains: This is the class used to represent the enemy ship in the game. Eventually, |
one ship class will represent both friendly and enemy ships, since the only |
major difference is the keyset. A computer controlled ship could be different. |
Written by: Timothy Carroll |
Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
7/2/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
1/23/97 Timothy Carroll Added include for Moofwars.h so that MrC |
will compile |
8/15/96 Timothy Carroll Initial Release |
*/ |
#include "Moofwars.h" |
#include "TEnemySprite.h" |
#include "TShotSprite.h" |
TEnemySprite::TEnemySprite (TEnemySpriteData *data): |
TSprite((TSpriteData *) data) |
{ |
fRotateInterval = data->rotateInterval; |
fRotateValue = 0; |
fShotInterval = data->shotInterval; |
fShotValue = 0; |
fShotsGroup = data->shotsGroup; |
} |
TEnemySprite::~TEnemySprite (void) |
{ |
} |
void |
TEnemySprite::ProcessSprite () |
{ |
// The enemy can thrust in either direction |
if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyThrustForward)) |
{ |
fVelocityY -= gSinLookup [fFace] >> 1; |
fVelocityX -= gCosLookup [fFace] >> 1; |
} |
if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyThrustBackward)) |
{ |
fVelocityY += gSinLookup [fFace] >> 1; |
fVelocityX += gCosLookup [fFace] >> 1; |
} |
// Fire a shot |
if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyFireShots) && fShotValue == 0) |
{ |
TShotSpriteData shotData; |
TShotSprite *shot; |
int index; |
// Delay for next set of shots |
fShotValue = fShotInterval; |
shotData.spriteData.spriteType = TShotSprite::kSpriteType; |
shotData.spriteData.visibility = kVisible; |
shotData.spriteData.face = 1; |
shotData.spriteData.collectionID = 1001; |
shotData.spriteData.preloadedCollection = NULL; |
shotData.duration = 60; |
index = fFace; |
shotData.spriteData.initialX = fCoordX - 60*gCosLookup [index]; |
shotData.spriteData.initialY = fCoordY - 60*gSinLookup [index]; |
shotData.spriteData.initialXVelocity = fVelocityX - 30*gCosLookup[index]; |
shotData.spriteData.initialYVelocity = fVelocityY - 30*gSinLookup[index]; |
shot = new TShotSprite (&shotData); |
shot->AddToGroup (fShotsGroup); |
} |
// Rotate right |
if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyRotateRight) && fRotateValue == 0) |
{ |
fFace = (fFace+1) % 48; |
fRotateValue = fRotateInterval; |
} |
// Rotate left |
if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyRotateLeft) && fRotateValue == 0) |
{ |
fFace = (fFace+47) % 48; |
fRotateValue = fRotateInterval; |
} |
// Adjust our intervals |
if (fRotateValue > 0) |
fRotateValue--; |
if (fShotValue > 0) |
fShotValue--; |
TSprite::ProcessSprite(); |
TSprite::Bounce (&gWorldBounds); |
} |
void |
TEnemySprite::Collision (TSprite *theSprite) |
{ |
#if qUsingSound |
if (gPlayingSound) |
HY_PlaySoundHandle (2, gSounds[3], NULL, 0, false); |
#endif |
// We take on some of the velocity of the shot. |
TShotSprite *theTarget = (TShotSprite *) theSprite; |
//this->fCurVelocityX += theTarget->GetXVelocity() >> 9; |
//this->fCurVelocityY += theTarget->GetYVelocity() >> 9; |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-10-14