private RenderWindow CreateWindow(ApplicationSettings settings) { var windowStyle = settings.Fullscreen ? Styles.Fullscreen : Styles.Close; var window = new RenderWindow(settings.VideoMode, settings.WindowCaption, windowStyle); window.SetMouseCursorVisible(settings.MouseCursorVisible); window.SetVerticalSyncEnabled(settings.VerticalSyncEnabled); if (settings.FramerateLimit > 0) window.SetFramerateLimit(settings.FramerateLimit); return window; }
private static void InitializeWindow() { //Construct window = new RenderWindow(new VideoMode(1920, 1080), "Orbs", IsFullscreen ? Styles.Fullscreen : Styles.Default); //Set parameters window.SetVisible(true); window.SetMouseCursorVisible(false); window.SetVerticalSyncEnabled(IsVSyncEnabled); //Bind events window.Closed += (sender, i) => window.Close(); window.KeyPressed += (sender, i) => stateManager.CurrentState?.HandleKeyPressed(i); window.KeyPressed += (sender, i) => { if (i.Code == Keyboard.Key.F11) { window.Close(); IsFullscreen = !IsFullscreen; InitializeWindow(); } }; }
static void Main(string[] args) { Running = true; IPAddress ipAddress; while (true) { Console.Clear(); Console.Write("IP to server: "); string line = Console.ReadLine(); if (IPAddress.TryParse(line, out ipAddress)) { break; } else { Console.WriteLine("Invalid IP address, press enter to try again."); Console.ReadKey(true); } } Console.Clear(); Console.WriteLine("Got IP: " + ipAddress.ToString()); NetworkManager.Initialize(ipAddress.ToString()); wnd = new RenderWindow(new VideoMode(800, 480), "HAPPY NEW CHRISTMAS", Styles.Close); wnd.SetMouseCursorVisible(true); wnd.SetFramerateLimit(120); wnd.Closed += (sender, eventArgs) => { wnd.Close(); NetworkManager.Disconnect(); }; wnd.KeyPressed += OnKeyPressed; wnd.MouseButtonPressed += OnMouseButtonPressed; wnd.MouseButtonReleased += OnMouseButtonReleased; wnd.MouseMoved += OnMouseMoved; Initialize(); Stopwatch stopwatch = Stopwatch.StartNew(); while (wnd.IsOpen() && Running) { var frameTime = (float) stopwatch.Elapsed.TotalSeconds; stopwatch.Restart(); wnd.DispatchEvents(); Update(frameTime); Draw(frameTime); } Running = false; wnd.Close(); }
/// <summary> /// Handles the <see cref="IGameContainer.RenderWindowChanged"/> event. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected virtual void OnRenderWindowChanged(RenderWindow oldValue, RenderWindow newValue) { if (newValue == null) return; newValue.SetMouseCursorVisible(ShowMouseCursor); newValue.SetVerticalSyncEnabled(UseVerticalSync); newValue.SetActive(); newValue.SetVisible(true); }
private void Init() { Music = new MusicPlayer(); Sounds = new SoundManager(); Assets = new Assets(); Assets.Load(); var vm = new SFML.Window.VideoMode(1000, 750, 32); var style = Styles.Close; var settings = new ContextSettings(0, 0, 8); Window = new SFML.Graphics.RenderWindow(vm, "", style, settings); Window.SetView(View); Window.SetVerticalSyncEnabled(true); Window.Closed += (sender, e) => { IsAppExited = true; }; Window.LostFocus += (sender, e) => { IsPaused = true; }; Window.GainedFocus += (sender, e) => { IsPaused = false; }; Window.SetMouseCursorVisible(true); var splash = new Space("Splash", true); var menu = new Space("Menu"); var inGame = new Space("InGame"); var gameOver = new Space("GameOver"); // ----- ----- ----- Splash ----- ----- ----- var images = new SplashImage[] { new SplashImage(Assets.Textures["sfml"], 3, 1, 1), new SplashImage(Assets.Textures["rsas"], 5, 1, 1) }; SplashImage.Prepare(images, e => { splash.IsActive = false; menu.IsActive = true; }); foreach(var image in images) splash.Add(image); // ----- ----- ----- Menu ----- ----- ----- var btnStart = new MenuButton("Play", 40, new Vector(100, 100)); var btnQuit = new MenuButton("Quit", 40, new Vector(100, 200)); var btnDiffEasy = new MenuButton("Easy", 30, new Vector(250, 100)); var btnDiffMedium = new MenuButton("Medium", 30, new Vector(250, 150)); var btnDiffHard = new MenuButton("Hard", 30, new Vector(250, 200)); var infoText = "- Instructions -\n" + "- Run, shoot and survive as long as possible.\n" + "- Collect white powersups to recover health.\n" + "- New weapons are unlocked after each 1000 kills.\n" + "\n" + "- Use WASD keys to move, and mouse to aim and shoot.\n" + "- Use the numbers keys to change weapons.\n" + "- During gameplay, press ESC to pause or F1 to give up."; var btnInfoText = new MenuButton(infoText, 20, new Vector(450, 125)); var highscoreList = new HighscoreList(new Vector2f(50, 300)); Difficulty = RSaS.Difficulty.Medium; btnDiffMedium.Text.Color = Color.Red; btnStart.Click += e => { if (IsGameOver) { IsGameOver = false; InitInGame(inGame); } Music.Play("music"); menu.IsActive = false; inGame.IsActive = true; IsOSCursorVisible = false; }; btnQuit.Click += e => { IsAppExited = true; }; btnDiffEasy.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Easy; btnDiffEasy.Text.Color = Color.Red; btnDiffMedium.Text.Color = Color.White; btnDiffHard.Text.Color = Color.White; }; btnDiffMedium.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Medium; btnDiffEasy.Text.Color = Color.White; btnDiffMedium.Text.Color = Color.Red; btnDiffHard.Text.Color = Color.White; }; btnDiffHard.Click += e => { if (!IsGameOver) return; Difficulty = RSaS.Difficulty.Hard; btnDiffEasy.Text.Color = Color.White; btnDiffMedium.Text.Color = Color.White; btnDiffHard.Text.Color = Color.Red; }; menu.Add(btnStart); menu.Add(btnQuit); menu.Add(btnDiffEasy); menu.Add(btnDiffMedium); menu.Add(btnDiffHard); menu.Add(btnInfoText); menu.Add(highscoreList); }
static void Main(string[] args) { Texture textureBack = new Texture(File.ReadAllBytes(@"assets/back.png")); textureBack.Smooth = true; Sprite spriteBack = new Sprite(textureBack, new IntRect(0, 0, 800, 500)); Texture textureLock = new Texture(File.ReadAllBytes(@"assets/lock.png")); textureLock.Smooth = true; Sprite spriteLock = new Sprite(textureLock, new IntRect(0, 0, 80, 80)); spriteLock.Position = new Vector2f(76, 68); icons = new List<Sprite>(); for (int index = 0; index < 15; index++) { int col = index % 5; int row = (index - col) / 5; Texture textureIcon = new Texture(File.ReadAllBytes(String.Format(@"assets/buttons/{0:00}.png", index + 1))); textureIcon.Smooth = true; Sprite spriteIcon = new Sprite(textureIcon, new IntRect(0, 0, 72, 72)); spriteIcon.Position = new Vector2f(80 + col * 72 + col * 70, 72 + row * 72 + row * 70); icons.Add(spriteIcon); } ContextSettings context = new ContextSettings(); context.DepthBits = 32; RenderWindow window = new RenderWindow(new VideoMode(800, 500), String.Empty, Styles.Default, context); window.SetActive(); window.SetVisible(true); window.SetKeyRepeatEnabled(true); window.SetMouseCursorVisible(true); window.SetVerticalSyncEnabled(false); window.Closed += new EventHandler( delegate(object sender, EventArgs e) { window.Close(); window.Dispose(); } ); window.GainedFocus += new EventHandler( delegate(object sender, EventArgs e) { } ); window.LostFocus += new EventHandler( delegate(object sender, EventArgs e) { } ); window.KeyPressed += new EventHandler<KeyEventArgs>( delegate(object sender, KeyEventArgs e) { if (e.Code == Keyboard.Key.Escape) { /* sound.Stop(); sound.Dispose(); buffer.Dispose(); */ window.Close(); window.Dispose(); } if (e.Code == Keyboard.Key.Right) { if (col < 4) { col += 1; } } if (e.Code == Keyboard.Key.Left) { if (col > 0) { col -= 1; } } if (e.Code == Keyboard.Key.Up) { if (row > 0) { row -= 1; } } if (e.Code == Keyboard.Key.Down) { if (row < 2) { row += 1; } } spriteLock.Position = new Vector2f(80 + col * 72 + col * 70 - 4, 72 + row * 72 + row * 70 - 4); } ); window.KeyReleased += new EventHandler<KeyEventArgs>( delegate(object sender, KeyEventArgs e) { } ); window.TouchBegan += new EventHandler<TouchEventArgs>( delegate(object sender, TouchEventArgs e) { } ); window.TouchEnded += new EventHandler<TouchEventArgs>( delegate(object sender, TouchEventArgs e) { } ); window.TouchMoved += new EventHandler<TouchEventArgs>( delegate(object sender, TouchEventArgs e) { } ); window.JoystickConnected += new EventHandler<JoystickConnectEventArgs>( delegate(object sender, JoystickConnectEventArgs e) { } ); window.JoystickDisconnected += new EventHandler<JoystickConnectEventArgs>( delegate(object sender, JoystickConnectEventArgs e) { } ); window.JoystickButtonPressed += new EventHandler<JoystickButtonEventArgs>( delegate(object sender, JoystickButtonEventArgs e) { //File.AppendAllText(@"joystick.log", Convert.ToString(e.Button) + ":JoystickButtonPressed\n"); // A 0 // B 1 // X 2 // Y 3 // BACK 6 // START 7 } ); window.JoystickButtonReleased += new EventHandler<JoystickButtonEventArgs>( delegate(object sender, JoystickButtonEventArgs e) { //File.AppendAllText(@"joystick.log", Convert.ToString(e.Button) + ":JoystickButtonReleased\n"); } ); window.JoystickMoved += new EventHandler<JoystickMoveEventArgs>( delegate(object sender, JoystickMoveEventArgs e) { //File.AppendAllText(@"joystick.log", Convert.ToString(e.Axis) + ":" + Convert.ToString(e.JoystickId) + ":" + Convert.ToString(e.Position) + "\n"); // RIGHT PovX +100 // LEFT PovX -100 if (e.Axis == Joystick.Axis.PovX) { if (e.Position.Equals(+100.0f)) { // RIGHT if (col < 4) { col += 1; } } if (e.Position.Equals(-100.0f)) { // LEFT if (col > 0) { col -= 1; } } } // UP PovY +100 // DOWN PovY -100 if (e.Axis == Joystick.Axis.PovY) { if (e.Position.Equals(+100.0f)) { // UP if (row > 0) { row -= 1; } } if (e.Position.Equals(-100.0f)) { // DOWN if (row < 2) { row += 1; } } } spriteLock.Position = new Vector2f(80 + col * 72 + col * 70 - 4, 72 + row * 72 + row * 70 - 4); } ); while (window.IsOpen) { window.DispatchEvents(); window.Clear(); window.Draw(spriteBack); foreach (Sprite icon in icons) { window.Draw(icon); } window.Draw(spriteLock); window.Display(); } }
private static void LoadContentInitialize() { Char1Model = new Model(); Char1Model.name = "Character_1_Model"; Char1Model.gibArmFile = "gibArm.png"; Char1Model.gibBodyFile = "gibBody.png"; Char1Model.gibHeadFile = "gibHead.png"; Char1Model.gibLowerLegFile = "gibLowerLeg.png"; Char1Model.gibUpperLegFile = "gibUpperLeg.png"; Char1Model.idleFile = "idle.png"; Char1Model.jumpDownFile = "jumpDown.png"; Char1Model.jumpUpFile = "jumpUp.png"; Char1Model.runFile = "run.png"; Char1Model.pistolHand = "pistolHand.png"; Char2Model = new Model(); Char2Model.name = "Character_2_Model"; Char2Model.gibArmFile = "char2_gibArm.png"; Char2Model.gibBodyFile = "char2_gibBody.png"; Char2Model.gibHeadFile = "char2_gibHead.png"; Char2Model.gibLowerLegFile = "char2_gibLowerLeg.png"; Char2Model.gibUpperLegFile = "char2_gibUpperLeg.png"; Char2Model.idleFile = "char2_idle.png"; Char2Model.jumpDownFile = "char2_jumpDown.png"; Char2Model.jumpUpFile = "char2_jumpUp.png"; Char2Model.runFile = "char2_run.png"; Char2Model.pistolHand = "char2_pistolHand.png"; window = new RenderWindow( new VideoMode(800, 600), "Project Iris", Styles.Resize); window.SetFramerateLimit(60); window.SetMouseCursorVisible(false); window.Closed += (o, e) => { dm.Close(); window.Close(); }; window.GainedFocus += (o, e) => { Input.isActive = true; }; window.LostFocus += (o, e) => { Input.isActive = false; }; Camera = new View(window.DefaultView); Camera.Size = new Vector2f(800 / 2, 600 / 2); GuiCamera = new View(window.DefaultView); GuiCamera.Size = new Vector2f(800 / 2, 600 / 2); soundInstances = new List<SoundInstance>() { }; dm = new Deathmatch(); mm = new Menu(); gamestate = mm; }
static void Main() { // Create the main window CurrentSaveData = 0; Data d = new Data(); Data = d; d.CreateTerrain(); d.CreateSpriteData(); d.CreateTileData(); d.CreateItems(); d.CreateSpawnable(); List<GameState> _gameState = new List<GameState>(); State = _gameState; MainMap m; MouseState = 0; InState = 0; MapGenerator mg = new MapGenerator(); m = mg.NewMap(); MyMap = m; Generator = mg; d.CreateLivingObjectData(); PlayerData test = new PlayerData(); test.MainParty.AddMember(((NPC)d.MyLivingObject[0])); d.MyPlayerData.Add(test); d.MyPlayerData[CurrentSaveData].MainParty.MyParty[0].Inventory[0] = new SpawnItems(0); d.MyPlayerData[CurrentSaveData].MainParty.MyParty[0].Inventory[1] = new SpawnItems(1); d.MyPlayerData[CurrentSaveData].MainParty.MyParty[0].Inventory[2] = new SpawnItems(1); //d.MyPlayerData[Program.CurrentSaveData].MainParty.MyParty[0].EquipItems(1); d.MyPlayerData[CurrentSaveData].MainParty.AddMember((NPC)d.MyLivingObject[1]); Font font = new Font("Georgia.ttf"); List<string> stuff = new List<string>(); RenderWindow Screen = new RenderWindow(new VideoMode(1040, 768), "Wandering Soul - The Legacy"); RW = Screen; Screen.SetFramerateLimit(60); Screen.Closed += new EventHandler(OnClose); Screen.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); Screen.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(OnMousePress); Screen.MouseMoved += new EventHandler<MouseMoveEventArgs>(OnMouseMove); Screen.MouseButtonReleased += new EventHandler<MouseButtonEventArgs>(OnMouseRelease); Screen.SetMouseCursorVisible(false); _gameState.Add(new MainMenuState(Screen)); _gameState.Add(new InGameState(Screen, 0)); Color windowColor = new Color(0, 0, 0); Text t; SFML.Graphics.Sprite s; // Start the game loop while (Screen.IsOpen()) { // Process events stuff.Clear(); string ministuff = ""; foreach (Terrain ter in MyMap.SpawnedTerrain) { ministuff = ""; ministuff += ter.MinHorizontal + ", " + ter.MaxHorizontal + ", " + ter.MinVertical + ", " + ter.MaxVertical; stuff.Add(ministuff); } Screen.DispatchEvents(); // Clear screen Screen.Clear(windowColor); _gameState[InState].Update(); _gameState[InState].Draw(); /*for (int i = 0; i < stuff.Count; i++) { t = new Text(stuff[i], font); t.Position = new Vector2f(50, i * 20 + 50); Screen.Draw(t); }*/ //t = new Text("Min X: " + MyMap.MinX + ", Min Y: " + MyMap.MinY + ", Max X: " + MyMap.MaxX + ", Max Y: " + MyMap.MaxY + ", " + MyMap.SpawnedTerrain[0].Size.ToString() + ", Spawned Terrain Count: " + MyMap.SpawnedTerrain.Count, font); //t.Position = new Vector2f(0, 0); //Screen.Draw(t); t = new Text("X: " + (Mouse.GetPosition(Screen).X / 16 + Program.Data.MyPlayerData[CurrentSaveData].MainParty.MyParty[0].X - Screen.Size.X / 2 / 16 - 1) + ", Y: " + ((Mouse.GetPosition(Screen).Y + 8) / 16 + Program.Data.MyPlayerData[CurrentSaveData].MainParty.MyParty[0].Y - Screen.Size.Y / 2 / 16 - 1), Program.Data.Font); Screen.SetView(new View(new FloatRect(0, 0, Screen.Size.X, Screen.Size.Y))); t.Position = new Vector2f(0, 0); Screen.Draw(t); s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Mouse)[MouseState]); switch ((MouseStateType)MouseState) { case MouseStateType.Normal: s.Position = new Vector2f(Mouse.GetPosition(Screen).X - 3, Mouse.GetPosition(Screen).Y); break; case MouseStateType.Dragging: s.Position = new Vector2f(Mouse.GetPosition(Screen).X - 2, Mouse.GetPosition(Screen).Y + 3); break; } Screen.Draw(s); // Update the window Screen.Display(); } //End game loop }
public static bool InitWindow(Styles style) { int width, height; if (!_game.TryGetData("screen_width", out width)) { Console.WriteLine("No screen width set in game.sgm."); return false; } if (!_game.TryGetData("screen_height", out height)) { Console.WriteLine("No screen height set in game.sgm."); return false; } if (width <= 0 || height <= 0) { Console.WriteLine("Invalid width and height in game.sgm."); return false; } GlobalProps.Width = width; GlobalProps.Height = height; if (Scaled) { width *= 2; height *= 2; } _clipper.Width = width; _clipper.Height = height; GlobalProps.BasePath = Path.GetDirectoryName(_game.FileName); if (!_game.TryGetData("name", out GlobalProps.GameName)) { Console.WriteLine("No name set in game.sgm."); return false; } if (style == Styles.Fullscreen && (width < 640 || height < 480)) { width = 640; height = 480; } _window = new RenderWindow(new VideoMode((uint)width, (uint)height), GlobalProps.GameName, style); if (Scaled) { View v = _window.GetView(); v.Size = new Vector2f(GlobalProps.Width, GlobalProps.Height); v.Center = new Vector2f(GlobalProps.Width / 2, GlobalProps.Height / 2); _window.SetView(v); } _window.SetMouseCursorVisible(false); GlobalInput.AddWindowHandlers(_window); Program._window.SetFramerateLimit((uint)_internal_fps); Program._window.SetMouseCursorVisible(false); GlobalPrimitives.Target = _window; Batch = new SpriteBatch(_window); FindIcon(); return true; }
static void Main() { // Create the main window CurrentSaveData = 0; Data d = new Data(); Data = d; d.CreateGraphicPath(); d.CreateTerrain(); d.CreateSpriteData(); d.CreateTileData(); d.CreateAnimation(); d.CreateAttack(); d.CreateItems(); d.CreateSpawnable(); d.CreateKnowledge(); d.CreateFaceData(); d.CreateBodyData(); d.CreateHairData(); d.CreateTileVariation(); d.LoadPlayerData(); d.LoadWorldData(); List<GameState> _gameState = new List<GameState>(); State = _gameState; MainMap m; MouseState = 0; InState = 0; MapGenerator mg = new MapGenerator(); m = mg.NewMap(); MyMap = m; Generator = mg; Font font = new Font("Georgia.ttf"); List<string> stuff = new List<string>(); RenderWindow Screen = new RenderWindow(new VideoMode(1040, 768), "Wandering Soul - The Legacy"); VisibleMaxX = 1040 / 16; VisibleMaxY = 768 / 16; RW = Screen; Screen.SetFramerateLimit(60); Screen.Closed += new EventHandler(OnClose); Screen.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); Screen.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(OnMousePress); Screen.MouseMoved += new EventHandler<MouseMoveEventArgs>(OnMouseMove); Screen.MouseButtonReleased += new EventHandler<MouseButtonEventArgs>(OnMouseRelease); Screen.Resized +=new EventHandler<SizeEventArgs>(OnScreenResize); Screen.SetMouseCursorVisible(false); _gameState.Add(new MainMenuState(Screen)); _gameState.Add(new InGameState(Screen)); Color windowColor = new Color(0, 0, 0); Text t; SFML.Graphics.Sprite s; // Start the game loop while (Screen.IsOpen()) { // Process events Screen.DispatchEvents(); // Clear screen Screen.Clear(windowColor); _gameState[InState].Update(); _gameState[InState].Draw(); /*for (int i = 0; i < stuff.Count; i++) { t = new Text(stuff[i], font); t.Position = new Vector2f(50, i * 20 + 50); Screen.Draw(t); }*/ //t = new Text("Min X: " + MyMap.MinX + ", Min Y: " + MyMap.MinY + ", Max X: " + MyMap.MaxX + ", Max Y: " + MyMap.MaxY + ", " + MyMap.SpawnedTerrain[0].Size.ToString() + ", Spawned Terrain Count: " + MyMap.SpawnedTerrain.Count, font); //t.Position = new Vector2f(0, 0); //Screen.Draw(t); Screen.SetView(new View(new FloatRect(0, 0, Screen.Size.X, Screen.Size.Y))); s = new SFML.Graphics.Sprite(Program.Data.SpriteBasedOnType(SpriteType.Mouse)[MouseState]); switch ((MouseStateType)MouseState) { case MouseStateType.Normal: s.Position = new Vector2f(Mouse.GetPosition(Screen).X - 3, Mouse.GetPosition(Screen).Y); break; case MouseStateType.Dragging: s.Position = new Vector2f(Mouse.GetPosition(Screen).X - 2, Mouse.GetPosition(Screen).Y + 3); break; } Screen.Draw(s); // Update the window Screen.Display(); } //End game loop }