Classes

You can define you own classes, which can then be used to make new instances of those objects. Class definitions are made using the 'class' keyword, and end with 'end'.

// a class with no methods
class Person
end

// creates an instance of Person
person = new Person()

Once a class is defined, instances of the class are created using the 'new' keyword, like above.

/**
 * A simple Sprite class, which can be moved.
 */
class Sprite
    // accessors for x/y fields
    getset( x, y )
    
    // getter only, no setter
    get( image )
    
    /**
     * Constructor, takes a starting x/y location, and image.
     */
    def new( x, y, image )
        @x = x
        @y = y
        @image = image
    end
    
    /**
     * Moves the Sprite by the amount given.
     */
    def move( x, y )
        @x = @x + x
        @y = @y + y
    end
    
    /**
     * Draws this sprite at it's current location, centred.
     */
    def draw()
        drawImage( @image, @x, @y, true )
    end
end

Methods

Constructors

Fields and Accessors

Inheritance