love:multiple_files
This is an old revision of the document!
Multiple files
The following assumes main.lua
and circle.lua
are in the same directory.
- circle.lua
--[[ Functions and constants for creating and using circles ]]-- -- This may not be the best place to define these global constants, -- but it shows that you can define constants in files as well. CIRCLE_DEFAULT_SPEED = 100 -- global constant CIRCLE_DEFAULT_SIZE = 30 -- global constant ---------------------------------------- -- Functions to create circle objects -- ---------------------------------------- --[[ Return a data object that has a circle's properties. ]]-- function createCircle(x_, y_, radius_, hSpeed_) local theCircle = { x = x_, y = y_, radius = radius_, hSpeed = hSpeed_ } return theCircle end ---------------------------------------- -- Functions for using circle objects -- ---------------------------------------- --[[ Move a circle to the right, wrapping it around when necessary. ]]-- function circleMoveHorizWrap(circle, dt) circle.x = circle.x + circle.hSpeed * dt if circle.x > (love.graphics.getWidth() + circle.radius) then circle.x = -circle.radius end end --[[ Render a circle on the screen. ]]-- function circleRender(circle) love.graphics.circle("fill", circle.x, circle.y, circle.radius) end
love/multiple_files.1633402969.txt.gz · Last modified: 2021/10/05 03:02 by mithat