Source

iPhone / solarwolf / Classes / Platforms.m

The default branch has multiple heads

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

#import "Platforms.h"


@implementation Platforms

-(id)initWithPos:(CGPoint)value:(NSString *) dir:(NSString *) sidePos{
	if(self = [super init]){
		position=value;
		direction=dir;
		sidePosition=sidePos;
		CGRect frame=[self convertPosToSquare];
		
		spirintView=[[UIView alloc]initWithFrame:frame];
		spirintView.backgroundColor=[UIColor blackColor];
	}
	return self;
	[spirintView release];
}

-(NSString*) sidePosition{
	return sidePosition;
}
-(void)setSidePosition:(NSString*)sidePos{
	sidePosition=sidePos;
}

	
-(Spirint*)launchFireball{
	NSString* sidePos=[self sidePosition];
	CGPoint platformPos =[self position];
	Spirint* fireball = [[Spirint alloc]init];
	CGPoint fireballPos=CGPointMake(platformPos.x,platformPos.y);
	[fireball setPosition:fireballPos];
	if([sidePos isEqualToString: @"Top"]){
		
		[fireball setDirection:@"Down"];
		
	}
	
	else if([sidePos isEqualToString:@"Bottom"]){
		[fireball setDirection:@"Up"];
	}
	
	else if([sidePos isEqualToString:@"Right"]){
		[fireball setDirection:@"Left"];
	}
	else if([sidePos isEqualToString:@"Left"]){
		[fireball setDirection:@"Right"];
	}
	return fireball;
	[fireball release];
}
	
-(CGRect)convertPosToSquare{
	
	NSString* sidePos=[self sidePosition];
	CGPoint temp =[self position];
	
	if([sidePos isEqualToString: @"Top"]){
		CGRect square=CGRectMake(25*temp.x+10, 25*temp.y,25, 5);
		return square;
	}
	
	else if([sidePos isEqualToString:@"Bottom"]){
		CGRect square=CGRectMake(25*temp.x+10, 25*temp.y+30,25, 5);
		return square;
	}
	
	else if([sidePos isEqualToString:@"Right"]){
		CGRect square=CGRectMake(25*temp.x+35, 25*temp.y+5,10, 25);
		return square;
	}
	
	
	else if([sidePos isEqualToString:@"Left"]){
		 CGRect square=CGRectMake(25*temp.x, 25*temp.y+5,10, 25);
		return square;
	}
	
}

-(void)oppositeDirection{
	if([[self direction] isEqualToString:@"Left"]){
		[self setDirection:@"Right"];
	}
	else if([[self direction] isEqualToString:@"Right"]){
		[self setDirection:@"Left"];
	}
	else if([[self direction] isEqualToString:@"Up"]){
		[self setDirection:@"Down"];
	}
	else if([[self direction] isEqualToString:@"Down"]){
			[self setDirection:@"Up"];
	}
}

-(void)check{
	
	if([self objectWillLeave]){
		[self oppositeDirection];
	}
}

-(void)move{
	[self check];
	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 oppositeDirection];
		[self setPosition:oldPos];
	}
	[self drawSpirint];
}

-(UIView *)drawSpirint{
	
	CGRect frame=[self convertPosToSquare];
	spirintView.frame=frame;
	return spirintView;
	
	
}


	

@end