How to end a 2 player turn based Game Center match when player quit out of trun - game-center

I have searched about everywhere and not found an anwer for this problem:
I have a 2 player game, turn based, via Game Center.
After a player has done his move, he has the ability in Game Center to quit the game. In my case, this automatically means the game has ended and the other player has won. However, I can not find a Game Centermethod to make this happen.
I can not use endMatchInTurnWithMatchData because it is not this players turn.
And if I try to use endMatchInTurnWithMatchData when it is the other player's turn, this isn't possible either, because there is no other player to send the endMatchInTurnWithMatchData to (because the other player already quit).
Is there anyone who knows the solution to this?
Thanks,
Martyn

You have to implement turnBasedMatchmakerViewController:playerQuitForMatch: method of GKTurnBasedMatchmakerViewControllerDelegate. Here is an example code:
-(void)turnBasedMatchmakerViewController: (GKTurnBasedMatchmakerViewController *)viewController playerQuitForMatch:(GKTurnBasedMatch *)match {
NSUInteger currentIndex = [match.participants indexOfObject:match.currentParticipant];
GKTurnBasedParticipant *next = [match.participants objectAtIndex:(currentIndex + 1)%[match.participants count]];
[match participantQuitInTurnWithOutcome:GKTurnBasedMatchOutcomeQuit nextParticipants:#[next] turnTimeout:MAXFLOAT matchData:match.matchData completionHandler:nil];
[next setMatchOutcome:GKTurnBasedMatchOutcomeWon];
[match endMatchInTurnWithMatchData:match.matchData completionHandler:nil];
}

I was struggling with the same issue. What ended up working for me is to set yourself as the next participant when calling participantQuitInTurnWithOutcome.
Hope it helps!

Related

How to get an enemy's information?

I'm a beginner and I created a code where I can get my enemy's information, but I believe it is very simple and maybe wrong, since the more information I want to get, the more lines of code will be needed.
My idea is that when I get this contact between the player and the enemy (or object), I have this informations and can use it in combat math.
Another question is that the RayCast "works", however, I don't get this information in the first contact with the enemy.
Player code:
func _unhandled_input(event):
for dir in inputs.keys():
if event. is_action_pressed(dir):
move(dir)
func move(dir):
ray.cast_to = inputs[dir] * grid_size
ray.force_raycast_update()
if !ray.is_colliding():
position += inputs[dir] * grid_size
if ray.is_colliding():
if "Enemy" in ray.get_collider().get_groups():
var AC_enemy = ray.get_collider().AC
print("Colisão com inimigo")
print(AC_enemy)
In the enemy code I left only the value of the AC variable.
Thanks

How do I make a kinematic body (3d) follow a player

I've been making a FPS in Godot and I'm having a hard time getting the kinematic body (the enemy) to go towards the player. Could someone please help?
The simplest way to do this is to get the player's position, compare it to the enemy position, and make the enemy move towards it every frame.
Full example code is at the bottom.
To get the player's position you first need a reference to it. You can usually do this through storing the reference in global singleton (autoload) or by exposing a public property.
If you are doing it with a global singleton, then you get the position by calling var player_position = my_singleton.player.global_transform.origin
If you are using an exported property, then you would get the position by calling var player_position = get_node(path_to_player).global_transform.origin
Once you have the player position, you can compare it to the enemy by writing var direction_to_target = player_position - global_transform.origin from inside the enemy node.
Now in order to follow the player, we override the _physics_process method with something like this:
### Inside the enemy script
var ENEMY_SPEED= 50
func _physics_process(delta):
var player_position = my_singleton.player.global_transform.origin
var direction_to_target = (player_position - global_transform.origin).normalized() # We normalize the vector because we only care about the direction
move_and_slide(direction_to_target * ENEMY_SPEED) # We multiply the direction by the speed

Create Dimensions from edge of wall, to sides of openings, to other edge of wall

I've been struggling with this issue off and on for the better part of a year.
As the title says, i wish to dimension from one side of a wall, to both sides of openings (door openings), then terminate at the other end of the wall (vertically and horizontally). I also wish to dimension to all families hosted in the wall, but i have been able to accomplish this using ScottWilson's voodo magic helper class. Found Here: http://thebuildingcoder.typepad.com/blog/2016/04/stable-reference-string-magic-voodoo.html
foreach (ElementId ele in selSet) {
FamilyInstance fi = doc.GetElement(ele) as FamilyInstance;
Reference reference = ScottWilsonVoodooMagic.GetSpecialFamilyReference(fi,ScottWilsonVoodooMagic.SpecialReferenceType.CenterLR,doc);
refs.Append(reference);
pts[i] = ( fi.Location as LocationPoint ).Point;
i++;
}
XYZ offset = new XYZ(0,0,4);
Line line = Line.CreateBound( pts[0]+offset, pts[selSet.Count - 1]+offset );
using( Transaction t = new Transaction( doc ) )
{
t.Start( "dimension embeds" );
Dimension dim = doc.Create.NewDimension(doc.ActiveView, line, refs );
t.Commit();
}
The problem lies in determining the appropriate stable references to the wall faces. I am able to find all faces on a wall, but this gives me 100+ faces to sort through.
If anyone can help me it would be greatly appreciated!
Side note: The closest of gotten is using a casting a ray trace through my panel, then using a reference intersector method to determine references. But i'm really struggling with implementation: http://thebuildingcoder.typepad.com/blog/2015/12/retrieving-wall-openings-and-sorting-points.html
These two posts should provide more than enough to solve all your issues:
Dimension walls by iterating their faces
Dimension walls by shooting a ray
Basically, you need to obtain references to the faces or edges that you wish to attach the dimensioning to. These references can be obtained in several ways. Two common and easy approaches are:
Retrieve the element geometry using the option ComputeReferences set to true and extract the specific face required.
Shoot a ray through the model to determine the required element and its face using the 2017
ReferenceIntersector Class.

how to loop a sound effect in Simple Audio Engine

I have searched extensively on how to loop a sound effect with simple audio engine, but haven't made much progress apart from hello with looping sfx on the cocos2d forum which has several issues. How can I loop a sound effect in Simple Audio Engine?
You would need to edit the SimpleAudioEngine
add this to SimpleAudioEngine.h
-(int) playEffect:(NSString*) file loop:(BOOL) loop;
add this method to SimpleAudioEngine.m
-(int) playEffect:(NSString*) file loop:(BOOL) loop
{
int handle = [[SimpleAudioEngine sharedEngine] playEffect:file];
if (loop) {
alSourcei(handle, AL_LOOPING, 1);
}
return handle;
}
to loop sound effects or music simply do this
ALuint yourSoundALuint = [[SimpleAudioEngine sharedEngine] playEffect:#"yourSound.caf" loop:YES];
and to stop the looping music when necessary
[[SimpleAudioEngine sharedEngine] stopEffect:yourSoundALuint]
For Sound Effect Infinite Looping until you want it to stop.
This is how you do it without messing up anything else.
Make Sure you save the CDSoundSource strong reference in the class or object that is using it so that way you are able to stop it whenever you want.
Since its a unique ID that identifies that sound effect, and this way you can have multiple instances of this sound effect running.
For example: when you need 2 helicopters and each with its own infinite engine sounds.
//Create SFX
-(CDSoundSource*)playInfiniteHeliPad
{
CDSoundSource *loopSound = [[SimpleAudioEngine sharedEngine] soundSourceForFile:#"Sound.m4a"];
loopSound.looping = YES;
loopSound.gain = 0.5f;//Volume
[loopSound play];
return loopSound; //Return the CDSoundSourse
}
//Stop Infinite loop SFX.
-(void)stopInfiniteHeliPad:(CDSoundSource*)loopSound {
[loopSound stop];
}
This is easy to implement and require no modification to root files from Cocos2Denshion

MPMoviePlayerContentPreloadDidFinishNotification seems more reliable than MPMoviePlayerLoadStateDidChangeNotification

I am streaming small movies (1-3MB) off my website into my iPhone app. I have a slicehost webserver, I think it's a "500MB slice". Not sure off the top of my head how this translates to bandwidth, but I can figure that out later.
My experience with MPMoviePlayerLoadStateDidChangeNotification is not very good.
I get much more reliable results with the old MPMoviePlayerContentPreloadDidFinishNotification
If I get a MPMoviePlayerContentPreloadDidFinishNotification, the movie will play without stuttering, but if I use MPMoviePlayerLoadStateDidChangeNotification, the movie frequently stalls.
I'm not sure which load state to check for:
enum {
MPMovieLoadStateUnknown = 0,
MPMovieLoadStatePlayable = 1 << 0,
MPMovieLoadStatePlaythroughOK = 1 << 1,
MPMovieLoadStateStalled = 1 << 2,
};
MPMovieLoadStatePlaythroughOK seems to be what I want (based on the description in the documentation):
MPMovieLoadStatePlaythroughOK
Enough data has been buffered for playback to continue uninterrupted.
Available in iOS 3.2 and later.
but that load state NEVER gets set to this in my app.
Am I missing something? Is there a better way to do this?
Just making sure that you noticed it's a flag, not a value?
MPMoviePlayerController *mp = [aNotification object];
NSLog(#"LoadState: %i", (NSInteger)mp.loadState);
if (mp.loadState & MPMovieLoadStatePlaythroughOK)
{
// Do stuff
}

Resources