Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using SFML.Graphics;
- using SFML.Window;
- using SFML.System;
- using SFML.Audio;
- namespace Game1
- {
- class Program
- {
- static Texture texture;
- static Texture back;
- static Texture backTwo;
- static Texture backThree;
- static Sprite player;
- static Sprite back_g;
- static Sprite backtoLoop;
- static Sprite spaceLoop;
- static RenderWindow window;
- static View camera;
- static Font font;
- static Text text;
- static bool w_pressed;
- static bool s_pressed;
- static bool d_pressed;
- static bool a_pressed;
- static float speed;
- static Vector2f playerCenter;
- static void Update() {
- //--------------------- Update ----------------------
- if (w_pressed)
- {
- player.Position -= new Vector2f(0, 1.0f) * speed;
- }
- if (s_pressed)
- {
- player.Position += new Vector2f(0, 1.0f) * speed;
- }
- if (d_pressed)
- {
- player.Position += new Vector2f(1.0f, 0) * speed;
- }
- if (a_pressed)
- {
- player.Position -= new Vector2f(1.0f, 0) * speed;
- }
- // camera.Center = player.Position + playerCenter;
- camera.Center = new Vector2f(400, player.Position.Y + playerCenter.Y);
- //---SPACE LOOP---
- Vector2f camPosition = new Vector2f(camera.Center.X - 400, camera.Center.Y - 300);
- if (camPosition.Y <= back_g.Position.Y)
- {
- }
- //-------SPACE LOOP-------///
- spaceLoop.Position = new Vector2f(backtoLoop.Position.X, backtoLoop.Position.Y - 800);
- //-------SPACE LOOP-------///
- //text.DisplayedString = speed + "kh/h";
- speed.ToString();
- window.DispatchEvents();
- //--------------------- Update ----------------------
- }
- static void Draw()
- {
- //--------------------- Rendering ----------------------
- window.Clear();
- window.SetView(camera);
- //window.Draw(text);
- window.Draw(back_g);
- window.Draw(backtoLoop);
- window.Draw(spaceLoop);
- window.Draw(player);
- window.Display();
- //DISPLAY INFO
- //font = new Font("spacefnt.TTF");
- //text = new Text();
- //text.Font = font;
- //text.Position += new Vector2f(33, 90);
- //text.Color = new Color(255, 255, 0, 255);
- //DISPLAY INFO
- //--------------------- Rendering ----------------------
- }
- static void Load()
- {
- font = new Font("spacefnt.TTF");
- text = new Text();
- text.Font = font;
- text.Position += new Vector2f(33, 90);
- text.Color = new Color(255, 255, 0, 255);
- }
- static void Main(string[] args)
- {
- window = new RenderWindow(new VideoMode(800, 600), "Game");
- camera = new View(new FloatRect(0, 0, 800, 600));
- window.KeyPressed += Window_KeyPressed;
- window.KeyReleased += Window_KeyReleased;
- System.Console.WriteLine("SpaceShooter_Practice_1_Adam.A");
- w_pressed = false;
- s_pressed = false;
- d_pressed = false;
- a_pressed = false;
- speed = 0.15f;
- texture = new Texture("char.png");
- back = new Texture("back.png");
- backTwo = new Texture("backtwo.png");
- backThree = new Texture("backTwo.png");
- back_g = new Sprite(back);
- player = new Sprite(texture);
- backtoLoop = new Sprite(backTwo);
- spaceLoop = new Sprite(backThree);
- player.Scale = new Vector2f(0.25f, 0.25f);
- back_g.Scale = new Vector2f(1.0f, 1.0f);
- backtoLoop.Position = new Vector2f(0, -600);
- spaceLoop.Position = new Vector2f(0, 600);
- playerCenter = new Vector2f(player.Texture.Size.X / 6, player.Texture.Size.Y / 6);
- player.Position = new Vector2f(400, 300) - playerCenter;
- playMusic();
- //Load();
- while (window.IsOpen)
- {
- Update();
- Draw();
- }
- }
- static void playMusic()
- {
- Music bg_Music = new Music("spacefiction.wav");
- bg_Music.Play();
- }
- //=--KEY PRESS FUNCTION
- private static void Window_KeyPressed(object sender, KeyEventArgs e)
- {
- if (e.Code == Keyboard.Key.W)
- {
- w_pressed = true;
- }
- if (e.Code == Keyboard.Key.S)
- {
- s_pressed = true;
- }
- if (e.Code == Keyboard.Key.D)
- {
- d_pressed = true;
- }
- if (e.Code == Keyboard.Key.A)
- {
- a_pressed = true;
- }
- }
- //---KEY RELEASE FUNCTION
- private static void Window_KeyReleased(object sender, KeyEventArgs e)
- {
- if (e.Code == Keyboard.Key.W)
- {
- w_pressed = false;
- }
- if (e.Code == Keyboard.Key.S)
- {
- s_pressed = false;
- }
- if (e.Code == Keyboard.Key.D)
- {
- d_pressed = false;
- }
- if (e.Code == Keyboard.Key.A)
- {
- a_pressed = false;
- }
- }
- //-------INFINITE SPACE BACKGROUND FUNCTION-------///
- private void SpaceReposition()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement