public SettingMenuState(GameWindow owner, GameFiniteStateMachine parent) : base(owner, parent) { var uiElementBehavior = new Behaviour <UiElementBase>(o => { var floatPos = BehaviorHelpers.EaseMouse(o.MousePosition); o.PositionAdd = floatPos / ((float)o.AttachedProperties["floatiness"]); }); var exitButton = new TextElement(owner, "return", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, -0.15f), Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 50f } }, MouseOverColor = Color4.White, }; exitButton.Clicked += args => TransitionOut("return"); GameElements.Add(new TextElement(owner, "Settings", ".\\fonts\\toxica.ttf", 72f) { NormalColor = Color4.DarkRed, Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 25f } }, Position = new Vector2(0f, -0.75f) }); GameElements.Add(new TextElement(owner, "alpha 0.1", ".\\fonts\\pixelmix.ttf", 12f) { Position = new Vector2(0.8f, 0.9f), Alignment = QFontAlignment.Left }); GameElements.Add(exitButton); }
public override GameElement Create(string element) { ElementType type; if (!Enum.TryParse(element.ToUpper().Replace(' ', '_'), out type)) { return(null); } GameElement gameElement = null; switch (type) { case ElementType.BUTTON: gameElement = Instantiate(m_ButtonTemplate).GetComponent <GameButton>(); break; case ElementType.TEXT_FIELD: gameElement = Instantiate(m_FieldTemplate).GetComponent <GameTextField>(); break; case ElementType.IMAGE: gameElement = Instantiate(m_ImageTemplate).GetComponent <GameImage>(); break; } gameElement.Type = type; GameElements.Add(gameElement); return(gameElement); }
public override void Load() { World = World.Load("world.dat"); _countries = World.Countries.Where(o => o.Cities.Count >= 2).ToList(); _cities = _countries.SelectMany(o => o.Cities).ToArray(); _points = _cities.Select(GenBufferElement).ToArray(); Scaling(out _scale, out _add, out _bounds); TransformPoints(_scale, _add); _highways = GenHighways(_scale, _add); Action prep = () => { GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.VertexPointer(2, VertexPointerType.Float, BufferElement.SizeInBytes, new IntPtr(0)); GL.ColorPointer(4, ColorPointerType.Float, BufferElement.SizeInBytes, new IntPtr(Vector2.SizeInBytes)); }; _pathBufferElement = new VboElement <BufferElement>(Owner, null, PrimitiveType.Lines); GameElements.Add(_pathBufferElement); GameElements.Add(new VboElement <BufferElement>(Owner, new VertexBuffer <BufferElement>(_highways, prep), PrimitiveType.Lines)); _citiesVboElement = new VboElement <BufferElement>(Owner, new VertexBuffer <BufferElement>(_points, prep), PrimitiveType.Points); GameElements.Add(_citiesVboElement); GameElements.Add(_debugText); GameElements.Add(_pathText); base.Load(); _debugText.Font.Options.Monospacing = QFontMonospacing.Yes; SetViewport(); Scheduler.TickItems.Add(new TickItem(UpdatePath, new TimeSpan(0, 0, 0, 0, 250), true)); Scheduler.TickItems.Add(new TickItem(UpdateVbos, new TimeSpan(0, 0, 0, 0, 1000 / 30))); }
public MainMenuState(GameWindow owner, GameFiniteStateMachine parent) : base(owner, parent) { var startButton = new TextElement(owner, "start", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, -0.4f), Behaviours = { { GameTriggers.MouseMove, FloatBehavior } }, AttachedProperties = { { FLOATINESS_PROP, 50f } }, MouseOverColor = Color4.White }; startButton.Clicked += args => { if (Transitioning) { return; } TransitionOut("start"); }; var settingsButton = new TextElement(owner, "settings", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, -0.15f), Behaviours = { { GameTriggers.MouseMove, FloatBehavior } }, AttachedProperties = { { FLOATINESS_PROP, 50f } }, MouseOverColor = Color4.White }; settingsButton.Clicked += args => { if (Transitioning) { return; } TransitionOut("settings"); }; var exitButton = new TextElement(owner, "exit", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, 0.1f), Behaviours = { { GameTriggers.MouseMove, FloatBehavior } }, AttachedProperties = { { FLOATINESS_PROP, 50f } }, MouseOverColor = Color4.White }; exitButton.Clicked += args => StateMachine.Transition("exit"); GameElements.Add(new TextElement(owner, "Apoplexy", ".\\fonts\\toxica.ttf", 72f) { NormalColor = Color4.DarkRed, Behaviours = { { GameTriggers.MouseMove, FloatBehavior } }, AttachedProperties = { { FLOATINESS_PROP, 25f } }, Position = new Vector2(0f, -0.75f) }); GameElements.Add(startButton); GameElements.Add(exitButton); GameElements.Add(settingsButton); }
public void Shuffle() { List <GameElement> sortingList = new List <GameElement>(); var rnd = new Random(); foreach (var gameElement in GameElements) { sortingList.Insert(rnd.Next(sortingList.Count + 1), gameElement); } GameElements.Clear(); foreach (var gameElement in sortingList) { GameElements.Add(gameElement); } }
public PauseMenuState(GameWindow owner, GameFiniteStateMachine parent) : base(owner, parent) { var uiElementBehavior = new Behaviour <UiElementBase>(o => { var floatPos = BehaviorHelpers.EaseMouse(o.MousePosition); o.PositionAdd = floatPos / ((float)o.AttachedProperties["floatiness"]); }); var resumeButton = new TextElement(owner, "resume", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, -0.4f), Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 50f } }, MouseOverColor = Color4.White }; resumeButton.Clicked += args => TransitionOut("return"); var settingsButton = new TextElement(owner, "settings", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, -0.15f), Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 50f } }, MouseOverColor = Color4.White, }; settingsButton.Clicked += args => TransitionOut("settings"); var mainMenuButton = new TextElement(owner, "main menu", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, 0.1f), Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 50f } }, MouseOverColor = Color4.White, }; mainMenuButton.Clicked += args => TransitionOut("main menu"); var exitButton = new TextElement(owner, "exit", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, 0.35f), Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 50f } }, MouseOverColor = Color4.White, }; exitButton.Clicked += args => StateMachine.Transition("exit"); GameElements.Add(new TextElement(owner, "Game Paused", ".\\fonts\\toxica.ttf", 72f) { NormalColor = Color4.DarkRed, Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 25f } }, Position = new Vector2(0f, -0.75f) }); GameElements.Add(resumeButton); GameElements.Add(exitButton); GameElements.Add(settingsButton); GameElements.Add(mainMenuButton); }
public void Start() { //add players to the game if (UserControlledPlayers.Count > 0) { GameElements.AddRange(UserControlledPlayers); } if (InitialBots.Count > 0) { GameElements.AddRange(InitialBots); } //start the Renderer to draw all elements on the screen //Render.Start(); //moved inside Logic Loop to show objective and players //we want to be able to cancel the Task therefore we need a Cancellation-Token GameLoopTokenSource = new CancellationTokenSource(); GameLoopCancellationToken = GameLoopTokenSource.Token; //Start the Logic Loop Task.Run(() => { GameObject CurrentPickup; int RespawnCounter = RespawnCounterSave; int PickupCounter = PickupCounterSave; int RespawnTeam = 1; Stopwatch stopper = new Stopwatch(); List <int> IndicesToRemove = new List <int>(); List <int> BulletIndicesToRemove = new List <int>(); List <int> PickupIndicesToRemove = new List <int>(); Team WinningTeam = null; Render.ShowStartConfig(); if (UserControlledPlayers.Count > 0) { Render.ShowFindPlayerDialog(); for (int i = 0; i < 300; i++) { if (Escape_Current_Intro) { Escape_Current_Intro = false; break; } else { Thread.Sleep(10); } } Render.HighlightPlayers(); for (int i = 0; i < 300; i++) { if (Escape_Current_Intro) { Escape_Current_Intro = false; break; } else { Thread.Sleep(10); } } } Render.ShowPlaymodeObjective(); for (int i = 0; i < 300; i++) { if (Escape_Current_Intro) { Escape_Current_Intro = false; break; } else { Thread.Sleep(10); } } for (int i = 5; i > 0; i--) { Render.ShowCountdownNumber(i); for (int j = 0; j < 100; j++) { if (Escape_Current_Intro) { Escape_Current_Intro = false; break; } else { Thread.Sleep(10); } } } Render.Start(); //The never-ending game loop while (true) { //check if our Task is canceled from outside if (GameLoopCancellationToken.IsCancellationRequested) { //if our Task was cancelled, end the loop break; } IndicesToRemove.Clear(); BulletIndicesToRemove.Clear(); PickupIndicesToRemove.Clear(); stopper.Start(); lock (GameElementListLock) for (int i = 0; i < GameElements.Count; i++) { GameElements[i].move(); if (GameElements[i].IsDead) { IndicesToRemove.Add(i); } } lock (BulletListLock) for (int i = 0; i < BulletElements.Count; i++) { BulletElements[i].move(); if (BulletElements[i].IsDead) { BulletIndicesToRemove.Add(i); } } lock (PickupListLock) for (int i = 0; i < PickupElements.Count; i++) { PickupElements[i].move(); if (PickupElements[i].IsDead) { PickupIndicesToRemove.Add(i); } } //IndicesToRemove = IndicesToRemove.OrderBy(x => x).ToList(); lock (GameElementListLock) for (int i = 0; i < IndicesToRemove.Count; i++) { GameElements.RemoveAt(IndicesToRemove[i] - i); } lock (BulletListLock) for (int i = 0; i < BulletIndicesToRemove.Count; i++) { BulletElements.RemoveAt(BulletIndicesToRemove[i] - i); } lock (PickupListLock) for (int i = 0; i < PickupIndicesToRemove.Count; i++) { PickupElements.RemoveAt(PickupIndicesToRemove[i] - i); } //Respawn if (RespawnCounter-- < 0) { RespawnCounter = RespawnCounterSave; lock (GameElementListLock) GameElements.Add(new Fighter(Lucky.Next(50, Width - 50), Lucky.Next(50, Height - 50), Teams[(RespawnTeam++ % Teams.Count)], this)); } //PickUps if (PickupCounter-- < 0) { PickupCounter = PickupCounterSave; CurrentPickup = PickupManager.SpawnRandomPickUp(); if (CurrentPickup != null) { lock (PickupListLock) PickupElements.Add((PickUp)CurrentPickup); } } //Special events from game mode PlayMode.SpecialEvent(); if (this.PlayMode.checkWin(out WinningTeam)) { GameOver(WinningTeam); } stopper.Stop(); if (stopper.ElapsedMilliseconds < LogicTime) { Thread.Sleep((int)(LogicTime - stopper.ElapsedMilliseconds)); } //to show Logic FPS in game LogicTimeActual = stopper.ElapsedMilliseconds; stopper.Reset(); } }); }