ftp.nice.ch/pub/next/developer/resources/libraries/gamekit_proj.NI.sa.tar.gz#/gamekit_proj/Examples/PacMan/PacManGameBrain.m

This is PacManGameBrain.m in view mode; [Download] [Up]

#import <gamekit/gamekit.h>
#import "PacManGameBrain.h"
#import "PacManView.h"
#import "Player.h"
#import "PacManPreferencesBrain.h"
#import "FruitView.h"
#import <stdio.h>
#import <string.h>

// fruit values
static long fruitval[NUMFRUITVALS] = { 100, 200, 300, 300, 500, 700,
	700, 1000, 1000, 2000, 2000, 3000, 3000, 3000, 3000, 5000 };

@implementation PacManGameBrain

- nextLevel		// we add fruit basket's display of the level to this
{
    [super nextLevel];
	[fruitBasket showLevel:level];
    return self;
}

- makeGameInfo
{	// This could be replaced by using the GameInfo palette.  I'm not using
	// the palette yet since the GameInfo object may change, and then trying
	// to load the .nib might crash until I add versioning in the read and
	// write methods...
	id info = [super makeGameInfo];

	// Set up for the sound in our game; 2 types with 3 sounds each.
	// 2 streams is enough to overlap the sounds a little without them
	// getting too delayed.
	[[[info setnumSoundTypes:1] setnumSoundStreams:3] setnumSounds:6];

	// Giving three pacs to begin with.
	[info setNumOneUps:3];

	// highscores:  only five per user on the network server:
	[info setMaxScoresPerPlayerTable:0 net:YES to:5];
	return info;
}

- appDidInit:sender		// after init, but before 1st event.
{	// Allocate the bonus trackers and a frame for the PlayerUpView
	id xtraManTracker = [[BonusTracker alloc] init];
	id ghostTracker = [[BonusTracker alloc] init];
	id fruitTracker = [[ArrayBonusTracker alloc]
			initForBonuses:fruitval count:NUMFRUITVALS];
	NXRect pacFrame = {{PAC_WIDTH * 2, PAC_WIDTH}, {PAC_WIDTH, PAC_WIDTH}};
	
	[super appDidInit:sender];
	
	// set up bonus trackers for eating ghosts and getting extra men
	[xtraManTracker setBaseValue:10000];	// first xtra man at 10,000 pts.
	[(BonusTracker *)xtraManTracker setIncrement:15000];
										// next xtra every 15,000 pts...
	[ghostTracker setBaseValue:200];	// first ghost is worth 200 pts.
	[ghostTracker setMultiplier:2];		// each ghost is worth 2x previous
	[gameScreen setGhostTracker:[scoreKeeper addBonusTracker:ghostTracker]];
	[gameScreen setFruitTracker:[scoreKeeper addBonusTracker:fruitTracker]];

	// configure the PlayerUpView
	[oneUpView setImage:[NXImage findImageNamed:"Pacs.tiff"]];
	[oneUpView setImageFrame:&pacFrame];
	[oneUpView setMargin:8.0];
	[oneUpView setExtraManBonusTracker:xtraManTracker];
	
	// Set up the FruitBasket window to autosave it's location.
	[[fruitBasket window] setFrameUsingName:"FruitBasket"];
	[[fruitBasket window] setFrameAutosaveName:"FruitBasket"];
	[fruitBasket showLevel:1];
	
    return self;
}

- layerWindows
{
	// make sure the windows are layered properly
	// Fruit Basket is to be on the bottom, so order it front first.
	if (![[fruitBasket window] delegate] ||
			[[[fruitBasket window] delegate] windowUp])
		[[fruitBasket window] orderFront:self];
	return [super layerWindows];
}

- windowDidMove:sender		// move fruit basket and status with game window 
{	// we completely override super's method, since the window goes to
	// a totally different spot... (lower left rather than upper left, and
	// we have to move two windows instead of just one.)
    NXRect gameFrame;
	
	[gameWindow getFrame:&gameFrame];
    [[fruitBasket window] moveTo:(NX_X(&gameFrame) - 137)
		:(NX_Y(&gameFrame) - 53)];
    [[levelText window] moveTo:(NX_X(&gameFrame) - 137)
		:NX_Y(&gameFrame)];
	return self;
}


@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.