-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pipe.lua
39 lines (28 loc) · 1.19 KB
/
Pipe.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--[[
Pipe Class
Author: Colton Ogden
The Pipe class represents the pipes that randomly spawn in our game, which act as our primary obstacles.
The pipes can stick out a random distance from the top or bottom of the screen. When the player collides
with one of them, it's game over. Rather than our bird actually moving through the screen horizontally,
the pipes themselves scroll through the game to give the illusion of player movement.
]]
Pipe = Class{}
-- since we only want the image loaded once, not per instantation, define it externally
local PIPE_IMAGE = love.graphics.newImage('pipe.png')
function Pipe:init(orientation, y)
self.x = VIRTUAL_WIDTH + 64
self.y = y
self.width = PIPE_WIDTH
self.height = PIPE_HEIGHT
self.orientation = orientation
end
function Pipe:update(dt)
end
function Pipe:render()
love.graphics.draw(PIPE_IMAGE, self.x,
-- shift pipe rendering down by its height if flipped vertically
(self.orientation == 'top' and self.y + PIPE_HEIGHT or self.y),
-- scaling by -1 on a given axis flips (mirrors) the image on that axis
0, 1, self.orientation == 'top' and -1 or 1)
end