Home > Articles > Programming > General Programming/Other Languages

  • Print
  • + Share This
This chapter is from the book

Creating the Viking Class

In the previous chapter, Ole the Viking was nothing more than a CCSprite. In this chapter you pull him out into his own class complete with animations and a state machine to transition him through his various states. If the Viking class code starts to look daunting, refer back to the RadarDish class: the Viking is simply a game character like the RadarDish, albeit with more functionality. Create the new Viking class in Xcode by:

  1. In Xcode, right-click on the GameObjects group.
  2. Select Add > New File, choose the Cocoa Touch category under iOS and Objective-C class as the file type, and click Next.
  3. For the Subclass field, enter GameCharacter and click Next.
  4. Enter Viking for the filename and click Save.

Open the Viking.h header file and change the contents to match the code in Listing 4.5.

Listing 4.5. Viking.h header file

//  Viking.h
//  SpaceViking
#import <Foundation/Foundation.h>
#import "GameCharacter.h"
#import "SneakyButton.h"
#import "SneakyJoystick.h"
typedef enum {
    kLeftHook,
    kRightHook
} LastPunchType;

@interface Viking : GameCharacter  {
    LastPunchType myLastPunch;
    BOOL isCarryingMallet;
    CCSpriteFrame *standingFrame;

    // Standing, breathing, and walking
    CCAnimation *breathingAnim;
    CCAnimation *breathingMalletAnim;
    CCAnimation *walkingAnim;
    CCAnimation *walkingMalletAnim;

    // Crouching, standing up, and Jumping
    CCAnimation *crouchingAnim;
    CCAnimation *crouchingMalletAnim;
    CCAnimation *standingUpAnim;
    CCAnimation *standingUpMalletAnim;
    CCAnimation *jumpingAnim;
    CCAnimation *jumpingMalletAnim;
    CCAnimation *afterJumpingAnim;
    CCAnimation *afterJumpingMalletAnim;

    // Punching
    CCAnimation *rightPunchAnim;
    CCAnimation *leftPunchAnim;
    CCAnimation *malletPunchAnim;

    // Taking Damage and Death
    CCAnimation *phaserShockAnim;
    CCAnimation *deathAnim;

    SneakyJoystick *joystick;
    SneakyButton *jumpButton ;
    SneakyButton *attackButton;

    float millisecondsStayingIdle;
}
// Standing, Breathing, Walking
@property (nonatomic, retain) CCAnimation *breathingAnim;
@property (nonatomic, retain) CCAnimation *breathingMalletAnim;
@property (nonatomic, retain) CCAnimation *walkingAnim;
@property (nonatomic, retain) CCAnimation *walkingMalletAnim;

// Crouching, Standing Up, Jumping
@property (nonatomic, retain) CCAnimation *crouchingAnim;
@property (nonatomic, retain) CCAnimation *crouchingMalletAnim;
@property (nonatomic, retain) CCAnimation *standingUpAnim;
@property (nonatomic, retain) CCAnimation *standingUpMalletAnim;
@property (nonatomic, retain) CCAnimation *jumpingAnim;
@property (nonatomic, retain) CCAnimation *jumpingMalletAnim;
@property (nonatomic, retain) CCAnimation *afterJumpingAnim;
@property (nonatomic, retain) CCAnimation *afterJumpingMalletAnim;

// Punching
@property (nonatomic, retain) CCAnimation *rightPunchAnim;
@property (nonatomic, retain) CCAnimation *leftPunchAnim;
@property (nonatomic, retain) CCAnimation *malletPunchAnim;

// Taking Damage and Death
@property (nonatomic, retain) CCAnimation *phaserShockAnim;
@property (nonatomic, retain) CCAnimation *deathAnim;

@property (nonatomic,assign) SneakyJoystick *joystick;
@property (nonatomic,assign) SneakyButton *jumpButton;
@property (nonatomic,assign) SneakyButton *attackButton;
@end

Listing 4.5 shows the large number of animations that are possible with the Viking character as well as instance variables to point to the onscreen joystick and button controls.

The key items to note are the typedef enumerator for the left and right punches, an instance variable to store what the last punch thrown was, and a float to keep track of how long the player has been idle. The code for the Viking implementation file is a bit on the lengthy side, hence it is broken up into four Listings, 4.6 through 4.9. Open the Viking.m implementation file and replace the code so that it matches the contents in Listings 4.6, 4.7, 4.8, and 4.9.

Listing 4.6. Viking.m implementation file (part 1 of 4)

//  Viking.m
//  SpaceViking
#import "Viking.h"

@implementation Viking
@synthesize joystick;
@synthesize jumpButton ;
@synthesize attackButton;

// Standing, Breathing, Walking
@synthesize breathingAnim;
@synthesize breathingMalletAnim;
@synthesize walkingAnim;
@synthesize walkingMalletAnim;
// Crouching, Standing Up, Jumping
@synthesize crouchingAnim;
@synthesize crouchingMalletAnim;
@synthesize standingUpAnim;
@synthesize standingUpMalletAnim;
@synthesize jumpingAnim;
@synthesize jumpingMalletAnim;
@synthesize afterJumpingAnim;
@synthesize afterJumpingMalletAnim;
// Punching
@synthesize rightPunchAnim;
@synthesize leftPunchAnim;
@synthesize malletPunchAnim;
// Taking Damage and Death
@synthesize phaserShockAnim;
@synthesize deathAnim;

- (void) dealloc {
    joystick = nil;
    jumpButton = nil;
    attackButton = nil;
    [breathingAnim release];
    [breathingMalletAnim release];
    [walkingAnim release];
    [walkingMalletAnim release];
    [crouchingAnim release];
    [crouchingMalletAnim release];
    [standingUpAnim release];
    [standingUpMalletAnim release];
    [jumpingAnim release];
    [jumpingMalletAnim release];
    [afterJumpingAnim release];
    [afterJumpingMalletAnim release];
    [rightPunchAnim release];
    [leftPunchAnim release];
    [malletPunchAnim release];
    [phaserShockAnim release];
    [deathAnim release];

    [super dealloc];
}

-(BOOL)isCarryingWeapon {
    return isCarryingMallet;
}

-(int)getWeaponDamage {
    if (isCarryingMallet) {
        return kVikingMalletDamage;
    }
    return kVikingFistDamage;
}
-(void)applyJoystick:(SneakyJoystick *)aJoystick forTimeDelta:(float)
deltaTime
{
    CGPoint scaledVelocity = ccpMult(aJoystick.velocity, 128.0f);
    CGPoint oldPosition = [self position];
    CGPoint newPosition =
    ccp(oldPosition.x +
        scaledVelocity.x * deltaTime,
        oldPosition.y);                                          // 1
    [self setPosition:newPosition];                              // 2

    if (oldPosition.x > newPosition.x) {
        self.flipX = YES;                                        // 3
    } else {
        self.flipX = NO;
    }
}

-(void)checkAndClampSpritePosition {
    if (self.characterState != kStateJumping) {
        if ([self position].y > 110.0f)
            [self setPosition:ccp([self position].x,110.0f)];
    }
    [super checkAndClampSpritePosition];
}

At the beginning of the Viking.m implementation file is the dealloc method. Far wiser Objective-C developers than this author have commented on the benefits of having your dealloc method up top and near your synthesize statements. The idea behind this move is to make sure you are deallocating any and all instance variables, therefore avoiding one of the main causes of memory leaks in Objective-C code.

Following the dealloc method, you have the isCarryingWeapon method, but since it is self-explanatory, move on to the applyJoystick method. This method is similar to the one back in Chapter 2, "Hello, Space Viking," Listing 2.10, but it has been modified to deal only with Ole's movement and removes the handling for the jump or attack buttons. The first change to applyJoystick is the creation of the oldPosition variable to track the Viking's position before it is moved. Looking at the applyJoystick method in Listing 4.6, take a note of the following key lines:

  1. Sets the new position based on the velocity of the joystick, but only in the x-axis. The y position stays constant, making it so Ole only walks to the left or right, and not up or down.
  2. Moves the Viking to the new position.
  3. Compares the old position with the new position, flipping the Viking horizontally if needed. If you look closely at the Viking images, he is facing to the right by default. If this method determines that the old position is to the right of the new position, Ole is moving to the left, and his pixels have to be flipped horizontally. If you don't flip Ole horizontally, he will look like he is trying to do the moonwalk when you move him to the left. It is a cool effect but not useful for your Viking.

Cocos2D has two built-in functions you will make use of frequently: flipX and flipY. These functions flip the pixels of a texture along the x- or y-axis, allowing you to display a mirror image of your graphics without having to have left- and right-facing copies of each image for each character. Figure 4.1 shows the effect of flipX on the Viking texture. This is a really handy feature to have, since it helps reduce the size of your application, and it keeps you from having to create images for every possible state.

Figure 4.1

Figure 4.1 Effects of the flipX function on the Viking texture or graphic

The next section of the Viking.m implementation file covers the changeState method. As you learned with the RadarDish class, the changeState method is used to transition the character from one state to another and to start the appropriate animations for each state. Copy the contents of Listing 4.7 into your Viking.m class.

Listing 4.7. Viking.m implementation file (part 2 of 4)

#pragma mark -
-(void)changeState:(CharacterStates)newState {
    [self stopAllActions];
    id action = nil;
    id movementAction = nil;
    CGPoint newPosition;
    [self setCharacterState:newState];

    switch (newState) {
        case kStateIdle:
            if (isCarryingMallet) {
                [self setDisplayFrame:[[CCSpriteFrameCache
                      sharedSpriteFrameCache]
                      spriteFrameByName:@"sv_mallet_1.png"]];
            } else {
                [self setDisplayFrame:[[CCSpriteFrameCache
                      sharedSpriteFrameCache]
                      spriteFrameByName:@"sv_anim_1.png"]];
            }
            break;

        case kStateWalking:
            if (isCarryingMallet) {
                action =
                    [CCAnimate actionWithAnimation:walkingMalletAnim
                               restoreOriginalFrame:NO];
            } else {
                action =
                    [CCAnimate actionWithAnimation:walkingAnim
                               restoreOriginalFrame:NO];
            }
            break;


        case kStateCrouching:
            if (isCarryingMallet) {
                action =
                    [CCAnimate actionWithAnimation:crouchingMalletAnim
                               restoreOriginalFrame:NO];
            } else {
                action =
                    [CCAnimate actionWithAnimation:crouchingAnim
                               restoreOriginalFrame:NO];
            }
            break;

        case kStateStandingUp:
            if (isCarryingMallet) {
                action =
                    [CCAnimate actionWithAnimation:standingUpMalletAnim
                               restoreOriginalFrame:NO];

            } else {
                action =
                    [CCAnimate actionWithAnimation:standingUpAnim
                               restoreOriginalFrame:NO];
            }
            break;

        case kStateBreathing:
            if (isCarryingMallet) {
                action =
                    [CCAnimate actionWithAnimation:breathingMalletAnim
                               restoreOriginalFrame:YES];
            } else {
                action =
                    [CCAnimate actionWithAnimation:breathingAnim
                               restoreOriginalFrame:YES];
            }
            break;

         case kStateJumping:
            newPosition = ccp(screenSize.width * 0.2f, 0.0f);
            if ([self flipX] == YES) {
                newPosition = ccp(newPosition.x * -1.0f, 0.0f);
            }
            movementAction = [CCJumpBy actionWithDuration:0.5f
                                                 position:newPosition
                                                   height:160.0f
                                                    jumps:1];

            if (isCarryingMallet) {
                // Viking Jumping animation with the Mallet
                action = [CCSequence actions:
                          [CCAnimate
                              actionWithAnimation:crouchingMalletAnim
                              restoreOriginalFrame:NO],
                          [CCSpawn actions:
                           [CCAnimate
                              actionWithAnimation:jumpingMalletAnim
                              restoreOriginalFrame:YES],
                           movementAction,
                           nil],
                          [CCAnimate
                             actionWithAnimation:afterJumpingMalletAnim
                             restoreOriginalFrame:NO],
                          nil];
            } else {
                // Viking Jumping animation without the Mallet
                action = [CCSequence actions:
                          [CCAnimate
                              actionWithAnimation:crouchingAnim
                              restoreOriginalFrame:NO],
                          [CCSpawn actions:
                           [CCAnimate
                               actionWithAnimation:jumpingAnim
                               restoreOriginalFrame:YES],
                           movementAction,
                           nil],
                          [CCAnimate
                              actionWithAnimation:afterJumpingAnim
                              restoreOriginalFrame:NO],
                          nil];
            }

            break;

        case kStateAttacking:
            if (isCarryingMallet == YES) {
                action = [CCAnimate
                             actionWithAnimation:malletPunchAnim
                             restoreOriginalFrame:YES];
            } else {
                if (kLeftHook == myLastPunch) {
                    // Execute a right hook
                    myLastPunch = kRightHook;
                    action = [CCAnimate
                                 actionWithAnimation:rightPunchAnim
                                 restoreOriginalFrame:NO];
                } else {
                    // Execute a left hook
                    myLastPunch = kLeftHook;
                    action = [CCAnimate
                                 actionWithAnimation:leftPunchAnim
                                 restoreOriginalFrame:NO];
                }
            }
            break;

        case kStateTakingDamage:
            self.characterHealth = self.characterHealth - 10.0f;
            action = [CCAnimate
                         actionWithAnimation:phaserShockAnim
                         restoreOriginalFrame:YES];
            break;

        case kStateDead:
            action = [CCAnimate
                         actionWithAnimation:deathAnim
                         restoreOriginalFrame:NO];
            break;

        default:
            break;
    }
    if (action != nil) {
        [self runAction:action];
    }
}

The first part of the changeState method stops any running actions, including animations. Any running actions would be a part of a previous state of the Viking and would no longer be valid. Following the first line, the Viking state is set to the new state value, and a switch statement is used to carry out the animations for the new state. A few items are important to note:

  1. Method variables cannot be declared inside a switch statement, as they would be out of scope as soon as the code exited the switch statement. Your id action variable is declared above the switch statement but initialized inside the switch branches.
  2. Most of the states have two animations: one for the Viking with the Mallet and one without. The isCarryingMallet Boolean instance variable is key in determining which animation to play.
  3. An action in Cocos2D can be made up of other actions in that it can be a compound action. The switch branch taken when the Viking state is kStateJumping has a compound action made up of CCSequence, CCAnimate, CCSpawn, and CCJumpBy actions. The CCJumpBy action provides the parabolic movement for Ole the Viking, while the CCAnimate actions play the crouching, jumping, and landing animations. The CCSpawn action allows for more than one action to be started at the same time, in this case the CCJumpBy and CCAnimate animation action of Ole jumping. The CCSequence action ties it all together by making Ole crouch down, then jump, and finally land on his feet in sequence.
  4. Taking a closer look at the kStateTakingDamage switch branch, you can see that after the animation completes, Ole reverts back to the frame that was displaying before the animation started. In this state transition, the CCAnimate action has the restoreOriginalFrame set to YES. The end effect of restoreOriginalFrame is that Ole will animate receiving a hit, and then return to looking as he did before the hit took place.

The first line of Listing 4.7 might be rather odd-looking: #pragma mark. The pragma mark serves as a formatting guide to Xcode and is not seen by the compiler. After the words #pragma mark you can place any text you would like displayed in the Xcode pulldown for this file. If you have just a hyphen (-), Xcode will create a separate section for that portion of the file. Using pragma mark can make your code easier to navigate. Figure 4.2 shows the effects of the pragma mark statements in the completed Viking.m file.

Figure 4.2

Figure 4.2 The effect of the pragma mark statements in the Xcode pulldown menus

The next section of the Viking.m file covers the updateStateWithDeltaTime and the adjustedBoundingBox methods. Copy the contents of Listing 4.8 into your Viking.m file immediately following the changeState method.

Listing 4.8. Viking.m implementation file (part 3 of 4)

#pragma mark -
-(void)updateStateWithDeltaTime:(ccTime)deltaTime
andListOfGameObjects:(CCArray*)listOfGameObjects {
    if (self.characterState == kStateDead)
        return; // Nothing to do if the Viking is dead

    if ((self.characterState == kStateTakingDamage) &&
       ([self numberOfRunningActions] > 0))
        return; // Currently playing the taking damage animation

    // Check for collisions
    // Change this to keep the object count from querying it each time
    CGRect myBoundingBox = [self adjustedBoundingBox];
    for (GameCharacter *character in listOfGameObjects) {
        // This is Ole the Viking himself
        // No need to check collision with one's self
        if ([character tag] == kVikingSpriteTagValue)
            continue;

        CGRect characterBox = [character adjustedBoundingBox];
        if (CGRectIntersectsRect(myBoundingBox, characterBox)) {
            // Remove the PhaserBullet from the scene
            if ([character gameObjectType] == kEnemyTypePhaser) {
                [self changeState:kStateTakingDamage];
                [character changeState:kStateDead];
            } else if ([character gameObjectType] ==
                       kPowerUpTypeMallet) {
                // Update the frame to indicate Viking is
                // carrying the mallet
                isCarryingMallet = YES;
                [self changeState:kStateIdle];
                // Remove the Mallet from the scene
                [character changeState:kStateDead];
            } else if ([character gameObjectType] ==
                        kPowerUpTypeHealth) {
                [self setCharacterHealth:100.0f];
                // Remove the health power-up from the scene
                [character changeState:kStateDead];
            }
        }
    }

    [self checkAndClampSpritePosition];
    if ((self.characterState == kStateIdle) ||
        (self.characterState == kStateWalking) ||
        (self.characterState == kStateCrouching) ||
        (self.characterState == kStateStandingUp) ||
        (self.characterState == kStateBreathing)) {

        if (jumpButton.active) {
            [self changeState:kStateJumping];
        } else if (attackButton.active) {
            [self changeState:kStateAttacking];
        } else if ((joystick.velocity.x == 0.0f) &&
                   (joystick.velocity.y == 0.0f)) {
            if (self.characterState == kStateCrouching)
                [self changeState:kStateStandingUp];
        } else if (joystick.velocity.y < -0.45f) {
            if (self.characterState != kStateCrouching)
                [self changeState:kStateCrouching];
        } else if (joystick.velocity.x != 0.0f) { // dpad moving
            if (self.characterState != kStateWalking)
                [self changeState:kStateWalking];
            [self applyJoystick:joystick
                   forTimeDelta:deltaTime];
        }
    }

    if ([self numberOfRunningActions] == 0) {
        // Not playing an animation
        if (self.characterHealth <= 0.0f) {
            [self changeState:kStateDead];
        } else if (self.characterState == kStateIdle) {
            millisecondsStayingIdle = millisecondsStayingIdle +
                                      deltaTime;
            if (millisecondsStayingIdle > kVikingIdleTimer) {
                [self changeState:kStateBreathing];
            }
        } else if ((self.characterState != kStateCrouching) &&
                   (self.characterState != kStateIdle)){
            millisecondsStayingIdle = 0.0f;
            [self changeState:kStateIdle];
        }
    }
}

#pragma mark -
-(CGRect)adjustedBoundingBox {
    // Adjust the bouding box to the size of the sprite
    // without the transparent space
    CGRect vikingBoundingBox = [self boundingBox];
    float xOffset;
    float xCropAmount = vikingBoundingBox.size.width * 0.5482f;
    float yCropAmount = vikingBoundingBox.size.height * 0.095f;

    if ([self flipX] == NO) {
        // Viking is facing to the rigth, back is on the left
        xOffset = vikingBoundingBox.size.width * 0.1566f;
    } else {
        // Viking is facing to the left; back is facing right
        xOffset = vikingBoundingBox.size.width * 0.4217f;
    }
    vikingBoundingBox =
    CGRectMake(vikingBoundingBox.origin.x + xOffset,
               vikingBoundingBox.origin.y,
               vikingBoundingBox.size.width - xCropAmount,
               vikingBoundingBox.size.height - yCropAmount);

    if (characterState == kStateCrouching) {
        // Shrink the bounding box to 56% of height
        // 88 pixels on top on iPad
        vikingBoundingBox = CGRectMake(vikingBoundingBox.origin.x,
        vikingBoundingBox.origin.y,
        vikingBoundingBox.size.width,
        vikingBoundingBox.size.height * 0.56f);
    }

    return vikingBoundingBox;
}

In the same manner as the RadarDish updateStateWithDeltaMethod worked, this method also returns immediately if the Viking is dead. There is no need to update a dead Viking because he won't be going anywhere.

If the Viking is in the middle of playing, the taking damage animation is played. This method again short-circuits and returns. The taking damage animation is blocking in that the player cannot do anything else while Ole the Viking is being shocked.

If the Viking is not taking damage or is dead, then the next step is to check what objects are coming in contact with the Viking. If there are objects in contact with the Viking, he checks to see if they are:

  • Phaser: Changes the Viking state to taking damage.
  • Mallet power-up: Gives Ole the Viking the mallet, a fearsome weapon.
  • Health power-up: Ole's health is restored back to 100.

After checking for contacts, often called collisions, a quick call is made to the checkAndClampSpritePosition method to ensure that the Viking sprite stays within the boundaries of the screen.

The next if statement block checks the state of the joystick, jump, and attack buttons and changes the state of the Viking to reflect which controls are being pressed. The if statement executes only if the Viking is not currently carrying out a blocking animation, such as jumping.

Lastly the Viking class reaches a section of the updateStateWithDeltaTime method that handles what happens when there are no animations currently running. Cocos2D has a convenience method on CCNodes that reports back the number of actions running against a particular CCNode object. If you recall from the beginning of this chapter, all animations have to be run by a CCAnimate action. Once the animation for a state completes, the numberOfRunningActions will return zero for the Viking, and this block of code will reset the Viking's state.

If the health is zero or less, the Viking will move into the dead state. Otherwise, if Viking is idle, a counter is incremented indicating how many seconds the player has been idle. Once that counter reaches a set limit, the Viking will play a heavy breathing animation. Finally, if the Viking is not already idle or crouching, he will move back into the idle state.

After the updateStateWithDeltaTime method, there is the adjustedBoundingBox method you declared inside the GameObject class. In Chapter 3, "Introduction to Cocos2D Animations and Actions," Figure 3.6 illustrated the transparent space in the Viking texture between the actual Viking and the edges of the image/texture. This method compensates for the transparent pixels by returning an adjusted bounding box that does not include the transparent pixels. The flipX parameter is used to determine which side the Viking is facing, as fewer pixels are trimmed off the back of the Viking image than the front.

The last part of the Viking.m implementation file sets up the animations inside the initAnimations method and the instance variables inside the init method. Once more, copy the contents of Listing 4.9 into your Viking.m implementation file immediately following the end of the adjustedBoundingBox method.

Listing 4.9. Viking.m implementation file (part 4 of 4)

#pragma mark -
-(void)initAnimations {

    [self setBreathingAnim:[self loadPlistForAnimationWithName:
@"breathingAnim" andClassName:NSStringFromClass([self class])]];

    [self setBreathingMalletAnim:[self loadPlistForAnimationWithName:
@"breathingMalletAnim" andClassName:NSStringFromClass([self class])]];

    [self setWalkingAnim:[self loadPlistForAnimationWithName:
@"walkingAnim" andClassName:NSStringFromClass([self class])]];

    [self setWalkingMalletAnim:[self loadPlistForAnimationWithName:
@"walkingMalletAnim" andClassName:NSStringFromClass([self class])]];

    [self setCrouchingAnim:[self loadPlistForAnimationWithName:
@"crouchingAnim" andClassName:NSStringFromClass([self class])]];

    [self setCrouchingMalletAnim:[self loadPlistForAnimationWithName:
@"crouchingMalletAnim" andClassName:NSStringFromClass([self class])]];

    [self setStandingUpAnim:[self loadPlistForAnimationWithName:
@"standingUpAnim" andClassName:NSStringFromClass([self class])]];

    [self setStandingUpMalletAnim:[self loadPlistForAnimationWithName:
@"standingUpMalletAnim" andClassName:NSStringFromClass([self class])]];

    [self setJumpingAnim:[self loadPlistForAnimationWithName:
@"jumpingAnim" andClassName:NSStringFromClass([self class])]];

    [self setJumpingMalletAnim:[self loadPlistForAnimationWithName:
@"jumpingMalletAnim" andClassName:NSStringFromClass([self class])]];

    [self setAfterJumpingAnim:[self loadPlistForAnimationWithName:
@"afterJumpingAnim" andClassName:NSStringFromClass([self class])]];

    [self setAfterJumpingMalletAnim:[self loadPlistForAnimationWithName:
@"afterJumpingMalletAnim" andClassName:NSStringFromClass([self class])]];

    // Punches
    [self setRightPunchAnim:[self loadPlistForAnimationWithName:
@"rightPunchAnim" andClassName:NSStringFromClass([self class])]];

    [self setLeftPunchAnim:[self loadPlistForAnimationWithName:
@"leftPunchAnim" andClassName:NSStringFromClass([self class])]];

    [self setMalletPunchAnim:[self loadPlistForAnimationWithName:
@"malletPunchAnim" andClassName:NSStringFromClass([self class])]];

    // Taking Damage and Death
    [self setPhaserShockAnim:[self loadPlistForAnimationWithName:
@"phaserShockAnim" andClassName:NSStringFromClass([self class])]];

    [self setDeathAnim:[self loadPlistForAnimationWithName:
@"vikingDeathAnim" andClassName:NSStringFromClass([self class])]];

}

#pragma mark -
-(id) init {
    if( (self=[super init]) ) {
        joystick = nil;
        jumpButton = nil;
        attackButton = nil;
        self.gameObjectType = kVikingType;
        myLastPunch = kRightHook;
        millisecondsStayingIdle = 0.0f;
        isCarryingMallet = NO;
        [self initAnimations];

    }
    return self;
}
@end

The initAnimation method, while quite long, is very basic in that it only initializes all of the Viking animations based on the display frames already loaded from the scene1atlas.plist file in the GameplayLayer class. The init method sets up the instance variables to their starting values.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020