// starts a new game public void PlayGame() { Debug.Log("Game Start"); GameAnalytics.NewProgressionEvent(GAProgressionStatus.Start, "game"); touchScreen.SetActive(true); //set up score score = 0; //set round to one gameRound = 1; //set hue to one blockColor = 1; //set num of balls to one numBalls = 1; //reset the number of grounded balls to zero // since main ball will always be used simply enable it in sceen mainBall.SetActive(true); // enable spawner spawner.SetActive(true); groundedBalls = 0; scoreUI.text = score.ToString(); MainMenuManager.instance.MenuHandler(); //set game state to ready so player can play game Ready(); gameRunning = GameRunning.Running; finger.SetActive(true); }
public void InitializeTest() { game = new Game(); gameR = new GameRunning(game, null); gameR.singletonScore = new SingletonScore(new Vec2F(0.3f, 0.3f), new Vec2F(0.3f, 0.3f)); stateMachine = new StateMachine(game); }
public PlayerShot(GameRunning gameRunning, DynamicShape shape, IBaseImage image) : base(shape, image) { this.gameRunning = gameRunning; this.shape = shape; Shape.AsDynamicShape().Direction = new Vec2F(0.0f, 0.01f); }
public void RenderState() { GameRunning.GetInstance().RenderState(); foreach (Text but in menuButtons) { but.RenderText(); } }
private void KeyPress(string key) { switch (key) { case "KEY_SPACE": GameRunning.GetInstance(this).player.CreateShot(); break; } }
private void KeyRelease(string key) { if (key.Equals("KEY_A") || key.Equals("KEY_D")) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForSpecificProcessor( GameEventType.PlayerEvent, this, GameRunning.GetInstance(this).player, "stop move", "", "")); } }
// public funcntion when player crashes public void GameOver() { GameAnalytics.NewProgressionEvent(GAProgressionStatus.Complete, "game", score); //destroy all objects DestroyAll(); //set num of balls to one numBalls = 1; //reset the number of grounded balls to zero groundedBalls = 0; ballsCollected = 1; //update number of games played gamesPlayed += 1; //disable main ball mainBall.SetActive(false); //disable spawner in scene spawner.SetActive(false); //should an ad pop up after game? if (gamesPlayed % adFrequency == 0 && PlayerPrefManager.GetNoAdsPurchased() == false) //check if product id for no ads is false { Debug.Log("Ad is showing"); if (PlayAd.pa) { PlayAd.pa.ShowAd(); } } if (highScore > 1000)// **find better substitue for when player should be requested to play a game** { iOSReviewRequest.Request(); } // update GUI SavePlayerState(); MainMenuManager.instance.MenuHandler(); //set highscore active if (highScoreUI) { highScoreUI.text = "Best score: " + PlayerPrefManager.GetHighscore().ToString(); } else { Debug.LogWarning("High Score UI not set"); } gameRunning = GameRunning.NotRunning; PlayerPrefManager.SetBool("gameRunning", false); }
public void AddShots(GameRunning game) { IBaseImage bulletPicture = new Image(Path.Combine("Assets", "Images", "BulletRed2.png")); PlayerShot pShot = new PlayerShot(new DynamicShape( new Vec2F(Entity.Shape.Position.X + 0.045f, Entity.Shape.Position.Y + 0.1f), new Vec2F(0.008f, 0.027f), new Vec2F(0.0f, 0.01f)), bulletPicture); game.playerShots.Add(pShot); }
public void CustomerTimeOut() { ChoseLevel.GetInstance().filename = "short-n-sweet.txt"; GameRunning.instance = null; GameOver.instance = null; GameRunning.GetInstance(game, null); // GameRunning.instance.player.thrust = new Vec2F(-0.00001f, 0f); //sets a convenient start position for player GameRunning.instance.player.Entity.Shape.SetPosition(new Vec2F(0.3f , 0.25f)); GameRunning.instance.gravity = new Vec2F(0f, -0.0000003f); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); SpaceTaxiBus.GetBus().ProcessEventsSequentially(); while (GameOver.instance == null) { game.gameTimer.MeasureTime(); while (game.gameTimer.ShouldUpdate()) { SpaceTaxiBus.GetBus().ProcessEvents(); game.win.PollEvents(); game.eventBus.ProcessEvents(); game.stateMachine.ActiveState.UpdateGameLogic(); } if (game.gameTimer.ShouldRender()) { game.win.Clear(); game.backGroundImage.RenderEntity(); game.stateMachine.ActiveState.RenderState(); game.win.SwapBuffers(); } if (game.gameTimer.ShouldReset()) { // 1 second has passed - display last captured ups and fps from the timer // win.Title = "Space Taxi | UPS: " + gameTimer.CapturedUpdates + ", FPS: " + // gameTimer.CapturedFrames; } } Assert.That(game.stateMachine.ActiveState, Is.InstanceOf <GameOver>()); }
CollisionReleasePlatformSingle(DynamicShape player, Passenger passenger) { if (passenger.GetReleasePlatformChar() != '^' && PlatformCollision.CollisionPlatform(player, passenger.GetReleasePlatform()) && GameRunning.GetLevelCounter() == passenger.SetOffLevel) { return(true); } return(false); }
/// <summary> /// Checks if the player is at the right platform /// </summary> /// <param name="player">player</param> /// <returns>bool checking if its the right platform</returns> public static bool CollisionReleasePlatform(DynamicShape player) { foreach (var passenger in PassengerCollision.GetPassengerPickups()) { if (passenger.GetReleasePlatformChar() != '^' && PlatformCollision.CollisionPlatform(player, passenger.GetReleasePlatform()) && GameRunning.GetLevelCounter() == passenger.SetOffLevel) { return(true); } } return(false); }
private void SwitchState(GameStateType stateType) { switch (stateType) { case (GameStateType.GameRunning): ActiveState = GameRunning.GetInstance(); break; case (GameStateType.GamePaused): ActiveState = GamePaused.GetInstance(); break; case (GameStateType.MainMenu): ActiveState = MainMenu.GetInstance(); break; } }
private void SwitchState(GameStateType stateType) { switch (stateType) { case GameStateType.MainMenu: GameRunning.GetInstance().InitializeGameState(); ActiveState = MainMenu.GetInstance(); break; case GameStateType.GamePaused: ActiveState = GamePaused.GetInstance(); break; case GameStateType.GameRunning: ActiveState = GameRunning.GetInstance(); break; } }
public void SwitchingState() { stateMachine.SwitchState(GameStateType.GamePaused); Assert.True(stateMachine.ActiveState == GamePaused.GetInstance()); stateMachine.SwitchState(GameStateType.ChooseLevel); Assert.True(stateMachine.ActiveState == ChooseLevel.GetInstance()); stateMachine.SwitchState(GameStateType.MainMenu); Assert.True(stateMachine.ActiveState == MainMenu.GetInstance()); GameRunning.NewInstance("the-beach.txt"); stateMachine.SwitchState(GameStateType.GameRunning); Assert.True(stateMachine.ActiveState == GameRunning.GetInstance()); stateMachine.SwitchState(GameStateType.MainMenu); Assert.True(stateMachine.ActiveState == MainMenu.GetInstance()); GameRunning.NewInstance("short-n-sweet.txt"); stateMachine.SwitchState(GameStateType.GameRunning); Assert.True(stateMachine.ActiveState == GameRunning.GetInstance()); }
/// <summary> /// Checks which platform the player is supposed to be collided with. /// </summary> /// <param name="player">player</param> public static void CheckDropOffCollision(Player player) { foreach (var passenger in PassengerCollision.passengerPickups) { if (passenger.PickedUp && !passenger.DroppedOff && GameRunning.GetLevelCounter() == passenger.SetOffLevel && PlatformCollision.CollisionReleasePlatformSingle(player.GetsShape(), passenger) ) { if (passenger.GetReleasePlatformChar() != '^') { passenger.SetPosition( passenger.GetReleasePlatform()[0].Shape.Position.X, passenger.GetReleasePlatform()[0].Shape.Position.Y + 0.04f); passenger.GetShape().Direction.X = 0.0f; } passenger.DroppedOff = true; passenger.SetReleasedWithinTimer(!passenger.ReleaseTimer()); } } }
public void CustomerCollision() { GameRunning.instance = null; GameRunning.GetInstance(game, null); // GameRunning.instance.player.thrust = new Vec2F(-0.00001f, 0f); //sets a convenient start position for player GameRunning.instance.player.Entity.Shape.SetPosition(new Vec2F(0.3f , GameRunning.instance.player.Entity.Shape.Position.Y - 0.1f)); // // changes currentVelocity to "move" player GameRunning.instance.currentVelocity = new Vec2F(0f, -0.002f); // mock game loop while (!GameRunning.instance.currentLevel.cusList[0].entity.IsDeleted()) { GameRunning.instance.UpdateGameLogic(); GameRunning.instance.RenderState(); } Assert.IsTrue(GameRunning.instance.currentLevel.cusList[0].entity.IsDeleted()); }
public void IterateShots() { foreach (var shot in playerShots) { shot.Shape.Move(); if (shot.Shape.Position.Y > 1.0f) { shot.DeleteEntity(); } foreach (var enemyIter in GameRunning.GetInstance(this).enemies) { var collisionData = CollisionDetection.Aabb(shot.shape.AsDynamicShape(), enemyIter.shape); if (collisionData.Collision) { shot.DeleteEntity(); enemyIter.DeleteEntity(); GameRunning.GetInstance(this).AddExplosion(enemyIter.shape.Position.X, enemyIter.shape.Position.Y, shot.shape.Extent.X + 0.1f, shot.shape.Extent.Y + 0.1f); GameRunning.GetInstance(this).score.AddPoint(); } } } foreach (Enemy enem in GameRunning.GetInstance(this).enemies) { if (!enem.IsDeleted()) { GameRunning.GetInstance(this).newEnemies.Add(enem); } } foreach (PlayerShot elem in playerShots) { if (!elem.IsDeleted()) { newPlayerShots.Add(elem); } } }
void Start() { gameRunning = GameRunning.NotRunning; highScore = PlayerPrefManager.GetHighscore(); UpdateHighScore(); // setup reference to game manager if (gm == null) { gm = this.GetComponent <GameManager>(); } else { Destroy(gameObject); } if (PlayerPrefManager.GetBool("gameRunning") == true) { Debug.Log("gamerunning"); numBalls = 1; LoadGame(); coinUI.text = coinsCollected.ToString(); scoreUI.text = score.ToString(); if (FB.IsInitialized) { FB.ActivateApp(); } else { //Handle FB.Init FB.Init(() => { FB.ActivateApp(); }); } } else { coinsCollected = PlayerPrefManager.GetCoins(); coinUI.text = coinsCollected.ToString(); highScore = PlayerPrefManager.GetHighscore(); //getGamesPlayed gamesPlayed = PlayerPrefManager.GetGamesPlayed(); //update score if (scoreUI) { scoreUI.text = score.ToString(); } if (FB.IsInitialized) { FB.ActivateApp(); } else { //Handle FB.Init FB.Init(() => { FB.ActivateApp(); }); } } Debug.Log(highScore); }
public void InitiateGame() { game = new Game(); gameR = new GameRunning(game, new Customer(",", 1, ",", ",", 4, 5)); }
public void Initialize() { game = new Game(); GameRunning.GetInstance(game, null); }
public async Task InitConnectionAsync() { if (IsConnected) { return; } var accessTokenState = await _tokenProvider.RequestAccessToken(); if (accessTokenState.TryGetToken(out var accessToken)) { var apiBaseUrl = _configurtion["api:baseUrl"]; var accessTokenString = accessToken.Value; _hubConnection = new HubConnectionBuilder() .WithUrl($"{apiBaseUrl}tictactoe?access_token={accessTokenString}", options => { options.AccessTokenProvider = () => Task.FromResult(accessTokenString); }) .WithAutomaticReconnect(new[] { TimeSpan.Zero, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10) }) .Build(); _hubConnection.On("StartGame", (GameSession data) => { GameRunning?.Invoke(this, new GameRunningEventArgs { Running = true }); ActiveSession?.Invoke(this, new ActiveSessionEventArgs { Session = data }); }); _hubConnection.On("GameOver", (string data) => { GameRunning?.Invoke(this, new GameRunningEventArgs { Running = false }); ActiveSession?.Invoke(this, new ActiveSessionEventArgs { Session = null }); GameOver?.Invoke(this, new GameOverEventArgs { WinnerId = data }); }); _hubConnection.On <int>("Play", (data) => { Console.WriteLine($"Round Played. Data is {data}"); RoundPlayed?.Invoke(this, new GameEventArgs() { Value = data }); }); _hubConnection.Closed += async(exception) => { _toaster.Add(exception.Message, MatToastType.Danger); await _sessionStateManager.SetSignOutState(); _navigationManager.NavigateTo("authentication/logout"); }; try { Console.WriteLine("start signalr connection"); await _hubConnection.StartAsync(); _toaster.Add("Erfolgreich angemeldet.", MatToastType.Success, null, null, (options) => { options.ShowProgressBar = false; options.ShowCloseButton = false; options.VisibleStateDuration = 2500; }); await JoinNewSession(); } catch (Exception e) { _toaster.Add( $"Beim Verbinden zum Server ist etwas schief gelaufen. Error: {e.Message}", MatToastType.Danger); } } }
public Down(GameRunning game, float speedMultiplier) { this.speedMultiplier = speedMultiplier; this.game = game; }
public void InitiateGame() { game = new Game(); gameR = GameRunning.GetInstance(game, null); stateMachine = new StateMachine(game); }
public void CustomerDropOff() { GameRunning.instance = null; GameRunning.GetInstance(game, null); // GameRunning.instance.player.thrust.Y = 0f; //sets a convenient start position for player GameRunning.instance.player.Entity.Shape.SetPosition(new Vec2F(0.3f , 0.25f)); GameRunning.instance.gravity = new Vec2F(0f, -0.0000003f); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); // game.GameLoop(); while (SingletonScore.Instance.score == 0) { if (GameRunning.instance != null) { if (GameRunning.instance.player.shape.Position.Y < 0.1) { GameRunning.instance.player.SetPosition(0.5f, 0.7f); GameRunning.instance.player.thrust.Y = 0.00001f; } } if (GameRunning.instance != null) { if (GameRunning.instance.currentLevel.levelName.Equals("the-beach.txt") && GameRunning.instance.player.shape.Position.Y < 0.8f) { GameRunning.instance.player.SetPosition(0.1f, 0.84f); GameRunning.instance.player.thrust.Y = 0.000001f; } } game.gameTimer.MeasureTime(); while (game.gameTimer.ShouldUpdate()) { SpaceTaxiBus.GetBus().ProcessEvents(); game.win.PollEvents(); game.eventBus.ProcessEvents(); game.stateMachine.ActiveState.UpdateGameLogic(); } if (game.gameTimer.ShouldRender()) { game.win.Clear(); game.backGroundImage.RenderEntity(); game.stateMachine.ActiveState.RenderState(); game.win.SwapBuffers(); } if (game.gameTimer.ShouldReset()) { // 1 second has passed - display last captured ups and fps from the timer // win.Title = "Space Taxi | UPS: " + gameTimer.CapturedUpdates + ", FPS: " + // gameTimer.CapturedFrames; } } Assert.AreEqual(100, SingletonScore.Instance.score); }
void LoadGame() { if (PlayerPrefs.HasKey("numBalls")) { ballsCollected = PlayerPrefs.GetInt("numBalls"); } else { ballsCollected = 1; } if (PlayerPrefs.HasKey("gameRound")) { gameRound = PlayerPrefs.GetInt("gameRound"); blockColor = PlayerPrefs.GetInt("gameRound"); } else { gameRound = 1; blockColor = 1; } if (PlayerPrefs.HasKey("numGems")) { coinsCollected = PlayerPrefs.GetInt("numGems"); } else { coinsCollected = PlayerPrefManager.GetCoins(); } if (PlayerPrefs.HasKey("numFeed")) { numFeed = PlayerPrefs.GetInt("numFeed"); } else { numFeed = 0; } if (PlayerPrefs.HasKey("numBlocks")) { numBlocks = PlayerPrefs.GetInt("numBlocks"); } else { numBlocks = 0; } if (PlayerPrefs.HasKey("score")) { score = PlayerPrefs.GetInt("score"); } else { score = 0; } // since main ball will always be used simply enable it in sceen mainBall.SetActive(true); // enable spawner spawner.SetActive(true); MainMenuManager.instance.MenuHandler(); //set game state to ready so player can play game Ready(); gameRunning = GameRunning.Running; finger.SetActive(true); SpawnBalls(); }
public Player(DynamicShape shape, IBaseImage image, GameRunning game) { Entity = new Entity(shape, image); Game = game; }
public Player(GameRunning gameRunning, DynamicShape shape, IBaseImage image) { this.gameRunning = gameRunning; player = new Entity(new DynamicShape(new Vec2F(0.45f, 0.1f), new Vec2F(0.1f, 0.1f)), new Image(Path.Combine("Assets", "Images", "Player.png"))); }