--- /dev/null
+ #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
--- /dev/null
+ #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
- //
- // 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> {
}