简单的飞机大战-(线程学习)

          飞机大战-(线程学习)

简单的飞机大战-(线程学习)_第1张图片

简单的飞机大战-(线程学习)_第2张图片

简单的飞机大战-(线程学习)_第3张图片

//
// ViewController.m
// fly_boow
//
// Created by 郭瞾阳 on 14-7-31.
// Copyright (c) 2014年 gzy. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

UIImage * fly_0;
UIImage * fly_1;
UIImage * fly_2;
UIImage * fly_3;
UIImage * boow;
CALayer * bg_1;
CALayer * bg_2;
CALayer * efly;
CATextLayer * socrelayer;

UIImage * zidan;
NSTimer * timer;
NSMutableArray * difly;
NSMutableArray * fly_dan;
NSInteger  intx;
NSInteger inty;
NSInteger score;
NSInteger sum;
- (void)viewDidLoad
{
    [super viewDidLoad];
    CGRect rect = [[UIScreen mainScreen]bounds];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(reback:) name:UIApplicationDidEnterBackgroundNotification object:[UIApplication sharedApplication] ];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(rego:) name:UIApplicationWillEnterForegroundNotification object:[UIApplication sharedApplication] ];

    intx = rect.size.width;
    inty = rect.size.height;
    fly_0 = [UIImage imageNamed:@"fly_0.png"];
    fly_1 = [UIImage imageNamed:@"fly_1.png"];
    fly_2 = [UIImage imageNamed:@"fly_2.png"];
    fly_3 = [UIImage imageNamed:@"fly_3.png"];
    difly = [[NSMutableArray alloc]init];
    fly_dan = [[NSMutableArray alloc]init];
    efly = [CALayer layer];
    efly.frame = CGRectMake((intx-56)/2, inty-60, 60, 60);
    [self.view.layer addSublayer:efly];
    socrelayer = [CATextLayer layer];
    socrelayer.frame = CGRectMake(10, 15, 120, 30);
    socrelayer.fontSize = 16;
    socrelayer.foregroundColor = (__bridge CGColorRef)([UIColor blackColor]);

       NSNumber * socre_1;
    if((socre_1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"score"]))
    {
        score = socre_1.integerValue;
    }
    socrelayer.string =[NSString stringWithFormat:@"我已打%d次飞机了,好厉害",score];
    [self.view.layer addSublayer:socrelayer];
    timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(move) userInfo:nil repeats:YES];

}
-(void)move
{
    efly.contents = (id)[fly_0 CGImage];
    for(int i = 0;iinty+50)
        {
            [fly removeFromSuperlayer];
            [difly removeObject:fly];
        }
    }
    for(int i = 0;i

你可能感兴趣的:(简单的飞机大战-(线程学习))