source: 2016/27/ohjaajat/VenienteFragore/VenienteFragore/VenienteFragore/SimplePlatformCharacter.cs @ 8007

Revision 7920, 1.2 KB checked in by sieerinn, 3 years ago (diff)

Hahmoille kuvat peliin, liike on myös vähän mariota muistuttavampi

Line 
1using Jypeli;
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6
7namespace VenienteFragore
8{
9    class SimplePlatformCharacter : InteractableObject
10    {
11        public bool IsGrounded { get; private set; }
12
13        public Direction FacingDirection { get; private set; }
14
15        public SimplePlatformCharacter(double width, double height) : base(width, height)
16        {
17            FacingDirection = Direction.Right;
18        }
19
20        public void Turn(Direction facingDirection)
21        {
22            if (facingDirection == FacingDirection || (facingDirection != Direction.Left && facingDirection != Direction.Right))
23                return;
24            FacingDirection = facingDirection;
25            TextureWrapSize = new Vector(-TextureWrapSize.X, TextureWrapSize.Y);
26        }
27
28        public virtual void Walk(double speed)
29        {
30            if (speed > 0) Turn(Direction.Right);
31            if (speed < 0) Turn(Direction.Left);
32            Velocity = new Vector(speed, Velocity.Y);
33        }
34
35        public override void Update(Time time)
36        {
37            base.Update(time);
38            IsGrounded = Game.Collisions(this, new Vector(0, -2), true).Count > 0;
39        }
40    }
41}
Note: See TracBrowser for help on using the repository browser.