我想移动得更快的球是*敌人;
我希望*敌人在 20 秒后在不触球的情况下移动得更快。*player 球是您可以控制的球。在这个游戏中,你不能触碰敌人的球。
我希望敌人的球每 20 秒变得更快.. 我在想一些带有数组循环的东西..
谢谢你的帮忙
。H
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UIButton *startButton;
NSTimer *randomMain;
CGPoint pos;
IBOutlet UIImageView *enemy;
IBOutlet UIImageView *player;
int MainInt;
IBOutlet UILabel *seconds;
IBOutlet UILabel *lastTime;
IBOutlet UILabel *theTime;
}
@property (nonatomic, retain) NSTimer *numro;
- (IBAction)start;
@end
.m
#import "ViewController.h"
@implementation ViewController
@synthesize numro;
- (IBAction)start {
[startButton setHidden:YES];
randomMain = [NSTimer scheduledTimerWithTimeInterval:(0.03)
target:self selector: @selector(onTimer) userInfo:(nil) repeats:YES];
numro = [NSTimer scheduledTimerWithTimeInterval:(1.0)
target:self selector:@selector(countup) userInfo:nil repeats:YES];
MainInt = 0;
[lastTime setHidden:YES];
[theTime setHidden:YES];
}
-(void)countup {
MainInt += 1;
seconds.text = [NSString stringWithFormat:@"%i", MainInt];
// I TRIED IT WITH "IF" BUT IT I DONT WANT TO WRITE THIS FOR EVERY 20 SECONDS
if (MainInt == 20) {
randomMain = [NSTimer scheduledTimerWithTimeInterval:(0.002)
target:self selector: @selector(checkCollision) userInfo:(nil) repeats:YES];
}
/* if (MainInt == 40) {
randomMain = [NSTimer scheduledTimerWithTimeInterval:(0.01)
target:self selector: @selector(onTimer) userInfo:(nil) repeats:YES];
}*/
}
-(void)onTimer{
[self checkCollision];
enemy.center = CGPointMake(enemy.center.x+pos.x,enemy.center.y+pos.y);
if (enemy.center.x > 320 || enemy.center.x < 0)
pos.x = -pos.x;
if (enemy.center.y > 480 || enemy.center.y < 0)
pos.y = -pos.y;
}
- (void)checkCollision {
if( CGRectIntersectsRect(player.frame,enemy.frame))
{
[randomMain invalidate];
[startButton setHidden:NO];
CGRect frame = [player frame];
frame.origin.x = 137.0f;
frame.origin.y = 326.0;
[player setFrame: frame];
CGRect frame2 = [enemy frame];
frame2.origin.x = 137.0f;
frame2.origin.y = 20.0;
[enemy setFrame: frame2];
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"AAA"
message: [NSString stringWithFormat:@"BBB"] delegate:nil
cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
MainInt = 0 ;
[numro invalidate];
[lastTime setHidden:NO];
[theTime setHidden:NO];
theTime.text = seconds.text;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [[event allTouches] anyObject];
player.center = [myTouch locationInView:self.view]; //player ball
}
-(void)viewDidLoad {
[lastTime setHidden:YES];
[super viewDidLoad];
// X Speed Y Speed
//I tried to do anything with the X and Y speed ... but it didn't work
pos = CGPointMake(5.0,4.0);
}
@end