#endif
+#import "qq/util/QQ_NARG.h"
+#import "qq/util/QQLogging.h"
+
#import "TanksMacros.h"
#import "qq/NSArray+QQExtensions.h"
#define SQRT_TWO 1.41421356237f
#define b2s(__val) ((__val)?("YES"):("NO"))
+
#define hex2color(__rgb) (ccc3( (((__rgb)>>16)&0xff), (((__rgb)>>8)&0xff), ((__rgb)&0xff) ))
+
#define v2p(__vec) (ccp( (__vec).x, (__vec).y ))
-#define p2v(__pt) (b2Vec2( (__pt).x, (__pt).y ))
+#define p2v(__pt) (Vec( (__pt).x, (__pt).y ))
+#define p2v2(__pt) (b2Vec2( (__pt).x, (__pt).y ))
+
+#define deg2rad(__theta) ((__theta) * 0.01745329252f) // PI / 180
+#define rad2deg(__theta) ((__theta) * 57.29577951f) // PI * 180
+
#endif
\ No newline at end of file
#import <Box2D/Box2D.h>
+#import "qq/util/QQLogging.h"
#import "game/QQGame.h"
#import "game/unit/QQActors.h"
#import "physics/event/QQContactNotification.h"
float wMax = frame.width / PIXELS_PER_METER;
float hMax = frame.height / PIXELS_PER_METER;
// [[[QQPlayer alloc] initNamed:@"Pink" atX:wMax/6 y:hMax/6 width:32 height:32 color:0xFF0071] autorelease];
- [[[QQUnit alloc] initAtX:wMax/3 y:hMax/2 width:32 height:32 color:0x4596FF] autorelease];
+ QQUnit* u = [[[QQUnit alloc] initAtX:wMax/3 y:hMax/2 width:32 height:32 color:0x4596FF] autorelease];
+ QQLog(u);
// CCSprite* shape = [[CCSprite spriteWithFile:@"1x1-white.png"] retain];
// shape.color = hex2color(0x4596FF);
- (NSString*) description {
+ float px = PIXELS_PER_METER;
b2Transform trans = self.body->GetTransform();
b2Vec2 pos = trans.position;
//b2Vec2 v = actor.body->GetLinearVelocity();
- return [NSString stringWithFormat:@"\v\t<%@ %p> {\v\t\tbox2d=[ (%f,%f) rotation=%f], \v\t\tshape=%@, \v\t\tcooldowns=%@}",
- [self class], self, pos.x,pos.y, trans.GetAngle(), self.shape, self.cooldowns];
+ CGPoint spos = self.shape.position;
+ return [NSString stringWithFormat:@"\v\t<%@ %p> {\v\t\tbox2d=[ (%f,%f) rotation=%f], \v\t\tshape=(%.2f,%.2f), %@}"//, \v\t\tcooldowns=%@}"
+ , [self class], self
+ , pos.x,pos.y, trans.GetAngle()
+ , spos.x/px, spos.y/px, self.shape
+ //, self.cooldowns
+ ];
}
+#import "cocos2d.h"
#import "QQPlayer.h"
#import "game/QQGame.h"
#import "game/unit/QQBullet.h"
@implementation QQPlayer
-- (id) initAtX:(float)x y:(float)y withShape:(SPDisplayObject*)shape {
+- (id) initAtX:(float)x y:(float)y withShape:(CCNode*)shape {
if ((self = [super initAtX:x y:y withShape:shape])){
[self.shape addEventListener:@selector(onSelfTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
[self.game.stage addEventListener:@selector(attackOnTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
self.shape = shape;
float dblpx = 2*PIXELS_PER_METER;
+ float w = 32;
+ float h = 32;
b2PolygonShape box;
- box.SetAsBox(shape.width/dblpx, shape.height/dblpx);
+ box.SetAsBox(w/dblpx, h/dblpx);
b2FixtureDef fix;
fix.shape = &box;
fix.density = 1.0f;
+++ /dev/null
-#import "QQGameLayer.h"
-
-
-
-@implementation QQGameLayer
-
-@synthesize game = _game;
-
-
-- (id) initWithGame:(QQGame*)game {
- if ((self = [super init])) {
- _game = game;
- self.isTouchEnabled = YES;
- self.isAccelerometerEnabled = YES;
-
- CGSize screenSize = [CCDirector sharedDirector].winSize;
- CCLOG(@"GameLayer: %0.2fx%0.2f", screenSize.width, screenSize.height);
-
- [self scheduleUpdate];
-
- // CCSpriteBatchNode* batch = [CCSpriteBatchNode batchNodeWithFile:@"blocks.png" capacity:150];
- // [self addChild:batch z:0 tag:kTagBatchNode];
- //
- // [self addNewSpriteWithCoords:ccp(screenSize.width/2, screenSize.height/2)];
- //
- // CCLabelTTF* label = [CCLabelTTF labelWithString:@"Tap screen" fontName:@"Marker Felt" fontSize:32];
- // [self addChild:label z:0];
- // [label setColor:ccc3(0,0,255)];
- // label.position = ccp( screenSize.width/2, screenSize.height-50);
- }
- return self;
-}
-
-- (void) dealloc {
- _game = nil;
- [super dealloc];
-}
-
-
-
-// - (void) addNewSpriteWithCoords:(CGPoint)p {
-// CCLOG(@"Add sprite %0.2f x %02.f",p.x,p.y);
-// CCSpriteBatchNode* batch = (CCSpriteBatchNode*) [self getChildByTag:kTagBatchNode];
-//
-// //We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is
-// //just randomly picking one of the images
-// int idx = (CCRANDOM_0_1() > .5 ? 0:1);
-// int idy = (CCRANDOM_0_1() > .5 ? 0:1);
-// CCSprite* sprite = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(32 * idx,32 * idy,32,32)];
-// [batch addChild:sprite];
-//
-// sprite.position = ccp( p.x, p.y);
-//
-// // Define the dynamic body.
-// //Set up a 1m squared box in the physics world
-// b2BodyDef bodyDef;
-// bodyDef.type = b2_dynamicBody;
-//
-// bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
-// bodyDef.userData = sprite;
-// b2Body* body = world->CreateBody(&bodyDef);
-//
-// // Define another box shape for our dynamic body.
-// b2PolygonShape dynamicBox;
-// dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
-//
-// // Define the dynamic body fixture.
-// b2FixtureDef fixtureDef;
-// fixtureDef.shape = &dynamicBox;
-// fixtureDef.density = 1.0f;
-// fixtureDef.friction = 0.3f;
-// body->CreateFixture(&fixtureDef);
-// }
-
-
-
-- (void) update:(float)elapsed {
- [_game tick:elapsed];
- //Iterate over the bodies in the physics world
- // for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
- // {
- // if (b->GetUserData() != NULL) {
- // //Synchronize the AtlasSprites position and rotation with the corresponding body
- // CCSprite* myActor = (CCSprite*)b->GetUserData();
- // myActor.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
- // myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
- // }
- // }
-}
-
-- (void) ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
- //Add a new body/atlas sprite at the touched location
- // for( UITouch *touch in touches ) {
- // CGPoint location = [touch locationInView: [touch view]];
- //
- // location = [[CCDirector sharedDirector] convertToGL: location];
- //
- // [self addNewSpriteWithCoords: location];
- // }
-}
-
-- (void) accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
- //#define kFilterFactor 0.05f
-// #define kFilterFactor 1.0f // don't use filter. the code is here just as an example
-
- // static float prevX=0, prevY=0;
- // float accelX = (float) acceleration.x * kFilterFactor + (1- kFilterFactor)*prevX;
- // float accelY = (float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY;
- //
- // prevX = accelX;
- // prevY = accelY;
- //
- // // accelerometer values are in "Portrait" mode. Change them to Landscape left
- // // multiply the gravity by 10
- // b2Vec2 gravity( -accelY * 10, accelX * 10);
- // world->SetGravity( gravity );
-}
-
-@end
#import "cocos2d.h"
-
#import "Tanks.h"
#import "physics/debug/QQPhysicsDebugView.h"
+#import "ui/game/QQViewportLayer.h"
+
@class QQGame;
CCLayer* _chrome;
QQPhysicsDebugView* _debugView;
- CCLayer* _viewport;
+ QQViewportLayer* _viewport;
}
- (id) initWithGame:(QQGame*)game;
@property (nonatomic, readonly, retain) CCLayer* chrome; /// Player UI
@property (nonatomic, readonly, retain) QQPhysicsDebugView* physicsDebugView; /// Debugging view of Box2D
-@property (nonatomic, readonly, retain) CCLayer* viewport; /// Viewport to gameworld
+@property (nonatomic, readonly, retain) QQViewportLayer* viewport; /// Viewport to gameworld
// TODO: Add methods for appending to various child-layers
if ((self = [super init])) {
_game = game;
- _viewport = [[CCNode alloc] init];
+ _viewport = [[QQViewportLayer alloc] initWithGame:_game];
[self addChild:_viewport z:1];
_debugView = [[QQPhysicsDebugView alloc] initWithWorld:_game.world];
#import "cocos2d.h"
-
#import "Tanks.h"
-#import "game/QQGame.h"
-@interface QQGameLayer : CCLayer {
+@class QQGame;
+
+
+@interface QQViewportLayer : CCLayer {
@private
QQGame* _game;
}
- (id) initWithGame:(QQGame*)game;
-- (void) update:(float)elapsed;
@end
--- /dev/null
+#import "QQViewportLayer.h"
+#import "game/QQGame.h"
+
+
+
+@implementation QQViewportLayer
+
+@synthesize game = _game;
+
+
+- (id) initWithGame:(QQGame*)game {
+ if ((self = [super init])) {
+ _game = game;
+ self.isTouchEnabled = YES;
+ self.isAccelerometerEnabled = YES;
+ }
+ return self;
+}
+
+- (void) dealloc {
+ _game = nil;
+ [super dealloc];
+}
+
+
+
+- (void) ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
+ for (UITouch* touch in touches){
+ CGPoint p = [touch locationInView: [touch view]];
+ QQLog(p);
+ CGPoint glP = [[CCDirector sharedDirector] convertToGL: p];
+ QQLog(glP);
+ }
+}
+
+
+/// Standard Touch Delegate:
+// - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
+// - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
+// - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
+// - (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
+
+/// Targeted Touch Delegate:
+// - (void) registerWithTouchDispatcher {
+// [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
+// }
+// - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event;
+// touch updates (optional):
+// - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event;
+// - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event;
+// - (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event;
+
+
+
+- (void) accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
+ //#define kFilterFactor 0.05f
+// #define kFilterFactor 1.0f // don't use filter. the code is here just as an example
+
+ // static float prevX=0, prevY=0;
+ // float accelX = (float) acceleration.x * kFilterFactor + (1- kFilterFactor)*prevX;
+ // float accelY = (float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY;
+ //
+ // prevX = accelX;
+ // prevY = accelY;
+ //
+ // // accelerometer values are in "Portrait" mode. Change them to Landscape left
+ // // multiply the gravity by 10
+ // b2Vec2 gravity( -accelY * 10, accelX * 10);
+ // world->SetGravity( gravity );
+}
+
+@end
492D80E4138BA4910042D918 /* QQCooldown.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D80DE138BA4910042D918 /* QQCooldown.h */; };
492D80E5138BA4910042D918 /* QQCooldown.mm in Sources */ = {isa = PBXBuildFile; fileRef = 492D80DF138BA4910042D918 /* QQCooldown.mm */; };
492D80F3138BA4CE0042D918 /* QQThing.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D80F2138BA4CE0042D918 /* QQThing.h */; };
- 493643BD13A504B1009FFEDC /* QQGameLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 493643B913A504B1009FFEDC /* QQGameLayer.h */; };
- 493643BE13A504B1009FFEDC /* QQGameLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 493643BA13A504B1009FFEDC /* QQGameLayer.mm */; };
493643BF13A504B1009FFEDC /* QQGameScene.h in Headers */ = {isa = PBXBuildFile; fileRef = 493643BB13A504B1009FFEDC /* QQGameScene.h */; };
493643C013A504B1009FFEDC /* QQGameScene.mm in Sources */ = {isa = PBXBuildFile; fileRef = 493643BC13A504B1009FFEDC /* QQGameScene.mm */; };
49454E0F13A1B17000157788 /* CCAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 49454D4013A1B17000157788 /* CCAction.h */; };
49454ED213A1B17000157788 /* CJSONSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 49454E0C13A1B17000157788 /* CJSONSerializer.m */; };
49454ED313A1B17000157788 /* JSONRepresentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 49454E0D13A1B17000157788 /* JSONRepresentation.h */; };
494DE9971376927C00FDB3D7 /* libBox2D.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 494DE9961376927C00FDB3D7 /* libBox2D.a */; };
+ 49507BC913B4527200DB5F57 /* QQ_NARG.h in Headers */ = {isa = PBXBuildFile; fileRef = 49507BC613B4527200DB5F57 /* QQ_NARG.h */; };
+ 49507BCA13B4527200DB5F57 /* QQLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = 49507BC713B4527200DB5F57 /* QQLogging.h */; };
+ 49507BCB13B4527200DB5F57 /* QQLogging.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49507BC813B4527200DB5F57 /* QQLogging.mm */; };
+ 49507BCE13B45E7600DB5F57 /* QQViewportLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49507BCC13B45E7600DB5F57 /* QQViewportLayer.h */; };
+ 49507BCF13B45E7600DB5F57 /* QQViewportLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49507BCD13B45E7600DB5F57 /* QQViewportLayer.mm */; };
496984B013A78BB50098352E /* pink.png in Resources */ = {isa = PBXBuildFile; fileRef = 496984AF13A78BB50098352E /* pink.png */; };
496984B213A78CA90098352E /* white.png in Resources */ = {isa = PBXBuildFile; fileRef = 496984B113A78CA90098352E /* white.png */; };
496984B513A78D1E0098352E /* 1x1-trans.png in Resources */ = {isa = PBXBuildFile; fileRef = 496984B313A78D1E0098352E /* 1x1-trans.png */; };
492D80DE138BA4910042D918 /* QQCooldown.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQCooldown.h; sourceTree = "<group>"; };
492D80DF138BA4910042D918 /* QQCooldown.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQCooldown.mm; sourceTree = "<group>"; };
492D80F2138BA4CE0042D918 /* QQThing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQThing.h; sourceTree = "<group>"; };
- 493643B913A504B1009FFEDC /* QQGameLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQGameLayer.h; sourceTree = "<group>"; };
- 493643BA13A504B1009FFEDC /* QQGameLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQGameLayer.mm; sourceTree = "<group>"; };
493643BB13A504B1009FFEDC /* QQGameScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQGameScene.h; sourceTree = "<group>"; };
493643BC13A504B1009FFEDC /* QQGameScene.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQGameScene.mm; sourceTree = "<group>"; };
49454D4013A1B17000157788 /* CCAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAction.h; sourceTree = "<group>"; };
49454E0C13A1B17000157788 /* CJSONSerializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CJSONSerializer.m; sourceTree = "<group>"; };
49454E0D13A1B17000157788 /* JSONRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONRepresentation.h; sourceTree = "<group>"; };
494DE9961376927C00FDB3D7 /* libBox2D.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libBox2D.a; sourceTree = SOURCE_ROOT; };
+ 49507BC613B4527200DB5F57 /* QQ_NARG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQ_NARG.h; sourceTree = "<group>"; };
+ 49507BC713B4527200DB5F57 /* QQLogging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQLogging.h; sourceTree = "<group>"; };
+ 49507BC813B4527200DB5F57 /* QQLogging.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQLogging.mm; sourceTree = "<group>"; };
+ 49507BCC13B45E7600DB5F57 /* QQViewportLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQViewportLayer.h; sourceTree = "<group>"; };
+ 49507BCD13B45E7600DB5F57 /* QQViewportLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQViewportLayer.mm; sourceTree = "<group>"; };
496984AF13A78BB50098352E /* pink.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pink.png; sourceTree = "<group>"; };
496984B113A78CA90098352E /* white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = white.png; sourceTree = "<group>"; };
496984B313A78D1E0098352E /* 1x1-trans.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "1x1-trans.png"; sourceTree = "<group>"; };
493643B813A504B1009FFEDC /* game */ = {
isa = PBXGroup;
children = (
- 493643B913A504B1009FFEDC /* QQGameLayer.h */,
- 493643BA13A504B1009FFEDC /* QQGameLayer.mm */,
+ 49507BCC13B45E7600DB5F57 /* QQViewportLayer.h */,
+ 49507BCD13B45E7600DB5F57 /* QQViewportLayer.mm */,
493643BB13A504B1009FFEDC /* QQGameScene.h */,
493643BC13A504B1009FFEDC /* QQGameScene.mm */,
);
path = JSON;
sourceTree = "<group>";
};
+ 49507BC513B4527200DB5F57 /* util */ = {
+ isa = PBXGroup;
+ children = (
+ 49507BC613B4527200DB5F57 /* QQ_NARG.h */,
+ 49507BC713B4527200DB5F57 /* QQLogging.h */,
+ 49507BC813B4527200DB5F57 /* QQLogging.mm */,
+ );
+ path = util;
+ sourceTree = "<group>";
+ };
4978AD151396302300930447 /* event */ = {
isa = PBXGroup;
children = (
isa = PBXGroup;
children = (
499F65BF139CBC0C00309DE4 /* event */,
+ 49507BC513B4527200DB5F57 /* util */,
499F65F9139CFD3700309DE4 /* NSArray+QQExtensions.h */,
499F65FA139CFD3700309DE4 /* NSArray+QQExtensions.mm */,
499F65FB139CFD3700309DE4 /* NSDictionary+QQExtensions.h */,
49454ED313A1B17000157788 /* JSONRepresentation.h in Headers */,
4987364313A23D6600CE6BCC /* QQCocosAppDelegate.h in Headers */,
4987364513A23D6600CE6BCC /* QQRootViewController.h in Headers */,
- 493643BD13A504B1009FFEDC /* QQGameLayer.h in Headers */,
493643BF13A504B1009FFEDC /* QQGameScene.h in Headers */,
496984BF13A7A3990098352E /* QQWorld_Internal.h in Headers */,
496984C213A7A8E00098352E /* CCNode+QQExtensions.h in Headers */,
+ 49507BC913B4527200DB5F57 /* QQ_NARG.h in Headers */,
+ 49507BCA13B4527200DB5F57 /* QQLogging.h in Headers */,
+ 49507BCE13B45E7600DB5F57 /* QQViewportLayer.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
499F6600139CFD3800309DE4 /* NSDictionary+QQExtensions.mm in Sources */,
4987364413A23D6600CE6BCC /* QQCocosAppDelegate.mm in Sources */,
4987364613A23D6600CE6BCC /* QQRootViewController.mm in Sources */,
- 493643BE13A504B1009FFEDC /* QQGameLayer.mm in Sources */,
493643C013A504B1009FFEDC /* QQGameScene.mm in Sources */,
49E834CE13814F7D007A6598 /* QQGLESDebugDraw.mm in Sources */,
4B91A15A138F644000EF4D7C /* QQPhysicsDebugView.mm in Sources */,
496984BC13A7A25A0098352E /* QQUnit.mm in Sources */,
496984BD13A7A3390098352E /* QQBullet.mm in Sources */,
496984C313A7A8E00098352E /* CCNode+QQExtensions.mm in Sources */,
+ 49507BCB13B4527200DB5F57 /* QQLogging.mm in Sources */,
+ 49507BCF13B45E7600DB5F57 /* QQViewportLayer.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};