-4

だから私はコーディングをしていましたが、ビルドを押したときにXcodeが動き始め、これまでにないエラーが発生しました。

ファイルは次のとおりです。

輸入

#import <OpenGLES/EAGLDrawable.h>

#import "EAGLView.h"

#define USE_DEPTH_BUFFER 0

// A class extension to declare private methods @interface EAGLView ()

@property (nonatomic, retain) EAGLContext *context; @property (nonatomic, assign) NSTimer *animationTimer;

- (BOOL) createFramebuffer;
- (void) destroyFramebuffer;
- (void) updateScene:(float)delta;
- (void) renderScene;

@end


@implementation EAGLView

@synthesize context; @synthesize animationTimer; @synthesize animationInterval;


// You must implement this method
+ (Class)layerClass {
    return [CAEAGLLayer class]; }


//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder {

    if ((self = [super initWithCoder:coder])) {
        // Get the layer
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

        eaglLayer.opaque = YES;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking,

kEAGLColorFormatRGBA8、kEAGLDrawablePropertyColorFormat、nil];

        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

        if (!context || ![EAGLContext setCurrentContext:context]) {
            [self release];
            return nil;
        }

        animationInterval = 1.0 / 60.0;
              CGRect rect = [[UIScreen mainScreen] bounds];
              // Set up OpenGL projection matrix      glMatrixMode(GL_PROJECTION);        glLoadIdentity();       glOrthof(0,

rect.size.width、0、rect.size.height、-1、1); glMatrixMode(GL_MODELVIEW); glViewport(0、0、rect.size.width、rect.size.height); // OpenGL状態を初期化しますglBlendFunc(GL_SRC_ALPHA、GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); glTexEnvi(GL_TEXTURE_ENV、GL_TEXTURE_ENV_MODE、GL_BLEND_SRC); glEnableClientState(GL_VERTEX_ARRAY); glClearColor(0.0f、0.0f、0.0f、1.0f); // init [self initGame];

        UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
        accel.delegate = self;
        accel.updateInterval = 1.0f / 60.0f;

        //[sharedSoundManager playMusicWithKey:@"song" timesToRepeat:-1];
    }
    return self; }

-(void) initGame{
    //SET GAME STATE
    //0 = Menu
    //1 = Gameplay
    //2 = death screen
    gameState = 0;

    player = [[Circle alloc] init];

    score = 0;
    scoreString = [NSString alloc];
    scoreAdder = 1;
    //[self setupScore];

    menu = [[Image alloc] initWithImage:[UIImage imageNamed:@"loadImage.png"]];
    bk = [[Image alloc] initWithImage:[UIImage imageNamed:@"bk.png"]];
    squared = [[Image alloc] initWithImage:[UIImage imageNamed:@"squared.png"]];

    gameRunning = TRUE;
    gameState = 0;

    squares = [[Squares alloc] init];
    [squares addSquare: CGPointMake(100, 100) : 0];
    //font = [[AngelCodeFont alloc]initWithFontImageNamed:@"font1.png" controlFile:@"font1.fnt"

スケール:0.0fフィルター:nil];

    // Init sound     sharedSoundManager = [SingletonSoundManager sharedSoundManager];    [sharedSoundManager loadSoundWithKey:@"menu"

fileName:@ "Menu" fileExt:@ "mp3"頻度:22050]; [sharedSoundManager loadBackgroundMusicWithKey:@ "music" fileName:@ "bkmusic" fileExt:@ "aif"];

    menuMusicVariable = 1;
    gameMusicVariable = 1;
     }

-(void) setRunning: (bool) boolean{
    gameRunning = boolean; }

-(void) runContinueCountdown{
    if(gameRunning == NO){

        int timer = 300;
        int countdownNum;
        timer --;


        if(timer <= 300){
            if(timer > 200){
                countdownNum = 3;
            }

        if(timer <= 200){
            if(timer > 100){
                countdownNum = 2;
            }
        }

        if(timer <= 100){
            if(timer >= 1){
                countdownNum = 1;
            }
        }

        if(timer == 0 && countdownNum == 1){
            [self setRunning: YES];
        }
    } }


- (void) mainGameLoop {   CFTimeInterval      time;   float               delta;  time = CFAbsoluteTimeGetCurrent();  delta = (time - lastTime);  

[self updateScene:delta]; [自己renderScene]; lastTime=時間; }

- (void)updateScene:(float)delta {    // Update Game Logic
    if(gameRunning){
        if(gameState == 0){

            //MENU

            if(menuMusicVariable == 1){
                [sharedSoundManager stopPlayingMusic];
                [sharedSoundManager playSoundWithKey:@"Menu" gain:10 pitch:10 location:Vector2fMake(0, 0) shouldLoop: TRUE];
                menuMusicVariable = 0;
            }

            [scoreLabel setHidden: YES];

        } else if(gameState == 1){

            //GAMEPLAY

            if(gameMusicVariable == 1){
                [sharedSoundManager stopPlayingMusic];
                [sharedSoundManager playMusicWithKey: @"music" timesToRepeat: -1];
                gameMusicVariable = 0;
            }

            [scoreLabel setHidden: NO];

            //game is running

            if([player getAlive] == true){
                score = score + scoreAdder;
            } else {
                score = score;
            }

            [player move];

            [self checkSquareToCircleCollisions];
            [self checkSquareToSquareCollisions];

            [squares update];

        } else if(gameState == 2){

            //DEATH SCREEN

            [sharedSoundManager stopPlayingMusic];

            [scoreLabel setBounds: CGRectMake(100, 100 , 100, 40)];
        }
    } else {
        //game is puased

    } }


- (void)renderScene {
      // Make sure we are renderin to the frame buffer
    [EAGLContext setCurrentContext:context];
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
      // Clear the color buffer with the glClearColor which has been set  glClear(GL_COLOR_BUFFER_BIT);       //Render the game Scene 
    if(gameState == 0){

        //MENU
        [menu renderAtPoint: CGPointMake(0, 0) centerOfImage: NO];

    } else if(gameState == 1){

        //GAMEPLAY

        [bk renderAtPoint: CGPointMake(0, 0) centerOfImage: NO];

        [self drawScore];

        [player draw];

        [squares render];
        //[font drawStringAt: CGPointMake(150, 100) text:@"HELLO FONTS"];
    } else if(gameState ==2){

        //DEATH SCREEN

        [squared renderAtPoint: CGPointMake(0, 0) centerOfImage: NO];

    }         // Switch the render buffer and framebuffer so our scene is displayed on the screen
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES]; }


- (void)layoutSubviews {
    [EAGLContext setCurrentContext:context];
    [self destroyFramebuffer];
    [self createFramebuffer];
    [self renderScene]; }


- (BOOL)createFramebuffer {

    glGenFramebuffersOES(1, &viewFramebuffer);
    glGenRenderbuffersOES(1, &viewRenderbuffer);

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);

    if (USE_DEPTH_BUFFER) {
        glGenRenderbuffersOES(1, &depthRenderbuffer);
        glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
        glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
        glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
    }

    if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
        NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
        return NO;
    }

    return YES; }


- (void)destroyFramebuffer {

    glDeleteFramebuffersOES(1, &viewFramebuffer);
    viewFramebuffer = 0;
    glDeleteRenderbuffersOES(1, &viewRenderbuffer);
    viewRenderbuffer = 0;

    if(depthRenderbuffer) {
        glDeleteRenderbuffersOES(1, &depthRenderbuffer);
        depthRenderbuffer = 0;
    } }


- (void)startAnimation {
    self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self

セレクター:@selector(mainGameLoop)userInfo:nil repeats:YES]; }

- (void)stopAnimation {
    self.animationTimer = nil; }


- (void)setAnimationTimer:(NSTimer *)newTimer {
    [animationTimer invalidate];
    animationTimer = newTimer; }


- (void)setAnimationInterval:(NSTimeInterval)interval {

    animationInterval = interval;
    if (animationTimer) {
        [self stopAnimation];
        [self startAnimation];
    } }



-(void) setupScore{

    scoreLabel = [NSString stringWithFormat:@"%d", score];
    scoreLabel.frame = CGRectMake(262, 250, 100, 40);
    [scoreLabel setText: scoreString];

    //normally you'll want a transparent background for your label
    scoreLabel.backgroundColor = [UIColor clearColor]; 

    //you can use non-standard fonts
    [scoreLabel setFont:[UIFont fontWithName:@"TimesNewRoman" size: 1.0f]];

    //change the label's text color
    scoreLabel.textColor = [UIColor whiteColor];

    //add it to your view
    scoreLabel.transform = CGAffineTransformMakeRotation(89.53);
    [self addSubview:scoreLabel]; }

-(void) resetScore {
    score = 0;
    scoreLabel.textColor = [UIColor blackColor];
    [scoreLabel release]; }

-(void)drawScore{  
    [scoreLabel setText: scoreString]; }

-(void) checkSquareToCircleCollisions{
    NSMutableArray *array = [squares getSquares];

    for(int i = 0; i < [squares getCount]; i++){

        Square *s = [array objectAtIndex: i];

        CGRect rect1 = [player getRect];
        CGRect rect2 = [s getRect];

        if (CGRectIntersectsRect(rect1, rect2)){

            player.alive = NO;
            gameState = 2;

        }

    } }

-(void) checkSquareToSquareCollisions{
    NSMutableArray *array = [squares getSquares];

    for(int i = 0; i < [squares getCount]; i++){

        Square *s = [array objectAtIndex: 0];
        Square *ss = [array objectAtIndex: i];

        CGRect rect1 = [s getRect];
        CGRect rect2 = [ss getRect];

        if (CGRectIntersectsRect(rect1, rect2)) {
            [s setDirection: [s getXDir] * -1 : [s getYDir] * -1];
            [ss setDirection: [ss getXDir] * -1 : [ss getYDir] * -1];
        }

    } }

-(void) spawnSquares {
    // FINISH METHOD
     }

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    if(gameState == 0){

        //MENU

        UITouch *touch = [[event allTouches] anyObject];

        gameState = 1;
        //[self initGame];

    } else if(gameState == 1){

        //GAMEPLAY

        UITouch *touch = [[event allTouches] anyObject];
        CGPoint touchPos = [touch locationInView:touch.view];
        touchPos.y = 480 - touchPos.y;
        [player setPos: touchPos];

    } else if(gameState == 2){

        //DEATH SCREEN

        UITouch *touch = [[event allTouches] anyObject];

        gameState = 0;
        //[self resetScore];
        [self initGame];
    } }

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    if(gameState == 0){

        //MENU

        UITouch *touch = [[event allTouches] anyObject];

        //[self initGame];

    } else if(gameState == 1){

        //GAMEPLAY

        UITouch *touch = [[event allTouches] anyObject];
        CGPoint touchPos = [touch locationInView:touch.view];
        touchPos.y = 480 - touchPos.y;
        [player setPos: touchPos];

    } else if(gameState == 2){

        //DEATH SCREEN

        UITouch *touch = [[event allTouches] anyObject];

    }}

- (void)accelerometer:(UIAccelerometer *)accelerometer
        didAccelerate:(UIAcceleration *)acceleration {

    point.y = acceleration.y * 10;
    point.x = acceleration.x * 10;

    CGPoint pos = [player getPos];

    pos = CGPointMake(pos.x + point.x, pos.y + point.y);
    [player setPos: pos];

    //Right - MAY HAVE TO CHANGE
    if(pos.x < 0){
        pos = CGPointMake(320, pos.y);
    }

    //left
    if(pos.x < 320){
        pos = CGPointMake(0, pos.y);
    }

    //Top
    if(pos.y < 0){
        pos = CGPointMake(pos.x, 460);
    }

    //Bottom
    if(pos.x < 460){
        pos = CGPointMake(pos.x, 0);
    }
     }

- (void)dealloc {

    [self stopAnimation];

    if ([EAGLContext currentContext] == context) {
        [EAGLContext setCurrentContext:nil];
    }

    [context release];  
    [player release];
    [menu release];
    [sharedSoundManager release];
    [bk release];
    [squared release];
    [squares release];
    [scoreLabel release];
    [scoreString release];

    [super dealloc]; }

@end // here it says: excepted } and also its excepting @end
4

1 に答える 1

2

runContinueCountdown2番目のifステートメントの最後に中括弧がありません。

if(timer <= 300){
            if(timer > 200){
                countdownNum = 3;
            }

ifこのステートメントの最後に中括弧を追加します

于 2012-08-17T16:03:18.563 に答える