private void updateUiAmmoAmmount(AmmoInfo ammoInfo) { if (ammoText != null) { ammoText.text = (ammoInfo.unlimited) ? "--" : ammoInfo.currentCount.ToString() + "/" + ammoInfo.max.ToString(); } }
public void SetAmmo(AmmoInfo info) { main.text = info.MainText(); secondary.text = info.SecondaryText(); secondary.rectTransform.anchoredPosition = new Vector2(main.rectTransform.anchoredPosition.x + main.preferredWidth + marginBetweenMainAndSecondary, secondary.rectTransform.anchoredPosition.y); }
public void updateUIInfo(AmmoInfo ammoInfo) { updateUiAmmoAmmount(ammoInfo); if (ammoImage != null) { ammoImage.sprite = ammoInfo.UiSprite; } }
//bool m_InstantAttack; //public bool IsInstantAttack { set { m_InstantAttack = value; } get { return Info.InstantProjectile && m_InstantAttack; } } public GlobalWeapon(WeaponInfo info) { if (info == null) { #if UNITY_EDITOR Debug.LogError(GetType() + " error: INIT IS BAD"); #endif info = new WeaponInfo(); } Info = info; ammo = new AmmoInfo(Info); }
private void GunChange(Gun gun) { AmmoInfo currentAmmo = gun.currentClip.GetAmmoInfo(); WidgetManager.RemoveWidget(currentGunWidget); currentGunWidget = gunIcons[currentAmmo.type]; WidgetManager.AddWidget(currentGunWidget); string ammoString = currentAmmo.loaded.ToString() + "/" + (currentAmmo.reservesLeft >= 0 ? currentAmmo.reservesLeft.ToString() : infSymbol); ammoDisplayWidget.DisplayString = ammoString; reloadBarWidget.SetProgress(gun.GetReloadLeft()); }
public void SetAmmo(AmmoInfo ammoInfo, int newAmmo) { newAmmo = Mathf.Clamp(newAmmo, 0, ammoInfo.maxAmmo); if (ammoDict.ContainsKey(ammoInfo)) { if (newAmmo == 0) { ammoDict.Remove(ammoInfo); } else { ammoDict[ammoInfo] = newAmmo; } } else { if (newAmmo > 0) { ammoDict.Add(ammoInfo, newAmmo); } } }
//Revision: 3636 //Author: zproxy //Date: 22. aprill 2012. a. 11:16:53 //Message: //---- //Added : /examples/java/OutRun4KTemplate //Added : /examples/java/OutRun4KTemplate/OutRun4KTemplate // http://www.digitalinsane.com/archives/2007/01/21/space_invaders/ public SpaceInvaders() { ImageResources gfx = "http://server/"; var overlay = new Overlay(); overlay.BackgroundColor = Color.Black; overlay.MaximumOpacity = 1; overlay.ControlInBack.style.zIndex = 100000; overlay.ControlInFront.style.zIndex = 100001; var view = overlay.ControlInFront; view.style.textAlign = IStyle.TextAlignEnum.center; view.style.SetSize(480, 480); view.style.backgroundColor = Color.Green; view.style.color = Color.White; view.style.fontFamily = IStyle.FontFamilyEnum.Fixedsys; //Native.Document.body.appendChild( // new IHTMLElement(IHTMLElement.HTMLElementEnum.center, // view) // ); //Native.Document.body.style.backgroundColor = Color.Black; // Native.Document.body.style.overflow = IStyle.OverflowEnum.hidden; System.Func<IHTMLDiv> CreateCanvas = delegate { var c = new IHTMLDiv(); c.style.overflow = IStyle.OverflowEnum.hidden; c.style.SetLocation(1, 1, 478, 478); return c; }; view.style.position = IStyle.PositionEnum.relative; var canvas = CreateCanvas(); var menu = CreateCanvas(); canvas.style.backgroundColor = Color.Black; view.appendChild(canvas, menu); var msg_loading = new IHTMLDiv("loading..."); msg_loading.style.color = Color.Green; menu.appendChild(msg_loading); // at this point we want our images overlay.Visible = true; ScriptCoreLib.JavaScript.Runtime.Timer.DoAsync(overlay.UpdateLocation); // now wait while all images are loaded/complete ((fbool)(() => !gfx.IsComplete)).Trigger( delegate { // loading images is done now. // build the scoreboard var MyEnemyDirectory = new EnemyDirectory(gfx); var board = new ScoreBoard(gfx); board.Control.style.SetLocation(8, 8, 464, 64); canvas.appendChild(board.Control); board.Lives = 2; board.Score = 450; // now we can see lives and score. // ie does not issue keypress for control keys. // scriptcorelib should filter firefox events... // lets show main menu var mmenu = new MainMenu(MyEnemyDirectory, gfx); var gameovermenu = new GameOverMenu(); menu.appendChild(mmenu.Control, gameovermenu.Control); gameovermenu.Visible = false; gameovermenu.Control.style.SetLocation(0, 100, 468, 468 - 100); mmenu.Control.style.SetLocation(0, 64, 468, 468 - 64); mmenu.Visible = true; var Enemy_Ammo = new AmmoInfo { Color = Color.White, Speed = 8 }; var Player = (IHTMLImage)gfx.biggun.Clone(); var Player_Ammo = new AmmoInfo { Color = Color.Green, Speed = -8 }; var Map_Top = 64; var Map_Left = 20; var Map_Right = 450; var Map_Bottom = 470; var Map_Rect = new Rectangle(); Map_Rect.Top = Map_Top; Map_Rect.Left = Map_Left; Map_Rect.Right = Map_Right; Map_Rect.Bottom = Map_Bottom; var Player_Y = 460; var Player_X = 200; var Player_X_step = 8; Action<int> UpdatePlayer = delegate(int v) { Player_X += v; if (Player_X < Map_Left) Player_X = Map_Left; if (Player_X > Map_Right) Player_X = Map_Right; Player.SetCenteredLocation(Player_X, Player_Y); Player.style.position = IStyle.PositionEnum.absolute; }; Player.Hide(); canvas.appendChild(Player, Player_Ammo.Control, Enemy_Ammo.Control); AmmoInfo[] KnownAmmo = new[] { Player_Ammo, Enemy_Ammo }; var KnownConcrete = new List<Concrete>(); var ConcreteTop = 432; KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 0, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 1, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 2, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 3, ConcreteTop))); foreach (Concrete v in KnownConcrete.ToArray()) { canvas.appendChild(v.Control); } var UFO = new EnemyUnit(MyEnemyDirectory.UFO); var UFO_Direction = 1; UFO.Visible = false; canvas.appendChild(UFO.Control); var EnemyTop = 128; var EnemySpacing = 32; var EnemyCount = 9; var KnownEnemies = new List<EnemyUnit>(); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.A, 20, EnemyTop + 0 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.B, 20, EnemyTop + 1 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.B, 20, EnemyTop + 2 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.C, 20, EnemyTop + 3 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.C, 20, EnemyTop + 4 * EnemySpacing, EnemyCount, EnemySpacing)); foreach (EnemyUnit v in KnownEnemies.ToArray()) { canvas.appendChild(v.Control); } var HitDamage = 40; var GameTimer = new ScriptCoreLib.JavaScript.Runtime.Timer(); int GangDirection = 1; Action<string> EndGame = delegate { gameovermenu.Visible = true; GameTimer.Stop(); }; #region DoAmmoDamage Func<AmmoInfo, bool> DoAmmoDamage = delegate(AmmoInfo a) { bool hit = false; #region did we hit ufo? if (UFO.Visible) { if (UFO.Bounds.Contains(a.Location)) { board.Score += UFO.Info.Points; UFO.Visible = false; hit = true; } } #endregion #region did we hit player if (Player.Bounds.Contains(a.Location)) { board.Lives--; hit = true; if (board.Lives < 1) { EndGame("Ship destroied"); } } #endregion foreach (Concrete v in KnownConcrete.ToArray()) { if (v.Visible) { if (v.Bounds.Contains(a.Location)) { v.Health -= HitDamage; if (v.Health > 0) { hit = true; } else { v.Visible = false; } } } } foreach (EnemyUnit v in KnownEnemies.ToArray()) { if (v.Visible) { if (v.Bounds.Contains(a.Location)) { v.Visible = false; hit = true; new SpaceInvadersTemplate.HTML.Audio.FromAssets.invaderexplode().play(); board.Score += v.Info.Points; } } } return hit; }; #endregion var MyRandom = new System.Random(); var mothershiploop = new SpaceInvadersTemplate.HTML.Audio.FromAssets.mothershiploopx { loop = true }; var duh = new IHTMLAudio[] { new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh0(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh1(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh2(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh3(), }; var duh_cycle = duh.ToCyclicAction(a => a.play()); #region EnemyAction Action EnemyAction = delegate { #region create ufo if (!UFO.Visible) { if (MyRandom.NextDouble() < 0.1) { Console.WriteLine("UFO!"); mothershiploop.play(); if (MyRandom.NextDouble() > 0.5) { UFO_Direction = 1; UFO.MoveTo(0, EnemyTop - UFO.Control.height * 2); } else { UFO_Direction = -1; UFO.MoveTo(478, EnemyTop - UFO.Control.height * 2); } UFO.Visible = true; } } #endregion var ev = Enumerable.Where(KnownEnemies.ToArray(), i => i.Visible); if (!Enemy_Ammo.Visible) { var ei = (int)System.Math.Round(MyRandom.NextDouble() * Enumerable.Count(ev)); EnemyUnit et = Enumerable.ElementAt(ev, ei); if (et == null) System.Console.WriteLine("element at " + ei + " not found"); else { int ey = Enumerable.Max( from i in ev where i.X == et.X select i.Y // Enumerable.Select(Enumerable.Where(ev, i => i.X == et.X), i => i.Y) ); Enemy_Ammo.MoveTo(et.X, ey + 20); Enemy_Ammo.Visible = true; } } #region MoveAll Action<Point> MoveAll = delegate(Point to) { var ConcreteReached = false; foreach (EnemyUnit v in ev) { var vy = v.Y + to.Y; if (vy > ConcreteTop) { ConcreteReached = true; } v.MoveTo(v.X + to.X, vy); } if (ConcreteReached) { EndGame("The walls have been breached."); } }; #endregion Action MoveAllDown = delegate { MoveAll(new Point(0, 8)); }; duh_cycle(); #region move the gang if (GangDirection > 0) { int ex_max = Enumerable.Max(Enumerable.Select(ev, i => i.X)); // gang goes right if (ex_max >= Map_Rect.Right) { GangDirection = -1; MoveAllDown(); } else { MoveAll(new Point(4, 0)); } } else { int ex_min = Enumerable.Min(Enumerable.Select(ev, i => i.X)); // gang goes left if (ex_min <= Map_Rect.Left) { GangDirection = 1; MoveAllDown(); } else { MoveAll(new Point(-4, 0)); } } #endregion }; #endregion bool GamePaused = false; GameTimer.Tick += delegate { #region only blink while paused if (GamePaused) { if (GameTimer.Counter % 15 == 0) { Player.ToggleVisible(); } return; } #endregion Player.Show(); #region move ufo if (UFO.Visible) { if (UFO_Direction > 0) { UFO.MoveTo(UFO.X + 4, UFO.Y); if (UFO.X > 478 + UFO.Control.width) { UFO.Visible = false; mothershiploop.pause(); } } else { UFO.MoveTo(UFO.X - 4, UFO.Y); if (UFO.X < -UFO.Control.width) { UFO.Visible = false; mothershiploop.pause(); } } } #endregion #region do ammo stuff foreach (AmmoInfo v in KnownAmmo) { if (v.Visible) { var y = v.Y + v.Speed; if (Map_Rect.Contains(new Point(v.X, y))) { // did we hit? if (DoAmmoDamage(v)) { v.Visible = false; } else { v.MoveTo(v.X, y); } } else { v.Visible = false; } } } #endregion var AliveEnemies = Enumerable.Where(KnownEnemies.ToArray(), i => i.Visible); var AliveCount = Enumerable.Count(AliveEnemies); if (AliveCount == 0) { EndGame("Aliens destoried"); return; } if (GameTimer.Counter % (AliveCount / 2) == 0) { EnemyAction(); } }; #region ResetGame Action ResetGame = delegate { mmenu.Visible = false; Player_X = 220; board.Score = 0; board.Lives = 3; Player.Show(); foreach (Concrete v in KnownConcrete.ToArray()) { v.Health = 255; v.Visible = true; } foreach (EnemyUnit v in KnownEnemies.ToArray()) { v.ResetPosition(); v.Visible = true; } EnemyAction(); GameTimer.StartInterval(50); UpdatePlayer(0); }; #endregion Action EgoShoot = delegate { if (!Player_Ammo.Visible) { Player_Ammo.MoveTo(Player_X, Player_Y - 20); new SpaceInvadersTemplate.HTML.Audio.FromAssets.firemissile().play(); Player_Ammo.Visible = true; } }; overlay.ControlInBack.onclick += delegate { if (mmenu.Visible) ResetGame(); else EgoShoot(); }; double gamma = 0; //Native.window.ondeviceorientation += // eventData => // { // if (eventData.gamma < -50) // gamma = eventData.beta; // else // gamma = eventData.gamma; // }; new ScriptCoreLib.JavaScript.Runtime.Timer( t => { // gamma is the left-to-right tilt in degrees, where right is positive if (gamma < -15) { if (mmenu.Visible) ResetGame(); else UpdatePlayer(-Player_X_step); } if (gamma > 15) { if (mmenu.Visible) ResetGame(); else UpdatePlayer(Player_X_step); } } ).StartInterval(100); Native.Document.onkeydown += delegate(IEvent ev) { Console.WriteLine(new { ev.KeyCode }.ToString()); if (mmenu.Visible) { if (ev.IsReturn) { ResetGame(); } return; } else { if (ev.IsEscape) { GameTimer.Stop(); Player.Hide(); mmenu.Visible = true; foreach (AmmoInfo v in KnownAmmo) { v.Visible = false; } foreach (Concrete v in KnownConcrete.ToArray()) { v.Visible = false; } foreach (EnemyUnit v in KnownEnemies.ToArray()) { v.Visible = false; } UFO.Visible = false; gameovermenu.Visible = false; // the animated gifs would stop after escape key ev.preventDefault(); GamePaused = false; } } int key_p = 80; if (ev.KeyCode == key_p) { GamePaused = !GamePaused; } // player shouldn't really move while game is paused // its cheating:) if (GamePaused) return; int key_right = 39; int key_left = 37; if (ev.KeyCode == key_left) { UpdatePlayer(-Player_X_step); } else if (ev.KeyCode == key_right) { UpdatePlayer(Player_X_step); } else if (ev.IsSpaceOrEnterKey()) { // the animated gifs would stop after escape key ev.preventDefault(); EgoShoot(); } else { Console.WriteLine(new { UnknownKeyCode = ev.KeyCode }.ToString()); } }; msg_loading.Orphanize(); } , 50); }
public CannonGump(BaseCannon cannon, Mobile from) : base(50, 50) { m_Cannon = cannon; m_From = from; AddBackground(0, 0, 300, 200, 2620); Type charge = cannon is LightShipCannon ? typeof(LightPowderCharge) : typeof(HeavyPowderCharge); bool cleaned = cannon.Cleaned; bool charged = cannon.Charged; bool primed = cannon.Primed; bool loaded = cannon.AmmoType != AmmunitionType.Empty; AddHtmlLocalized(0, 10, 300, 16, 1149614 + (int)m_Cannon.Position, 21758, false, false); AddHtmlLocalized(45, 40, 100, 16, 1149626, LabelColor, false, false); //CLEAN if (!charged) { AddHtmlLocalized(45, 60, 100, 16, 1149630, LabelColor, false, false); //CHARGE } else { AddHtmlLocalized(45, 60, 100, 16, 1149629, LabelColor, false, false); //REMOVE } if (!loaded) { AddHtmlLocalized(45, 80, 100, 16, 1149635, LabelColor, false, false); //LOAD } else { AddHtmlLocalized(45, 80, 100, 16, 1149629, LabelColor, false, false); //REMOVE } if (!primed) { AddHtmlLocalized(45, 100, 100, 16, 1149637, LabelColor, false, false); //PRIME } else if (cannon.CanLight) { AddHtmlLocalized(45, 100, 100, 16, 1149638, LabelColor, false, false); //FIRE } else { AddHtmlLocalized(45, 100, 100, 16, 1149629, LabelColor, false, false); //REMOVE } if (!cleaned) { AddHtmlLocalized(150, 40, 100, 16, 1149628, RedHue, false, false); //Dirty } else { AddHtmlLocalized(150, 40, 100, 16, 1149627, GreenHue, false, false); //Clean } if (!charged) { AddHtmlLocalized(150, 60, 100, 16, 1149632, RedHue, false, false); //Not Charged } else { AddHtmlLocalized(150, 60, 100, 16, 1149631, GreenHue, false, false); //Charged } if (!loaded) { AddHtmlLocalized(150, 80, 100, 16, 1149636, RedHue, false, false); //Not Loaded } else { AddHtmlLocalized(150, 80, 100, 16, 1114057, AmmoInfo.GetAmmoName(cannon), GreenHue, false, false); } //AddHtmlLocalized(150, 80, 100, 16, cannon.AmmoType == AmmoType.Grapeshot ? 1095741 : 1116029, GreenHue, false, false); if (!primed) { AddHtmlLocalized(150, 100, 100, 16, 1149639, RedHue, false, false); //No Fuse } else { AddHtmlLocalized(150, 100, 100, 16, 1149640, GreenHue, false, false); //Primed } AddButton(10, 40, 0xFA5, 0xFA7, 1, GumpButtonType.Reply, 0); AddButton(10, 60, 0xFA5, 0xFA7, 2, GumpButtonType.Reply, 0); AddButton(10, 80, 0xFA5, 0xFA7, 3, GumpButtonType.Reply, 0); AddButton(10, 100, 0xFA5, 0xFA7, 4, GumpButtonType.Reply, 0); if (!cannon.Actions.ContainsKey(from) || cannon.Actions[from].Count == 0) { cannon.AddAction(from, 1149653); //You are now operating the cannon. } int y = 170; int count = cannon.Actions[from].Count - 1; int hue = 0; for (int i = count; i >= 0; i--) { if (i < count - 3) { break; } if (i == count) { hue = 29315; //0xFFFF00; } else { hue = 12684; } AddHtmlLocalized(10, y, 385, 20, cannon.Actions[from][i], hue, false, false); y -= 16; } }
public abstract void SetAmmoInfo(AmmoInfo info);
//Revision: 3636 //Author: zproxy //Date: 22. aprill 2012. a. 11:16:53 //Message: //---- //Added : /examples/java/OutRun4KTemplate //Added : /examples/java/OutRun4KTemplate/OutRun4KTemplate // http://www.digitalinsane.com/archives/2007/01/21/space_invaders/ public SpaceInvaders() { ImageResources gfx = "http://server/"; var overlay = new Overlay(); overlay.BackgroundColor = Color.Black; overlay.MaximumOpacity = 1; overlay.ControlInBack.style.zIndex = 100000; overlay.ControlInFront.style.zIndex = 100001; var view = overlay.ControlInFront; view.style.textAlign = IStyle.TextAlignEnum.center; view.style.SetSize(480, 480); view.style.backgroundColor = Color.Green; view.style.color = Color.White; view.style.fontFamily = IStyle.FontFamilyEnum.Fixedsys; //Native.Document.body.appendChild( // new IHTMLElement(IHTMLElement.HTMLElementEnum.center, // view) // ); //Native.Document.body.style.backgroundColor = Color.Black; // Native.Document.body.style.overflow = IStyle.OverflowEnum.hidden; System.Func <IHTMLDiv> CreateCanvas = delegate { var c = new IHTMLDiv(); c.style.overflow = IStyle.OverflowEnum.hidden; c.style.SetLocation(1, 1, 478, 478); return(c); }; view.style.position = IStyle.PositionEnum.relative; var canvas = CreateCanvas(); var menu = CreateCanvas(); canvas.style.backgroundColor = Color.Black; view.appendChild(canvas, menu); var msg_loading = new IHTMLDiv("loading..."); msg_loading.style.color = Color.Green; menu.appendChild(msg_loading); // at this point we want our images overlay.Visible = true; ScriptCoreLib.JavaScript.Runtime.Timer.DoAsync(overlay.UpdateLocation); // now wait while all images are loaded/complete ((fbool)(() => !gfx.IsComplete)).Trigger( delegate { // loading images is done now. // build the scoreboard var MyEnemyDirectory = new EnemyDirectory(gfx); var board = new ScoreBoard(gfx); board.Control.style.SetLocation(8, 8, 464, 64); canvas.appendChild(board.Control); board.Lives = 2; board.Score = 450; // now we can see lives and score. // ie does not issue keypress for control keys. // scriptcorelib should filter firefox events... // lets show main menu var mmenu = new MainMenu(MyEnemyDirectory, gfx); var gameovermenu = new GameOverMenu(); menu.appendChild(mmenu.Control, gameovermenu.Control); gameovermenu.Visible = false; gameovermenu.Control.style.SetLocation(0, 100, 468, 468 - 100); mmenu.Control.style.SetLocation(0, 64, 468, 468 - 64); mmenu.Visible = true; var Enemy_Ammo = new AmmoInfo { Color = Color.White, Speed = 8 }; var Player = (IHTMLImage)gfx.biggun.Clone(); var Player_Ammo = new AmmoInfo { Color = Color.Green, Speed = -8 }; var Map_Top = 64; var Map_Left = 20; var Map_Right = 450; var Map_Bottom = 470; var Map_Rect = new Rectangle(); Map_Rect.Top = Map_Top; Map_Rect.Left = Map_Left; Map_Rect.Right = Map_Right; Map_Rect.Bottom = Map_Bottom; var Player_Y = 460; var Player_X = 200; var Player_X_step = 8; Action <int> UpdatePlayer = delegate(int v) { Player_X += v; if (Player_X < Map_Left) { Player_X = Map_Left; } if (Player_X > Map_Right) { Player_X = Map_Right; } Player.SetCenteredLocation(Player_X, Player_Y); Player.style.position = IStyle.PositionEnum.absolute; }; Player.Hide(); canvas.appendChild(Player, Player_Ammo.Control, Enemy_Ammo.Control); AmmoInfo[] KnownAmmo = new[] { Player_Ammo, Enemy_Ammo }; var KnownConcrete = new List <Concrete>(); var ConcreteTop = 432; KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 0, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 1, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 2, ConcreteTop))); KnownConcrete.AddRange(Concrete.BuildAt(new Point(62 + 120 * 3, ConcreteTop))); foreach (Concrete v in KnownConcrete.ToArray()) { canvas.appendChild(v.Control); } var UFO = new EnemyUnit(MyEnemyDirectory.UFO); var UFO_Direction = 1; UFO.Visible = false; canvas.appendChild(UFO.Control); var EnemyTop = 128; var EnemySpacing = 32; var EnemyCount = 9; var KnownEnemies = new List <EnemyUnit>(); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.A, 20, EnemyTop + 0 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.B, 20, EnemyTop + 1 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.B, 20, EnemyTop + 2 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.C, 20, EnemyTop + 3 * EnemySpacing, EnemyCount, EnemySpacing)); KnownEnemies.AddRange(EnemyUnit.Build(MyEnemyDirectory.C, 20, EnemyTop + 4 * EnemySpacing, EnemyCount, EnemySpacing)); foreach (EnemyUnit v in KnownEnemies.ToArray()) { canvas.appendChild(v.Control); } var HitDamage = 40; var GameTimer = new ScriptCoreLib.JavaScript.Runtime.Timer(); int GangDirection = 1; Action <string> EndGame = delegate { gameovermenu.Visible = true; GameTimer.Stop(); }; #region DoAmmoDamage Func <AmmoInfo, bool> DoAmmoDamage = delegate(AmmoInfo a) { bool hit = false; #region did we hit ufo? if (UFO.Visible) { if (UFO.Bounds.Contains(a.Location)) { board.Score += UFO.Info.Points; UFO.Visible = false; hit = true; } } #endregion #region did we hit player if (Player.Bounds.Contains(a.Location)) { board.Lives--; hit = true; if (board.Lives < 1) { EndGame("Ship destroied"); } } #endregion foreach (Concrete v in KnownConcrete.ToArray()) { if (v.Visible) { if (v.Bounds.Contains(a.Location)) { v.Health -= HitDamage; if (v.Health > 0) { hit = true; } else { v.Visible = false; } } } } foreach (EnemyUnit v in KnownEnemies.ToArray()) { if (v.Visible) { if (v.Bounds.Contains(a.Location)) { v.Visible = false; hit = true; new SpaceInvadersTemplate.HTML.Audio.FromAssets.invaderexplode().play(); board.Score += v.Info.Points; } } } return(hit); }; #endregion var MyRandom = new System.Random(); var mothershiploop = new SpaceInvadersTemplate.HTML.Audio.FromAssets.mothershiploopx { loop = true }; var duh = new IHTMLAudio[] { new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh0(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh1(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh2(), new SpaceInvadersTemplate.HTML.Audio.FromAssets.duh3(), }; var duh_cycle = duh.ToCyclicAction(a => a.play()); #region EnemyAction Action EnemyAction = delegate { #region create ufo if (!UFO.Visible) { if (MyRandom.NextDouble() < 0.1) { Console.WriteLine("UFO!"); mothershiploop.play(); if (MyRandom.NextDouble() > 0.5) { UFO_Direction = 1; UFO.MoveTo(0, EnemyTop - UFO.Control.height * 2); } else { UFO_Direction = -1; UFO.MoveTo(478, EnemyTop - UFO.Control.height * 2); } UFO.Visible = true; } } #endregion var ev = Enumerable.Where(KnownEnemies.ToArray(), i => i.Visible); if (!Enemy_Ammo.Visible) { var ei = (int)System.Math.Round(MyRandom.NextDouble() * Enumerable.Count(ev)); EnemyUnit et = Enumerable.ElementAt(ev, ei); if (et == null) { System.Console.WriteLine("element at " + ei + " not found"); } else { int ey = Enumerable.Max( from i in ev where i.X == et.X select i.Y // Enumerable.Select(Enumerable.Where(ev, i => i.X == et.X), i => i.Y) ); Enemy_Ammo.MoveTo(et.X, ey + 20); Enemy_Ammo.Visible = true; } } #region MoveAll Action <Point> MoveAll = delegate(Point to) { var ConcreteReached = false; foreach (EnemyUnit v in ev) { var vy = v.Y + to.Y; if (vy > ConcreteTop) { ConcreteReached = true; } v.MoveTo(v.X + to.X, vy); } if (ConcreteReached) { EndGame("The walls have been breached."); } }; #endregion Action MoveAllDown = delegate { MoveAll(new Point(0, 8)); }; duh_cycle(); #region move the gang if (GangDirection > 0) { int ex_max = Enumerable.Max(Enumerable.Select(ev, i => i.X)); // gang goes right if (ex_max >= Map_Rect.Right) { GangDirection = -1; MoveAllDown(); } else { MoveAll(new Point(4, 0)); } } else { int ex_min = Enumerable.Min(Enumerable.Select(ev, i => i.X)); // gang goes left if (ex_min <= Map_Rect.Left) { GangDirection = 1; MoveAllDown(); } else { MoveAll(new Point(-4, 0)); } } #endregion }; #endregion bool GamePaused = false; GameTimer.Tick += delegate { #region only blink while paused if (GamePaused) { if (GameTimer.Counter % 15 == 0) { Player.ToggleVisible(); } return; } #endregion Player.Show(); #region move ufo if (UFO.Visible) { if (UFO_Direction > 0) { UFO.MoveTo(UFO.X + 4, UFO.Y); if (UFO.X > 478 + UFO.Control.width) { UFO.Visible = false; mothershiploop.pause(); } } else { UFO.MoveTo(UFO.X - 4, UFO.Y); if (UFO.X < -UFO.Control.width) { UFO.Visible = false; mothershiploop.pause(); } } } #endregion #region do ammo stuff foreach (AmmoInfo v in KnownAmmo) { if (v.Visible) { var y = v.Y + v.Speed; if (Map_Rect.Contains(new Point(v.X, y))) { // did we hit? if (DoAmmoDamage(v)) { v.Visible = false; } else { v.MoveTo(v.X, y); } } else { v.Visible = false; } } } #endregion var AliveEnemies = Enumerable.Where(KnownEnemies.ToArray(), i => i.Visible); var AliveCount = Enumerable.Count(AliveEnemies); if (AliveCount == 0) { EndGame("Aliens destoried"); return; } if (GameTimer.Counter % (AliveCount / 2) == 0) { EnemyAction(); } }; #region ResetGame Action ResetGame = delegate { mmenu.Visible = false; Player_X = 220; board.Score = 0; board.Lives = 3; Player.Show(); foreach (Concrete v in KnownConcrete.ToArray()) { v.Health = 255; v.Visible = true; } foreach (EnemyUnit v in KnownEnemies.ToArray()) { v.ResetPosition(); v.Visible = true; } EnemyAction(); GameTimer.StartInterval(50); UpdatePlayer(0); }; #endregion Action EgoShoot = delegate { if (!Player_Ammo.Visible) { Player_Ammo.MoveTo(Player_X, Player_Y - 20); new SpaceInvadersTemplate.HTML.Audio.FromAssets.firemissile().play(); Player_Ammo.Visible = true; } }; overlay.ControlInBack.onclick += delegate { if (mmenu.Visible) { ResetGame(); } else { EgoShoot(); } }; double gamma = 0; //Native.window.ondeviceorientation += // eventData => // { // if (eventData.gamma < -50) // gamma = eventData.beta; // else // gamma = eventData.gamma; // }; new ScriptCoreLib.JavaScript.Runtime.Timer( t => { // gamma is the left-to-right tilt in degrees, where right is positive if (gamma < -15) { if (mmenu.Visible) { ResetGame(); } else { UpdatePlayer(-Player_X_step); } } if (gamma > 15) { if (mmenu.Visible) { ResetGame(); } else { UpdatePlayer(Player_X_step); } } } ).StartInterval(100); Native.Document.onkeydown += delegate(IEvent ev) { Console.WriteLine(new { ev.KeyCode }.ToString()); if (mmenu.Visible) { if (ev.IsReturn) { ResetGame(); } return; } else { if (ev.IsEscape) { GameTimer.Stop(); Player.Hide(); mmenu.Visible = true; foreach (AmmoInfo v in KnownAmmo) { v.Visible = false; } foreach (Concrete v in KnownConcrete.ToArray()) { v.Visible = false; } foreach (EnemyUnit v in KnownEnemies.ToArray()) { v.Visible = false; } UFO.Visible = false; gameovermenu.Visible = false; // the animated gifs would stop after escape key ev.preventDefault(); GamePaused = false; } } int key_p = 80; if (ev.KeyCode == key_p) { GamePaused = !GamePaused; } // player shouldn't really move while game is paused // its cheating:) if (GamePaused) { return; } int key_right = 39; int key_left = 37; if (ev.KeyCode == key_left) { UpdatePlayer(-Player_X_step); } else if (ev.KeyCode == key_right) { UpdatePlayer(Player_X_step); } else if (ev.IsSpaceOrEnterKey()) { // the animated gifs would stop after escape key ev.preventDefault(); EgoShoot(); } else { Console.WriteLine(new { UnknownKeyCode = ev.KeyCode }.ToString()); } }; msg_loading.Orphanize(); } , 50); }
public int GetAmmo(AmmoInfo ammoInfo) { int ammo = 0; ammoDict.TryGetValue(ammoInfo, out ammo); return ammo; }
public void AddAmmo(AmmoInfo ammoInfo, int count) { SetAmmo(ammoInfo, GetAmmo(ammoInfo)+count); }
public void SetAmmo(AmmoInfo info) { }
public void SetAmmoCount(AmmoInfo ammoInfo) { text.SetText("" + ammoInfo.loaded + "/" + ammoInfo.reservesLeft + "\n" + ammoInfo.type.Name); }
public override void SetAmmoInfo(AmmoInfo info) { player.GetAmmoDisplayService().SetAmmo(info); }
public void OnChangeAmmo(AmmoInfo ammo) { m_UnitUI.SetCountAmmo(ammo.CurCountAmmoInCage); }
void OnChangeAmmo(AmmoInfo ammo) { m_UI.OnChangeAmmo(ammo); }
void Start() { myPlayerAmmoinfo = GameManager.Instance.myPlayer.GetComponent <AmmoInfo>(); }