Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using SFML.Window;
- using SFML.Graphics;
- using MWM;
- namespace Entity
- {
- class Player
- {
- private Texture t = null;
- private Sprite player = null;
- private int velocity = 0;
- private Sprite[] solidObjects = null;
- private bool jumpable = false;
- private bool jumpSwitch = false;
- public Player(String loc, Vector2f Position)
- {
- t = new Texture(loc);
- player = new Sprite(t);
- player.Position = Position;
- }
- public void walk(String direction, double speed)
- {
- speed = speed * 8;
- int rounded = (int)Math.Round(speed, 0);
- if (direction == "left")
- {
- Vector2f pos = player.Position;
- player.Position = new Vector2f(pos.X - rounded, pos.Y);
- }
- if (direction == "right")
- {
- Vector2f pos = player.Position;
- player.Position = new Vector2f(pos.X + rounded, pos.Y);
- }
- }
- public void jump(double height)
- {
- if (jumpable)
- {
- height = height * 8;
- int rounded = (int)Math.Round(height, 0);
- velocity += rounded;
- jumpable = false;
- }
- }
- public void draw(ref RenderWindow window)
- {
- window.Draw(player);
- }
- public void updateV(ref RenderWindow window)
- {
- if (jumpSwitch)
- {
- Vector2f pos = player.Position;
- player.Position = new Vector2f(pos.X, pos.Y - velocity);
- Console.WriteLine(velocity);
- if (pos.Y + 128 > window.Size.Y)
- {
- jumpable = true;
- if (velocity <= 0){
- velocity = 0;
- }
- }
- else if (velocity > MWM.Program.gravity * -8)
- {
- velocity -= MWM.Program.gravity;
- Console.WriteLine(velocity);
- }
- }
- else
- {
- jumpSwitch = true;
- }
- }
- public Vector2f getPos()
- {
- return player.Position;
- }
- public void setSolids(Sprite[] solids)
- {
- solidObjects = solids;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment