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); }
void SfmlControl_Resize(object sender, EventArgs e) { Vector2f size = new Vector2f(1920f, 1080f); SFML.Graphics.View v = new SFML.Graphics.View(m_currentViewPosition, size); v.Zoom(m_currentZoom); float windowRatio = (float)this.Size.Width / (float)this.Size.Height; float viewRatio = 16f / 9f; float sizeX = 1f; float sizeY = 1f; float posX = 0f; float posY = 0f; bool horizontalSpacing = (windowRatio > viewRatio); if (horizontalSpacing) { sizeX = viewRatio / windowRatio; posX = (1f - sizeX) / 2f; } else { sizeY = windowRatio / viewRatio; posY = (1f - sizeY) / 2f; } v.Viewport = new FloatRect(posX, posY, sizeX, sizeY); m_renderWindow.SetView(v); }
public MapRenderer(IntPtr mapRenderWindowHandle, IntPtr tileSetRenderHandle, MapEditor.MapEditorProperties mapEditorProperties) { _mapRenderWindow = new RenderWindow(mapRenderWindowHandle); _tileSetRenderWindow = new RenderWindow(tileSetRenderHandle); _mapRenderWindow.MouseButtonPressed += mapRenderWindow_MouseButtonPressed; _mapRenderWindow.MouseMoved += mapRenderWindow_MouseMoved; _tileSetRenderWindow.MouseButtonPressed += tileSetRenderWindow_MouseButtonPressed; _tileSetRenderWindow.MouseMoved += tileSetRenderWindow_MouseMoved; _tileSetRenderWindow.MouseButtonReleased += tileSetRenderWindow_MouseButtonReleased; _mapEditorProperties = mapEditorProperties; _mapEditorProperties.CurrentLayer = World.Map.Layers.Ground; _mapEditorProperties.MapView = new View(this._mapRenderWindow.DefaultView); _mousePositionText = new Text("", new Font(AppDomain.CurrentDomain.BaseDirectory + "/Data/Graphics/Fonts/MainFont.ttf"), 20); this.LoadTileSets(); _tileSetView = this._tileSetRenderWindow.DefaultView; this.Running = true; this._mapRenderWindow.SetActive(false); this._tileSetRenderWindow.SetActive(false); new Thread(UpdateLoop).Start(); }
public override void DrawIn(RenderWindow window, Time deltaTime) { this.UpdateGraphics(deltaTime); List <AEntity2D> listObjects = this.objectToObject2Ds.Values.ToList(); listObjects.Sort(new EntityComparer()); foreach (AEntity2D entity2D in listObjects) { entity2D.UpdateGraphics(deltaTime); } SFML.Graphics.View defaultView = window.DefaultView; this.UpdateViewSize(defaultView.Size, deltaTime); window.SetView(this.view); FloatRect bounds = this.Bounds; foreach (AEntity2D entity2D in listObjects) { if (entity2D.IsActive && entity2D.Bounds.Intersects(bounds)) { entity2D.DrawIn(window, deltaTime); } } window.SetView(defaultView); }
void SfmlControl_Resize(object sender, EventArgs e) { Vector2f size = new Vector2f(this.Size.Width, this.Size.Height); SFML.Graphics.View v = new SFML.Graphics.View(new Vector2f(), size); m_renderWindow.SetView(v); }
public void RunGame(RenderWindow window, bool continueGame = false) { window.MouseButtonPressed += GameMouseDown; window.MouseButtonReleased += GameMouseUp; window.KeyPressed += GameKeyDown; InitGame(continueGame); Clock timer = new Clock(); View mainView = new SFML.Graphics.View { Size = new Vector2f(1600, 900), Center = new Vector2f(Game.Pentities[0].Position.X, Game.Pentities[0].Position.Y), Viewport = new FloatRect(0, 0, 1, 1) }; while (!exit) { if (Game.Start) { InitGame(true); } NextStep(mainView, window, timer.Restart()); } window.MouseButtonPressed -= GameMouseDown; window.MouseButtonReleased -= GameMouseUp; window.KeyPressed -= GameKeyDown; }
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 MainForm() { InitializeComponent(); resDispl = new DrawingSurface(); resDispl.Target.SetActive(false); resSprite = new DynamicSprite(); var tmp = new DrawingSurface(); tmp.Dock = DockStyle.Fill; Program.Display = tmp.Target; DisplayPanel.Controls.Add(tmp); Program.Display.Resized += (sender, e) => { SFML.Graphics.View view = new SFML.Graphics.View(new Vector2f(), new Vector2f(e.Width, e.Height)); Program.Display.SetView(view); }; tmp = new DrawingSurface(); Displayer = tmp; tmp.Dock = DockStyle.Fill; Program.Timeline = tmp.Target; TimelinePanel.Controls.Add(tmp); Program.Timeline.Resized += (sender, e) => { SFML.Graphics.View view = new SFML.Graphics.View(new FloatRect(0, 0, e.Width, e.Height)); Program.Timeline.SetView(view); Program.ResizeTimeline(); }; }
private void GenerateWorld() { if (m_initialized) { m_track.Dispose(); m_population.Dispose(); m_overviewView.Dispose(); } // create the world World = new World(Gravity); m_track = new Track(this); m_track.Generate(); m_track.FinishLineCrossed += TrackOnFinishLineCrossed; Car.Car.StartPosition = new Vector2(m_track.StartingLine, (2 * Definition.MaxBodyPointDistance) + Definition.MaxWheelRadius); // rebuild the view to match the track var size = m_overviewWindow.Size; var ratio = (float)size.Y / size.X; m_overviewView = new View { Center = m_track.Center.ToVector2f().InvertY(), Size = new Vector2f(m_track.Dimensions.X, m_track.Dimensions.X * ratio), Viewport = new FloatRect(0, 0, 1, 1) }; ResetPopulation(); }
public CluwneView(CluwneWindow window) { this._window = window; _worldView = new View(new FloatRect(0.0f, 0.0f, window.Size.X, window.Size.Y)); _interfaceView = new View(new FloatRect(0.0f, 0.0f, window.Size.X, window.Size.Y)); window.SetView(_worldView); }
public override void Init(Entity entity) { base.Init(entity); camera = new View(Target.Transform.Position, Global.Screen); camera.Zoom(2f); //camera.Rotate(45f); }
public Camera(GameWindow mGameWindow, int mWidth, int mHeight) { Debug.Assert(mGameWindow != null); _renderWindow = mGameWindow.RenderWindow; View = new View(new FloatRect(0, 0, mWidth, mHeight)); }
//// TO REMOVE //protected override void UpdateFocusedEntity2Ds() //{ // Vector2i mousePosition = this.MousePosition; // AEntity2D newFocusedEntity2D = null; // IEnumerable<AEntity2D> focusableEntities2D = this.GetEntities2DFocusable(); // foreach (AEntity2D entity2D in focusableEntities2D) // { // IHitRect hitRect = entity2D as IHitRect; // if (hitRect != null // && hitRect.IsFocusable(this) // && hitRect.HitZone.Contains(mousePosition.X, mousePosition.Y)) // { // if (newFocusedEntity2D == null // || (Math.Abs(mousePosition.X - entity2D.Position.X) + Math.Abs(mousePosition.Y - entity2D.Position.Y) // < Math.Abs(mousePosition.X - newFocusedEntity2D.Position.X) + Math.Abs(mousePosition.Y - newFocusedEntity2D.Position.Y))) // { // newFocusedEntity2D = entity2D; // } // } // } // this.FocusedGraphicEntity2D = newFocusedEntity2D as IHitRect; //} //// public override void DrawIn(RenderWindow window, Time deltaTime) { base.DrawIn(window, deltaTime); SFML.Graphics.View defaultView = window.DefaultView; window.SetView(this.view); //FloatRect bounds = this.Bounds; //foreach (CardEntity2D removingCardEntity2D in this.pendingRemovingCardEntities) //{ // if (removingCardEntity2D.IsActive // && removingCardEntity2D.Bounds.Intersects(bounds)) // { // removingCardEntity2D.DrawIn(window, deltaTime); // } //} this.awakenedBannerLabel2D.DrawIn(window, deltaTime); this.effectBanner2D.DrawIn(window, deltaTime); this.effectLabel2D.DrawIn(window, deltaTime); this.effectBehaviorLabel2D.DrawIn(window, deltaTime); this.endTurnButton.DrawIn(window, deltaTime); window.SetView(defaultView); }
public Camera(View view) { View = new View(view); Position = View.Size / 2; originalSize = View.Size; ActualPosition = Position; }
static void OnKeyPressed(object sender, KeyEventArgs e) { RenderWindow window = (RenderWindow)sender; SFML.Graphics.View v = window.GetView(); if (Keyboard.IsKeyPressed(Keyboard.Key.Add)) { v.Zoom(0.75f); } if (Keyboard.IsKeyPressed(Keyboard.Key.Subtract)) { v.Zoom(1.25f); } if (Keyboard.IsKeyPressed(Keyboard.Key.Return)) { conf.Speed += 50; } if (Keyboard.IsKeyPressed(Keyboard.Key.Space) && conf.Speed - 50 > 0) { conf.Speed -= 50; } window.SetView(v); }
private void SetupGrid(Vector2u mapSize) { const int gridSize = 16; _gridTexture = new RenderTexture(2000, 2000); var col = new Color(120, 120, 120); var verticies = new List<Vertex>(); for (int x = 0; x < mapSize.X; x += gridSize) { verticies.Add(new Vertex(new Vector2f(x, 0), col)); verticies.Add(new Vertex(new Vector2f(x, mapSize.Y), col)); } for (int y = 0; y < mapSize.Y; y += gridSize) { verticies.Add(new Vertex(new Vector2f(0, y), col)); verticies.Add(new Vertex(new Vector2f(mapSize.X, y), col)); } _gridlines = verticies.ToArray(); _gridTexture.Clear(new Color(190, 190, 190)); //_view = new View(new FloatRect(0,0,displaySize.X, displaySize.Y)); _view = new View(new FloatRect(0, 0, DisplayView.Size.X, DisplayView.Size.Y)); DisplayView = _view; //_gridTexture.SetView(_view); _gridTexture.Draw(_gridlines, PrimitiveType.Lines); _gridTexture.Display(); _grid = new Sprite(_gridTexture.Texture); AddItemToDraw(_grid, 0); }
public ALayer2D(World2D world2D, IObject2DFactory layerFactory, ALayer layer) : base(layerFactory) { this.parentFactory = layerFactory; this.ChildrenLayer2D = new List <ALayer2D>(); this.view = new SFML.Graphics.View(); this.defaultViewSize = new Vector2f(-1, -1); this.Position = new Vector2f(0, 0); this.Area = new Vector2i(0, 0); this.objectToObject2Ds = new Dictionary <AEntity, AEntity2D>(); this.object2DToObjects = new Dictionary <AEntity2D, AEntity>(); //this.focusedEntity2Ds = new HashSet<IHitRect>(); this.world2D = new WeakReference <World2D>(world2D); this.zoom = 1; this.parentLayer = layer; this.parentLayer.EntityAdded += OnEntityAdded; this.parentLayer.EntityRemoved += OnEntityRemoved; this.parentLayer.PositionChanged += OnPositionChanged; this.parentLayer.RotationChanged += OnRotationChanged; this.parentLayer.EntityPropertyChanged += OnEntityPropertyChanged; this.parentLayer.LevelStateChanged += OnLevelStateChanged; }
public Form1() { InitializeComponent(); RENDER_SURFACE = new DrawingSurface(); RENDER_SURFACE.Size = new System.Drawing.Size(1920, 1080); RENDER_SURFACE.Dock = DockStyle.Fill; Controls.Add(RENDER_SURFACE); RENDER_SURFACE.Location = new System.Drawing.Point(100, 100); RENDER_SURFACE.BringToFront(); //Init sfml settings.AntialiasingLevel = 16; RENDER_WINDOW = new RenderWindow(RENDER_SURFACE.Handle, settings); //Create the main viewport view VIEWPORT_CAMERA_VIEW = new EditorCamera(new FloatRect(0, 0, RENDER_SURFACE.Width, RENDER_SURFACE.Height)); VIEWPORT_UI_VIEW = new SFML.Graphics.View(new FloatRect(0, 0, RENDER_SURFACE.Width, RENDER_SURFACE.Height)); //Render surface events RENDER_SURFACE.MouseClick += new MouseEventHandler(VIEWPORT_CAMERA_VIEW.OnMouseClick); RENDER_SURFACE.MouseWheel += new MouseEventHandler(VIEWPORT_CAMERA_VIEW.OnMouseScroll); //Init editor debug info EditorDebugInfo = new string[1]; this.FormClosed += new FormClosedEventHandler(OnEditorClose); }
public ExploringState() { //Pretty loading here map = new TileMap(); player = new PlayerCharacter(map, new Vector2i(15,15)); exploringView = new View(Program.Window.GetView()); defaultView = Program.Window.DefaultView; }
//////////////////////////////////////////////////////////// /// <summary> /// Create the render-texture with the given dimensions and /// an optional depth-buffer attached /// </summary> /// <param name="width">Width of the render-texture</param> /// <param name="height">Height of the render-texture</param> /// <param name="depthBuffer">Do you want a depth-buffer attached?</param> //////////////////////////////////////////////////////////// public RenderTexture(uint width, uint height, bool depthBuffer) : base(sfRenderTexture_create(width, height, depthBuffer)) { myDefaultView = new View(sfRenderTexture_getDefaultView(CPointer)); myTexture = new Texture(sfRenderTexture_getTexture(CPointer)); GC.SuppressFinalize(myDefaultView); GC.SuppressFinalize(myTexture); }
//////////////////////////////////////////////////////////// /// <summary> /// Create the render image with the given dimensions and /// an optional depth-buffer attached /// </summary> /// <param name="width">Width of the render image</param> /// <param name="height">Height of the render image</param> /// <param name="depthBuffer">Do you want a depth-buffer attached?</param> //////////////////////////////////////////////////////////// public RenderImage(uint width, uint height, bool depthBuffer) : base(sfRenderImage_Create(width, height, depthBuffer)) { myDefaultView = new View(sfRenderImage_GetDefaultView(This)); myImage = new Image(sfRenderImage_GetImage(This)); GC.SuppressFinalize(myDefaultView); GC.SuppressFinalize(myImage); }
public SfmlVisualizer() { // init sprites background = Sprites.Background_Union(); // init fonts var courierFontFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "cour.ttf"); if (!File.Exists(courierFontFileName)) { courierFontFileName = Path.Combine(Settings.Default.ResourcesDir, "cour.ttf"); if (!File.Exists(courierFontFileName)) { MessageBox.Show($"cour.ttf could not be found, please copy it into the folder '{Settings.Default.ResourcesDir}'"); } } courier = new Font(courierFontFileName); // init window var contextSettings = new ContextSettings(); WindowSizeW = Settings.Default.WindowSizeW; WindowSizeH = Settings.Default.WindowSizeH; window = new RenderWindow(new VideoMode(WindowSizeW, WindowSizeH), "AI Cup 2016 Visualizer", Styles.Resize | Styles.Close, contextSettings); window.SetVerticalSyncEnabled(false); window.Closed += OnClose; // window.Resized += OnResized; window.MouseWheelScrolled += WindowOnMouseWheelScrolled; window.KeyPressed += WindowOnKeyPressed; window.MouseButtonReleased += WindowOnMouseButtonReleased; window.MouseMoved += WindowOnMouseMoved; // generate background random tiles tmpTexture = new RenderTexture((uint)mapSize.X, (uint)mapSize.Y); tmpTexture.Draw(background); DrawGroundRandomTiles(tmpTexture); tmpTexture.Display(); background = new Sprite(tmpTexture.Texture); // background.Texture.CopyToImage().SaveToFile(Path.Combine(Settings.Default.ResourcesDir, "1.bmp")); // init views defaultView = window.DefaultView; worldView = new View(new FloatRect(0, 0, mapSize.X, mapSize.Y)); worldTexture = new RenderTexture((uint)mapSize.X, (uint)mapSize.Y); visibleAreaTexture = new RenderTexture((uint)mapSize.X, (uint)mapSize.Y); minimapTexture = new RenderTexture((uint)mapSize.X, (uint)mapSize.Y); minimapView = new View(new FloatRect(0, 0, mapSize.X, mapSize.Y)); // init other stuff clock = new Clock(); observeTarget = Settings.Default.ObserveTarget; showDebugInfo = false; showHealth = false; showMinimap = Settings.Default.ShowMinimap; ForceSmooth = false; showWayPoints = false; Audios.EnabledAudio = Settings.Default.EnableAudio; }
public EditorScene(SFML.Graphics.RenderWindow drawingWindow, SFML.Graphics.View drawingView) { w = drawingWindow; v = drawingView; //Debug, add new sprites here spriteBatch = new Sprite[0]; sceneObjects = new PixelEngineProj.System.PixelObject[0]; }
public IngameShipState(WindowManager WM) : base(WM) { CurrentMap = new IngameObjects.NetworkWorld(this); GameView = new View(); //WM.AddWindow(new Windows.MainMenu(WM, this, 100, 100, 250, 200)); Chat = new Windows.ChatBox(WM, this, 100, 100, 250, 200); WM.AddWindow(Chat); }
private void MainWindowResizeEnd(object sender, SizeEventArgs e) { var view = new SFML.Graphics.View( new SFML.System.Vector2f(e.Width / 2, e.Height / 2), new SFML.System.Vector2f(e.Width, e.Height) ); CluwneLib.Screen.SetView(view); _stateManager.FormResize(); }
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(); }
public void Run() { TextureLoader.Init(); Window = new RenderWindow(videoMode, title, Styles.Close); States = new RenderStates(RenderStates.Default); Window.Closed += (s, e) => { Console.WriteLine("Closing..."); Window.Close(); }; Window.SetVerticalSyncEnabled(true); defaultView = Window.DefaultView; gameView = Window.DefaultView; gameView.Viewport = new FloatRect(0, 0, .85f, .85f); BackgroundColor = new Color(100, 149, 237); // dat cornflower blue Tilemap = new Tilemap(this); SelectedTileID = 1; var timer = new Stopwatch(); while (Window.IsOpen) { timer.Restart(); Window.DispatchEvents(); var mouse = Mouse.GetPosition(Window); //if (Mouse.IsButtonPressed(Mouse.Button.Right)) // gameView.Move(new Vector2f(prevMouse.X - mouse.X, prevMouse.Y - mouse.Y)); Tilemap.Update(Frametime); Window.Clear(BackgroundColor); Window.SetView(gameView); Tilemap.Draw(Window, States); Window.SetView(defaultView); Debug.Draw(Window); Window.Display(); prevMouse = mouse; timer.Stop(); Frametime = (float)timer.Elapsed.TotalMilliseconds; Window.SetTitle($"{title} ({(1d / timer.Elapsed.TotalSeconds):0}fps)"); } }
public override void DrawIn(RenderWindow window, Time deltaTime) { base.DrawIn(window, deltaTime); SFML.Graphics.View defaultView = window.DefaultView; window.SetView(this.view); this.imageBackground2D.DrawIn(window, deltaTime); window.SetView(defaultView); }
public void Initialize() { world = (LayeredWorld)WorldManager.Worlds["first_world"]; view = new View(new Vector2f(100, 0), new Vector2f(50, 50)); view.Zoom(10); player = new Player(world.PlayerStartPosition); Program.RenderWindow.KeyPressed += RenderWindow_KeyPressed; }
public static void Initialize() { gTime = new GameTime(); map = new Map(new System.Drawing.Bitmap("Bilder/Map.bmp")); Player = new Player(new Vector2f(map.TileSize + 30, map.TileSize + 30)); mons01 = new Monster01("Bilder/Monster.png", new Vector2f(800, 100)); mons02 = new Monster01("Bilder/Monster.png", new Vector2f(100, 600)); tool = new Tools("Bilder/Tool1.png", new Vector2f (800, 800)); // vulkan = new Vulkan("Bilder/Vulkan.png", new Vector2f(500, 500); view = new View(); view.Center = Player.Position; }
public GameStateStart(Game game) { this._view = new View(); this.Game = game; var pos = (Vector2f)this.Game.Window.Size;//new Vector2f(this.Game.Window.Size.X, this.Game.Window.Size.Y); this._view.Size = pos; this._view.Center = pos * 0.5f; this.Game.Window.Resized += Window_Resized; this.Game.Window.KeyPressed += Window_KeyPressed; }
public void Resize(float mXOffset, float mYOffset, float mWidth, float mHeight) { Debug.Assert(mWidth > 0 && mHeight > 0); View = new View(new FloatRect(0, 0, mWidth, mHeight)) { Viewport = new FloatRect(mXOffset/_renderWindow.Size.X, mYOffset/_renderWindow.Size.Y, mWidth/_renderWindow.Size.X, mHeight/_renderWindow.Size.Y) }; }
public override void DrawIn(RenderWindow window, Time deltaTime) { base.DrawIn(window, deltaTime); SFML.Graphics.View defaultView = window.DefaultView; window.SetView(this.view); //this.cardToolTip.DrawIn(window, deltaTime); //this.endTurnButton.DrawIn(window, deltaTime); this.scoreLabel.DrawIn(window, deltaTime); window.SetView(defaultView); }
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 override void DrawIn(RenderWindow window, Time deltaTime) { base.DrawIn(window, deltaTime); SFML.Graphics.View defaultView = window.DefaultView; window.SetView(this.view); this.startButton.DrawIn(window, deltaTime); this.player1DeckBuildingButton.DrawIn(window, deltaTime); this.player2DeckBuildingButton.DrawIn(window, deltaTime); window.SetView(defaultView); }
public void Run() { //Construction de la première matrice Clock c = new Clock(); matrice = Decorator.Decorate(grid, conf.pixelSize); //Boucle d'affichage while (App.IsOpen) { //Gestion des évènements fenêtre App.DispatchEvents(); SFML.Graphics.View v = App.GetView(); if (Keyboard.IsKeyPressed(Keyboard.Key.Up)) { v.Move(new Vector2f(0.0f, -0.5f)); } if (Keyboard.IsKeyPressed(Keyboard.Key.Down)) { v.Move(new Vector2f(0.0f, 0.5f)); } if (Keyboard.IsKeyPressed(Keyboard.Key.Right)) { v.Move(new Vector2f(0.5f, 0.0f)); } if (Keyboard.IsKeyPressed(Keyboard.Key.Left)) { v.Move(new Vector2f(-0.5f, 0.0f)); } App.SetView(v); if (c.ElapsedTime.AsMilliseconds() > conf.Speed && !Over) //Tous les X temps { Observable(this, new TickEvent()); //Envoit d'un event de tick c.Restart(); //Restart de l'horloge } if (Over) { Console.Out.WriteLine("Fin du Game"); App.Close(); } //CDD App.Clear(Color.Cyan); App.Draw(matrice); App.Display(); } }
private void CompositionTarget_Rendering(object sender, EventArgs e) { float deltaTime = clock.Restart().AsSeconds(); time += deltaTime; if (time >= 1) { Title = initialTitle + " " + ((uint)(1 / deltaTime)).ToString() + " FPS"; time = 0; } surface.DispatchEvents(); robot.UpdatePointCloud(obstacles); robot.Update(deltaTime); var updateView = new SFML.Graphics.View(robot.Position, (Vector2f)surface.Size); updateView.Zoom(Zoom); surface.SetView(updateView); surface.Clear(); surface.Draw(simulationGrid); foreach (var obstacle in obstacles) { surface.Draw(obstacle.ToArray(), PrimitiveType.LineStrip); } foreach (var trajectoryCirlce in robot.Trajectory) { surface.Draw(trajectoryCirlce); foreach (var impactCircle in trajectoryCirlce.ImpactCircles) { surface.Draw(impactCircle); } } foreach (var sensor in robot.Sensors) { surface.Draw(sensor); } surface.Draw(robot); surface.Display(); }
private void TrackOnFinishLineCrossed(int id) { PauseSimulation(); // render a zoomed in view of the winning car const float width = 8; var ratio = m_drawingView.Size.Y / m_drawingView.Size.X; View winnerView = new View { Center = m_population.Leader.Position.ToVector2f().InvertY(), Size = new Vector2f(width, width * ratio), Viewport = new FloatRect(0, 0, 1, 1) }; m_drawingWindow.SetView(winnerView); m_drawingWindow.Clear(Color.White); m_track.Draw(m_drawingWindow); m_population.Draw(m_drawingWindow); m_drawingWindow.Display(); // save a screenshot var filename = string.Format( "pid{3}_gen{0}_car{1}_{2:yyyy-MM-dd_HH-mm-ss}.png", m_population.Generation, id, DateTime.Now, Process.GetCurrentProcess().Id); m_drawingWindow.Capture().SaveToFile(filename); Log.InfoFormat("Screenshot of winner saved to {0}", filename); var message = string.Format( "Track defeated in generation {0} by car {1}.\n" + "Click Yes to generate a new world with a new seed, or No to exit.", m_population.Generation, id ); var result = MessageBox.Show(message, "Great Success", MessageBoxButtons.YesNo, MessageBoxIcon.None); if (result == DialogResult.Yes) { m_newWorld = true; } else { m_exit = true; } ResumeSimulation(); }
// BASE OVERRIDES public override void InitializeState() { Vector2f vecViewCenter = new Vector2f((Engine.Instance.GameWindow.Size.X) / 2, (Engine.Instance.GameWindow.Size.Y) / 2); View = new SFML.Graphics.View(vecViewCenter, (Vector2f)Engine.Instance.GameWindow.Size); Engine.Instance.GameWindow.SetView(View); this.UI = UI_MainMenu.CreateMainMenuInterface(ref Engine.Instance, this); this.IsStateActive = true; this.IsStateAlive = true; this.StateName = nameof(MainMenuState); FileStream fsImageStream = new FileStream(@"Assets\Backgrounds\MMBG01.png", FileMode.Open); BGTexture = new Texture(fsImageStream); BGSprite = new Sprite(BGTexture); }
public void draw(RenderWindow win, View view) { if (resetView) { view.Center = Vector2.Zero; view.Zoom(100F / view.Size.Y); resetView = false; } win.Draw(bg); Map.Draw(win); AlignmentManager.Draw(win); ParticleManager.Draw(win); EnemyManager.Draw(win); Player.Draw(win); }
/// <summary> /// Derived classes override this to initialize their drawing code. /// </summary> protected override void Initialize() { base.Initialize(); if (DesignMode) { return; } m = new TransBoxManager(); _drawingManager = new DrawingManager(); _drawView = new View(); _camera = new Camera2D(new Vector2(400, 300)); _camera.Size = ScreenSize; _camera.Scale = 1.0f; }
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(); }
static public List <PopUpInfo> ListOfPopingUpInfo = new List <PopUpInfo>();// if public GameObj() { ObjectsBank.GameFrame = this; UserLeftSite = new SFML.Graphics.View(new FloatRect(0, 0, 800, 900)) { Viewport = new FloatRect(0, 0, 8 / 18f, 1f) }; MapRightSite = new SFML.Graphics.View(new FloatRect(0, 0, 1000, 900)) { Viewport = new FloatRect(8 / 18f, 0, 10 / 18f, 1f) }; ListOfPopingUpInfo.Add(new PopUpInfo("Siema siema, o tej porze kazdy wypic morze", this)); ListOfPopingUpInfo.Add(new PopUpInfo("A to kolejne info w kolejce", this)); ListOfPopingUpInfo.Add(new PopUpInfo("A te jeszcze jedno", this)); }
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 TilesOnWindow(SFML.Graphics.View view)// this function specifiin which tiles should be drawn on descop { TilesOnScreen.Clear(); int squareside = 700; UpRow = (int)((view.Center.Y - squareside) / 80); DownRow = (int)((view.Center.Y + squareside) / 80); LeftColumn = (int)((view.Center.X - squareside) / 80); RightColumn = (int)((view.Center.X + squareside) / 80); if (UpRow < 0) { UpRow = 0; } ; if (DownRow > nr_rows - 1) { DownRow = nr_rows - 1; } ; if (LeftColumn < 0) { LeftColumn = 0; } ; if (RightColumn > nr_columns - 1) { RightColumn = nr_columns - 1; } ; lock (TilesOnScreen) { for (int i = UpRow; i <= DownRow; i++) { for (int j = LeftColumn; j <= RightColumn; j++) { TilesOnScreen.Add(MapStructure[i, j]); } } } }
public World(RenderWindow window) { mWindow = window; mWorldView = window.DefaultView; mWorldBounds = new IntRect(0, 0, (int)mWorldView.Size.X, 2000); //have to explcitly cast Size.X from float to int because of cast issues between IntRect and FloatRect later on mSpawnPosition = new Vector2f(mWorldView.Size.X / 2, mWorldBounds.Height - mWorldView.Size.Y); //original code is mWorldBounds.Height - mWorldView.Size, but caused error mScrollSpeed = -50; //this is not included in book but in source code mSceneLayers = new SceneNode[(int)Layer.LayerCount]; mTextures = new ResourceHolder<Texture, ResourceID>(); mSceneGraph = new SceneNode(); mPlayerAircraft = null; mCommandQueue = new CommandQueue(); mWorldView.Center = mSpawnPosition; loadTextures(); buildScene(); }
/// <summary> /// initialize Player and Enemies, by calling the constructors /// </summary> public static void Initialize() { gTime = new GameTime(); BackgroundMusic = new Sound(new SoundBuffer("Sound/asia_1.ogg")); BackgroundMusic.Loop = true; BackgroundMusic.Volume = 30; BackgroundMusic.Play(); JumpSound = new Sound(new SoundBuffer("Sound/jumpSound.wav")); JumpSound.Volume = 100; map = new Map(new System.Drawing.Bitmap("Pictures/Map.bmp")); Player = new Player(new Vector2f(map.TileSize + 30, map.TileSize + 30)); enemy1 = new Enemy("Pictures/EnemyGreen.png", new Vector2f(800, 100), "Pictures/EnemyGreenMove.png"); enemy2 = new Enemy("Pictures/EnemyRed.png", new Vector2f(100, 600), "Pictures/EnemyGreenMove.png"); Camera = new View(new FloatRect(0, 0, 1200, 1000)); }
public void TilesToCheckColision(SFML.Graphics.View view) // need additional if , if tile is land (or city) or mielizna add to list !!! { // one additional if will be excecudet on about 10 tiles so t is not very hard TilesToColision = new ConcurrentBag <RectangleShape>(); int squareColision = 40; UpRow = (int)((view.Center.Y - squareColision) / 80); DownRow = (int)((view.Center.Y + squareColision) / 80); LeftColumn = (int)((view.Center.X - squareColision) / 80); RightColumn = (int)((view.Center.X + squareColision) / 80); if (UpRow < 0) { UpRow = 0; } ; if (DownRow > nr_rows - 1) { DownRow = nr_rows - 1; } ; if (LeftColumn < 0) { LeftColumn = 0; } ; if (RightColumn > nr_columns - 1) { RightColumn = nr_columns - 1; } ; for (int i = UpRow; i <= DownRow; i++) { for (int j = LeftColumn; j <= RightColumn; j++) { if (MapStructure[i, j].type > 0)// becouse 0 means pure water, so look for anything but water { TilesToColision.Add(MapStructure[i, j]); } } } }
public MenuState(StateStack stack, Context context) : base(stack, context) { mGUIContainer = new Container(); mBackgroundSprite = new Sprite(context.textures.get(ResourceID.TitleScreen)); mViewBounds = new IntRect(0, 0, (int)mContext.window.Size.X, (int)mContext.window.Size.Y); Vector2f center = new Vector2f(mContext.window.Size.X / 2, mContext.window.Size.Y / 2); mView = mContext.window.DefaultView; mView.Center = center; Button playButton = new Button(context.fonts, context.textures); playButton.Position = new Vector2f(100, 250); playButton.setText("Play"); playButton.setCallback(() => { requestStackPop(); requestStackPush(StateID.Game); }); Button settingsButton = new Button(context.fonts, context.textures); settingsButton.Position = new Vector2f(100, 300); settingsButton.setText("Settings"); settingsButton.setCallback(() => { requestStackPush(StateID.Setting); }); Button exitButton = new Button(context.fonts, context.textures); exitButton.Position = new Vector2f(100, 350); exitButton.setText("Exit"); exitButton.setCallback(() => { requestStackPop(); }); mGUIContainer.pack(playButton); mGUIContainer.pack(settingsButton); mGUIContainer.pack(exitButton); }
public static void MoveCameraTo(View camera, Vector2f focus, float speed) { if (camera.Center.X > focus.X) { camera.Center -= new Vector2f((Math.Abs(camera.Center.X - focus.X) * speed), 0); } if (camera.Center.X < focus.X) { camera.Center += new Vector2f((Math.Abs(camera.Center.X - focus.X) * speed),0); } if (camera.Center.Y > focus.Y) { camera.Center -= new Vector2f(0,(Math.Abs(camera.Center.Y - focus.Y) * speed)); } if (camera.Center.Y < focus.Y) { camera.Center += new Vector2f(0,(Math.Abs(camera.Center.Y - focus.Y) * speed)); } }
public override void Update() { _game.Update(); if (_viewToggle) { _view = _game.View; } else { _view = new View { Size = new Vector2f(_game.Map.Size.X * _game.Map.CellSize, _game.Map.Size.Y * _game.Map.CellSize), Center = new Vector2f(_game.Map.Size.X * (_game.Map.CellSize / 2), _game.Map.Size.Y * (_game.Map.CellSize / 2)) }; } _msFLabel.Text.DisplayedString = "ms / frame : " + Math.Round(Game.DeltaTime.AsMicroseconds() / 1000f, 2); }
public override void DrawIn(RenderWindow window, Time deltaTime) { base.DrawIn(window, deltaTime); SFML.Graphics.View defaultView = window.DefaultView; window.SetView(this.view); FloatRect bounds = this.Bounds; foreach (IObject2D object2D in this.nameToTiles.Values) { if (object2D.Bounds.Intersects(bounds)) { object2D.DrawIn(window, deltaTime); } } window.SetView(defaultView); }
public GameScreen() { _game = new Game(); _view = new View(); // ms / f text var msFText = new Text { Font = new Font("fonts/Quicksand-Bold.ttf"), DisplayedString = " ms / frame: ", Color = Color.White, CharacterSize = 19 }; msFText.SetOriginAtCenter(); msFText.Position = new Vector2f(75, WindowConfig.WindowHeight - 25); _msFLabel = new Label(msFText); Widgets.Add(_msFLabel); }
public Game() { View = new View { Size = new Vector2f(320, 240), Center = new Vector2f(320, 240) }; _player = new Entity(EntityType.Player); _frameClock = new Clock(); Map = new Map("testmap", 40, 30); for (var x = 0; x < Map.Size.X; x++) { for (var y = 0; y < Map.Size.Y; y++) { Map.AddTile(TileType.Stonefloor, x, y, 0); } } Map.AmbientLightColor = new Color(70, 70, 70, 255); _player.Position = new Vector2f(20 * 32, 15 * 32); Map.AddEntity(_player); _playerLight = new PointLight(Color.White, 1.0f, 128, _player.Position); _mouseLight = new PointLight(Color.Red, 1.0f, 128, (Vector2f) InputHandler.MousePosition); Map.AddLight(_mouseLight); Map.AddLight(_playerLight); Map.AddTile(TileType.StonewallNorth, 22, 18, 1); Map.AddTile(TileType.StonewallNorth, 22, 14, 1); Map.AddTile(TileType.StonewallNorth, 18, 18, 1); Map.AddTile(TileType.StonewallNorth, 18, 14, 1); Map.AddTile(TileType.StonewallNorth, 20, 12, 1); Map.AddTile(TileType.StonewallNorth, 16, 16, 1); Map.AddTile(TileType.StonewallNorth, 20, 20, 1); Map.AddTile(TileType.StonewallNorth, 24, 16, 1); }
public MainForm() { InitializeComponent(); shipNames = new List<string>(); Client.Start(); Window = new RenderWindow(Display.Handle, new ContextSettings(0, 0, 32)); Window.SetFramerateLimit(60); Camera = new Camera(Window.DefaultView); HudCamera = new Camera(Window.DefaultView); Window.Resized += (sender, args) => { var view = new View(Camera.Position, new Vector2f(args.Width, args.Height)); Camera = new Camera(view); view = new View(new Vector2f(args.Width / 2f, args.Height / 2f), new Vector2f(args.Width, args.Height)); HudCamera = new Camera(view); }; }
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(); }
public MainForm() { InitializeComponent(); shipNames = new List <string>(); Client.Start(); Window = new RenderWindow(Display.Handle, new ContextSettings(0, 0, 32)); Window.SetFramerateLimit(60); Camera = new Camera(Window.DefaultView); HudCamera = new Camera(Window.DefaultView); Window.Resized += (sender, args) => { var view = new View(Camera.Position, new Vector2f(args.Width, args.Height)); Camera = new Camera(view); view = new View(new Vector2f(args.Width / 2f, args.Height / 2f), new Vector2f(args.Width, args.Height)); HudCamera = new Camera(view); }; }
public override void DrawIn(RenderWindow window, Time deltaTime) { base.DrawIn(window, deltaTime); SFML.Graphics.View defaultView = window.DefaultView; window.SetView(this.view); this.domainToolTip.DrawIn(window, deltaTime); this.turnBanner2D.DrawIn(window, deltaTime); this.cardsToPlaceBanner2D.DrawIn(window, deltaTime); this.bannerEntity2D.DrawIn(window, deltaTime); this.headerEntity2D.DrawIn(window, deltaTime); this.scoreDomainLabel2D.DrawIn(window, deltaTime); this.endLevelBanner2D.DrawIn(window, deltaTime); this.returnMenuButton2D.DrawIn(window, deltaTime); this.replayMenuButton2D.DrawIn(window, deltaTime); window.SetView(defaultView); }
private void UpdateCamera() { SFML.Graphics.View view = RendWind.DefaultView; //centrowanie kamery Vector2f center = new Vector2f(0, 0); foreach (var item in wierzcholkiList) { center += item.Position; } center /= wierzcholkiList.Count; view.Center = center; //zoomowanie kamery Vector2f maxxy = new Vector2f(0, 0); for (int i = 0; i < wierzcholkiList.Count; i++) { Vector2f n = wierzcholkiList[i].Position - center; n = new Vector2f(Math.Abs(n.X), Math.Abs(n.Y)); if (n.X > maxxy.X) { maxxy.X = n.X; } if (n.Y > maxxy.Y) { maxxy.Y = n.Y; } } maxxy += new Vector2f(40, 40); maxxy *= 2; float zoomfactor = (maxxy.X > maxxy.Y) ? maxxy.X / view.Size.X : maxxy.Y / view.Size.Y; view.Zoom(zoomfactor); RendWind.SetView(view); }
public void UpdateView(SFML.Graphics.View view) { UpdateShip(); view.Rotation = DegreeOfShip; view.Center = PositionOnMap; }