annotate sprite.lua @ 48:eeb43b94f625 default tip

merge
author Makdaam
date Sun, 16 Dec 2012 19:50:44 +0100
parents 98ab870293bc
children
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
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
3 local function newSprite(x, y, image, animation)
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
4 local sprite = setmetatable({
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
5 x = x,
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
6 y = y,
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
7 image = image,
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
8 animation = animation,
2
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
9 }, { __index = Sprite })
0
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
10 return sprite
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
11 end
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
12
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
13 function Sprite:draw()
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
14 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
15 end
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
16
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
17 function Sprite:update(dt)
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
18 self.animation:update(dt)
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
19 end
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
20
2
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
21
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
22 local Shadow = {}
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
23
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
24 function newShadow(image, sprite)
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
25 return setmetatable({
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
26 image = image,
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
27 sprite = sprite,
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
28 }, { __index = Shadow })
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
29 end
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
30
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
31 function Shadow:draw()
5
98ab870293bc make the villain local
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 2
diff changeset
32 love.graphics.draw(self.image, math.floor(self.sprite.x), math.floor(self.sprite.y + 8))
2
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
33 end
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
34
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
35 function Shadow:update(dt)
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
36 end
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
37
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
38
0
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
39 local sprite = {
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
40 newSprite = newSprite,
5
98ab870293bc make the villain local
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 2
diff changeset
41 Sprite = Sprite,
2
0c46edeabad6 scrolling map
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents: 0
diff changeset
42 newShadow = newShadow,
0
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
43 }
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
44
716ff40413d2 initial commit
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff changeset
45 return sprite