0 Replies - 21853 Views - Last Post: 05 January 2013 - 04:25 AM

#1 computerguy3100  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 04-June 12

Asteroids Game Crashes

Posted 05 January 2013 - 04:25 AM

Ok, so, I have been programming an asteroids game in Obj-C on Xcode 4.5.2 All I have done is animated the ball, and would like to test my animation. When try to compile, it compiles and then crashes, my main.m file shows "SIGABRT". Here is the code from my ViewController.m file

#import "ViewController.h"

@implementation ViewController


@synthesize asteroid, ship, scorelabel1, fireball;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}



#pragma mark - View lifecycle
- (void)moveAsteroid {
    
    dirx = 15.0;
    diry = 10.0;
    



    
    CGPoint center = asteroid.center;
    
    CGRect astroidrec = asteroid.frame;
    
    
    astroidrec.origin.x += dirx;
    astroidrec.origin.y += diry;
    
    if (astroidrec.origin.x < 0) {
        dirx *= -1;
        astroidrec.origin.x = 0;
    } else if (astroidrec.origin.x > self.frame.size.width - astroidrec.size.width) {
        astroidrec.origin.y = 0;
        dirx *= -1;
        astroidrec.origin.x = self.frame.size.width - astroidrec.size.width;
    }
    
    if (astroidrec.origin.y < 0) {
        diry *= -1;
        astroidrec.origin.y = 0;
    } else if (astroidrec.origin.y > self.frame.size.height - astroidrec.size.height) {
        diry *= -1;
        astroidrec.origin.y = self.frame.size.height - astroidrec.size.height;
        
    }
    [self setNeedsDisplay];

CGRect shiprec = ship.frame;
CGRect fireballrec = fireball.frame;

center.x += dirx;
center.y += diry;


if (center.x < 12.0) {
    center.x = 12.0;
    dirx = dirx * -1;
} else if (center.x > 756.0) {
    center.x = 756.0;
    dirx = dirx * -1;
}

if (center.x > fireballrec.origin.x &&
    center.x < (fireballrec.origin.x + fireballrec.size.width) &&
    center.y <= (fireballrec.origin.y + fireballrec.size.height)
    ) {
    if (center.x > shiprec.origin.y + shiprec.size.height + 12.0)
        (score--);
    else if (center.y < 12.0) {
        center.y = 12.0;
        (score ++);
        
    }
    
}
    
}


@end


And here is the code from my ViewController.h file:
#import <UIKit/UIKit.h>

@interface ViewController : UIView {
 
    
    NSTimer *timer;
    
    UIImageView *asteroid;
    UIImageView *fireball;
    UIImageView *ship;
    
    UILabel *scorelabel1;
    
    float dirx;
    float diry;
    

    
    int score;
    
    
    
}

    
@property (nonatomic, retain) IBOutlet UIImageView *asteroid;
@property (nonatomic, retain) IBOutlet UIImageView *fireball;
@property (nonatomic, retain) IBOutlet UIImageView *ship;
@property (nonatomic, retain) IBOutlet UILabel *scorelabel1;

- (void)moveAsteroid;


@end


Any help would be great. thanks!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1