Dragging reference.
authorchsieh <chester.developer@hotmail.com>
Sun, 8 May 2011 04:39:47 +0000 (21:39 -0700)
committerchsieh <chester.developer@hotmail.com>
Sun, 8 May 2011 04:39:47 +0000 (21:39 -0700)
tanks/tanks.xcodeproj/project.pbxproj
tanks/tanks/Game.h
tanks/tanks/Game.m
tanks/tanks/Game/Unit/Unit.h [new file with mode: 0644]
tanks/tanks/Game/Unit/Unit.m [new file with mode: 0644]

index 18a38f9..defd577 100644 (file)
@@ -30,6 +30,7 @@
                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 */
@@ -95,6 +96,8 @@
                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;
                };
index 92a1fec..7bd6a65 100644 (file)
@@ -8,8 +8,11 @@
 
 #import <Foundation/Foundation.h>
 #import "Sparrow.h"
+#import "Game/Unit/Unit.h"
 
 
 @interface Game : SPStage
 
+@property(nonatomic, assign) Unit* unit;
+
 @end
index 7948dbb..3f58a87 100644 (file)
 
 @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
diff --git a/tanks/tanks/Game/Unit/Unit.h b/tanks/tanks/Game/Unit/Unit.h
new file mode 100644 (file)
index 0000000..1c8fea5
--- /dev/null
@@ -0,0 +1,20 @@
+//
+//  Unit.h
+//  tanks
+//
+//  Created by Doris Chen on 5/7/11.
+//  Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "Sparrow.h"
+
+
+@interface Unit : NSObject {
+}
+
+@property(nonatomic, retain) SPQuad* quad;
+
+-(Unit*)initWithWidth:(int)width height:(int)height X:(int)x Y:(int)y;
+-(void)onTouch:(SPTouchEvent*)event;
+@end
diff --git a/tanks/tanks/Game/Unit/Unit.m b/tanks/tanks/Game/Unit/Unit.m
new file mode 100644 (file)
index 0000000..66da593
--- /dev/null
@@ -0,0 +1,34 @@
+//
+//  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