--- /dev/null
+#import "Sparrow.h"
+
+
+@protocol Displayable
+
+@property (nonatomic, retain, readonly) SPDisplayObject* shape;
+
+@end
\ No newline at end of file
--- /dev/null
+#import "Sparrow.h"
+
+#import "game/actor/Unit.h"
+#import "physics/World.h"
+
+
+@interface Game : SPStage {
+@private
+ Unit* _unit;
+ World* _world;
+}
+
+@property (nonatomic, retain) World* world;
+
+- (void) onEnterFrame:(SPEnterFrameEvent*)event;
+
++ (Game*) current;
+
+@end
--- /dev/null
+#import "Game.h"
+#import "game/actor/Unit.h"
+
+
+
+static Game* _currentGame = NULL;
+
+
+
+@interface Game ()
+@property (nonatomic, retain) Unit* unit;
+@end
+
+
+@implementation Game
+@synthesize world = _world;
+@synthesize unit = _unit;
+
+
+- (id) init {
+ if (_currentGame) {
+ [self release];
+ [NSException raise:@"TooManyGames" format:@"cannot instantiate more than one Game at a time!"];
+ }
+
+ if ( (self = [super init]) ){
+ _currentGame = self;
+
+ _world = [[World alloc] init];
+ [self addEventListener:@selector(onEnterFrame:) atObject:self forType:SP_EVENT_TYPE_ENTER_FRAME];
+
+ _unit = [[Unit alloc] init];
+ // [self addEventListener:@selector(onTouch:) atObject:_unit forType:SP_EVENT_TYPE_TOUCH];
+ // if (_unit.shape) [self addChild:_unit.shape];
+ }
+ return self;
+}
+
+- (void) dealloc {
+ // [self setUnit:nil];
+ // [self setWorld:nil];
+ [_unit release];
+ [_world release];
+ _currentGame = NULL;
+ [super dealloc];
+}
+
+- (void) onEnterFrame:(SPEnterFrameEvent*)event {
+ NSLog(@"Time passed since last frame: %f", event.passedTime);
+ // [world step];
+}
+
++ (Game*) current {
+ if (!_currentGame)
+ [[[Game alloc] init] // init assigns to singleton, but singleton is a weakref,
+ autorelease]; // XXX: so game will still be released if not retained...
+ return _currentGame;
+}
+
+
+@end
\ No newline at end of file
-#import "tanks/Active.h"
-#import "tanks/Displayable.h"
-
+#import "game/Active.h"
+#import "game/Displayable.h"
#import "physics/World.h"
+@class Game;
+
@interface Actor : NSObject <Active, Displayable> {
@private
- BOOL _active;
- World* _world;
+ BOOL _active;
}
+@property (nonatomic, readonly) Game* game;
@property (nonatomic, readonly) World* world;
-- (id) init:(World*)theWorld;
@end
--- /dev/null
+#import "Actor.h"
+#import "game/Game.h"
+
+
+@implementation Actor
+
+@synthesize active;
+
+- (Game*) game { return Game.current; }
+- (World*) world { return self.game.world; }
+
+- (SPDisplayObject*) shape { return nil; }
+
+- (void) act {
+ // stub
+}
+
+@end
--- /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
-//
-// main.m
-// tanks
-//
-// Created by dsc on 4/27/11.
-// Copyright 2011 lttlst.com. All rights reserved.
-//
-
#import <UIKit/UIKit.h>
+
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#include <Box2D/Box2D.h>
-#import "ui/GLES-Render.h"
+#import "physics/debug/GLESDebugDraw.h"
@interface World : NSObject {
* 3. This notice may not be removed or altered from any source distribution.
*/
-#ifndef RENDER_H
-#define RENDER_H
+#ifndef GLES_DEBUG_DRAW_H
+#define GLES_DEBUG_DRAW_H
#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
* 3. This notice may not be removed or altered from any source distribution.
*/
-#include "GLES-Render.h"
+#include "GLESDebugDraw.h"
#include <cstdio>
--- /dev/null
+#import "SPDisplayObject.h"
+
+
+@interface SPDisplayObject (QQSparrowExtensions)
+
+- (id) setPositionX:(float)x y:(float)y;
+
+@end
+
--- /dev/null
+#import "QQSparrowExtensions.h"
+
+
+@implementation SPDisplayObject (QQSparrowExtensions)
+
+- (id) setPositionX:(float)x y:(float)y {
+ self.x = x;
+ self.y = y;
+ return self;
+}
+
+@end
\ No newline at end of file
-//
-// AnimationContainer.h
-// tanks
-//
-// Created by Doris Chen on 5/12/11.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
#import "SPTextureAtlas.h"
////////////////////////////////////////////////////////////////////////////////////
+++ /dev/null
-#import "Sparrow.h"
-
-
-@protocol Displayable
-
-@property (nonatomic, readonly) SPDisplayObject* shape;
-
-@end
\ No newline at end of file
+++ /dev/null
-#import "Sparrow.h"
-
-#import "physics/World.h"
-
-
-@interface Game : SPStage
-
-@property (nonatomic, retain) World* world;
-
-- (void) onEnterFrame:(SPEnterFrameEvent*)event;
-
-@end
+++ /dev/null
-#import "Game.h"
-#import "tanks/unit/Unit.h"
-
-
-@interface Game ()
-
-@property (nonatomic, retain) Unit* unit;
-
-@end
-
-
-@implementation Game
-
-@synthesize unit;
-@synthesize world;
-
-
-- (id) init {
- if ( (self = [super init]) ){
- world = [[[World alloc] init] autorelease];
- [self addEventListener:@selector(onEnterFrame:) atObject:self forType:SP_EVENT_TYPE_ENTER_FRAME];
-
- unit = [[[Unit alloc] init:world] autorelease];
- [self addEventListener:@selector(onTouch:) atObject:unit forType:SP_EVENT_TYPE_TOUCH];
- [self addChild:unit.quad];
- }
- return self;
-}
-
-- (void) dealloc {
- [self setUnit:nil];
- [self setWorld:nil];
- [super dealloc];
-}
-
-- (void) onEnterFrame:(SPEnterFrameEvent*)event {
- NSLog(@"Time passed since last frame: %f", event.passedTime);
- // [world step];
-}
-
-
-
-
-@end
\ No newline at end of file
+++ /dev/null
-#import "Actor.h"
-
-
-@implementation Actor
-
-@synthesize active;
-@synthesize world = _world;
-
-
-- (id) init:(World*)theWorld {
- if ((self = [super init])) {
- _world = theWorld; // weakref: does not inc refcount
- }
- return self;
-}
-
-- (SPDisplayObject*) shape {
- return nil;
-}
-
-
-- (void) act {}
-
-@end
+++ /dev/null
-#import "Sparrow.h"
-#import "tanks/unit/Actor.h"
-#import "physics/World.h"
-
-
-@interface Unit : Actor {
-}
-
-@property (nonatomic, retain) SPQuad* quad;
-
-- (Unit*) initWithWidth:(float)width height:(float)height X:(float)x Y:(float)y color:(int)color;
-- (Unit*) initWithFile:(NSString*)fileName atX:(float)x andY:(float)y;
-
-- (void) onTouch:(SPTouchEvent*)event;
-
-@end
+++ /dev/null
-#import "Unit.h"
-#import "Sparrow.h"
-
-
-@implementation Unit
-
-@synthesize quad;
-
-- (SPDisplayObject*) shape { return quad; }
-
-
-
-- (Unit*) init:(World*)theWorld {
- if ((self = [super init:theWorld])) {
- quad = [SPQuad quadWithWidth:32 height:32];
- quad.color = 0xff0000;
- quad.x = 0;
- quad.y = 0;
- }
- 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
#import "Sparrow.h"
-#import "Game.h"
+#import "game/Game.h"
-@interface RootAppDelegate : NSObject <UIApplicationDelegate>
+@interface AppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow* window;
SPView* sparrowView;
- Game* game;
+ Game* _game;
}
@property (nonatomic, retain) IBOutlet UIWindow* window;
//
-// RootAppDelegate.m
+// AppDelegate.m
// tanks
//
// Created by dsc on 4/27/11.
// Copyright 2011 lttlst.com. All rights reserved.
//
-#import "RootAppDelegate.h"
-#import "Game.h"
+#import "AppDelegate.h"
+#import "game/Game.h"
-@implementation RootAppDelegate
+@implementation AppDelegate
@synthesize window;
@synthesize sparrowView;
-@synthesize game;
+@synthesize game = _game;
- (void) applicationDidFinishLaunching:(UIApplication*)application {
[SPAudioEngine start];
if ( sparrowView.frameRate != 60.0f )
sparrowView.frameRate = 60.0f;
+ // sparrowView.stage = [[[SPStage alloc] init] autorelease];
- game = [[[Game alloc] init] autorelease];
- sparrowView.stage = game;
+ _game = [[Game alloc] init];
+ sparrowView.stage = _game;
[window makeKeyAndVisible];
[sparrowView start];
}
- (void) dealloc {
- [self setGame:nil];
+ // [self setGame:nil];
+ [_game release];
[sparrowView release];
[window release];
[super dealloc];
-#include <Box2D/Box2D.h>
#import "Sparrow.h"
#import "physics/World.h"
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
+
#import "Sparrow.h"
#import "Viewport.h"
-#import "World.h"
+#import "physics/World.h"
+
@implementation Viewport
//
-// RootAppDelegate_iPad.h
+// AppDelegate_iPad.h
// tanks
//
// Created by dsc on 4/27/11.
//
#import <UIKit/UIKit.h>
-#import "RootAppDelegate.h"
+#import "ui/AppDelegate.h"
-@interface RootAppDelegate_iPad : RootAppDelegate {
+@interface AppDelegate_iPad : AppDelegate {
}
//
-// RootAppDelegate_iPad.m
+// AppDelegate_iPad.m
// tanks
//
// Created by dsc on 4/27/11.
// Copyright 2011 lttlst.com. All rights reserved.
//
-#import "RootAppDelegate_iPad.h"
+#import "AppDelegate_iPad.h"
-@implementation RootAppDelegate_iPad
+@implementation AppDelegate_iPad
- (void)dealloc
{
<reference key="source" ref="250404236"/>
<reference key="destination" ref="607297697"/>
</object>
- <int key="connectionID">14</int>
+ <int key="connectionID">15</int>
</object>