-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWuLinScene.m
More file actions
122 lines (101 loc) · 3.55 KB
/
WuLinScene.m
File metadata and controls
122 lines (101 loc) · 3.55 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// WuLinScene.m
// Ennuma
//
// Created by ennuma on 14-7-1.
// Copyright 2014年 ennuma. All rights reserved.
//
#import "WuLinScene.h"
#import "MenPai.h"
#import "HuaShanPai.h"
#import "HengShanPai.h"
#import "SongShanPai.h"
@implementation WuLinScene
MenPai* currentSelected;
static CGPoint lasttouchloc;
+ (WuLinScene *)scene
{
WuLinScene* ret = [[self alloc] init];
[ret initBackgorund];
[ret initMenPai];
[ret setUserInteractionEnabled:YES];
return ret;
}
-(id)init
{
self = [super init];
if (!self) {
return nil;
}
menPaiArr = [[NSMutableArray alloc]init];
return self;
}
-(void)initBackgorund
{
CCSprite* bg = [CCSprite spriteWithImageNamed:@"bg_map.png"];
bg.position = CGPointMake([bg contentSize].width*0.5, [bg contentSize].height*0.5);
[self addChild:bg z:-99 name:@"bg_map"];
[self setContentSize:bg.contentSize];
}
-(void)initMenPai
{
//CCLOG(@"%f", [self contentSize].width);
//CCLOG(@"%f", [self contentSize].height);
HuaShanPai* huashan = [HuaShanPai menPaiWithLocation:CGPointMake([self contentSize].width/4, [self contentSize].height/4)];
[self addMenPai: huashan z:0 name:@"huashan"];
HengShanPai* henshan = [HengShanPai menPaiWithLocation:CGPointMake([self contentSize].width/4, [self contentSize].height*3/4)];
[self addMenPai: henshan z:0 name:@"henshan"];
MenPai* songshan = [SongShanPai menPaiWithLocation:CGPointMake([self contentSize].width*3/4, [self contentSize].height/4)];
[self addMenPai: songshan z:0 name:@"songshan"];
MenPai* taishan = [MenPai menPaiWithLocation:CGPointMake([self contentSize].width*3/4, [self contentSize].height*3/4)];
[self addMenPai: taishan z:0 name:@"taishan"];
[huashan.neighbours addObject:henshan];
[huashan.neighbours addObject:songshan];
[henshan.neighbours addObject:huashan];
[henshan.neighbours addObject:taishan];
[songshan.neighbours addObject:huashan];
[songshan.neighbours addObject:taishan];
[taishan.neighbours addObject:henshan];
[taishan.neighbours addObject:songshan];
CCLOG(@"%f", [huashan contentSize].width);
CCLOG(@"%f", [huashan contentSize].height);
CCLOG(@"%f", [huashan boundingBox].origin.x);
CCLOG(@"%f", [huashan boundingBox].origin.y);
huashan.controlByPlayer=YES;
henshan.controlByPlayer = YES;
}
-(void)addMenPai:(CCNode*)child z:(int)zorder name:(NSString*) name
{
[menPaiArr addObject:child];
[self addChild:child z:zorder name:name];
}
-(void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
lasttouchloc = [touch locationInNode:self];
for (MenPai* menpai in menPaiArr) {
if (CGRectContainsPoint([menpai boundingBox], lasttouchloc)) {
currentSelected = menpai;
break;
}
}
}
-(void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint pos = [touch locationInNode:self];
CGPoint moveBy = ccpSub(pos, lasttouchloc);
lasttouchloc = pos;
CCActionMoveBy* moveby = [CCActionMoveBy actionWithDuration:0.5 position:moveBy];
CCActionEase* action = [CCActionEase actionWithAction:moveby];
[self runAction:action];
currentSelected = nil;
}
-(void)touchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
if (currentSelected!=nil) {
CCScene* menpaiscene = [currentSelected getMenPaiScene];
//[[CCDirector sharedDirector] pushScene:menpaiscene];
[self addChild:menpaiscene z:99 name:@"menpai"];
menpaiscene.position = CGPointMake(-self.position.x, -self.position.y);
}
}
@end