4996691A136930E8006E8125 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49966915136930E8006E8125 /* OpenGLES.framework */; };
4996691B136930E8006E8125 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49966916136930E8006E8125 /* QuartzCore.framework */; };
4996691E13693180006E8125 /* Game.m in Sources */ = {isa = PBXBuildFile; fileRef = 4996691D13693180006E8125 /* Game.m */; };
+ 4B7EFC0813763A5700EC81CB /* Unit.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B7EFC0713763A5700EC81CB /* Unit.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
49966916136930E8006E8125 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
4996691C13693180006E8125 /* Game.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Game.h; sourceTree = "<group>"; };
4996691D13693180006E8125 /* Game.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Game.m; sourceTree = "<group>"; };
+ 4B7EFC0613763A5700EC81CB /* Unit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Unit.h; path = tanks/Game/Unit/Unit.h; sourceTree = "<group>"; };
+ 4B7EFC0713763A5700EC81CB /* Unit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Unit.m; path = tanks/Game/Unit/Unit.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
children = (
499668D513692E2D006E8125 /* tanksAppDelegate.h */,
499668D613692E2D006E8125 /* tanksAppDelegate.m */,
+ 4B7EFC04137639FE00EC81CB /* Game */,
499668D813692E2D006E8125 /* iPhone */,
499668DF13692E2D006E8125 /* iPad */,
499668CD13692E2D006E8125 /* Supporting Files */,
name = "Supporting Files";
sourceTree = "<group>";
};
+ 4B7EFC04137639FE00EC81CB /* Game */ = {
+ isa = PBXGroup;
+ children = (
+ 4B7EFC0513763A1400EC81CB /* Unit */,
+ );
+ name = Game;
+ path = ..;
+ sourceTree = "<group>";
+ };
+ 4B7EFC0513763A1400EC81CB /* Unit */ = {
+ isa = PBXGroup;
+ children = (
+ 4B7EFC0613763A5700EC81CB /* Unit.h */,
+ 4B7EFC0713763A5700EC81CB /* Unit.m */,
+ );
+ name = Unit;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
499668DB13692E2D006E8125 /* tanksAppDelegate_iPhone.m in Sources */,
499668E213692E2D006E8125 /* tanksAppDelegate_iPad.m in Sources */,
4996691E13693180006E8125 /* Game.m in Sources */,
+ 4B7EFC0813763A5700EC81CB /* Unit.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@implementation Game
+@synthesize unit;
+
- (id)initWithWidth:(float)width height:(float)height
{
- if ((self = [super initWithWidth:width height:height]))
- {
- // this is where the code of your game will start.
- // in this sample, we add just a simple quad to see
- // if it works.
+ if ((self = [super initWithWidth:width height:height]))
+ {
+ // this is where the code of your game will start.
+ // in this sample, we add just a simple quad to see
+ // if it works.
- SPQuad *quad = [SPQuad quadWithWidth:100 height:100];
- quad.color = 0xff0000;
- quad.x = 50;
- quad.y = 50;
- [self addChild:quad];
- }
- return self;
+ unit = [[Unit alloc] initWithWidth:100 height:100 X:50 Y:50];
+ [self addEventListener:@selector(onTouch:) atObject:unit forType:SP_EVENT_TYPE_TOUCH];
+ [self addChild:unit.quad];
+ }
+ return self;
}
+
@end
\ No newline at end of file
--- /dev/null
+//
+// Unit.m
+// tanks
+//
+// Created by Doris Chen on 5/7/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "Unit.h"
+
+
+@implementation Unit
+
+@synthesize quad;
+
+-(Unit*)initWithWidth:(int)width height:(int)height X:(int)x Y:(int)y {
+ quad = [SPQuad quadWithWidth:width height:height];
+ quad.color = 0xff0000;
+ quad.x = x;
+ quad.y = y;
+
+ return self;
+}
+
+-(void)onTouch:(SPTouchEvent*)event {
+ SPTouch* touch = [[event touchesWithTarget:quad.parent] anyObject];
+ if (touch) {
+ SPPoint* touchPosition = [touch locationInSpace:quad.parent];
+ quad.x = touchPosition.x - quad.width / 2.0f;
+ quad.y = touchPosition.y - quad.height / 2.0f;
+ }
+}
+
+@end