Waternode

Main Game Class

Feb 3rd, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using SFML.Audio;
  4. using SFML.Window;
  5. using SFML.Graphics;
  6. using Entity;
  7.  
  8. namespace MWM
  9. {
  10.     class Program
  11.     {
  12.         List<Sprite> entities = new List<Sprite>();
  13.         List<Sprite> blocks = new List<Sprite>();
  14.         List<String> blocksInfo = new List<String>();
  15.         static Player p = null;
  16.         static double speed = 1;
  17.         public static int gravity = 1;
  18.         static void OnClose(object sender, EventArgs e)
  19.         {
  20.             // Close the window when OnClose event is received
  21.             RenderWindow window = (RenderWindow)sender;
  22.             window.Close();
  23.         }
  24.         static void OnKeyPressed(object sender, KeyEventArgs e)
  25.         {
  26.             if (e.Code == Keyboard.Key.W)
  27.             {
  28.                 p.jump(2);
  29.             }
  30.             if (e.Code == Keyboard.Key.A)
  31.             {
  32.                 p.walk("left", speed);
  33.             }
  34.             if (e.Code == Keyboard.Key.D)
  35.             {
  36.                 p.walk("right", speed);
  37.             }
  38.         }
  39.         static void Main(string[] args)
  40.         {
  41.             // Program Starting Code
  42.             RenderWindow window = new RenderWindow(new VideoMode(1024, 768), "Game");
  43.             window.Closed += new EventHandler(OnClose);
  44.             window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
  45.             p = new Player("Graphics/mainCharStand.PNG", new Vector2f(320, 320));
  46.             Text hi = new Text(p.getPos().X.ToString() + ", " + p.getPos().Y.ToString());
  47.            
  48.             // Loop
  49.             while (window.IsOpen())
  50.             {
  51.                 System.Threading.Thread.Sleep(50); // Loop Timer
  52.                 window.DispatchEvents(); // Send Events To Handlers
  53.                 hi.DisplayedString = p.getPos().X.ToString() + ", " + p.getPos().Y.ToString(); // Display Player Location
  54.                 p.updateV(ref window); // Update Player Velocity
  55.                
  56.                 // Program Drawing Code
  57.                 window.Clear();
  58.  
  59.                 p.draw(ref window);
  60.                 window.Draw(hi);
  61.  
  62.                 window.Display();
  63.             }
  64.  
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment