-
Notifications
You must be signed in to change notification settings - Fork 1
/
Danbo.m
executable file
·65 lines (55 loc) · 1.6 KB
/
Danbo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Danbo.m
// TouchBattle
//
// Created by keitanxkeitan on 11/08/26.
// Copyright 2011 keitanxkeitan. All rights reserved.
//
#import "Danbo.h"
NSString * const kDanboColors[] = {
@"red", @"green", @"blue", @"black",
};
@implementation Danbo
@synthesize canTouch = canTouch_, broken = broken_;
- (id)initWithTexture:(CCTexture2D *)texture rect:(CGRect)rect {
self = [super initWithTexture:texture rect:rect];
if (self) {
canTouch_ = YES;
broken_ = NO;
life_ = 5;
}
return self;
}
- (id)initWithPosition:(CGPoint)point type:(DanboType)type {
NSString *filename = [NSString stringWithFormat:@"danbo_%@.png", kDanboColors[type]];
self = [super initWithFile:filename];
if (self) {
self.position = ccp(point.x, point.y);
life_ = 5;
lifeLabel_ = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%d", life_]
fontName:@"Marker Felt"
fontSize:24];
lifeLabel_.position = ccp(self.contentSize.width / 2, self.contentSize.height / 2);
[self addChild:lifeLabel_ z:100];
}
return self;
}
- (void)jump {
id actionBy = [CCJumpBy actionWithDuration:0.2 position:ccp(0,0) height:30 jumps:1];
[self runAction:[CCSequence actions:actionBy,
[CCCallFunc actionWithTarget:self selector:@selector(jumpEnd)],
nil]];
canTouch_ = NO;
}
- (void)jumpEnd {
canTouch_ = YES;
}
- (void)damage:(int)dam {
life_ -= dam;
[lifeLabel_ setString:[NSString stringWithFormat:@"%d", life_]];
if (life_ <= 0) {
[self removeFromParentAndCleanup:NO];
broken_ = YES;
}
}
@end