public override void Tick(float dt) { //base.Tick(dt); if (Player.Instance == null) { } else { setCameraPosition(); } //check bullet delay if (Bullet.bulletDelay > 0) { Bullet.bulletDelay--; } //check buttons if (Input2.GamePad0.Cross.Down || Input2.GamePad0.R.Down) { if (Bullet.bulletDelay == 0 && Player.Instance.ammo > 0) { SoundSystem.Instance.Play("shot.wav"); Bullet bullet = new Bullet(); bulletList.Add(bullet); World.AddChild(bullet); Bullet.bulletDelay = 2; Player.Instance.ammo--; //update player's sprite Player.Instance.playerBodySprite.TileIndex1D = Player.Instance.animationFrame; Player.Instance.animationFrame = (Player.Instance.animationFrame + 1) % Player.Instance.playerBodySprite.TextureInfo.NumTiles.X; } } //check buttons if (Input2.GamePad0.Cross.Release || Input2.GamePad0.R.Release) { //update player's sprite Player.Instance.playerBodySprite.TileIndex1D = 0; } //check start button(for pause menu) if (Input2.GamePad0.Start.Press) { this.paused = true; SceneManager.Instance.pushScene(PauseScene.Instance); } // pinch-to-zoom //only check for multitouch points if device supports more than one touch point if (Input2.Touch.MaxTouch > 1) { //only proceed if the user is actually touching both points if (Input2.Touch.GetData(0)[0].Down && Input2.Touch.GetData(0)[1].Down) { //first touch point Vector2 touch1 = Director.Instance.CurrentScene.GetTouchPos(0); //second touch point Vector2 touch2 = Director.Instance.CurrentScene.GetTouchPos(1); //reset the distance measure if the screen has just been touched if (Input2.Touch.GetData(0)[0].Press || Input2.Touch.GetData(0)[1].Press) { multitouchDistance = touch1.Distance(touch2); } else { var newDistance = touch1.Distance(touch2); cameraHeight += (multitouchDistance - newDistance); this.Camera2D.SetViewFromHeightAndCenter(cameraHeight, Player.Instance.Position); } } } //check if the player has collected any ammo packs AmmoItem ammoItemToRemove; if (Collisions.checkAmmoPackCollisions(Player.Instance, ammoList, out ammoItemToRemove)) { Game.Instance.EffectsLayer.AddChild(new ammoMarker(ammoItemToRemove.Position)); SoundSystem.Instance.Play("ammoclip.wav"); World.RemoveChild(ammoItemToRemove, true); ammoList.Remove(ammoItemToRemove); Player.Instance.ammo = (int)FMath.Clamp((Player.Instance.ammo + 50), 100, 100); ammoItemToRemove.Die(); } if (Player.Instance.Health <= 0) { Background.RemoveAllChildren(true); Foreground.RemoveAllChildren(true); EffectsLayer.RemoveAllChildren(true); World.RemoveAllChildren(true); Interface.RemoveAllChildren(true); SceneManager.Instance.changeSceneTo(GameOverScene.Instance); //Sce.PlayStation.HighLevel.GameEngine2D.Scheduler.Instance.Unschedule(Scene, gameTick); //Sce.PlayStation.HighLevel.GameEngine2D.Scheduler.Instance.Schedule(Scene, gameoverTick, 0.0f, false); } }
public void initGame() { cameraHeight = (float)Convert.ToDouble(Support.GameParameters["StartingCameraHeight"]); //set view close to the scene this.Camera2D.SetViewFromHeightAndCenter(cameraHeight, Sce.PlayStation.HighLevel.GameEngine2D.Base.Math._00); //add all sprites loaded from the map foreach (SpriteList sl in MapManager.Instance.currentMap.spriteList) { Background.AddChild(sl); } //load the fire texture for the bullet Bullet.fireTexture = new Texture2D("/Application/data/tiles/fire.png", false); //texture for the points marker pointMarker.texture = new Texture2D("/Application/data/points100.png", false); //texture for the ammo marker ammoMarker.texture = new Texture2D("/Application/data/plusammo.png", false); Player.Instance = new Player(); Foreground.AddChild(Player.Instance); //create the list for bullets bulletList = new List <Bullet>(); //create ammo packs ammoList = new List <AmmoItem>(); List <MapTile> list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor); //add a specified number of ammo packs for (int i = 0; i < AmmoItem.noOfAmmoToGenerate; i++) { AmmoItem a = new AmmoItem(list[Support.random.Next(0, list.Count - 1)].position); ammoList.Add(a); World.AddChild(a); } //create the quad tree quadTree = new QuadTree(new Vector2(MapManager.Instance.currentMap.width / 2.0f, MapManager.Instance.currentMap.height / 2.0f), new Vector2(MapManager.Instance.currentMap.width / 2.0f, MapManager.Instance.currentMap.height / 2.0f)); //create enemies var tex = new Texture2D("/Application/data/tiles/enemy_sword2.png", false); tex.SetFilter(TextureFilterMode.Disabled); tex.SetWrap(TextureWrapMode.ClampToEdge); var texture = new TextureInfo(tex, new Vector2i(25, 1)); //spritelist for the enemies enemySpriteList = new SpriteList(texture) { BlendMode = BlendMode.Normal }; //spriteList.EnableLocalTransform = true; enemyList = new List <Enemy>(); list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor); //generate a given number of enemies for (int i = 0; i < BasicEnemy.noOfEnemiesToGenerate; i++) { Enemy e = new BasicEnemy(list[Support.random.Next(0, list.Count - 1)].position, texture); enemyList.Add(e); enemySpriteList.AddChild(((BasicEnemy)e).sprite); EffectsLayer.AddChild(e); quadTree.insert(e); } Foreground.AddChild(enemySpriteList); ui = new UI(); Interface.AddChild(ui); //add an enemy spawner every second Sce.PlayStation.HighLevel.GameEngine2D.Scheduler.Instance.Schedule(this, (dt) => { list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor); EnemySpawnPoint esp = new EnemySpawnPoint(list[Support.random.Next(0, list.Count - 1)].position); World.AddChild(esp); ; }, 1.0f, false, -1); }
public void AddComponents(int layerIndex, GameObject spriteObject, Sprite sprite, TextureImporterSettings settings) { var layerText = layer.LayerText; Color textColor = layerText.FillColor; if (PsdSetting.Instance.curGUIType == GUIType.UGUI) { Text text = spriteObject.AddComponent <Text>(); text.horizontalOverflow = HorizontalWrapMode.Overflow; text.verticalOverflow = VerticalWrapMode.Overflow; if (PsdSetting.Instance.DefaultFontPath.EndsWith(".ttf")) { text.font = AssetDatabase.LoadAssetAtPath <Font>(PsdSetting.Instance.DefaultFontPath); } text.fontStyle = GetFontStyle(layerText); text.fontSize = (int)layerText.FontSize; text.rectTransform.SetAsFirstSibling(); text.rectTransform.sizeDelta = new Vector2(layer.Rect.width, layer.Rect.height); text.text = layerText.Text.Replace("\r\n", "\n").Replace("\r", "\n"); text.color = textColor; } else if (PsdSetting.Instance.curGUIType == GUIType.NGUI) { #if NGUI UILabel text = spriteObject.AddComponent <UILabel>(); //竖屏 text.overflowMethod = layer.Rect.width < layer.Rect.height ? UILabel.Overflow.ResizeHeight : UILabel.Overflow.ResizeFreely; if (PsdSetting.Instance.DefaultFontPath.EndsWith(".ttf")) { text.trueTypeFont = AssetDatabase.LoadAssetAtPath <Font>(PsdSetting.Instance.DefaultFontPath); } else { text.trueTypeFont = Resources.GetBuiltinResource <Font>("Arial.ttf"); } NGUISettings.ambigiousFont = text.trueTypeFont; text.depth = layerIndex; text.fontStyle = layerText.Style; if (text.fontStyle == FontStyle.Bold) { text.spacingX = (int)layerText.FontSize / 4; } text.fontSize = layerText.FontBaseline != 0 ? (int)layerText.FontSize / 2 : (int)layerText.FontSize; text.transform.SetAsFirstSibling(); if (layer.BaseEffect != null) { GradientEffect gradient = layer.BaseEffect.Gradient; if (gradient != null) { text.applyGradient = true; textColor = Color.white; text.gradientTop = gradient.TopColor; text.gradientBottom = gradient.BottomColor; } } if (layer.Effects != null) { EffectsLayer effectLayer = layer.Effects; if (effectLayer.IsDropShadow) { text.effectStyle = UILabel.Effect.Shadow; text.effectDistance = new Vector2(2, 2); text.effectColor = effectLayer.DropShadow.Color; } if (effectLayer.IsOuterGlow) { text.effectStyle = UILabel.Effect.Outline; text.effectColor = effectLayer.OuterGlow.Color; } } if (layerText.Underline) { text.text = string.Format("[u]{0}[/u]", layerText.Text); } else if (layerText.Strikethrough) { text.text = string.Format("[s]{0}[/s]", layerText.Text); } else if (layerText.FontBaseline == 1) { text.text = string.Format("[sub]{0}[/sub]", layerText.Text); } else if (layerText.FontBaseline == 2) { text.text = string.Format("[sup]{0}[/sup]", layerText.Text); } else { text.text = layerText.Text; } text.color = textColor; int width = text.overflowMethod == UILabel.Overflow.ResizeHeight ? (int)Math.Max(text.fontSize, layer.Rect.width) : (int)layer.Rect.width; int height = text.overflowMethod == UILabel.Overflow.ResizeHeight ? (int)layer.Rect.height : (int)Math.Max(text.fontSize, layer.Rect.height); text.SetDimensions(width, (int)height); if (text.overflowMethod == UILabel.Overflow.ClampContent) { NGUIEditorTools.RegisterUndo("Snap Dimensions", text); NGUIEditorTools.RegisterUndo("Snap Dimensions", text.transform); text.MakePixelPerfect(); } #endif } }