please explain these lines of code
Posted: Tue Jul 21, 2020 4:14 pm
i am taking the cs50 game development course and came across the following code for one project. i believe it is to print a flipped sprite
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
can some one please explain the draw part. there should be a y value after self.x but (self.orientation == 'top' and self.y + PIPE_HEIGHT or self.y) will return true or false
pls send help
here is the full code in question
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
heres the link
https://github.com/games50/fifty-bird/b ... 6/Pipe.lua
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
can some one please explain the draw part. there should be a y value after self.x but (self.orientation == 'top' and self.y + PIPE_HEIGHT or self.y) will return true or false
pls send help
here is the full code in question
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
heres the link
https://github.com/games50/fifty-bird/b ... 6/Pipe.lua