⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttrapp.m

📁 TTR的一个经典游戏
💻 M
📖 第 1 页 / 共 2 页
字号:
#import <CoreFoundation/CoreFoundation.h>#import <Foundation/Foundation.h>#import <UIKit/CDStructures.h>#import <UIKit/UIWindow.h>#import <UIKit/UIView-Hierarchy.h>#import <UIKit/UIHardware.h>#import <UIKit/UIKit.h>#import <UIKit/UIApplication.h>#import <UIKit/UITextView.h>#import <UIKit/UIView.h>#import <UIKit/UIKeyboard.h>#import <UIKit/UIBox.h>#import <Celestial/AVItem.h>#import <Celestial/AVController.h>#import <Celestial/AVQueue.h>#import <WebCore/WebFontCache.h>#import <objc/objc-class.h>#import "Animatables.h"#import "Downloader.h"#import "TtrApp.h"#import "TtrView.h"#import "LabelButton.h"#import <WebCore/WebFontCache.h>#include <math.h>#include <string.h>typedef struct {	float t, x, y;	int column;	BOOL tapped;} songTap;songTap * taps;int tapcount, tapcapacity;#define show_count 20#define slide_time 3#define bad_time 0.3#define ok_time 0.2#define good_time 0.1#define perfect_time 0.05#define wrong_score -30#define bad_score 0#define ok_score 50#define good_score 75#define perfect_score 150@implementation TtrApp- (void) applicationDidFinishLaunching: (id) unused{    UIWindow *window;	UIImageView * uiv;    int i;    struct CGRect rect = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);    window = [[UIWindow alloc] initWithContentRect: rect];    [window orderFront: self];    [window makeKey: self];    [window _setHidden: NO];        mainView = [[TtrView alloc] initWithFrame: rect];    [mainView setApp: self];        menuView = [[UIView alloc] initWithFrame: rect];    gameView = [[UIView alloc] initWithFrame: rect];    effectsView = [[UIView alloc] initWithFrame: rect];        float boxback[4] = {0, 0, 0, 1};    [mainView setBackgroundColor: CGColorCreate( CGColorSpaceCreateDeviceRGB(), boxback)];    [window setContentView: mainView];            sparkles = [NSMutableArray arrayWithCapacity: show_count];    [sparkles retain];    [menuView addSubview: [[[UIImageView alloc]				initWithImage:					[[UIImage alloc]						initWithContentsOfFile: 							@"Default.png"]] retain]];    [menuView addSubview: [[[UIImageView alloc]				initWithImage:					[[UIImage alloc]						initWithContentsOfFile: 							@"menuback.png"]] retain]];    [gameView addSubview: [[[UIImageView alloc]				initWithImage:					[[UIImage alloc]						initWithContentsOfFile: 							@"background.png"]] retain]];        for (i = 0; i < show_count; i++) {		uiv = [[[UIImageView alloc]				initWithImage:					[[UIImage alloc]						initWithContentsOfFile: 							@"sparkle1.png"]] retain];		[uiv setTransform: CGAffineTransformMakeTranslation(-1000, -1000)];		[gameView addSubview: uiv];		[sparkles addObject: uiv];    }    		timer = [NSTimer scheduledTimerWithTimeInterval: 0.01	                 target: self	                 selector: @selector(fireTimer:)	                 userInfo: nil	                 repeats: YES];              	taps = (songTap *) malloc(sizeof(songTap) * 100);	tapcount = 0; tapcapacity = 100;	glowlevels[0] = 1;	glowlevels[1] = 1;	glowlevels[2] = 1;	glowlevels[3] = 1;    glows = [NSMutableArray arrayWithCapacity: 4];    [glows retain];		uiv = [[[UIImageView alloc]				initWithImage:					[[UIImage alloc]						initWithContentsOfFile: 							@"redglow.png"]] retain];		[gameView addSubview: uiv];		[uiv setAlpha: 0];		[glows addObject: uiv];		uiv = [[[UIImageView alloc]				initWithImage:					[[UIImage alloc]						initWithContentsOfFile: 							@"greenglow.png"]] retain];		[uiv setTransform: CGAffineTransformMakeTranslation(100, 0)];		[gameView addSubview: uiv];		[uiv setAlpha: 0];		[glows addObject: uiv];		uiv = [[[UIImageView alloc]				initWithImage:					[[UIImage alloc]						initWithContentsOfFile: 							@"blueglow.png"]] retain];		[gameView addSubview: uiv];		[uiv setTransform: CGAffineTransformMakeTranslation(200, 0)];		[uiv setAlpha: 0];		[glows addObject: uiv];		uiv = [[[UIImageView alloc]				initWithImage:					[[UIImage alloc]						initWithContentsOfFile: 							@"whiteglow.png"]] retain];		[gameView addSubview: uiv];		[uiv setTransform: CGAffineTransformMakeTranslation(0, 360)];		[uiv setAlpha: 0];		[glows addObject: uiv];		perfectImage = [[UIImage alloc] initWithContentsOfFile: @"perfect.png"];	goodImage = [[UIImage alloc] initWithContentsOfFile: @"good.png"];	wrongImage = [[UIImage alloc] initWithContentsOfFile: @"wrong.png"];    animatables = [NSMutableArray arrayWithCapacity: 10];    [animatables retain];        buttons = [NSMutableArray arrayWithCapacity: 10];    [buttons retain];	scoreLabel = [[UITextLabel alloc] initWithFrame: CGRectMake(0.0f, 20.0f, 320.0f, 14.0f)];    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();    float textcomponents[4] = {0, 1, 0, 1};    float backgroundcomponents[4] = {0,0,0,1};	[scoreLabel setColor: CGColorCreate( colorSpace, textcomponents)];	[scoreLabel setBackgroundColor: CGColorCreate( colorSpace, backgroundcomponents)];	[scoreLabel setCentersHorizontally: YES];	[scoreLabel setFont: [NSClassFromString(@"WebFontCache") createFontWithFamily: @"Courier New" traits: 2 size: 14]];	[scoreLabel setText: @"Score: 0"];	[gameView addSubview: scoreLabel];		[mainView addSubview: effectsView];	[effectsView setEnabled: NO];		mstate = msNoMenu;	songDownload = nil;	tapDownload = nil;		//[self playGameWithSong: @"dance.mp3" tapFile: @"dance.tap"];	[self menuInterface];	[self displayMainMenu];		NSLog(@"Initialized");}- (void) displayMainMenu {	[self clearButtons];	[self addButton: [[LabelButton alloc] initWithText: @"Play"		rect: CGRectMake(85, 261, 168, 33)		triggerWord: @"play"		fontSize: 16		app: self]];		/*	[self addButton: [[LabelButton alloc] initWithText: @"Create"		rect: CGRectMake(85, 300, 168, 33)		triggerWord: @"create"		fontSize: 16		app: self]];*/	mstate = msMainMenu;}- (void) displayPlayMenu {	[self clearButtons];	[self addButton: [[LabelButton alloc] initWithText: @"New Tracks"		rect: CGRectMake(85, 261, 168, 33)		triggerWord: @"newtracks"		fontSize: 16		app: self]];	[self addButton: [[LabelButton alloc] initWithText: @"Downloaded Tracks"		rect: CGRectMake(85, 300, 168, 33)		triggerWord: @"downtracks"		fontSize: 16		app: self]];	[self addButton: [[LabelButton alloc] initWithText: @"Back"		rect: CGRectMake(33, 410, 60, 33)		triggerWord: @"back"		fontSize: 14		app: self]];	mstate = msPlayMenu;}- (void) displayCreateMenu {	[self clearButtons];	//Grab list for artists	mstate = msCreateMenu;}- (void) displayTracksMenu {	[self clearButtons];	NSArray *songs = [[NSFileManager defaultManager] directoryContentsAtPath: @"/var/root/Media/TTR/Music/"];	int i, t = 0;	int ypos = 197;	for (i = 0; i < [songs count]; i++) {		NSString * s = [songs objectAtIndex: i];		NSString * n = [s substringToIndex: [s length] - 4];		NSString * t = [[NSString stringWithFormat: @"playsong /var/root/Media/TTR/Music/%@", s] retain];		if (![[NSFileManager defaultManager] fileExistsAtPath: [NSString 			stringWithFormat: @"/var/root/Media/TTR/Taps/%@.tap", n]]) {			[t release];			t = [[NSString stringWithFormat: @"recordsong /var/root/Media/TTR/Music/%@", s] retain];			n = [n stringByAppendingString: @" (rec)"];			}		NSLog(@"Button: %@, %@", n, t);		[self addButton: [[LabelButton alloc] initWithText: n			rect: CGRectMake(0, ypos, 320, 15)			triggerWord: t			fontSize: 14			app: self]];		ypos += 20;		t++;	}	if (t == 0) {		[self addButton: [[LabelButton alloc] initWithText: @"(No songs)"			rect: CGRectMake(0, ypos, 320, 15)			triggerWord: @"back"			fontSize: 14			app: self]];	}	[self addButton: [[LabelButton alloc] initWithText: @"Back"		rect: CGRectMake(33, 410, 60, 33)		triggerWord: @"back"		fontSize: 14		app: self]];	mstate = msPlayMenu;}- (void) displayNewTracksMenu {	[self clearButtons];	NSArray *songs = [NSArray arrayWithContentsOfURL: [NSURL URLWithString: 		@"http://ibrickr.com/ttr/songs.php"]];	int i, t = 0;	int ypos = 197;	for (i = 0; i < [songs count]; i++) {		NSDictionary * d = [songs objectAtIndex: i];		NSString * s = [d objectForKey: @"tap"];		if ([[NSFileManager defaultManager] fileExistsAtPath: [NSString 			stringWithFormat: @"/var/root/Media/TTR/Taps/%@", s]]) continue;		NSString * t = [[NSString stringWithFormat: @"getsong %@", [d objectForKey: @"id"]] retain];		NSLog(@"Button: %@", t);		[self addButton: [[LabelButton alloc] initWithText: [d objectForKey: @"id"]			rect: CGRectMake(0, ypos, 320, 15)			triggerWord: t			fontSize: 14			app: self]];		ypos += 20;		t++;	}	if (t == 0) {		[self addButton: [[LabelButton alloc] initWithText: @"Sorry, no new songs yet"			rect: CGRectMake(0, ypos, 320, 15)			triggerWord: @"back"			fontSize: 14			app: self]];			}	[self addButton: [[LabelButton alloc] initWithText: @"Back"		rect: CGRectMake(33, 410, 150, 33)		triggerWord: @"back"		fontSize: 14		app: self]];	mstate = msPlayMenu;}- (void) displayDownloader {	[self clearButtons];	[self addButton: [[LabelButton alloc] initWithText: @"Downloading, please wait"		rect: CGRectMake(0, 261, 320, 15)		triggerWord: @"downloading"		fontSize: 14		app: self]];	mstate = msDownloading;}- (void) triggerButton: (NSString *) trig {	NSLog(@"Cliccotash: %@", trig);	switch (mstate) {		case msMainMenu:			if ([trig isEqualToString: @"start"]) {				[self playGameWithSong: @"dance.mp3" tapFile: @"dance.tap"];				}			if ([trig isEqualToString: @"play"]) {				[self displayPlayMenu];				}			if ([trig isEqualToString: @"create"]) {				[self displayCreateMenu];				}		break;		case msPlayMenu:			if ([trig isEqualToString: @"downtracks"]) {				[self displayTracksMenu];			}			if ([trig isEqualToString: @"newtracks"]) {				[self displayNewTracksMenu];			}			if ([trig isEqualToString: @"back"]) {				[self displayMainMenu];			}			if ([trig hasPrefix: @"getsong "]) {				NSString * s = [trig substringFromIndex: 8];				[self downloadSong: s];			}			if ([trig hasPrefix: @"playsong "]) {				NSString * s = [trig substringFromIndex: 9];				NSString * t = [NSString stringWithFormat: @"/var/root/Media/TTR/Taps/%@.tap", 					[[s substringToIndex: [s length] - 4] lastPathComponent]];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -