love:multiple_files
Differences
This shows you the differences between two versions of the page.
Last revisionBoth sides next revision | |||
love:multiple_files [2021/10/05 03:02] – created mithat | love:multiple_files [2021/10/05 03:08] – mithat | ||
---|---|---|---|
Line 4: | Line 4: | ||
<file lua main.lua> | <file lua main.lua> | ||
- | </ | + | --[[------------------------------------- |
+ | - Using multiple files. | ||
+ | - Mithat Konar | ||
+ | -------------------------------------]]-- | ||
+ | require(' | ||
+ | |||
+ | -------------------- | ||
+ | -- LÖVE functions -- | ||
+ | -------------------- | ||
+ | --[[ Create game globals and initial conditions. ]]-- | ||
+ | function love.load() | ||
+ | -- create array of drawable circles | ||
+ | circlesArray = {} | ||
+ | | ||
+ | -- populate the array with as many circles as you want! | ||
+ | table.insert(circlesArray, | ||
+ | table.insert(circlesArray, | ||
+ | table.insert(circlesArray, | ||
+ | table.insert(circlesArray, | ||
+ | end | ||
+ | |||
+ | --[[ Update values of game parameters. ]]-- | ||
+ | function love.update(dt) | ||
+ | -- move all the circles as needed | ||
+ | for i=1,# | ||
+ | circleMoveHorizWrap(circlesArray[i], | ||
+ | end | ||
+ | end | ||
+ | |||
+ | --[[ Render the game elements. ]]-- | ||
+ | function love.draw() | ||
+ | -- draw all the circles | ||
+ | for i=1,# | ||
+ | circleRender(circlesArray[i]) | ||
+ | end | ||
+ | end | ||
+ | </ | ||
<file lua circle.lua> | <file lua circle.lua> | ||
--[[ Functions and constants for creating and using circles ]]-- | --[[ Functions and constants for creating and using circles ]]-- | ||
- | -- This may not be the best place to define these global constants, | + | -- It may make more sense to define these global constants |
- | -- but it shows that you can define constants in files as well. | + | -- but this shows that you can define constants in files as well. |
CIRCLE_DEFAULT_SPEED = 100 -- global constant | CIRCLE_DEFAULT_SPEED = 100 -- global constant | ||
CIRCLE_DEFAULT_SIZE = 30 -- global constant | CIRCLE_DEFAULT_SIZE = 30 -- global constant |
love/multiple_files.txt · Last modified: 2021/10/05 03:08 by mithat