static void Main(string[] args) { // initialize window and view win = new RenderWindow(new VideoMode(1000, 700), "Hadoken!!!"); view = new View(); resetView(); gui = new GUI(win, view); // exit Program, when window is being closed //win.Closed += new EventHandler(closeWindow); win.Closed += (sender, e) => { (sender as Window).Close(); }; // initialize GameState handleNewGameState(); // initialize GameTime GameTime gameTime = new GameTime(); gameTime.Start(); // debug Text Text debugText = new Text("debug Text", new Font("Fonts/calibri.ttf")); while (running && win.IsOpen()) { KeyboardInputManager.update(); currentGameState = state.update(); // gather draw-stuff win.Clear(new Color(100, 149, 237)); //cornflowerblue ftw!!! 1337 state.draw(win, view); state.drawGUI(gui); // first the state must be drawn, before I can change the currentState if (currentGameState != prevGameState) { handleNewGameState(); } // do the actual drawing win.SetView(view); win.Display(); // check for window-events. e.g. window closed win.DispatchEvents(); // update GameTime gameTime.Update(); float deltaTime = (float)gameTime.EllapsedTime.TotalSeconds; // idleLoop for fixed FrameRate float deltaPlusIdleTime = deltaTime; while (deltaPlusIdleTime < (1F / fixedFps)) { gameTime.Update(); deltaPlusIdleTime += (float)gameTime.EllapsedTime.TotalSeconds; } Console.WriteLine("real fps: " + (int)(1F / deltaPlusIdleTime) + ", theo fps: " + (int)(1F / deltaTime)); } }
public ViewAnimateSprite(IntPtr handle) { _animatedSpriteViewer = new RenderWindow(handle); _view = new View(new FloatRect(0, 0, Editor.Instance.curGame.TileX, Editor.Instance.curGame.TileY)); _curFrame = 0; _animatedSpriteViewer.SetView(_view); }
public static void OnResized(object sender, SizeEventArgs e) { LocalWindow = (RenderWindow) sender; LocalWindow.Size = new Vector2u(e.Width, e.Height); // ReSharper disable PossibleLossOfFraction LocalWindow.SetView(new View(new Vector2f((e.Width)/2, (e.Height)/2), new Vector2f(e.Width, e.Height))); // ReSharper restore PossibleLossOfFraction }
public override void intialize(RenderWindow window) { base.intialize(window); window.SetView(new View(new FloatRect(0, 0, Game1.drawResolution.X, Game1.drawResolution.Y))); window.SetFramerateLimit(60); window.MouseButtonPressed += window_MouseButtonPressed; window.KeyPressed += window_KeyPressed; window.Resized += window_Resized; }
public static void Main(string[] args) { Window = new RenderWindow(new VideoMode(640, 480), "", Styles.Close); Window.SetFramerateLimit(60); Window.Closed += (sender, eventArgs) => Window.Close(); Window.Resized += (sender, eventArgs) => { var view = new View(); view.Size = new Vector2f(eventArgs.Width, eventArgs.Height); view.Center = view.Size / 2; Window.SetView(view); }; Machine = new VirtualMachine(512 * 1024); var prog = File.ReadAllBytes("bios.bin"); for (var i = 0; i < prog.Length; i++) Machine.Memory[i] = prog[i]; var kbd = new Devices.Keyboard(0x02, Window); Machine.Attach(kbd); var display = new Devices.Display(0x06, Machine, Window); Machine.Attach(display); var hdd = new Devices.HardDrive(0x08, "disk.img"); Machine.Attach(hdd); var running = true; var stepThread = new Thread(() => { while (running) { Machine.Step(); } }); stepThread.Start(); while (Window.IsOpen()) { Window.DispatchEvents(); Window.Clear(); Window.Draw(display); Window.Display(); } running = false; stepThread.Join(); Machine.Dispose(); }
/// <summary> /// clear the window /// <para>draws all gameobjects in the window</para> /// <para>displays all drawn objects</para> /// </summary> static void Draw(RenderWindow window) { window.Clear(new Color(50, 120, 190)); window.SetView(Camera); map.Draw(window); Player.Draw(window); enemy1.Draw(window); enemy2.Draw(window); window.Display(); }
public void Draw(RenderWindow win) { win.SetView(Camera); map.Draw(win); Player.Draw(win); enemy1.Draw(win); enemy2.Draw(win); foreach (ParticleHandler p in pHandler) p.Draw(win); }
public override void Draw(RenderWindow window) { try { window.SetView(Level.Camera); Level.Draw(window); } catch (Exception e) { Log.WriteError("Erreur lors du dessinage du niveau ! Le niveau est sûrement corrompu ou comporte des erreurs ! Erreur : " + e.Message); Game.LoadScene(new MainMenuScene(Game)); } }
static void Draw(RenderWindow window) { window.Clear(new SFML.Graphics.Color(50, 120, 190)); map.Draw(window); mons01.Draw(window); mons02.Draw(window); // vulkan.Draw(window); if(tool.isOnMap)tool.Draw(window); Player.Draw(window); window.Display(); window.SetView(view); }
public void Update() { window.SetView(setCameraToPlayer(window)); if (eContrainer.AllEnemyDead && !player.isDead) { initLevel(); } eContrainer.Update(); HandleInputCommands(); player.Update(); statusbar.Update(player.BulletCount, eContrainer.EnemyCount); world.Step(.01639344262f); }
public void Run() { //var mode = new SFML.Window.VideoMode(800, 600); var window = new SFML.Graphics.RenderWindow(SFML.Window.VideoMode.FullscreenModes[0], "Repair Project", SFML.Window.Styles.Fullscreen); window.KeyPressed += Window_KeyPressed; window.MouseButtonPressed += OnMouseButtonPressed; window.MouseButtonReleased += OnMouseButtonReleased; window.MouseMoved += OnMouseMoved; //this.object2DManager.SizeScreen = window.GetView().Size; SFML.Graphics.View view = window.GetView(); this.resolutionScreen = new Vector2f(view.Size.X, view.Size.Y); view.Center = new Vector2f(0, 0); window.SetView(view); window.SetVerticalSyncEnabled(true); Clock clock = new Clock(); this.officeWorld.StartLevel(); // Start the game loop while (window.IsOpen) { Time deltaTime = clock.Restart(); // Game logic update this.officeWorld.UpdateLogic(deltaTime); window.Clear(); this.object2DManager.DrawIn(window); // Process events window.DispatchEvents(); AObject2D.UpdateZoomAnimationManager(deltaTime); // Finally, display the rendered frame on screen window.Display(); } this.object2DManager.Dispose(this.officeWorld); AObject2D.StopAnimationManager(); }
public Game() { Resolution = new Sfs.Vector2u(1280, 720); #if DEBUG _window = new Sfg.RenderWindow(new Sfw.VideoMode(Resolution.X, Resolution.Y), new string(Strings.GameName)); #else _window = new Sfg.RenderWindow(new Sfw.VideoMode(1280, 720), new string(Strings.GameName), Sfw.Styles.Fullscreen); #endif var cameraView = _window.DefaultView; cameraView.Center = new Sfs.Vector2f(300f, 200f); _window.SetView(cameraView); var gameplayState = new GameplayState(); _userInputController = new UserInputController { ActualState = gameplayState, ActualViewContainer = new GameplayStateView(gameplayState) }; }
public MapViewer(IntPtr obj, int objw, int objh) { _xoffset = _yoffset = 0; _mapWindow = new RenderWindow(obj); _mapWindow.SetFramerateLimit(60); _mapView = new View(new FloatRect(0, 0, objw, objh)); _mapWindow.SetView(_mapView); _grid = true; _block = true; _showGround = true; _showFringe = true; _gEngine = new GEngine(); LoadedNewTS(); }
public Game() { RWindow = new RenderWindow(new VideoMode(800, 600),"",Styles.Close); //RWindow.SetFramerateLimit(60); RWindow.MouseMoved += RWindow_MouseMoved; RWindow.KeyPressed += RWindow_KeyPressed; RWindow.KeyReleased += RWindow_KeyReleased; RWindow.MouseButtonPressed += RWindow_MouseButtonPressed; RWindow.MouseButtonReleased += RWindow_MouseButtonReleased; RWindow.MouseLeft += RWindow_MouseLeft; RWindow.MouseEntered += RWindow_MouseEntered; RWindow.MouseWheelMoved += RWindow_MouseWheelMoved; RWindow.TextEntered += RWindow_TextEntered; RWindow.Closed += RWindow_Closed; RWindow.LostFocus += RWindow_LostFocus; RWindow.GainedFocus += RWindow_GainedFocus; MainView = new View(RWindow.DefaultView); RWindow.SetView(MainView); //SM = new UI.ScreenManager(this); WM = new DystopiaUI.WindowManager(this); GameLoop(); }
static void Main(string[] args) { Log.GlobalLevel = Log.Level.Debug; RenderWindow app = new RenderWindow(new VideoMode(800, 600), "HP!", Styles.Default, new ContextSettings(0, 0, 4)); app.SetFramerateLimit(60); app.Closed += delegate { app.Close(); }; app.SetVisible(true); app.SetActive(true); L.I("Assuming assets in \"assets\""); Assets assets = new Assets("assets"); LoadAnimations(assets); Level level1 = assets.Level("level1.json"); Game game = new Game(assets, level1); var view = new View(); int lastFrameTime = Environment.TickCount; while (app.IsOpen) { app.DispatchEvents(); float aspect = (float)app.Size.X / app.Size.Y; float targetWidth = 20, targetHeight = targetWidth / aspect; view.Reset(new FloatRect(0, 0, targetWidth, targetHeight)); app.SetView(view); int ticks = Environment.TickCount; float delta = (ticks - lastFrameTime) / 1000F; lastFrameTime = ticks; game.Update(delta); game.Render(app); app.Display(); } }
public void SetViewToThisNPC(RenderWindow rw) { int tempoffsetX = 0; int tempoffsetY = 0; switch (TargetDir) { case 0: tempoffsetX = -WalkCount; tempoffsetX /= 8; break; case 1: tempoffsetY = -WalkCount; tempoffsetY /= 8; break; case 2: tempoffsetX = WalkCount; tempoffsetX /= 8; break; case 3: tempoffsetY = WalkCount; tempoffsetY /= 8; break; } rw.SetView(new View(new FloatRect((LastX + CurMap.MinX) * 16 - 8 - rw.Size.X / 2 + tempoffsetX, (LastY + CurMap.MinY) * 16 - 8 - rw.Size.Y / 2 + tempoffsetY, rw.Size.X, rw.Size.Y))); }
static void Draw(RenderWindow window) { window.Clear(new SFML.Graphics.Color(100, 100, 100)); window.Draw(map); Player.Draw(window); Schaf1.Draw(window); Schaf2.Draw(window); window.Display(); window.SetView(view); }
public static void Init() { ContextSettings settings = new ContextSettings (32, 8, 4, 3, 3); Styles windowStyle = Styles.Close; if (FULLSCREEN) { windowStyle = Styles.Fullscreen; Game.Width = FULLSCREEN_WIDTH; Game.Height = FULLSCREEN_HEIGHT; Game.CameraWidth = FULLSCREEN_WIDTH; Game.CameraHeight = FULLSCREEN_HEIGHT; } Context = new RenderWindow (new VideoMode ((uint)Game.Width, (uint)Game.Height), WindowTitleText, windowStyle, settings); Context.Closed += OnClose; Context.KeyPressed += KeyPressed; Context.KeyReleased += KeyReleased; Context.SetKeyRepeatEnabled (true); Rand = new Random (); EventMgr = new EventManager (); World = new GameWorld (); Camera = new View (); Camera.Center = new Vector2f (CameraWidth / 2, CameraHeight / 2); Camera.Size = new Vector2f (CameraWidth, CameraHeight); // Half Size Context.SetView (Camera); }
// Window Management public void CreateWindow() { Window = new RenderWindow(new VideoMode(ResolutionDefault.X, ResolutionDefault.Y), "Cannon Island Defence", WindowStyle, WindowSettings); Window.Closed += OnClose; Window.KeyReleased += OnKeyReleased; Window.MouseButtonPressed += OnMouseButtonPressed; if (WindowStyle == Styles.Fullscreen) { float difference = (float)ResolutionDefault.Y / (float)Resolution.Y; View view = new View(new FloatRect((ResolutionDefault.X - (Resolution.X * difference)) / 2, 0, Resolution.X * difference, ResolutionDefault.Y)); Window.SetView(view); } else if (WindowStyle == Styles.None) { Window.Size = new Vector2u(Resolution.X, Resolution.Y); Window.Position = new Vector2i(0, 0); float difference = (float)ResolutionDefault.Y / (float)Resolution.Y; View view = new View(new FloatRect((ResolutionDefault.X - (Resolution.X * difference)) / 2, 0, Resolution.X * difference, ResolutionDefault.Y)); Window.SetView(view); } else { Window.Size = WindowSizeDefault; Window.Position = new Vector2i((int)((Resolution.X - WindowSizeDefault.X) / 2), (int)((Resolution.Y - WindowSizeDefault.Y) / 2)); //View view = new View(new FloatRect((Resolution.X - ResolutionDefault.X) / 2, 0, ResolutionDefault.X, ResolutionDefault.Y)); //Window.SetView(view); } if (NewWindow != null) NewWindow(this, EventArgs.Empty); }
public static void Run() { Sound.Loop("music/seaponies"); window = new RenderWindow(videomode, title, Styles.Default); window.Closed += new EventHandler(OnClosed); window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed); window.Resized += new EventHandler<SizeEventArgs>(OnResized); window.SetIcon(48, 48, new Image("data/tilesheets/pinktaffy48.png").Pixels); Sprite titleScreen = new Sprite(new Texture(new Image("data/tilesheets/title.png"))); lastTick = DateTime.Now; View originView = new View(new Vector2f(400, 300), new Vector2f(800, 600)); DateTime starttime = DateTime.Now; while (window.IsOpen()) { if (TotalTaffies != 0 && StaticResources.State.Candies >= TotalTaffies){ var t = (DateTime.Now - starttime).TotalMilliseconds/1000; System.Windows.Forms.MessageBox.Show("You win! Time: " + t); System.IO.File.AppendAllText("scores.txt", t + "\n"); Environment.Exit(0); } DeltaTimeMS = (DateTime.Now - lastTick).TotalMilliseconds; if (DeltaTimeMS < MSPF) { System.Threading.Thread.Sleep((int)(MSPF - DeltaTimeMS)); DeltaTimeMS = MSPF; } lastTick = DateTime.Now; window.DispatchEvents(); window.SetView(originView); window.Draw(StaticResources.State.Background); switch (mode) { case ExecMode.Title: window.Draw(titleScreen); break; case ExecMode.Intro: StaticResources.State.Tick(); DialogIfDialog(); break; case ExecMode.Main: StaticResources.State.Tick(); if (StaticResources.State.MainCharacter != null){ window.SetView(StaticResources.State.MainCharacter.View); //window.SetTitle(StaticResources.State.MainCharacter.Position.ToString()); } foreach (SeaPonyDash.Actor a in StaticResources.State.Actors) { if (!a.Hidden && a.OnScreen) { //if (a.Type == ActorType.Taffy) //{ // Sprite b = new Sprite(a.Sprite); // b.Position = a.Position; // b.TextureRect = new IntRect(0, 0, 64, 64); // //works // window.Draw(b); //} //shows nothing on all but a few of the taffy sprites window.Draw(new Sprite(a.Sprite) { Position = a.Position, TextureRect = a.Sprite.TextureRect }); //System.Windows.Forms.MessageBox.Show(a.Sprite.Position.ToString() + " " + a.Frame.ToXml() + " " + a.Animation.ToXml()); } else { } } window.SetView(originView); Text txt = new Text("Taffies: " + StaticResources.State.Candies + " / " + (TotalTaffies), StaticResources.CelestiaRedux); txt.CharacterSize = 30; DialogIfDialog(); window.Draw(txt); if (StaticResources.State.MainCharacter != null) window.SetView(StaticResources.State.MainCharacter.View); break; case ExecMode.End: break; } window.Display(); } }
private void SetView(SFML.Graphics.RenderWindow window, SFML.Graphics.View view) { this.boundsView = new FloatRect(view.Center.X - view.Size.X / 2, view.Center.Y - view.Size.Y / 2, view.Size.X, view.Size.Y); window.SetView(view); }
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); }
public override void draw(GameTime time, RenderWindow window) { window.SetView(view); if (showGrid) drawGrid(window); contentManager.draw(time, window); if (lightLayerEnabled) lightLayer.draw(window); guide.draw(window); }
private static void UpdateDraw(RenderWindow window) { //float ratio = 800 / 600; window.Size = new Vector2u(800u, 600u); window.Clear(Color.Black); window.DispatchEvents(); UpdateSoundInstances(); Input.Update(); updateWorldMousePos(); gamestate.Update(); gamestate.Draw(); window.SetView(GuiCamera); window.SetView(Camera); window.Display(); Input.refreshState(); //Always call last if (Input.isKeyDown(Keyboard.Key.Escape)) { if (dm.Mailman != null) { dm.Close(); } window.Close(); } }
static void Main(string[] args) { // init screen related constants Constants.windowSizeY = (int)VideoMode.DesktopMode.Height; Constants.windowSizeX = Constants.windowSizeY * 4 / 3; Constants.windowScaleFactor = Constants.windowSizeY / 600f; Constants.screenRatio = (float)Constants.windowSizeY / Constants.windowSizeX; Constants.worldToScreenRatio = Constants.windowSizeX / Constants.worldSizeX; Constants.worldSizeY = Constants.worldSizeX * Constants.screenRatio; // initialize window and view win = new RenderWindow(new VideoMode((uint)Constants.windowSizeX, (uint)Constants.windowSizeY), "Shøøp"); view = new View(); resetView(); gui = new GUI(win, view); // exit Program, when window is being closed //win.Closed += new EventHandler(closeWindow); win.Closed += (sender, e) => { (sender as Window).Close(); }; // initialize GameState handleNewGameState(); // initialize GameTime gameTime = new GameTime(); float deltaTime = 0f; gameTime.Start(); while (running && win.IsOpen()) { // gameTime.Update(); GamePadInputManager.update(); KeyboardInputManager.update(); if (currentGameState == GameState.InGame) { inGameFrameCount++; } currentGameState = state.update(deltaTime * Constants.gameSpeedFactor); if (currentGameState != prevGameState) { handleNewGameState(); } // draw current frame win.Clear(new Color(100, 149, 237)); //cornflowerblue ftw!!! 1337 state.draw(win, view); state.drawGUI(gui); win.SetView(view); win.Display(); // check for window-events. e.g. window closed win.DispatchEvents(); System.Threading.Thread.Sleep(5); // update GameTime gameTime.Update(); deltaTime = (float)gameTime.EllapsedTime.TotalSeconds; // int waitTime = (int)(16.667f - gameTime.EllapsedTime.TotalMilliseconds); // if (waitTime > 0) System.Threading.Thread.Sleep(waitTime); // win.SetTitle(waitTime.ToString()); // win.SetTitle((count/60f).ToString("0.0") + " | " + gameTime.TotalTime.TotalSeconds.ToString("0.0")); } }
public override void Draw(RenderWindow window) { window.SetView(Level.Camera); _mousePositionInWorld = window.MapPixelToCoords(Mouse.GetPosition(window), Level.Camera); Level.Draw(window); window.SetView(window.DefaultView); }
private static void UpdateDraw(RenderWindow window) { cameraPos = new Vector2f((int)clientPlayer.position.X, (int)clientPlayer.position.Y); camera2D = new View(cameraPos, new Vector2f(640, 480)); camera2D.Zoom(.5f); View noCamera = new View(new Vector2f(0, 0), new Vector2f(640, 480)); window.SetView(camera2D); UpdateSounds(); window.DispatchEvents(); window.Clear(Color.Black); for (int i = 0; i < connectedPlayers.Count; i++) { connectedPlayers[i].connectColor = Color.White; } //window.Draw(background); window.Draw(basicLevelDec); HandleMessages(); Text _chatCompose = new Text(clientPlayer.textCapture, font); float chatScale = .4f; _chatCompose.Scale = new Vector2f(chatScale, chatScale); _chatCompose.Position = new Vector2f(-300, 200);// clientPlayer.position; Text _textConnected = new Text(connected ? "CONNECTED" : "DISCONNECTED", font); _textConnected.Scale = new Vector2f(chatScale, chatScale); _textConnected.Position = new Vector2f(-300, -230);// clientPlayer.position; Text _playersConnectedText = new Text(connectedPlayers.Count + " Player Connected", font); _playersConnectedText.Scale = new Vector2f(chatScale, chatScale); _playersConnectedText.Position = new Vector2f(-300, -220);// clientPlayer.position; drawPlayers(); updatePlayers(); window.SetView(noCamera); window.Draw(_chatCompose); window.Draw(_textConnected); window.Draw(_playersConnectedText); Color pingColor = Color.White; if (ping == 0) { //connected = false; pingColor = Color.Red; } if (ping > 100) { pingColor = Color.Yellow; } Render.drawString(font, ping + " ms", new Vector2f(-300, -240), pingColor, .4f, false); for (int i = 0; i < chatMessages.Count; i++) { Text chatMessage = new Text(chatMessages[i], font); chatMessage.Scale = new Vector2f(chatScale, chatScale); chatMessage.Position = new Vector2f(-300, -200 + (i * 10));// clientPlayer.position; window.Draw(chatMessage); } window.Display(); }
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; }
public void setview(RenderWindow window) { Vector2f camPos = Position; Vector2f map = Map01.map.map; //Console.WriteLine(map.Y); //Console.WriteLine(map.X); //Console.WriteLine(window.Size.X); //Console.WriteLine(window.Size.Y); //Console.WriteLine(map.Y - window.Size.Y); view.Size = new Vector2f(window.Size.X,window.Size.Y); if (camPos.X < window.Size.X / 2) { camPos.X = window.Size.X / 2; } else if (camPos.X > map.X - window.Size.X / 2) { camPos.X = map.X - window.Size.X / 2; } if (camPos.Y < window.Size.Y / 2) { camPos.Y = window.Size.Y / 2; } else if (camPos.Y > map.Y - window.Size.Y / 2) { camPos.Y = map.Y - window.Size.Y / 2; } view.Center = camPos; window.SetView(view); Map01.hud.setView(view); }
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 void WinMenu() { View view1 = new View(new Vector2f(Settings.XResolution / 2, Settings.YResolution / 2), new Vector2f(Settings.XResolution, Settings.YResolution)); view1.Viewport = new FloatRect(0f, 0f, 1f, 1f); view1.Size = new Vector2f(Settings.XResolution, Settings.YResolution); _window.SetView(view1); SFML.Graphics.Sprite background = new SFML.Graphics.Sprite(new Texture(@"..\..\..\..\Assets\Backgrounds\time-travel-background.png")); if (background == null) { throw new Exception("Sprite null!"); } _window.Draw(background); List <Text> lines = new List <Text>(); //Lines lines.Add(new Text("PLAYER 1 WIN !", _globalFont, 64)); lines.Add(new Text("in : " + _game.TimeElapsed / 1000 + " seconds !", _globalFont, 48)); lines.Add(new Text("With " + _game.GetPlayer.GetLife.GetCurrentPoint + " HP.", _globalFont, 32)); lines.Add(new Text("Press ENTER/A to QUIT", _globalFont, 32)); for (int i = 0; i < lines.Count; i++) { RectangleShape r = new RectangleShape(new Vector2f(lines[i].GetGlobalBounds().Width + 20, lines[i].GetGlobalBounds().Height + 20)); r.FillColor = Color.White; if (i == 0) { lines[i].FillColor = Color.Green; } else if (i == lines.Count - 1) { r.FillColor = Color.Black; lines[i].FillColor = Color.White; } else { lines[i].FillColor = Color.Black; } lines[i].Position = new SFML.System.Vector2f(_window.Size.X / 2 - (lines[i].GetGlobalBounds().Width) / 2, (_window.Size.Y / 6) * (i + 1)); r.Position = new Vector2f(lines[i].Position.X - 10, lines[i].Position.Y); _window.Draw(r); _window.Draw(lines[i]); } _window.Display(); bool quit = false; while (!quit) { Joystick.Update(); if (Keyboard.IsKeyPressed(Keyboard.Key.Enter) || (Joystick.IsConnected(0) && Joystick.IsButtonPressed(0, 0))) { quit = true; } System.Threading.Thread.Sleep(1); } // QUAND QUITTE LE MENU _menu = new Menu(_window); _settings = new Settings(this, _window); _gui = new GUI(this, _window); _timer = new Stopwatch(); _timer.Start(); _game = null; }
public static void Init() { ContextSettings settings = new ContextSettings (32, 8, 4, 3, 3); Styles windowStyle = Styles.Close; if (FULLSCREEN) { windowStyle = Styles.Fullscreen; Game.Width = FULLSCREEN_WIDTH; Game.Height = FULLSCREEN_HEIGHT; Game.CameraWidth = FULLSCREEN_WIDTH; Game.CameraHeight = FULLSCREEN_HEIGHT; } Context = new RenderWindow (new VideoMode ((uint)Game.Width, (uint)Game.Height), WindowTitleText, windowStyle, settings); Context.Closed += OnClose; Context.KeyPressed += KeyPressed; Context.KeyReleased += KeyReleased; // Context.MouseMoved += MouseMoved; // Context.MouseButtonPressed += MouseButtonPressed; // Context.MouseButtonReleased += MouseButtonReleased; // Context.MouseWheelMoved += MouseWheelMoved; // Context.JoystickButtonPressed += JoystickButtonPressed; // Context.JoystickButtonReleased += JoystickButtonReleased; // Context.JoystickConnected += JoystickConnected; // Context.JoystickDisconnected += JoystickDisconnected; // Context.JoystickMoved += JoystickMoved; Context.SetKeyRepeatEnabled (true); Rand = new Random (); EventMgr = new EventManager (); World = new GameWorld (); Camera = new View (); Camera.Center = new Vector2f (CameraWidth / 2, CameraHeight / 2); Camera.Size = new Vector2f (CameraWidth, CameraHeight); // Half Size Context.SetView (Camera); // Context.SetView(Context.DefaultView); // Resets the view to the window size. Good for drawing UI }
static void Main() { //Get the splash screen graphic System.Windows.SplashScreen EngineSplashScreen = new System.Windows.SplashScreen("Resources/SplashScreen.jpg"); EngineSplashScreen.Show(true);//Show splash screen // initialize the main engine form EngineMessage("Intializing Pixel Engine", eEngineMessageType.NONE); form = new Form1(); form.Show(); // show our form LoadCfg(); //Load config files DrawingSurface rendersurface = new DrawingSurface(); rendersurface.Size = new System.Drawing.Size(form.Width, form.Height); rendersurface.Location = new System.Drawing.Point(0, 0); form.Controls.Add(rendersurface); EngineMessage("Pixel Engine Ready!", eEngineMessageType.CONFIRM); // initialize sfml SFML.Graphics.RenderWindow renderwindow = new SFML.Graphics.RenderWindow(rendersurface.Handle); //Main cam SFML.Graphics.View mainRenderView = new SFML.Graphics.View(new FloatRect(0, 0, 1920, 1080)); renderwindow.SetView(mainRenderView); //UI Cam SFML.Graphics.View uiRenderView = new SFML.Graphics.View(new FloatRect(0, 0, 1920, 1080)); _scene = new EditorScene(renderwindow, mainRenderView); //Initialize the resources form resourcesForm = new ResourcesForm(); resourcesForm.Size = new System.Drawing.Size(800, 600); resourcesForm.Location = new System.Drawing.Point(form.Location.X + form.Width, form.Location.Y); resourcesForm.Show(); resourcesForm.Disposed += new EventHandler(DisposedResourceForm); //Debug: create sprite PixelEngineProj.Gameplay.PixelSprite newSprite = new PixelEngineProj.Gameplay.PixelSprite("Resources/SpriteIcon.png", new IntRect(0, 0, 128, 128), new Vector2f(0, 0)); newSprite.Position = new Vector2f(0, 0); Text t = new Text("Testing", new Font("Resources/pixelmix.ttf")); // drawing loop while (form.Visible) { System.Windows.Forms.Application.DoEvents(); renderwindow.DispatchEvents(); renderwindow.Clear(new SFML.Graphics.Color(40, 40, 40)); //Draw main scene renderwindow.SetView(mainRenderView); _scene.Draw(renderwindow); renderwindow.SetView(uiRenderView); //Draw engine text renderwindow.SetView(uiRenderView); t.Position = new Vector2f(1700, 100); t.Draw(renderwindow, RenderStates.Default); renderwindow.Display(); rendersurface.Size = new System.Drawing.Size(form.Width - 300, form.Height); } }
public override void Draw(RenderWindow window) { window.SetView(window.DefaultView); window.Draw(_background); window.Draw(_logo); }
public void SetViewToThisNPC(RenderWindow rw) { int tempoffsetX = 0; int tempoffsetY = 0; switch (Dir) { case 0: tempoffsetX = -WalkCount; break; case 1: tempoffsetY = -WalkCount; break; case 2: tempoffsetX = WalkCount; break; case 3: tempoffsetY = WalkCount; break; } rw.SetView(new View(new FloatRect((X + Program.MyMap.MinX) * 16 - 8 - rw.Size.X / 2 + tempoffsetX, (Y + Program.MyMap.MinY) * 16 - 8 - rw.Size.Y / 2 + tempoffsetY, rw.Size.X, rw.Size.Y))); }
public void Run() { window = new RenderWindow(new VideoMode(1280, 720), "DOX30 Editor", Styles.Titlebar | Styles.Close); window.Closed += window_Closed; window.Resized += window_Resized; window.MouseWheelMoved += window_MouseWheelMoved; window.MouseButtonPressed += window_MouseButtonPressed; window.MouseMoved += window_MouseMoved; window.MouseButtonReleased += window_MouseButtonReleased; window.KeyPressed += window_KeyPressed; window.KeyReleased += window_KeyReleased; world = new PhysicsWorld(true); ui = new UISceneManager(); ui.Init(window); Scene scene = new Scene(ScrollInputs.None); RectControl bg = new RectControl() { Position = new Vector2f(0, 0), Size = new Vector2f(1280, 50), Anchor = AnchorPoints.Left | AnchorPoints.Top | AnchorPoints.Right, BackgroundColor = Colors.WhiteSmoke }; FastButton runButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/playButton.png", "Content/playButton.png", "Content/playButton.png") { Position = new Vector2f(0, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; runButton.OnClick += (s, e) => { enabled = true; }; FastButton pauseButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/pauseButton.png", "Content/pauseButton.png", "Content/pauseButton.png") { Position = new Vector2f(50, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; pauseButton.OnClick += (s, e) => { enabled = false; }; FastButton saveButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/saveButton.png", "Content/saveButton.png", "Content/saveButton.png") { Position = new Vector2f(125, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; saveButton.OnClick += (s, e) => { Export(); }; FastButton loadButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/loadButton.png", "Content/loadButton.png", "Content/loadButton.png") { Position = new Vector2f(175, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; loadButton.OnClick += (s, e) => { var ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Filter = "Level Files (*.json)|*.json"; ofd.InitialDirectory = Directory.GetCurrentDirectory(); var r = ofd.ShowDialog(); if (r == System.Windows.Forms.DialogResult.OK) { Import(ofd.FileName); } }; FastButton addBoxButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/boxButton.png", "Content/boxButton.png", "Content/boxButton.png") { Position = new Vector2f(250, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; addBoxButton.OnClick += (s, e) => { world.CreateBox(new Vector2f(10, 10), 4, BodyType.Static).Position = new Vector2(offset.X, offset.Y) * -0.1f; world.Step(0); }; FastButton addCircleButton = new FastButton(new Font("Content/font.ttf"), 22, "Content/circleButton.png", "Content/circleButton.png", "Content/circleButton.png") { Position = new Vector2f(300, 0), Size = new Vector2f(50, 48), Text = "", Anchor = AnchorPoints.Left | AnchorPoints.Top }; addCircleButton.OnClick += (s, e) => { world.CreateCircle(5, 5, BodyType.Static).Position = new Vector2(offset.X, offset.Y) * -0.1f; world.Step(0); }; scene.AddComponent(bg); scene.AddComponent(runButton); scene.AddComponent(pauseButton); scene.AddComponent(addBoxButton); scene.AddComponent(addCircleButton); scene.AddComponent(saveButton); scene.AddComponent(loadButton); // scene.AddComponent(new WorldHierachyRenderer(world) { Size = new Vector2f(300, 670), Position = new Vector2f(0, 50), BackgroundColor = Colors.Snow }); // Does not update on change dynamic/static ui.CurrentScene = scene; grid = new Sprite(new Texture("Content/grid.png")); grid.Origin = new Vector2f(512, 512); contextMenu = new ContextMenu(); contextMenu.Add(() => { selected.BodyType = BodyType.Dynamic; }, "Set Dynamic"); contextMenu.Add(() => { selected.BodyType = BodyType.Static; }, "Set Static"); contextMenu.Add(() => { world.FindBody(selected).GameDimension = Dimension.None; }, "Set No Dimension"); contextMenu.Add(() => { world.FindBody(selected).GameDimension = world.FindBody(selected).GameDimension == Dimension.OneO ? Dimension.TwoX : Dimension.OneO; }, "Switch Dimension"); contextMenu.Add(() => { selected.Rotation += 0.0872664626f; }, "+5 Rotation"); contextMenu.Add(() => { selected.Rotation += 0.785398163f; }, "+45 Rotation"); contextMenu.Add(() => { selected.Rotation -= 0.0872664626f; }, "-5 Rotation"); contextMenu.Add(() => { selected.Rotation -= 0.785398163f; }, "-45 Rotation"); contextMenu.Add(() => { world.Copy(selected, new Vector2(offset.X, offset.Y) * -0.1f); }, "Duplicate"); contextMenu.Add(() => { world.Remove(selected); }, "Remove"); messageScene = new Scene(ScrollInputs.None); Stopwatch sw = new Stopwatch(); TimeSpan elapsed = TimeSpan.Zero; TimeSpan secondCounter = TimeSpan.Zero; int frames = 0; world.Step(0); View v; Console.WriteLine(window.GetView().Center); while (window.IsOpen()) { sw.Start(); window.DispatchEvents(); window.Clear(); if (enabled) world.Step((float)elapsed.TotalSeconds); v = window.GetView(); v.Zoom(zoom); v.Center = (world.CamLock == null ? -offset : new Vector2f(world.CamLock.Position.X * 10, world.CamLock.Position.Y * 10)); if (world.CamLock != null) v.Rotation = world.CamLock.Rotation * 57.2957795f; else v.Rotation = 0; window.SetView(v); window.Draw(grid); world.Render(window); v = window.GetView(); v.Size = new Vector2f(1280, 720); v.Rotation = 0; v.Center = new Vector2f(640, 360); window.SetView(v); ui.Render(window); ui.CurrentScene = messageScene; ui.Render(window); ui.CurrentScene = scene; contextMenu.Render(window); window.Display(); sw.Stop(); elapsed = sw.Elapsed; secondCounter += elapsed; frames++; if (secondCounter >= TimeSpan.FromSeconds(1)) { Console.WriteLine(frames / secondCounter.TotalSeconds); secondCounter -= TimeSpan.FromSeconds(1); frames = 0; } sw.Reset(); } }