/
BlockRectangle.m
58 lines (44 loc) · 1.02 KB
/
BlockRectangle.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
//
// BlockRectangle.m
// TotemBalance
//
// Created by Raúl Uranga on 7/6/11.
// Copyright 2011 GrupoW. All rights reserved.
//
#import "BlockRectangle.h"
#import "GameScene.h"
@implementation BlockRectangle
-(void) dealloc
{
[super dealloc];
}
-(id) initWithPosition: (CGPoint)pos theGame:(GameLayer *) game
{
if ((self = [super init])) {
self.theGame = game;
[game addChild:self z:1];
mySprite = [CCSprite spriteWithFile:@"block_rect.png"];
[mySprite setPosition:pos];
[game addChild:mySprite z:1];
int num = 4;
CGPoint verts[] =
{
ccp(-33,-12),
ccp(-33,12),
ccp(33,12),
ccp(33,-12),
};
myBody = cpBodyNew(1.0f,cpMomentForPoly(1.0f, num, verts, CGPointZero));
myBody->p = pos;
myBody->data = self;
cpSpaceAddBody(game.space, myBody);
myShape = cpPolyShapeNew(myBody, num, verts, CGPointZero);
myShape->e = 0.5;
myShape->u = 0.5;
myShape->data = mySprite;
myShape->collision_type = 3;
cpSpaceAddShape(game.space, myShape);
}
return self;
}
@end