annotate sprite.lua @ 0:716ff40413d2

initial commit
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 15 Dec 2012 10:23:11 +0100
parents
children 0c46edeabad6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
1 local Sprite = {}
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
2 local Sprite_mt = { __index = Sprite }
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
3
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
4 local function newSprite(x, y, image, animation)
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
5 local sprite = setmetatable({
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
6 x = x,
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
7 y = y,
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
8 image = image,
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
9 animation = animation,
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
10 }, Sprite_mt)
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
11 return sprite
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
12 end
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
13
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
14 function Sprite:draw()
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
15 self.animation:draw(self.image, math.floor(self.x), math.floor(self.y))
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
16 end
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
17
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
18 function Sprite:update(dt)
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
19 self.animation:update(dt)
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
20 end
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
21
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
22 local sprite = {
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
23 newSprite = newSprite,
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
24 }
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
25
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
26 return sprite