static void Main(string[] args) { Texture textureBack = new Texture(File.ReadAllBytes(@"assets/back.png")); textureBack.Smooth = true; Sprite spriteBack = new Sprite(textureBack, new IntRect(0, 0, 800, 500)); Texture textureLock = new Texture(File.ReadAllBytes(@"assets/lock.png")); textureLock.Smooth = true; Sprite spriteLock = new Sprite(textureLock, new IntRect(0, 0, 80, 80)); spriteLock.Position = new Vector2f(76, 68); icons = new List<Sprite>(); for (int index = 0; index < 15; index++) { int col = index % 5; int row = (index - col) / 5; Texture textureIcon = new Texture(File.ReadAllBytes(String.Format(@"assets/buttons/{0:00}.png", index + 1))); textureIcon.Smooth = true; Sprite spriteIcon = new Sprite(textureIcon, new IntRect(0, 0, 72, 72)); spriteIcon.Position = new Vector2f(80 + col * 72 + col * 70, 72 + row * 72 + row * 70); icons.Add(spriteIcon); } ContextSettings context = new ContextSettings(); context.DepthBits = 32; RenderWindow window = new RenderWindow(new VideoMode(800, 500), String.Empty, Styles.Default, context); window.SetActive(); window.SetVisible(true); window.SetKeyRepeatEnabled(true); window.SetMouseCursorVisible(true); window.SetVerticalSyncEnabled(false); window.Closed += new EventHandler( delegate(object sender, EventArgs e) { window.Close(); window.Dispose(); } ); window.GainedFocus += new EventHandler( delegate(object sender, EventArgs e) { } ); window.LostFocus += new EventHandler( delegate(object sender, EventArgs e) { } ); window.KeyPressed += new EventHandler<KeyEventArgs>( delegate(object sender, KeyEventArgs e) { if (e.Code == Keyboard.Key.Escape) { /* sound.Stop(); sound.Dispose(); buffer.Dispose(); */ window.Close(); window.Dispose(); } if (e.Code == Keyboard.Key.Right) { if (col < 4) { col += 1; } } if (e.Code == Keyboard.Key.Left) { if (col > 0) { col -= 1; } } if (e.Code == Keyboard.Key.Up) { if (row > 0) { row -= 1; } } if (e.Code == Keyboard.Key.Down) { if (row < 2) { row += 1; } } spriteLock.Position = new Vector2f(80 + col * 72 + col * 70 - 4, 72 + row * 72 + row * 70 - 4); } ); window.KeyReleased += new EventHandler<KeyEventArgs>( delegate(object sender, KeyEventArgs e) { } ); window.TouchBegan += new EventHandler<TouchEventArgs>( delegate(object sender, TouchEventArgs e) { } ); window.TouchEnded += new EventHandler<TouchEventArgs>( delegate(object sender, TouchEventArgs e) { } ); window.TouchMoved += new EventHandler<TouchEventArgs>( delegate(object sender, TouchEventArgs e) { } ); window.JoystickConnected += new EventHandler<JoystickConnectEventArgs>( delegate(object sender, JoystickConnectEventArgs e) { } ); window.JoystickDisconnected += new EventHandler<JoystickConnectEventArgs>( delegate(object sender, JoystickConnectEventArgs e) { } ); window.JoystickButtonPressed += new EventHandler<JoystickButtonEventArgs>( delegate(object sender, JoystickButtonEventArgs e) { //File.AppendAllText(@"joystick.log", Convert.ToString(e.Button) + ":JoystickButtonPressed\n"); // A 0 // B 1 // X 2 // Y 3 // BACK 6 // START 7 } ); window.JoystickButtonReleased += new EventHandler<JoystickButtonEventArgs>( delegate(object sender, JoystickButtonEventArgs e) { //File.AppendAllText(@"joystick.log", Convert.ToString(e.Button) + ":JoystickButtonReleased\n"); } ); window.JoystickMoved += new EventHandler<JoystickMoveEventArgs>( delegate(object sender, JoystickMoveEventArgs e) { //File.AppendAllText(@"joystick.log", Convert.ToString(e.Axis) + ":" + Convert.ToString(e.JoystickId) + ":" + Convert.ToString(e.Position) + "\n"); // RIGHT PovX +100 // LEFT PovX -100 if (e.Axis == Joystick.Axis.PovX) { if (e.Position.Equals(+100.0f)) { // RIGHT if (col < 4) { col += 1; } } if (e.Position.Equals(-100.0f)) { // LEFT if (col > 0) { col -= 1; } } } // UP PovY +100 // DOWN PovY -100 if (e.Axis == Joystick.Axis.PovY) { if (e.Position.Equals(+100.0f)) { // UP if (row > 0) { row -= 1; } } if (e.Position.Equals(-100.0f)) { // DOWN if (row < 2) { row += 1; } } } spriteLock.Position = new Vector2f(80 + col * 72 + col * 70 - 4, 72 + row * 72 + row * 70 - 4); } ); while (window.IsOpen) { window.DispatchEvents(); window.Clear(); window.Draw(spriteBack); foreach (Sprite icon in icons) { window.Draw(icon); } window.Draw(spriteLock); window.Display(); } }
static void Main() { Console.Title = "Tetraquark Console"; Running = true; const string ConfigFile = "cfg.yaml"; if (File.Exists(ConfigFile)) { Console.WriteLine("Loading config file {0}", ConfigFile); Settings.Load(File.ReadAllText(ConfigFile)); } GameWatch = new Stopwatch(); GameWatch.Start(); PackMgr.Mount("Default.zip"); string[] Files = PackMgr.GetFiles(); for (int i = 0; i < Files.Length; i++) { if (Files[i].StartsWith("resources/fonts/")) ResourceMgr.Register<Font>(PackMgr.OpenFile(Files[i]), Path.GetFileNameWithoutExtension(Files[i])); else if (Files[i].StartsWith("resources/textures/")) ResourceMgr.Register<Texture>(PackMgr.OpenFile(Files[i]), Path.GetFileNameWithoutExtension(Files[i])); } Scales.Init(new Vector2f(ResX, ResY)); // OpenTK ToolkitOptions TOpt = ToolkitOptions.Default; TOpt.Backend = PlatformBackend.PreferNative; TOpt.EnableHighResolution = true; Toolkit.Init(TOpt); // SFML VideoMode VMode = new VideoMode((uint)Scales.XRes, (uint)Scales.YRes, (uint)BitsPerPixel); ContextSettings CSet = new ContextSettings((uint)DepthBits, (uint)StencilBits); CSet.MajorVersion = 4; CSet.MinorVersion = 2; CSet.AntialiasingLevel = (uint)Samples; Styles S = Styles.None; if (Border) S |= Styles.Titlebar | Styles.Close; RenderWindow RWind = new RenderWindow(VMode, "Tetraquark", S, CSet); RWind.Closed += (Snd, E) => Running = false; RWind.SetKeyRepeatEnabled(false); // OpenTK IWindowInfo WindInfo = Utilities.CreateWindowsWindowInfo(RWind.SystemHandle); var GfxMode = new GraphicsMode(new ColorFormat(BitsPerPixel), DepthBits, StencilBits, Samples, new ColorFormat(0)); var GfxCtx = new GraphicsContext(GfxMode, WindInfo, (int)CSet.MajorVersion, (int)CSet.MinorVersion, GfxCtxFlags.Default); GfxCtx.MakeCurrent(WindInfo); GfxCtx.LoadAll(); RWind.ResetGLStates(); //GL.Enable(EnableCap.FramebufferSrgb); Renderer.Init(RWind); Stopwatch Clock = new Stopwatch(); Clock.Start(); while (Running) { RWind.DispatchEvents(); while (Clock.ElapsedMilliseconds < 10) ; float Dt = (float)Clock.ElapsedMilliseconds / 1000; Clock.Restart(); Renderer.Update(Dt); Renderer.Draw(RWind); RWind.Display(); } RWind.Close(); RWind.Dispose(); Console.WriteLine("Flushing configs"); File.WriteAllText(ConfigFile, Settings.Save()); Environment.Exit(0); }
static void Main() { //try { const int width = 1024; const int height = 768; // Create main window m_Window = new RenderWindow(new VideoMode(width, height), "GWEN.Net SFML test", Styles.Titlebar|Styles.Close|Styles.Resize, new ContextSettings(32, 0)); // Setup event handlers m_Window.Closed += OnClosed; m_Window.KeyPressed += OnKeyPressed; m_Window.Resized += OnResized; m_Window.KeyReleased += window_KeyReleased; m_Window.MouseButtonPressed += window_MouseButtonPressed; m_Window.MouseButtonReleased += window_MouseButtonReleased; m_Window.MouseWheelMoved += window_MouseWheelMoved; m_Window.MouseMoved += window_MouseMoved; m_Window.TextEntered += window_TextEntered; //m_Window.SetFramerateLimit(60); const int fps_frames = 50; List<long> ftime = new List<long>(fps_frames); long lastTime = 0; // create GWEN renderer Renderer.SFML gwenRenderer = new Renderer.SFML(m_Window); // Create GWEN skin //Skin.Simple skin = new Skin.Simple(GwenRenderer); Skin.TexturedBase skin = new Skin.TexturedBase(gwenRenderer, "DefaultSkin.png"); // set default font Font defaultFont = new Font(gwenRenderer) {Size = 10, FaceName = "Arial Unicode MS"}; // try to load, fallback if failed if (gwenRenderer.LoadFont(defaultFont)) { gwenRenderer.FreeFont(defaultFont); } else // try another { defaultFont.FaceName = "Arial"; if (gwenRenderer.LoadFont(defaultFont)) { gwenRenderer.FreeFont(defaultFont); } else // try default { defaultFont.FaceName = "OpenSans.ttf"; } } skin.SetDefaultFont(defaultFont.FaceName); defaultFont.Dispose(); // skin has its own // Create a Canvas (it's root, on which all other GWEN controls are created) m_Canvas = new Canvas(skin); m_Canvas.SetSize(width, height); m_Canvas.ShouldDrawBackground = true; m_Canvas.BackgroundColor = System.Drawing.Color.FromArgb(255, 150, 170, 170); m_Canvas.KeyboardInputEnabled = true; // create the unit test control m_UnitTest = new UnitTest.UnitTest(m_Canvas); // Create GWEN input processor m_Input = new Input.SFML(); m_Input.Initialize(m_Canvas, m_Window); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (m_Window.IsOpen()) { m_Window.SetActive(); m_Window.DispatchEvents(); m_Window.Clear(); // Clear depth buffer Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_COLOR_BUFFER_BIT); if (ftime.Count == fps_frames) ftime.RemoveAt(0); ftime.Add(stopwatch.ElapsedMilliseconds - lastTime); lastTime = stopwatch.ElapsedMilliseconds; if (stopwatch.ElapsedMilliseconds > 1000) { m_UnitTest.Fps = 1000f * ftime.Count / ftime.Sum(); stopwatch.Restart(); } // render GWEN canvas m_Canvas.RenderCanvas(); m_Window.Display(); } // we only need to dispose the canvas, it will take care of disposing all its children m_Canvas.Dispose(); // also dispose of these skin.Dispose(); gwenRenderer.Dispose(); } //catch (Exception e) //{ //String msg = String.Format("Exception: {0}\n{1}", e.Message, e.StackTrace); //MessageBox.Show(msg); //} m_Window.Dispose(); }