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

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

#import "FruitView.h"
//#import <dpsclient/psops.h>	// PSxxx functions

int fruits[FRUIT_LEVELS + 1] =
	{ 19, 5, 6, 8, 8, 9, 7, 7, 15, 15, 17, 17, 16, 16, 16, 16, 18 };


@implementation FruitView

- initFrame:(const NXRect *)frm		// initialize instance
{
	[super initFrame:frm];
	lastLevel = 0;
	fruit = [NXImage findImageNamed:"FruitBig.tiff"];
	return self;
}

- drawSelf:(NXRect *)rects :(int)rectCount  // standard rendering method
{	// This is a hacked up mess.  Basically, it draw a horizontal line of
	// fruits.  It starts at the left of the view and goes to the right.
	// If you're level is higher than the width of the view would allow
	// then we start on the left with a higher level of fruit so that the
	// fruits will appear to scroll left as the level increases.
	int j, jj, k, f;
	NXRect from;
	NXPoint pos;
	
	[self lockFocus];
	PSsetgray(0.666);
	NXRectFill(&bounds);
	pos.y = 0; f = 0;
	jj = bounds.size.width / (FRUIT_SIZE * 2) - 1;
	j = lastLevel - jj;
	if (j<1) j = 1;
	for (k=0; k<=jj; k++) {
		f = k + j;
		if (f > lastLevel) f = 0;
		if (f > FRUIT_LEVELS) f = FRUIT_LEVELS;
		f = fruits[f];
		NXSetRect(&from,
			(f % FRUIT_PER_ROW) * (FRUIT_SIZE * 2),
			(f / FRUIT_PER_ROW) * (FRUIT_SIZE * 2),
			(FRUIT_SIZE * 2), (FRUIT_SIZE * 2));
		pos.x = k * (FRUIT_SIZE * 2);

		[fruit composite:NX_SOVER fromRect:&from toPoint:&pos];
	}
	
	[self unlockFocus];
	NXPing();
	return self;
}

- showLevel:(int)num				// draw all fruits up to level
{
	if (lastLevel == num) return self;
	lastLevel = num;
	[self update];
	return self;
}


@end

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