Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

mymove() method c#


public class Monster
{
    private const int MIN_X = 156;
    private const int MAX_X = 501;
    private int _x;

    //your TL(probably) will tell you to use Enum 
    private bool _toLeft;

    public Monster()
    {
        _toLeft = false;
        _x = MIN_X;
    }

    public void Move()
    {
        if (_toLeft)
        {
            _x--;
        }
        else
        {
            _x++;
        }
        CheckEdges();
    }

    private void CheckEdges()
    {
        if (_x == MAX_X || _x == MIN_X)
            _toLeft = !_toLeft;
    }

}

Source by coders911.org #
 
PREVIOUS NEXT
Tagged: #method
ADD COMMENT
Topic
Name
7+6 =