Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:MobileApplicationsCSM/PeerPong in…

…to momo

Conflicts:
	Unicorn-Framework-iOS
  • Loading branch information...
commit 05b6580e7a437414d6a0f3684e1b8695cc546669 2 parents 666c361 + c7b383d
@moritzh moritzh authored
View
4 PeerPong.xcodeproj/project.pbxproj
@@ -1620,7 +1620,7 @@
"GCC_THUMB_SUPPORT[arch=armv6]" = "";
GCC_VERSION = "";
INFOPLIST_FILE = PeerPong/Resources/Info.plist;
- IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.2;
OTHER_LDFLAGS = "-lz";
PRODUCT_NAME = "$(TARGET_NAME)";
SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = NO;
@@ -1640,7 +1640,7 @@
"GCC_THUMB_SUPPORT[arch=armv6]" = "";
GCC_VERSION = "";
INFOPLIST_FILE = PeerPong/Resources/Info.plist;
- IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.2;
OTHER_LDFLAGS = "-lz";
PRODUCT_NAME = "$(TARGET_NAME)";
SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = NO;
View
BIN  ...xcodeproj/project.xcworkspace/xcuserdata/tommy.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
16 PeerPong/AppDelegate.mm
@@ -116,15 +116,9 @@ - (void) applicationDidFinishLaunching:(UIApplication*)application
- (void)applicationWillResignActive:(UIApplication *)application {
[[CCDirector sharedDirector] pause];
-
- //gameplay = [PeerPongGameplay sharedInstance];
- //[gameplay destroyGame];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
- //gameplay = [PeerPongGameplay sharedInstance];
- //[gameplay initiateGame];
-
[[CCDirector sharedDirector] resume];
}
@@ -134,10 +128,20 @@ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
-(void) applicationDidEnterBackground:(UIApplication*)application {
[[CCDirector sharedDirector] stopAnimation];
+
+ // destroy server
+ gameplay = [PeerPongGameplay sharedInstance];
+ [gameplay destroyGame];
}
-(void) applicationWillEnterForeground:(UIApplication*)application {
[[CCDirector sharedDirector] startAnimation];
+
+ // start server
+ gameplay = [PeerPongGameplay sharedInstance];
+ [gameplay initiateGame];
+
+ NSLog(@"Started again");
}
- (void)applicationWillTerminate:(UIApplication *)application {
View
5 PeerPong/BallLayer.mm
@@ -49,7 +49,10 @@ -(void)addBall {
self.fixture = body->CreateFixture(&shapeDef);
// Define impulse for ball
- b2Vec2 force = b2Vec2(20, 20);
+ int signatures[2] = {-1, 1};
+ int randomSign1 = arc4random() % 2;
+ int randomSign2 = arc4random() % 2;
+ b2Vec2 force = b2Vec2(signatures[randomSign1] * 20, signatures[randomSign2] * 20);
body->ApplyLinearImpulse(force, bodyDef.position);
}
View
4 PeerPong/MainScene.mm
@@ -173,25 +173,21 @@ - (void)tick:(ccTime) dt {
//
if ((contact.fixtureA == ballLayer.fixture && contact.fixtureB == gameBoxLayer.leftEdge) ||
(contact.fixtureA == gameBoxLayer.leftEdge && contact.fixtureB == ballLayer.fixture)) {
- NSLog(@"Left edge got hit!");
hitsWall = YES;
}
if ((contact.fixtureA == ballLayer.fixture && contact.fixtureB == gameBoxLayer.topEdge) ||
(contact.fixtureA == gameBoxLayer.topEdge && contact.fixtureB == ballLayer.fixture)) {
- NSLog(@"Top edge got hit!");
hitsWall = YES;
}
if ((contact.fixtureA == ballLayer.fixture && contact.fixtureB == gameBoxLayer.rightEdge) ||
(contact.fixtureA == gameBoxLayer.rightEdge && contact.fixtureB == ballLayer.fixture)) {
- NSLog(@"Right edge got hit!");
hitsWall = YES;
}
if ((contact.fixtureA == ballLayer.fixture && contact.fixtureB == gameBoxLayer.bottomEdge) ||
(contact.fixtureA == gameBoxLayer.bottomEdge && contact.fixtureB == ballLayer.fixture)) {
- NSLog(@"Bottom edge got hit!");
hitsWall = YES;
}
if(hitsWall) [gameplay playSound:kSoundBallOnWall];
View
47 PeerPong/PeerPongGameplay.mm
@@ -43,16 +43,6 @@ - (id)init {
self.ballTag = 50;
self.queueSpriteTag = 60;
-
- // Create a world with no gravity
- b2Vec2 gravity = b2Vec2(0.0f, 0.0f);
- bool doSleep = true;
- self.world = new b2World(gravity, doSleep);
-
- self.windowSize = [[CCDirector sharedDirector] winSize];
-
- self.players = [[[NSMutableDictionary alloc] init] autorelease];
- self.playerQueue = [[[NSMutableArray alloc] init] autorelease];
}
return self;
}
@@ -112,21 +102,21 @@ -(void)receivedDisconnectFromClient:(GCDAsyncSocket *)client {
#pragma mark - Game controls
-(void)initiateGame {
-
-
[self startServer];
self.gameIsRunning = NO;
- // Run the intro Scene
- [[CCDirector sharedDirector] runWithScene: [MainScene node]];
+ // start scene if not already running
+ if(![[CCDirector sharedDirector] runningScene]){
+ [[CCDirector sharedDirector] runWithScene: [MainScene node]];
+ } else {
+ [[CCDirector sharedDirector] replaceScene: [MainScene node]];
+ }
+
}
-(void)destroyGame{
[self stopServer];
- self.peerPongServer = nil;
- self.players = nil;
- self.playerQueue = nil;
- delete world;
+ self.gameIsRunning = NO;
}
-(void)startGame {
@@ -136,6 +126,22 @@ -(void)startGame {
}
-(void)startServer {
+ // reset server
+ delete self.world;
+ self.world = nil;
+ self.peerPongServer = nil;
+ self.players = nil;
+ self.playerQueue = nil;
+
+ // setup world
+ b2Vec2 gravity = b2Vec2(0.0f, 0.0f);
+ bool doSleep = true;
+ self.world = new b2World(gravity, doSleep);
+ self.windowSize = [[CCDirector sharedDirector] winSize];
+ self.players = [[[NSMutableDictionary alloc] init] autorelease];
+ self.playerQueue = [[[NSMutableArray alloc] init] autorelease];
+
+ // start server
self.peerPongServer = [[[PeerPongServer alloc] init] autorelease];
[self.peerPongServer start];
self.serverName = self.peerPongServer.server.name;
@@ -149,7 +155,6 @@ -(void)stopServer {
#pragma mark - Sound
-(void)playSound:(int)aSound {
- NSLog(@"Playing sound %d", aSound);
switch (aSound) {
case kSoundPlayerJoined:
[[SimpleAudioEngine sharedEngine] playEffect:@"player_joined.mp3"];
@@ -275,10 +280,11 @@ -(void)movePlayerFromSlotToQueue:(PeerPongPlayer *)aPlayer {
[self.playerQueue addObject:aPlayer];
[self.players removeObjectForKey:aPlayer.slot];
[scene updateQueue];
- [self askFirstPlayerForReadiness];
PeerPongPlayer *firstPlayer = [self.playerQueue objectAtIndex:0];
if(firstPlayer != aPlayer) [self sendPlayerGameOver:aPlayer];
+
+ [self askFirstPlayerForReadiness];
}
}
@@ -301,7 +307,6 @@ -(void)ballIsOnPosition:(CGPoint)aPosition {
}
-(void)ballWentAway:(CGPoint)aPosition {
- NSLog(@"Ball went away!");
int failedPlayerSlot = 0;
if(aPosition.x < 0) {
View
32 PeerPong/PeerPongPaddle.mm
@@ -95,7 +95,7 @@ -(void)updateLivesLeftLabel {
-(void)addPhysics {
// Create paddle body
b2BodyDef bodyDef;
- bodyDef.type = b2_staticBody;
+ bodyDef.type = b2_dynamicBody;
b2Vec2 pos = [self getLocation];
bodyDef.position.Set(pos.x, pos.y);
@@ -116,10 +116,20 @@ -(void)addPhysics {
shapeDef.restitution = 0.1f;
fixture = body->CreateFixture(&shapeDef);
+ // Restrict paddle along the x axis
+ b2PrismaticJointDef jointDef;
+ jointDef.collideConnected = true;
+ jointDef.Initialize(body, gameplay.groundBody,
+ body->GetWorldCenter(), [self getAxis]);
+ joint = gameplay.world->CreateJoint(&jointDef);
}
-(void)removePhysics {
-
+ // If user didn't move his paddle mouseJoint is NULL
+ if (mouseJoint != NULL) {
+ gameplay.world->DestroyJoint(mouseJoint);
+ }
+ gameplay.world->DestroyJoint(joint);
body->DestroyFixture(fixture);
gameplay.world->DestroyBody(body);
}
@@ -153,8 +163,24 @@ -(b2Vec2)getAxis {
}
-(void)update {
+ if (mouseJoint == NULL) {
b2Vec2 locationWorld = [self getLocation];
- body->SetTransform(locationWorld, 0);
+
+ if (fixture->TestPoint(locationWorld)) {
+ b2MouseJointDef md;
+ md.bodyA = gameplay.groundBody;
+ md.bodyB = body;
+ md.target = locationWorld;
+ md.collideConnected = true;
+ md.maxForce = 1000.0f * body->GetMass();
+
+ mouseJoint = (b2MouseJoint *)gameplay.world->CreateJoint(&md);
+ body->SetAwake(true);
+ }
+ } else {
+ b2Vec2 locationWorld = [self getLocation];
+ mouseJoint->SetTarget(locationWorld);
+ }
}
2  Unicorn-Framework-iOS
@@ -1 +1 @@
-Subproject commit fbc907732cf566c453972d2a85ecf0eec4b29221
+Subproject commit 00d7ba18945afc2627c92ec8909aeed3bd6a32d7
View
6,843 gfx/layout/icon.ai
901 additions, 5,942 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.