
#import <libc.h>
#import "NXISaucer.h"
#import "NXIGameBrain.h"
#import "NXIPlayer.h"


@implementation NXISaucer

- init
{
	id ret = [super init];
	renderedImage = [NXImage findImageNamed:"Saucer.tiff"];
	NX_HEIGHT(&boundingBox) = SAUCER_WIDTH;
	NX_WIDTH(&boundingBox) = SAUCER_HEIGHT;
	maxFrames[0] = SAUCER_FRAMES;
	nextTime = SAUCER_DELAY;
	return ret;
}

- setStage:aStage
{
	id ret = [super setStage:aStage];
	NXRect bounds;
	[[aStage bufferType:GK_SCREEN_BUFFER] getBounds:&bounds];
	screenWidth = NX_WIDTH(&bounds);
	screenHeight = NX_HEIGHT(&bounds);
	return ret;
}

- collidedWith:anActor	// called when it is detected that we hit something
{
	// ***** need to remove us from the stage if hit by
	// one of the player's bullets and award points, and make sound
	return self;
}

- move:sender		// move one frame
{
	if (state == SAUCER_INACTIVE) {
		// decide whether or not to activate
		if (!nextTime--) {
			state = SAUCER_ACTIVE;
			nextTime = SAUCER_DELAY;
			GK_SET_VECTOR(&nextLocation, -SAUCER_WIDTH,
				screenHeight - SAUCER_HEIGHT - 4);
		}
		return self;
	}
	GK_VECTOR_X(&nextLocation) += SAUCER_MOVE_SPEED;
	// all collisions are handles by collision detection machinery
	if (GK_VECTOR_X(&nextLocation) >= screenWidth) {
		// take saucer off of screen
		state = SAUCER_INACTIVE;
		nextTime = SAUCER_DELAY;
	}
	// ***** play "saucer on screen" sound
	return self;
}

@end
