public void SetupLightSprite() { lightTex = new Texture(@"Resources/sprites/sprite.png"); lightSprite = new Sprite(lightTex); lightSprite.Scale = new SFML.System.Vector2f(2, 2); lightSprite.Origin = new SFML.System.Vector2f(lightSprite.Texture.Size.X / 2, lightSprite.Texture.Size.Y / 2); lightSprite.Position = window.GetView().Center; }
public GameScreen(RenderWindow window) { Window = window; GuiView = new View(Window.GetView()); GameGuiView = new View(Window.GetView()); Gui = new EditorBaseWidget(Window, GuiView); Gui.Dimension = GuiView.Size; PlayerHdl.Instance.Init(""); MapHandler.Instance.SetGameRoot(Window); MapMan.Instance.InitMap(GameData.INIT_MAP); Gui.AddWindow(MiscWidget.Instance, true); Gui.AddWindow(MapHandler.Instance, true); Gui.AddWindow(MapMan.Instance, true); Gui.AddWindow(PointCreator.Instance); Gui.AddWindow(WarpPointCreator.Instance); Gui.AddWindow(MapCreator.Instance); Gui.AddWindow(ObjectMan.Instance); Gui.AddWindow(ObjectCreator.Instance); Gui.AddWindow(TextureMan.Instance); Gui.AddWindow(TextureCreator.Instance); Gui.AddWindow(TextureRemover.Instance); Gui.AddWindow(InformationDialogBox.Instance); Gui.AddWindow(ConfirmationDialogBox.Instance); Gui.AddWindow(BoundingBoxCreator.Instance); Gui.AddWindow(TextureRectDrawer.Instance); Gui.AddWindow(TileMan.Instance); Gui.AddWindow(TileSetMan.Instance); Gui.AddWindow(TileSetCreator.Instance); Gui.AddWindow(TileCreator.Instance); Gui.AddWindow(EventCreator.Instance); Gui.AddWindow(ActionCreator.Instance); Gui.AddKeyWindowBind(Keyboard.Key.M, MapMan.Instance); Gui.AddKeyWindowBind(Keyboard.Key.G, MiscWidget.Instance); Gui.AddKeyWindowBind(Keyboard.Key.O, ObjectMan.Instance); Gui.AddKeyWindowBind(Keyboard.Key.T, TextureMan.Instance); Gui.AddKeyWindowBind(Keyboard.Key.H, MapHandler.Instance); Gui.AddKeyWindowBind(Keyboard.Key.I, TileMan.Instance); Gui.AddKeyWindowBind(Keyboard.Key.L, TileSetMan.Instance); PlayerHdl.Vlad.ToScript(); }
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(); }
BlazeraProgram() { // GameEngine init ScriptEngine.Instance.Init("ProgramData"); TextureManager.Instance.Init(); SoundManager.Instance.Init(); // GraphicsEngine init Window = new RenderWindow(new VideoMode(GameData.WINDOW_WIDTH, GameData.WINDOW_HEIGHT), "Blazera program", GameData.WINDOW_STYLE); Window.Closed += new System.EventHandler(Window_Closed); WindowEvents.Instance.Init(Window); GuiView = new View(Window.GetView()); Gui = new EditorBaseWidget(Window, GuiView); Gui.Dimension = GuiView.Size; Border.Init(); Gui.AddWindow(ConfirmationDialogBox.Instance); Gui.AddWindow(InformationDialogBox.Instance); CallOnInit(); }
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(); } }
public override void input(RenderWindow _window) { if (Keyboard.IsKeyPressed(Keyboard.Key.A)) { if (mPosition.X > 0) mBody.ApplyLinearImpulse(new Vector2(-0.3f * Delta.mDelta, 0f)); else mBody.ApplyLinearImpulse(new Vector2(0.3f * Delta.mDelta, 0f)); } else if (Keyboard.IsKeyPressed(Keyboard.Key.D)) { if(mPosition.Y < 1280) mBody.ApplyLinearImpulse(new Vector2( 0.3f * Delta.mDelta, 0f)); else mBody.ApplyLinearImpulse(new Vector2(-0.3f * Delta.mDelta, 0f)); } if(Keyboard.IsKeyPressed(Keyboard.Key.Return)) { if(!mOnce) invincible(); } if (Keyboard.IsKeyPressed(Keyboard.Key.Space)) { if (mPosition.X > 0 && mPosition.X < 1280) mBody.ApplyLinearImpulse(new Vector2(0f, -0.9f * Delta.mDelta)); } if (Mouse.IsButtonPressed(Mouse.Button.Left)) { if (mShoot.ElapsedMilliseconds > 250) { Vector2i mousePos = Mouse.GetPosition(_window); Vector2f translated = _window.MapPixelToCoords(mousePos, _window.GetView()); Vector2f aim = new Vector2f(translated.X - mPosition.X, translated.Y - mPosition.Y); double angle = Math.Atan2(aim.Y, aim.X); mWorld.createBullet(mPosition, this, "resources/bullet.png", angle); mShoot.Restart(); } } }
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 Run() { var mode = new SFML.Window.VideoMode(800, 600); //var window = new SFML.Graphics.RenderWindow(SFML.Window.VideoMode.FullscreenModes[0], "Pokemon Union", SFML.Window.Styles.Fullscreen); var window = new SFML.Graphics.RenderWindow(mode, "Pokemon Union"); 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(); view.Size = new Vector2f(400, 300); this.resolutionScreen = new Vector2f(view.Size.X, view.Size.Y); view.Center = new Vector2f(9492, -12595); this.SetView(window, view); window.SetVerticalSyncEnabled(true); Clock clock = new Clock(); this.landWorld.OnFocusAreaChanged(view.Center / MODEL_TO_VIEW, this.resolutionScreen / MODEL_TO_VIEW); // Start the game loop while (window.IsOpen) { Time deltaTime = clock.Restart(); // Game logic update this.landWorld.UpdateLogic(null, deltaTime); // Draw window AObject2D.UpdateZoomAnimationManager(deltaTime); window.Clear(); this.landWorld2D.DrawIn(window, ref this.boundsView); // Process events window.DispatchEvents(); //// To remove after. //if (Keyboard.IsKeyPressed(Keyboard.Key.Z)) //{ // view.Center += new Vector2f(0, -2f); //} //else if(Keyboard.IsKeyPressed(Keyboard.Key.S)) //{ // view.Center += new Vector2f(0, 2f); //} //if (Keyboard.IsKeyPressed(Keyboard.Key.D)) //{ // view.Center += new Vector2f(2f, 0); //} //else if (Keyboard.IsKeyPressed(Keyboard.Key.Q)) //{ // view.Center += new Vector2f(-2f, 0); //} //// Console.WriteLine(view.Center.X + " : " + view.Center.Y); //this.landWorld.OnFocusAreaChanged(view.Center / MODEL_TO_VIEW, this.resolutionScreen / MODEL_TO_VIEW, 0); //this.SetView(window, view); // Finally, display the rendered frame on screen window.Display(); } this.landWorld2D.Dispose(this.landWorld); this.landWorld.Dispose(); AObject2D.StopAnimationManager(); }