Merge from master.
authorchsieh <chester.developer@hotmail.com>
Tue, 17 May 2011 04:21:48 +0000 (21:21 -0700)
committerchsieh <chester.developer@hotmail.com>
Tue, 17 May 2011 04:21:48 +0000 (21:21 -0700)
1  2 
src/game/actor/Unit.h
src/game/actor/Unit.mm
src/render/animation/AnimationContainer.h
src/render/animation/AnimationContainer.mm

index 0000000,c6650c2..5ce2e6d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,21 +1,24 @@@
+ #import "Sparrow.h"
+ #import "render/QQSparrowExtensions.h"
+ #import "game/actor/Actor.h"
+ #import "physics/World.h"
++////////////////////////////////////////////////////////////////////////////////////
+ @interface Unit : Actor {
+ @private
+     SPDisplayObject* _shape;
+ }
++////////////////////////////////////////////////////////////////////////////////////
+ @property (nonatomic, retain, readwrite) SPDisplayObject* shape;
++////////////////////////////////////////////////////////////////////////////////////
+ - (id) initWithFile:(NSString*)fileName atX:(float)x y:(float)y;
+ - (id) initWithShape:(SPDisplayObject*)aShape;
+ - (void) onTouch:(SPTouchEvent*)event;
+ @end
index 0000000,f37dd31..88e057a
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,52 +1,60 @@@
+ #import "Sparrow.h"
+ #import "Unit.h"
++////////////////////////////////////////////////////////////////////////////////////
+ @implementation Unit
++////////////////////////////////////////////////////////////////////////////////////
+ @synthesize shape = _shape;
++////////////////////////////////////////////////////////////////////////////////////
+ - (id) init {
+     return [self initWithShape:[[SPQuad quadWithWidth:32 height:32 color:0xff0000] setPositionX:50 y:50]];
+ }
++////////////////////////////////////////////////////////////////////////////////////
+ - (id) initWithFile:(NSString*)fileName atX:(float)x y:(float)y {
+     return [self initWithShape:[[[[SPImage alloc] initWithContentsOfFile:fileName] autorelease] setPositionX:x y:y]];
+ }
++////////////////////////////////////////////////////////////////////////////////////
+ - (id) initWithShape:(SPDisplayObject*)aShape {
+     if ((self = [super init])) {
+         self.shape = aShape;
+         [self.game addEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
+     }
+     return self;
+ }
++////////////////////////////////////////////////////////////////////////////////////
+ - (void) dealloc {
+     [self.game removeEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
+     [self.game removeChild:_shape];
+     [_shape release];
+     [super dealloc];
+ }
++////////////////////////////////////////////////////////////////////////////////////
+ - (void) setShape:(SPDisplayObject*)newShape {
+     if (_shape != newShape) {
+         [self.game removeChild:_shape];
+         [_shape release];
+         _shape = [newShape retain];
+         [self.game addChild:_shape];
+     }
+ }
++////////////////////////////////////////////////////////////////////////////////////
+ - (void) onTouch:(SPTouchEvent*)event {
+     NSLog(@"%@ onTouch! shape=%@ parent=%@", self, self.shape, self.shape.parent);
+     SPTouch* touch = [[event touchesWithTarget:self.shape.parent] anyObject];
+     if (touch) {
+         SPPoint* touchPosition = [touch locationInSpace:self.shape.parent];
+         self.shape.x = touchPosition.x - self.shape.width / 2.0f;
+         self.shape.y = touchPosition.y - self.shape.height / 2.0f;
+     }
+ }
+ @end
@@@ -1,16 -1,5 +1,6 @@@
- //
- //  AnimationContainer.h
- //  tanks
- //
- //  Created by Doris Chen on 5/12/11.
- //  Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import <Foundation/Foundation.h>
  #import "SPTextureAtlas.h"
  
 +
  ////////////////////////////////////////////////////////////////////////////////////
  @interface AnimationContainer : NSObject <NSXMLParserDelegate> {
  }