-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pipe.lua
42 lines (31 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
40
41
42
--[[
Pipe Class
Author: Ilias
mister.tolegenov@gmail.com
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')
-- speed at which the pipe should scroll right to left
PIPE_SPEED = 60
-- height of pipe image, globally accessible
PIPE_HEIGHT = 288
PIPE_WIDTH = 70
function Pipe:init(orientation, y)
self.x = VIRTUAL_WIDTH
self.y = y
self.width = PIPE_IMAGE:getWidth()
self.height = PIPE_HEIGHT
self.orientation = orientation
end
function Pipe:update(dt)
end
function Pipe:render()
love.graphics.draw(PIPE_IMAGE, self.x,
(self.orientation == 'top' and self.y + PIPE_HEIGHT or self.y),
0, 1, self.orientation == 'top' and -1 or 1)
end