Source

iPhone / solarwolf / Classes / Ship.m

The default branch has multiple heads

Full commit
//
//  Ship.m
//  solarwolf
//
//  Created by Tau Bernstorff Lehmann on 10/08/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "Ship.h"


@implementation Ship
-(id)initWithPos:(CGPoint) value{
	if(self=[super init])
	{
		
		position=value;
		CGRect frame=[self convertPosToSquare];
		
		spirintView=[[UIView alloc]initWithFrame:frame];
		spirintView.backgroundColor=[UIColor blueColor];
		
	}
	return self;
	[spirintView release];
}

-(void)moveShip:(CGPoint)move{
	
	CGRect shipframe=[self convertPosToSquare];
	CGPoint click;
	click.x=(shipframe.origin.x+12.5)-move.x;
	click.y=(shipframe.origin.y+12.5)-move.y;
	
	
	if(fabs(click.x)>fabs(click.y)){
		if(shipframe.origin.x>move.x){
			[self setDirection:@"Left"];
		}
		else{
			[self setDirection:@"Right"];
		}
	}
	else{
		
		if(shipframe.origin.y>move.y){
			[self setDirection:@"Up"];
		}
		else{
			[self setDirection:@"Down"];
			
			
		}
		
		
	}
	[self move];
	
}

-(void)move{
	CGPoint temp=[self position];
	CGPoint oldPos=[self position];
	if([[self direction] isEqual:@"Up"]){
		temp.y--;
	}
	else if([[self direction] isEqual:@"Down"]){
		temp.y++;
	}
	else if([[self direction] isEqual:@"Right"]){
		temp.x++;
	}
	else if([[self direction] isEqual:@"Left"]){
		temp.x--;
		
	}
	[self setPosition:temp];
	if([self objectWillLeave])
	{
		[self setPosition:oldPos];
	}
	
	[self drawSpirint];
	
}

@end