Skip to content

Commit

Permalink
Merge branch 'feature/touchableBlocks' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rauluranga committed Jul 6, 2011
2 parents c70dc77 + 3f95b29 commit fc33674
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Classes/BlockCircle.h
@@ -0,0 +1,21 @@
//
// BlockCircle.h
// TotemBalance
//
// Created by Raúl Uranga on 7/6/11.
// Copyright 2011 GrupoW. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "chipmunk.h"
#import "TouchableBlock.h"

@class TouchableBlock;


@interface BlockCircle : TouchableBlock {

}

@end
50 changes: 50 additions & 0 deletions Classes/BlockCircle.m
@@ -0,0 +1,50 @@
//
// BlockCircle.m
// TotemBalance
//
// Created by Raúl Uranga on 7/6/11.
// Copyright 2011 GrupoW. All rights reserved.
//

#import "BlockCircle.h"
#import "GameScene.h"

@implementation BlockCircle

-(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_circ.png"];
[mySprite setPosition:pos];

[game addChild:mySprite z:1];

myBody = cpBodyNew(1.0f,cpMomentForCircle(1, 16, 16, CGPointZero));
myBody->p = pos;
myBody->data = self;

cpSpaceAddBody(game.space, myBody);

myShape = cpCircleShapeNew(myBody, 16, CGPointZero);
myShape->e = 0.5;
myShape->u = 0.5;
myShape->data = mySprite;
myShape->collision_type = 3;

cpSpaceAddShape(game.space, myShape);

}

return self;
}


@end
20 changes: 20 additions & 0 deletions Classes/BlockRectangle.h
@@ -0,0 +1,20 @@
//
// BlockRectangle.h
// TotemBalance
//
// Created by Raúl Uranga on 7/6/11.
// Copyright 2011 GrupoW. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "chipmunk.h"
#import "TouchableBlock.h"

@class TouchableBlock;

@interface BlockRectangle : TouchableBlock {

}

@end
58 changes: 58 additions & 0 deletions Classes/BlockRectangle.m
@@ -0,0 +1,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
21 changes: 21 additions & 0 deletions Classes/BlockTriangle.h
@@ -0,0 +1,21 @@
//
// BlockTriangle.h
// TotemBalance
//
// Created by Raúl Uranga on 7/6/11.
// Copyright 2011 GrupoW. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "chipmunk.h"
#import "TouchableBlock.h"

@class TouchableBlock;


@interface BlockTriangle : TouchableBlock {

}

@end
57 changes: 57 additions & 0 deletions Classes/BlockTriangle.m
@@ -0,0 +1,57 @@
//
// BlockTriangle.m
// TotemBalance
//
// Created by Raúl Uranga on 7/6/11.
// Copyright 2011 GrupoW. All rights reserved.
//

#import "BlockTriangle.h"
#import "GameScene.h"

@implementation BlockTriangle

-(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_tri.png"];
[mySprite setPosition:pos];

[game addChild:mySprite z:1];

int num = 3;
CGPoint verts[] =
{
ccp(0,15),
ccp(16,-15),
ccp(-16,-15),
};

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
2 changes: 2 additions & 0 deletions Classes/GameScene.h
Expand Up @@ -20,11 +20,13 @@
cpSpace *space;
Totem *totem;
Goal *goal;
NSMutableArray *touchableBlocks;
}

@property (nonatomic, retain) Goal *goal;
@property (nonatomic, retain) Totem *totem;
@property (nonatomic, readwrite) cpSpace *space;
@property (nonatomic, retain) NSMutableArray *touchableBlocks;



Expand Down
28 changes: 28 additions & 0 deletions Classes/GameScene.m
Expand Up @@ -9,6 +9,9 @@

// Import the interfaces
#import "GameScene.h"
#import "BlockRectangle.h"
#import "BlockTriangle.h"
#import "BlockCircle.h"

enum {
kTagBatchNode = 1,
Expand Down Expand Up @@ -38,7 +41,13 @@ @implementation GameLayer
@synthesize goal;
@synthesize totem;
@synthesize space;
@synthesize touchableBlocks;

-(void) dealloc
{
[touchableBlocks release];
[super dealloc];
}

+(id) scene
{
Expand Down Expand Up @@ -125,6 +134,25 @@ -(id) init
totem = [[Totem alloc] initWithPosition:ccp(160,340) theGame:self];
goal = [[Goal alloc] initWithPosition:ccp(160,25) theGame:self];

touchableBlocks = [[NSMutableArray alloc] init];
for (int i = 0; i<5; i++) {
BlockRectangle * b = [[BlockRectangle alloc] initWithPosition:ccp(160,50 + 50 * i) theGame:self];
[touchableBlocks addObject:b];
[b release];
}

for (int i = 0; i<5; i++) {
BlockTriangle * b = [[BlockTriangle alloc] initWithPosition:ccp(80,50 + 50 * i) theGame:self];
[touchableBlocks addObject:b];
[b release];
}

for (int i = 0; i<5; i++) {
BlockCircle * b = [[BlockCircle alloc] initWithPosition:ccp(240 + 10 * i,50 + 50 * i) theGame:self];
[touchableBlocks addObject:b];
[b release];
}

/*/
// top
shape = cpSegmentShapeNew(staticBody, ccp(0,wins.height), ccp(wins.width,wins.height), 0.0f);
Expand Down
37 changes: 37 additions & 0 deletions Classes/TouchableBlock.h
@@ -0,0 +1,37 @@
//
// TouchableBlock.h
// TotemBalance
//
// Created by Raúl Uranga on 7/6/11.
// Copyright 2011 GrupoW. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "chipmunk.h"

typedef enum tagState
{
kStateGrabbed,
kStateUngrabbed
} touchState;

@class GameLayer;

@interface TouchableBlock : CCNode <CCTargetedTouchDelegate> {
CCSprite *mySprite;
cpBody *myBody;
cpShape *myShape;
GameLayer *theGame;
touchState state;

}

@property (nonatomic, retain) CCSprite *mySprite;
@property (nonatomic, retain) GameLayer *theGame;
@property (nonatomic, readwrite) cpBody *myBody;
@property (nonatomic, readwrite) cpShape *myShape;
@property (nonatomic, readwrite) touchState state;;


@end
34 changes: 34 additions & 0 deletions Classes/TouchableBlock.m
@@ -0,0 +1,34 @@
//
// TouchableBlock.m
// TotemBalance
//
// Created by Raúl Uranga on 7/6/11.
// Copyright 2011 GrupoW. All rights reserved.
//

#import "TouchableBlock.h"
#import "GameScene.h"


@implementation TouchableBlock

@synthesize mySprite;
@synthesize theGame;
@synthesize myBody;
@synthesize myShape;
@synthesize state;

-(void) dealloc
{
[super dealloc];
}

-(id) init
{
if ((self=[super init])) {
self.state = kStateUngrabbed;
}
return self;
}

@end
Binary file added Classes/block_circ.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Classes/block_rect.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Classes/block_tri.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fc33674

Please sign in to comment.