Advertisement
Guest User

SpaceShooter_Practice_1_1

a guest
Jul 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using SFML.Graphics;
  7. using SFML.Window;
  8. using SFML.System;
  9. using SFML.Audio;
  10.  
  11. namespace Game1
  12. {
  13.     class Program
  14.     {
  15.         static Texture texture;
  16.         static Texture back;
  17.         static Texture backTwo;
  18.         static Texture backThree;
  19.  
  20.  
  21.         static Sprite player;
  22.         static Sprite back_g;
  23.         static Sprite backtoLoop;
  24.         static Sprite spaceLoop;
  25.  
  26.         static RenderWindow window;
  27.         static View camera;
  28.  
  29.         static Font font;
  30.         static Text text;
  31.  
  32.  
  33.         static bool w_pressed;
  34.         static bool s_pressed;
  35.         static bool d_pressed;
  36.         static bool a_pressed;
  37.  
  38.         static float speed;
  39.  
  40.         static Vector2f playerCenter;
  41.  
  42.         static void Update() {
  43.  
  44.             //--------------------- Update ----------------------
  45.  
  46.             if (w_pressed)
  47.             {
  48.                 player.Position -= new Vector2f(0, 1.0f) * speed;
  49.             }
  50.  
  51.             if (s_pressed)
  52.             {
  53.                 player.Position += new Vector2f(0, 1.0f) * speed;
  54.             }
  55.  
  56.             if (d_pressed)
  57.             {
  58.                 player.Position += new Vector2f(1.0f, 0) * speed;
  59.             }
  60.  
  61.             if (a_pressed)
  62.             {
  63.                 player.Position -= new Vector2f(1.0f, 0) * speed;
  64.             }
  65.  
  66.  
  67.             // camera.Center = player.Position + playerCenter;
  68.             camera.Center = new Vector2f(400, player.Position.Y + playerCenter.Y);
  69.  
  70.             //---SPACE LOOP---
  71.             Vector2f camPosition = new Vector2f(camera.Center.X - 400, camera.Center.Y - 300);
  72.  
  73.             if (camPosition.Y <= back_g.Position.Y)
  74.             {
  75.  
  76.             }
  77.             //-------SPACE LOOP-------///
  78.             spaceLoop.Position = new Vector2f(backtoLoop.Position.X, backtoLoop.Position.Y - 800);
  79.             //-------SPACE LOOP-------///
  80.  
  81.             //text.DisplayedString = speed + "kh/h";
  82.             speed.ToString();
  83.  
  84.             window.DispatchEvents();
  85.             //--------------------- Update ----------------------
  86.  
  87.  
  88.         }
  89.  
  90.         static void Draw()
  91.         {
  92.             //--------------------- Rendering ----------------------
  93.             window.Clear();
  94.             window.SetView(camera);
  95.             //window.Draw(text);
  96.             window.Draw(back_g);
  97.             window.Draw(backtoLoop);
  98.             window.Draw(spaceLoop);
  99.             window.Draw(player);
  100.             window.Display();
  101.  
  102.             //DISPLAY INFO
  103.             //font = new Font("spacefnt.TTF");
  104.             //text = new Text();
  105.             //text.Font = font;
  106.             //text.Position += new Vector2f(33, 90);
  107.             //text.Color = new Color(255, 255, 0, 255);
  108.             //DISPLAY INFO
  109.             //--------------------- Rendering ----------------------
  110.         }
  111.  
  112.         static void Load()
  113.         {
  114.             font = new Font("spacefnt.TTF");
  115.             text = new Text();
  116.             text.Font = font;
  117.             text.Position += new Vector2f(33, 90);
  118.             text.Color = new Color(255, 255, 0, 255);
  119.         }
  120.  
  121.  
  122.         static void Main(string[] args)
  123.         {
  124.             window = new RenderWindow(new VideoMode(800, 600), "Game");
  125.             camera = new View(new FloatRect(0, 0, 800, 600));
  126.             window.KeyPressed += Window_KeyPressed;
  127.             window.KeyReleased += Window_KeyReleased;
  128.  
  129.  
  130.             System.Console.WriteLine("SpaceShooter_Practice_1_Adam.A");
  131.  
  132.  
  133.  
  134.             w_pressed = false;
  135.             s_pressed = false;
  136.             d_pressed = false;
  137.             a_pressed = false;
  138.  
  139.             speed = 0.15f;
  140.  
  141.  
  142.             texture = new Texture("char.png");
  143.             back = new Texture("back.png");
  144.             backTwo = new Texture("backtwo.png");
  145.             backThree = new Texture("backTwo.png");
  146.  
  147.             back_g = new Sprite(back);
  148.             player = new Sprite(texture);
  149.             backtoLoop = new Sprite(backTwo);
  150.             spaceLoop = new Sprite(backThree);
  151.  
  152.             player.Scale = new Vector2f(0.25f, 0.25f);
  153.             back_g.Scale = new Vector2f(1.0f, 1.0f);
  154.             backtoLoop.Position = new Vector2f(0, -600);
  155.             spaceLoop.Position = new Vector2f(0, 600);
  156.  
  157.  
  158.            
  159.             playerCenter = new Vector2f(player.Texture.Size.X / 6, player.Texture.Size.Y / 6);
  160.             player.Position = new Vector2f(400, 300) - playerCenter;
  161.  
  162.             playMusic();
  163.             //Load();
  164.  
  165.             while (window.IsOpen)
  166.             {
  167.                 Update();
  168.                 Draw();
  169.  
  170.              
  171.             }
  172.         }
  173.  
  174.         static void playMusic()
  175.         {
  176.             Music bg_Music = new Music("spacefiction.wav");
  177.             bg_Music.Play();
  178.         }
  179.         //=--KEY PRESS FUNCTION
  180.         private static void Window_KeyPressed(object sender, KeyEventArgs e)
  181.         {
  182.             if (e.Code == Keyboard.Key.W)
  183.             {
  184.                 w_pressed = true;
  185.             }
  186.  
  187.             if (e.Code == Keyboard.Key.S)
  188.             {
  189.                 s_pressed = true;
  190.             }
  191.  
  192.             if (e.Code == Keyboard.Key.D)
  193.             {
  194.                 d_pressed = true;
  195.             }
  196.  
  197.             if (e.Code == Keyboard.Key.A)
  198.             {
  199.                 a_pressed = true;
  200.             }
  201.         }
  202.  
  203.         //---KEY RELEASE FUNCTION
  204.         private static void Window_KeyReleased(object sender, KeyEventArgs e)
  205.         {
  206.             if (e.Code == Keyboard.Key.W)
  207.             {
  208.                 w_pressed = false;
  209.             }
  210.  
  211.             if (e.Code == Keyboard.Key.S)
  212.             {
  213.                 s_pressed = false;
  214.             }
  215.  
  216.             if (e.Code == Keyboard.Key.D)
  217.             {
  218.                 d_pressed = false;
  219.             }
  220.  
  221.             if (e.Code == Keyboard.Key.A)
  222.             {
  223.                 a_pressed = false;
  224.             }
  225.         }
  226.  
  227.         //-------INFINITE SPACE BACKGROUND FUNCTION-------///
  228.         private void SpaceReposition()
  229.         {
  230.            
  231.         }
  232.     }
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement