User Tools

Site Tools


love:multiple_files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revisionBoth sides next revision
love:multiple_files [2021/10/05 03:02] – created mithatlove:multiple_files [2021/10/05 03:08] mithat
Line 4: Line 4:
  
 <file lua main.lua> <file lua main.lua>
-</file>+--[[------------------------------------- 
 +- Using multiple files. 
 +- Mithat Konar 
 +-------------------------------------]]--
  
 +require('circle'  -- get the contents of file circle.lua.
 +
 +--------------------
 +-- 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, createCircle(0, 100, CIRCLE_DEFAULT_SIZE, CIRCLE_DEFAULT_SPEED))
 +    table.insert(circlesArray, createCircle(0, 200, CIRCLE_DEFAULT_SIZE / 1.5, CIRCLE_DEFAULT_SPEED * 1.5))
 +    table.insert(circlesArray, createCircle(0, 300, CIRCLE_DEFAULT_SIZE * 1.5, CIRCLE_DEFAULT_SPEED / 1.5))
 +    table.insert(circlesArray, createCircle(0, 400, CIRCLE_DEFAULT_SIZE / 2, CIRCLE_DEFAULT_SPEED * 2))
 +end
 +
 +--[[ Update values of game parameters. ]]--
 +function love.update(dt)
 +    -- move all the circles as needed
 +    for i=1,#circlesArray do
 +        circleMoveHorizWrap(circlesArray[i], dt)
 +    end
 +end
 +
 +--[[ Render the game elements. ]]--
 +function love.draw()
 +    -- draw all the circles
 +    for i=1,#circlesArray do
 +        circleRender(circlesArray[i])
 +    end
 +end
 +</file>
  
 <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 in main.lua
--- 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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki