Game Development Reference
In-Depth Information
float dx =
tankStatsForLocal.tankPosition.x -
tankStatsForLocal.tankDestination.x;
float dy =
tankStatsForLocal.tankPosition.y -
tankStatsForLocal.tankDestination.y;
float at = atan2( dy, dx );
// 1.0 is the "speed"
tankStatsForLocal.tankPosition.x -=
kTankSpeed * cos(at);
tankStatsForLocal.tankPosition.y -=
kTankSpeed * sin(at);
}
} else {
tankStatsForLocal.tankPosition.x =
tankStatsForLocal.tankDestination.x;
tankStatsForLocal.tankPosition.y =
tankStatsForLocal.tankDestination.y;
}
tankStatsForLocal.tankPreviousPosition =
self.localTankSprite.position;
self.localTankSprite.position =
tankStatsForLocal.tankPosition;
self.localTankSprite.zRotation =
tankStatsForLocal.tankRotation;
// Send NetworkPacket for syncing the data at
both the players
[self sendNetworkPacketToPeerId:self.gamePeerID
forPacketCode:KNetworkPacketCodePlayerMove
withData:&tankStatsForLocal
ofLength:sizeof(TankInfo)
reliable:YES];
}
Search WWH ::




Custom Search