imSimReal

The imSimReal framework and projects built from it

imSimReal: A Cocoa Framework for Mac Games

imSimReal 0.1 RC3 available

January 24th, 2009 · No Comments · imSimReal

IMSRGravity now has a new data member and a new method. It stores the selected body. The new method provides the means of getting the gravity value of the selectedBody.

There is also a new initializer -initWithBody:

- (id)initWithBody: (NSString *)body
{
if (![super init])
{
return nil;
}

bodyGravity = [[NSDictionary alloc] initWithContentsOfFile: @"Gravity.plist"];
selectedBody = body;

return self;
}

Note that the initializer takes an NSString object that provides the key into the bodyGravity NSDictionary. With this change, the default -init: method changes to call -initWithBody: with Earth as the default selectedBody:

- (id)init
{
return [self initWithBody: @"Earth"]; // Use Earth in the absence of other values
}

The new -gravityForSelectedBody: method returns 0.0 if the selectedBody is nil, otherwise it gets accesses the bodyGravity NSDictionary to get the gravity value for the selectedBody key.

At this point there is some error handling missing for the case where the selectedBody does not match any element in the NSDictionary.

- (double)gravityForSelectedBody
{
if (selectedBody == nil)
{
return 0.0;
}

NSNumber *gravity = [bodyGravity valueForKey: selectedBody];
return [gravity doubleValue];
}

The current class declaration looks like:

@interface IMSRGravity : NSObject
{
NSDictionary *bodyGravity;
NSString *selectedBody;
}

@property (nonatomic, retain)NSDictionary *bodyGravity;
@property (nonatomic, retain)NSString *selectedBody;

/**
* An initializer for selecting the body to use when initializing. If no body is
* selected, the default init: method sets body to Earth
*
* @param body The body to set selectedBody to
*
* @return a newly initialized IMSRGravity object
*/
- (id)initWithBody: (NSString *)body;

/**
* Get the gravity value for the selectedBody.
*
* @return gravity for the selectedBody variable, in meters/second.
*/
- (double)gravityForSelectedBody;

@end

This is available from GitHub as tag 0.1RC3, and as a disk image at the downloads page.

Technorati Tags:
,

Tags:

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

Please copy the string nA81Qi to the field below: