/// <summary> /// /// </summary> /// <param name="otherGameObject"></param> public override void onCollisionEnterDelegate(IGameObject otherGameObject) { switch (otherGameObject.getGameObjectTag()) { case Tags.CUT_TAG: this.isCut = true; Random random = new Random(); //create floating death label GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(new GameFloatingLabelObject(this, GameFloatingLabelObject.points2string(FRUIT_DEATH_POINTS)), null)); Image stainImage = new Image(); stainImage.Source = new BitmapImage(new Uri(BitmapUtility.getImgResourcePath("stain" + random.Next(1, 21) + ".png"))); stainImage.Height = 260; stainImage.Width = 390; StainGameObject stainFadeOutGameObject = new StainGameObject(this._xPosition - stainImage.Width * 0.5, this._yPosition - stainImage.Height * 0.5, stainImage, 4500, 2000); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(stainFadeOutGameObject, null)); break; case Tags.USER_TAG: this.isCollected = true; //create floating death label GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(new GameFloatingLabelObject(this, GameFloatingLabelObject.points2string(FRUIT_COLLECTION_POINTS)), null)); {// fruit collected sound SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\fruit_collected.wav", UriKind.Relative), false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } break; } }
/// <summary> /// /// </summary> public override void onRendererDisplayDelegate() { GameLoop.getSceneManager().canvasDisplayImage(this, 1); { //fruit appear sound SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\fruit_appear.wav", UriKind.Relative), 1, false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } }
public override void onRendererRemoveDelegate() { base.onRendererRemoveDelegate(); if (!this.isCollected && !this.isCut) { //vanish sound SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\fruit_vanish.wav", UriKind.Relative), 0.2, false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } }
/// <summary> /// /// </summary> public override void onRendererRemoveDelegate() { if (!this.cutSuccess) { SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\air_cut.wav", UriKind.Relative), false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } ISceneManager sceneManager = GameLoop.getSceneManager(); sceneManager.canvasRemoveImage(this); }
/// <summary> /// /// </summary> /// <param name="otherGameObject"></param> public override void onCollisionEnterDelegate(IGameObject otherGameObject) { if (otherGameObject.getGameObjectTag() == Tags.FRUIT_TAG) { this.cutSuccess = true; //cut success sound SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\fruit_cutted.wav", UriKind.Relative), false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } }
protected override List<KeyValuePair<IGameObject, IGameObject>> spawnGameObjectsOnStart() { {// user dead sound SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\user_dead.wav", UriKind.Relative), false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } List<KeyValuePair<IGameObject, IGameObject>> ret = base.spawnGameObjectsOnStart(); ISceneManager sceneManager = GameLoop.getSceneManager(); //add user object Image image = new Image(); image.Source = new BitmapImage(new Uri(BitmapUtility.getImgResourcePath(@"hand.png"))); image.Height = 150; image.Width = 150; Image notAlreadyTracketImage = new Image(); notAlreadyTracketImage.Source = new BitmapImage(new Uri(BitmapUtility.getImgResourcePath(@"wave.png"))); notAlreadyTracketImage.Height = 129; notAlreadyTracketImage.Width = 600; Geometry boundingBoxGeometry = new EllipseGeometry(new Point(75, 75), 10, 10); double halfCanvasWidth = sceneManager.getCanvasWidth() * 0.5; double halfCanvasHeight = sceneManager.getCanvasHeight() * 0.5; HandUserGameObject userGameObject = new HandUserGameObject(0, 0, boundingBoxGeometry, notAlreadyTracketImage, image, SkeletonSmoothingFilter.HIGH_SMOOTHING_LEVEL); ret.Add(new KeyValuePair<IGameObject, IGameObject>(userGameObject, null)); #if DEBUG ret.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(userGameObject), userGameObject)); #endif //add game score and time labels CenteredScreenAreaGameObject centeredScreenAreaGameObject = new CenteredScreenAreaGameObject(sceneManager.getCanvasWidth(), sceneManager.getCanvasHeight(), 1024, 320); ret.Add(new KeyValuePair<IGameObject, IGameObject>(centeredScreenAreaGameObject, null)); //init accumulators double currentHeight = 0; double finalScore = 0; double diffMultiplier = 1; switch (this.gameDifficulty) { case Configuration.GameDifficultyEnum.Medium: diffMultiplier = 1.5; break; case Configuration.GameDifficultyEnum.Hard: diffMultiplier = 2; break; } double controlMultiplier = 1; if (this.userControlMethod == Configuration.UserControlMethodEnum.Head) { controlMultiplier = 3; } //game score label double multiplier = POINTS_PER_BONUS * controlMultiplier * diffMultiplier; double currentScore = this.bonusPoints * multiplier; finalScore += currentScore; IGameObject gameObject = new GameLabelObject(0, currentHeight, "Saved fruits score : " + currentScore + " (" + this.bonusPoints + " x " + multiplier + ")", -1); ret.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, centeredScreenAreaGameObject)); #if DEBUG ret.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), userGameObject)); #endif currentHeight += VERTICAL_LABEL_SPACE + gameObject.getBoundingBoxGeometry().Bounds.Height; //game length label multiplier = diffMultiplier * POINTS_PER_MILLIS; currentScore = this.gameLength * multiplier; finalScore += currentScore; gameObject = new GameLabelObject(0, currentHeight, "Survival bonus : " + Math.Round(currentScore, 1) + " (" + this.millis2time(this.gameLength) + ")", -1); ret.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, centeredScreenAreaGameObject)); #if DEBUG ret.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), userGameObject)); #endif currentHeight += VERTICAL_LABEL_SPACE + gameObject.getBoundingBoxGeometry().Bounds.Height; //rage score label multiplier = POINTS_PER_RAGE * diffMultiplier; currentScore = this.ragePoints * multiplier; finalScore += currentScore; gameObject = new GameLabelObject(0, currentHeight, "Enemy rage bonus : " + currentScore + " (" + this.ragePoints + " x " + multiplier + ")", -1); ret.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, centeredScreenAreaGameObject)); #if DEBUG ret.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), userGameObject)); #endif currentHeight += VERTICAL_LABEL_SPACE + gameObject.getBoundingBoxGeometry().Bounds.Height; gameObject = this.createBackButton(); //difficulty bonus label finalScore *= diffMultiplier; gameObject = new GameLabelObject(0, currentHeight, "Difficulty bonus " + (diffMultiplier > 1 ? "x " + diffMultiplier : "NO BONUS"), -1); ret.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, centeredScreenAreaGameObject)); #if DEBUG ret.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), userGameObject)); #endif currentHeight += VERTICAL_LABEL_SPACE + gameObject.getBoundingBoxGeometry().Bounds.Height; //control bonus label finalScore *= controlMultiplier; gameObject = new GameLabelObject(0, currentHeight, "Control bonus " + (controlMultiplier > 1 ? "x " + controlMultiplier : "NO BONUS"), -1); ret.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, centeredScreenAreaGameObject)); #if DEBUG ret.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), userGameObject)); #endif currentHeight += VERTICAL_LABEL_SPACE + gameObject.getBoundingBoxGeometry().Bounds.Height; //final score label gameObject = new GameLabelObject(0, currentHeight, "FINAL SCORE : " + Math.Round(finalScore), -1); ret.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, centeredScreenAreaGameObject)); #if DEBUG ret.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), userGameObject)); #endif currentHeight += VERTICAL_LABEL_SPACE + gameObject.getBoundingBoxGeometry().Bounds.Height; gameObject = this.createBackButton(); ret.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, null)); #if DEBUG ret.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), gameObject)); #endif return ret; }
/// <summary> /// /// </summary> /// <returns></returns> private List<KeyValuePair<IGameObject, IGameObject>> spawnBaseMenuInitialObject() { List<KeyValuePair<IGameObject, IGameObject>> gameObjectParentGameObjectPairList = new List<KeyValuePair<IGameObject, IGameObject>>(); { // selection sound SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\selection.wav", UriKind.Relative), false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } { // Menu theme SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources/Sounds/menu_theme.mp3", UriKind.Relative), 0.4, true); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(soundGameObject, null)); } { //userObject Image image = new Image(); image.Source = new BitmapImage(new Uri(BitmapUtility.getImgResourcePath(@"hand.png"))); image.Height = 150; image.Width = 150; Image notAlreadyTracketImage = new Image(); notAlreadyTracketImage.Source = new BitmapImage(new Uri(BitmapUtility.getImgResourcePath(@"wave.png"))); notAlreadyTracketImage.Height = 129; notAlreadyTracketImage.Width = 600; Geometry boundingBoxGeometry = new EllipseGeometry(new Point(75, 75), 10, 10); HandUserGameObject userGameObject = new HandUserGameObject(0, 0, boundingBoxGeometry, notAlreadyTracketImage, image, SkeletonSmoothingFilter.HIGH_SMOOTHING_LEVEL); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(userGameObject, null)); #if DEBUG gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(userGameObject), userGameObject)); #endif } { //logo Image logoImage = new Image(); logoImage.Source = new BitmapImage(new Uri(BitmapUtility.getImgResourcePath(@"logo.png"))); logoImage.Height = 221; logoImage.Width = 400; ImageGuiGameObject logoGameObject = new ImageGuiGameObject(600, 20, logoImage); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(logoGameObject, null)); } { //menu area ISceneManager sceneManager = GameLoop.getSceneManager(); CenteredScreenAreaGameObject areaGameObject = new CenteredScreenAreaGameObject(sceneManager.getCanvasWidth(), sceneManager.getCanvasHeight(), 1366, 700); this.menuAreaGameObject = areaGameObject; gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(areaGameObject, null)); #if DEBUG gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(areaGameObject), areaGameObject)); #endif } this.spawnerStateFunction = this.spawnMainMenu; this.stateChanged = true; return gameObjectParentGameObjectPairList; }
private void playSelectionSound() { SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\selection.wav", UriKind.Relative), false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); }
/// <summary> /// /// </summary> /// <returns></returns> protected override List<KeyValuePair<IGameObject, IGameObject>> spawnGameObjectsPerFrame() { //spawn objs only if game start countdown is expired //Debug.Assert(typeof(GameSceneBrain).IsAssignableFrom(GameLoop.getSceneBrain().GetType()), "Expected a GameSceneBrain object"); //GameSceneBrain sceneBrain = (GameSceneBrain)GameLoop.getSceneBrain(); List<KeyValuePair<IGameObject, IGameObject>> gameObjectParentGameObjectPairList = new List<KeyValuePair<IGameObject, IGameObject>>(); if (gameSceneBrain.getGameStartCountdownMillis() <= 0) { if (this.gameFirstStart) { IGameObject lengthLabelGameObject = new GameLengthLabelObject(HORIZ_RAGE_IMG_SPACE, VERTICAL_LABEL_SPACE, gameSceneBrain); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(lengthLabelGameObject, null)); IGameObject scoreLabelGameObject = new GameScoreLabelObject(HORIZ_RAGE_IMG_SPACE, (2 * VERTICAL_LABEL_SPACE) + lengthLabelGameObject.getBoundingBoxGeometry().Bounds.Height, gameSceneBrain); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(scoreLabelGameObject, null)); {// gong sound SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\gong.wav", UriKind.Relative), 0.2, false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } this.gameFirstStart = false; } int deltaTimeMillis = Time.getDeltaTimeMillis(); this.updateSpawnOffsets(deltaTimeMillis); ISceneManager sceneManager = GameLoop.getSceneManager(); Dictionary<String, List<IGameObject>> gameObjectListMapByType = sceneManager.getGameObjectListMapByTag(); //userGameObjectList Debug.Assert(gameObjectListMapByType.ContainsKey(Tags.USER_TAG), "the userGameObject must be created."); List<IGameObject> userGameObjectList = userGameObjectList = gameObjectListMapByType[Tags.USER_TAG]; Debug.Assert(userGameObjectList.Count > 0, "expected userGameObjectList.Count > 0"); //friendlyObjectList List<IGameObject> friendlyObjectList; if (gameObjectListMapByType.ContainsKey(Tags.FRUIT_TAG)) { friendlyObjectList = gameObjectListMapByType[Tags.FRUIT_TAG]; } else { friendlyObjectList = new List<IGameObject>(); } //unfriendlyObjectList List<IGameObject> unfriendlyObjectList; if (gameObjectListMapByType.ContainsKey(Tags.CUT_TAG)) { unfriendlyObjectList = gameObjectListMapByType[Tags.CUT_TAG]; } else { unfriendlyObjectList = new List<IGameObject>(); } //spawn a new unfriendly obj if (this.shouldSpawnNewCutGameObject(unfriendlyObjectList.Count, gameSceneBrain.getMaxNumberOfChopAllowed(), this.unfriendlyObjCooldown, this.lastUnfriendlyObjSpawned)) { IGameObject gameObject = this.spawnNewCutGameObject(userGameObjectList, friendlyObjectList); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, null)); this.unfriendlyObjCooldown = this.generateNewChopCooldown(); this.lastUnfriendlyObjSpawned = 0; #if DEBUG gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), gameObject)); #endif } else { this.lastUnfriendlyObjSpawned += deltaTimeMillis; } //spawn new friendly obj, with potentially different probability distribution if (this.shouldSpawnNewFruitGameObject(friendlyObjectList.Count, gameSceneBrain.getMaxNumberOfUserFriendlyGameObjectAllowed(), this.friendlyObjCooldown, this.lastFriendlyObjSpawned)) { IGameObject gameObject = this.spawnNewFruitGameObject(friendlyObjectList); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, null)); this.friendlyObjCooldown = random.Next(currentConfiguration.minFriendlyObjectSpawnCooldownTimeMillis, currentConfiguration.maxFriendlyObjectSpawnCoooldownTimeMillis); this.lastFriendlyObjSpawned = 0; #if DEBUG gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), gameObject)); #endif } else { this.lastFriendlyObjSpawned += deltaTimeMillis; } } return gameObjectParentGameObjectPairList; }
/// <summary> /// /// </summary> /// <returns></returns> protected override List<KeyValuePair<IGameObject, IGameObject>> spawnGameObjectsOnStart() { {//selection sound SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\selection.wav", UriKind.Relative), false); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } {//game main theme SoundGameObject soundGameObject = new SoundGameObject(new Uri(@"Resources\Sounds\game_theme.mp3", UriKind.Relative), 0.2, true); GameLoop.getSpawnerManager().specialRequestToSpawn(new GameObjectSpawnRequest(soundGameObject, null)); } //userGameObject spawn List<KeyValuePair<IGameObject, IGameObject>> gameObjectParentGameObjectPairList = new List<KeyValuePair<IGameObject, IGameObject>>(); IGameObject gameObject = this.spawnUserGameObject(); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, null)); #if DEBUG gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(new BoundingBoxViewerGameObject(gameObject), gameObject)); #endif #if DEBUG //debug cooldown label objs gameObject = new DEBUG_LabelObject(10, (3 * VERTICAL_LABEL_SPACE) + (2 * gameObject.getBoundingBoxGeometry().Bounds.Height)); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, null)); #endif //rage icons spawn ISceneManager sceneManager = GameLoop.getSceneManager(); gameObject = new RageItemGUIGameObject(gameSceneBrain, 3, sceneManager.getCanvasWidth() - (4 * HORIZ_RAGE_IMG_SPACE + 3 * RageItemGUIGameObject.IMAGE_WIDTH), VERTICAL_LABEL_SPACE); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, null)); gameObject = new RageItemGUIGameObject(gameSceneBrain, 2, sceneManager.getCanvasWidth() - (3 * HORIZ_RAGE_IMG_SPACE + 2 * RageItemGUIGameObject.IMAGE_WIDTH), VERTICAL_LABEL_SPACE); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, null)); gameObject = new RageItemGUIGameObject(gameSceneBrain, 1, sceneManager.getCanvasWidth() - (2 * HORIZ_RAGE_IMG_SPACE + 1 * RageItemGUIGameObject.IMAGE_WIDTH), VERTICAL_LABEL_SPACE); gameObjectParentGameObjectPairList.Add(new KeyValuePair<IGameObject, IGameObject>(gameObject, null)); return gameObjectParentGameObjectPairList; }