From d4693a35e8d27cf8ad7b548ec260f1b6f760d7e2 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sun, 13 Mar 2011 01:14:52 +0100 Subject: [PATCH] Update documentation for hump.class --- index.html | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index bc15348..d766764 100644 --- a/index.html +++ b/index.html @@ -91,7 +91,7 @@
hump.gamestate^ top
-
require "hump.gamestate"
+
Gamestate = require "hump.gamestate"

A gamestate encapsulates independant data an behaviour into a single entity.

A typical game could consist of a menu-state, a level-state and a game-over-state.

@@ -335,7 +335,7 @@ end
hump.timer^ top
-
require "hump.timer"
+
Timer = require "hump.timer"

hump.timer provides a simple interface to use delayed functions, i.e. functions that will only be executed after some amount time.

In addition, the module offers facilities to create functions that @@ -542,7 +542,7 @@ end

hump.vector^ top
-
require "hump.vector"
+
vector = require "hump.vector"

A handy 2D vector class defining the most common things you do with vectors.

You can access the individual coordinates by using vec.x and vec.y.

@@ -983,7 +983,7 @@ spawner.direction:rotate_inplace(dt)
hump.class^ top
-
require "hump.class"
+
Class = require "hump.class"
A small, handy class implementation with multiple inheritance.
@@ -1003,6 +1003,8 @@ spawner.direction:rotate_inplace(dt)
function new(constructor)^ top
function new{name = the_name, constructor}
+
function new{name = the_name, inherits = super, constructor}
+
function new{name = the_name, inherits = {super1, super2, ...}, constructor}

Define a new class.

The constructor will receive the newly created object as first argument.

If you required the module to a variable, you can use the variable @@ -1013,6 +1015,8 @@ spawner.direction:rotate_inplace(dt)

Class constructor.
string the_name
Class name to be returned when calling tostring() on the class.
+
class super
+
Super class to inherit from. Can also be an array of classes to inherit from.
Returns: @@ -1050,6 +1054,27 @@ end} garfield = Feline(.7, 45) print(Feline, garfield) -- prints 'Feline <instance of Feline>' +
Class = require 'hump.class'
+A = Class{name = 'A'}
+function A:foo()
+    print('foo')
+end
+
+B = Class{name = 'B'}
+function C:bar()
+    print('bar')
+end
+
+-- single inheritance
+C = Class{name = 'C', inherits = A}
+instance = C()
+instance:foo() -- prints 'foo'
+
+-- multiple inheritance
+D = Class{name = 'D', inherits = {A,B}}
+instance = D()
+instance:foo() -- prints 'foo'
+instance:bar() -- prints 'bar'
@@ -1177,7 +1202,7 @@ result:foo() -- error: method does not exist
hump.camera^ top
-
require "hump.camera"
+
camera = require "hump.camera"

Depends on vector

Camera abstraction for LÖVE. A camera "looks" at a position and can be moved, zoomed and rotated.

@@ -1432,7 +1457,7 @@ unit:plotPathTo(target)
hump.ringbuffer^ top
-
require "hump.ringbuffer"
+
ringbuffer = require "hump.ringbuffer"

A ring-buffer is a circular array. That means it does not have a first nor a last, but only a selected/current element.

You can use this to implement Tomb Raider style inventories, looping