/// <summary> /// /// </summary> /// <param name="gameObject"></param> /// <param name="targetGameObjectListMapByTag"></param> private void deleteGameObject(IGameObject gameObject, Dictionary<String, List<IGameObject>> targetGameObjectListMapByTag) { Debug.Assert(gameObject != null, "expected gameObject not null."); Debug.Assert(targetGameObjectListMapByTag != null, "expected targetGameObjectListMapByTypeEnum not null"); String gameObjectTag = gameObject.getGameObjectTag(); if (targetGameObjectListMapByTag.ContainsKey(gameObjectTag) && targetGameObjectListMapByTag[gameObjectTag].Contains(gameObject)) { targetGameObjectListMapByTag[gameObjectTag].Remove(gameObject); } }
/// <summary> /// /// </summary> /// <param name="gameObject"></param> /// <param name="targetGameObjectListMapByTag"></param> private void registerGameObject(IGameObject gameObject, Dictionary<String, List<IGameObject>> targetGameObjectListMapByTag) { Debug.Assert(gameObject != null, "expected gameObject not null."); Debug.Assert(targetGameObjectListMapByTag != null, "expected targetGameObjectListMapByTypeEnum not null"); String gameObjectTag = gameObject.getGameObjectTag(); if (!targetGameObjectListMapByTag.ContainsKey(gameObjectTag)) { targetGameObjectListMapByTag.Add(gameObjectTag, new List<IGameObject>(20)); } targetGameObjectListMapByTag[gameObjectTag].Add(gameObject); }
/// <summary> /// /// </summary> /// <param name="collidableGameObject"></param> public void promoteToCollidableGameObject(IGameObject collidableGameObject) { Debug.Assert(this.gameObjectListMapByTag.ContainsKey(collidableGameObject.getGameObjectTag()), "add the specified object before try to register it as collidable."); Debug.Assert(this.gameObjectListMapByTag[collidableGameObject.getGameObjectTag()].Contains(collidableGameObject), "add the specified object before try to register it as collidable."); this.registerGameObject(collidableGameObject, this.collidableGameObjectListMapByTag); }
/// <summary> /// /// </summary> /// <param name="gameObject"></param> public void removeGameObject(IGameObject gameObject) { SceneNode targetSceneNode = SceneNode.getSceneNodeByGameObject(this.sceneNodeTree, gameObject); //if targetSceneNode equals to null then it is the special case when its parent node and this gameObject node has //expired at the same frame, so sceneBrain calls removeGameObject on both, but it calls removeGameObject on parent node first, //forcing the sceneManager to delete all the childs node too. Consequentially, the later call to removeGameObject on the child node //traduces to a tree-search miss. if (targetSceneNode == null) { //assert that all data of this game object was already removed. Debug.Assert(!this.gameObjectListMapByTag.ContainsKey(gameObject.getGameObjectTag()) || !this.gameObjectListMapByTag[gameObject.getGameObjectTag()].Contains(gameObject)); Debug.Assert(!this.collidableGameObjectListMapByTag.ContainsKey(gameObject.getGameObjectTag()) || !this.collidableGameObjectListMapByTag[gameObject.getGameObjectTag()].Contains(gameObject)); } else { this.recursiveRemoveGameObject(targetSceneNode); } }
/// <summary> /// /// </summary> /// <param name="gameObject"></param> /// <returns></returns> public bool gameObjectExist(IGameObject gameObject) { return gameObject == null || ( this.gameObjectListMapByTag.ContainsKey(gameObject.getGameObjectTag()) && this.gameObjectListMapByTag[gameObject.getGameObjectTag()].Contains(gameObject)); }
/// <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> /// <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)); } }
/// <summary> /// /// </summary> /// <param name="otherGameObject"></param> public override void onCollisionEnterDelegate(IGameObject otherGameObject) { if (otherGameObject.getGameObjectTag() == Tags.USER_TAG) { GameLoop.getSceneManager().applyScale(this, 1.2, 1.2, this.getImage().Width * 0.5, this.getImage().Height * 0.5, true); this.pointedByObject = true; this.runningHourglass = new HourglassGUIGameObject(otherGameObject, new string[] { @"Hourglass_1.png", @"Hourglass_2.png", @"Hourglass_3.png", @"Hourglass_4.png" }); GameLoop.getSceneManager().addGameObject(runningHourglass, otherGameObject); } }
/// <summary> /// /// </summary> /// <param name="otherGameObject"></param> public override void onCollisionExitDelegate(IGameObject otherGameObject) { if (otherGameObject.getGameObjectTag() == Tags.USER_TAG) { ISceneManager sceneManager = GameLoop.getSceneManager(); sceneManager.applyScale(this, 1 / 1.2, 1 / 1.2, this.getImage().Width * 0.5, this.getImage().Height * 0.5, true); this.pointedByObject = false; this.internalCountDown = USER_INTERACTION_DELAY; if (this.runningHourglass != null) { sceneManager.removeGameObject(runningHourglass); } } }