fixes for postshaders and most of the examples to use the new apis

This commit is contained in:
Tim Anema 2016-04-26 09:23:11 -04:00
parent eedd980ff2
commit 127063a061
16 changed files with 1930 additions and 1112 deletions

View File

@ -9,12 +9,12 @@ function love.load()
colorAberration = 0.0 colorAberration = 0.0
-- load images -- load images
image = love.graphics.newImage("examples/gfx/machine2.png") image = love.graphics.newImage("examples/gfx/machine2.png")
quadScreen = love.graphics.newQuad(0, 0, love.window.getWidth() + 32, love.window.getHeight() + 24, 32, 24) quadScreen = love.graphics.newQuad(0, 0, love.graphics.getWidth() + 32, love.graphics.getHeight() + 24, 32, 24)
imgFloor = love.graphics.newImage("examples/gfx/floor.png") imgFloor = love.graphics.newImage("examples/gfx/floor.png")
imgFloor:setWrap("repeat", "repeat") imgFloor:setWrap("repeat", "repeat")
post_shader = PostShader() post_shader = PostShader()
render_buffer = love.graphics.newCanvas(love.window.getWidth(), love.window.getHeight()) render_buffer = love.graphics.newCanvas(love.graphics.getWidth(), love.graphics.getHeight())
end end
function love.keypressed(k) function love.keypressed(k)
@ -92,9 +92,9 @@ end
function love.draw() function love.draw()
local w, h = love.graphics.getWidth(), love.graphics.getHeight() local w, h = love.graphics.getWidth(), love.graphics.getHeight()
render_buffer:clear()
love.graphics.push() love.graphics.push()
love.graphics.setCanvas(render_buffer) love.graphics.setCanvas(render_buffer)
love.graphics.clear()
love.graphics.translate(x, y) love.graphics.translate(x, y)
love.graphics.scale(scale) love.graphics.scale(scale)

View File

@ -17,7 +17,7 @@ function love.load()
shadowBlur = 0.0 shadowBlur = 0.0
}) })
map = sti.new("examples/gfx/map") map = sti.new("examples/gfx/map.lua")
image_normal = love.graphics.newImage("examples/gfx/border_NRM.png") image_normal = love.graphics.newImage("examples/gfx/border_NRM.png")
-- create light -- create light

View File

@ -1,22 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

View File

@ -1,215 +0,0 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg

388
examples/vendor/sti/CHANGELOG.md vendored Executable file
View File

@ -0,0 +1,388 @@
# Change Log
## 2016-01-12: v0.14.1.12
* Added: Basic support for object layers in Bump plugin (thanks @premek)
* Changed: New line token from CRLF to LF
* Fixed: Sprite batches should now respect the map draw order
## 2016-01-01: v0.14.1.11
* Fixed: Various bugs in the Box2D plugin (thanks @ChrisWeisiger)
* Fixed: Various bugs in the Bump plugin (thanks @bobbyjoness)
## 2015-12-31: v0.14.1.10
* Fixed: Box2D plugin was not recognizing a tile's embedded object group
## 2015-11-19: v0.14.1.9
* Changed: key in image cache to formatted path of image
## 2015-11-16: v0.14.1.8
* Added: image cache to STI module [sponsored by Binary Cocoa]
* Added: STI:flush() to clear out image cache
## 2015-11-15: v0.14.1.7
* Added: support for offsetting maps [sponsored by Binary Cocoa]
* Changed: Map.setDrawRange is more optimized via recycling tables
* Changed: render order now defaults to "right-down"
## 2015-11-07: v0.14.1.6
* Fixed: tileset images not being properly filtered
* Fixed: bump.lua plugin missing world argument in draw
## 2015-10-14: v0.14.1.5
* Added: bump.lua plugin (thanks @bobbyjoness)
## 2015-10-12: v0.14.1.4
* Fixed: removing a layer now properly removes tile and object instances
* Fixed: box2d plugin now properly removes collision objects
## 2015-10-09: v0.14.1.3
* Fixed: flipping animated tiles properly display
* Fixed: rotating animated tiles properly display
* Fixed: rotating tile objects properly display
* Fixed: box2d plugin properly creates rotated and flipped tile objects
* Fixed: box2d plugin no longer crashes when drawing a line with two vertices
## 2015-10-07: v0.14.1.2
* Added: support for all render orders (rd, ru, ld, lu)
* Added: support for sensors in the box2d plugin (only works on individual tiles and objects; sensor = true)
* Changed: addCustomLayer's index argument is now optional and defaults to the end of the array
* Fixed: a crash when using Base64 (uncompressed) with LOVE 0.9.2
## 2015-10-03: v0.14.1.1
* Added: support for gzip compressed maps (requires LOVE 0.10.0+)
## 2015-09-30: v0.14.1.0
* Added: support for Base64 compressed maps (requires LuaJIT)
* Added: support for zlib compressed maps (requires LOVE 0.10.0+)
## 2015-09-28: v0.14.0.1
* Added: Support for all staggered types (x/y, even/odd, iso/hex)
## 2015-09-27: v0.14.0.0
* Added: Hexagonal map support (thanks EntranceJew!)
* Added: Error message for compressed maps
* Fixed: box2d plugin threw an error in some cases (thanks maxha651!)
## 2015-09-17: v0.13.1.4
* Changed: sanity checks now search for love.physics instead of love.physics.*
## 2015-09-16: v0.13.1.3
* Changed: Improved documentation
## 2015-09-16: v0.13.1.2
* Changed: Simplified plugins
* Changed: Namespaced the box2d plugin
* Removed: Non-LOVE frameworks (they didn't work)
## 2015-09-16: v0.13.1.1
* Added: LDoc documentation
* Added: Plugin system where devs can extend STI
* Added: Reinstated the Box2D integration as a plugin
## 2015-09-15: v0.13.1.0
* Added: Map:convertToCustomLayer() now returns the layer
* Changed: Tightened localization of some functions
* Removed: Box2D collision integration
* Removed: Unused functions
## 2015-07-31: v0.12.3.0
* Added: Tiled version number to Map.tiledversion
* Added: Map.objects table indexed by unique object IDs
* Added: A better error message when trying to use Tile Collections
* Changed: Version number should now match Tiled's version number
* Changed: You must now add ".lua" in the filename of a new map as this is consistent with other libraries
* Changed: Renamed "pure" framework to "lua" (still doesn't work, though!)
* Changed: Map:setDrawRange no longer inverts tx and ty for you, do it yourself!
* Changed: Map:draw no longer accepts scale values, use love.graphics.scale!
* Fixed: A bug where tile objects were drawing an object border
* Removed: Corona framework file
## 2015-03-22: v0.9.8
* Fixed: A bug where Tiles without a Properties list would crash
## 2015-02-02: v0.9.7
* Added: userdata to Box2D fixtures
* Changed: changelog.txt -> CHANGELOG.md
* Changed: Flipping tiles now happens in both tile layers and object layers
* Fixed: A bug where tile objects were drawing oddly in some cases
* Fixed: A bug where circles would error if physics was disabled
## 2015-01-28: v0.9.6
* Added: getLayerProperties(), getTileProperties(), and getObjectProperties()
* Fixed: A bug where flipped tiles crashed STI during initCollision()
* Fixed: Flipped collision tiles now have correct offset
* Removed: Reverted the change in v0.9.3 that filled in empty tiles with false
## 2014-12-15: v0.9.5
* Fixed: A bug where tile collision objects were using the wrong size in some cases
* Fixed: A bug where flipped tiles weren't always creating collision objects
## 2014-12-05: v0.9.4
* Changed: STI's canvas plays nicely with other libraries
* Changed: addCustomLayer() now returns a handle on the created layer
## 2014-12-03: v0.9.3
* Added: Local Tile IDs to Tile objects
* Added: Terrain information
* Fixed: Some conversion functions
* Changed: Tile Layers now contain "false" instead of "nil" where there is no tile
* Changed: Added \_LICENSE, \_URL, \_VERSION, and \_DESCRIPTION properties to core STI object
## 2014-09-29: v0.9.2
* Added: Support for drawing tiles in object layers
* Fixed: Incorrect calculation of some collision objects
## 2014-09-26: v0.9.1
* Fixed: A crash when a collidable tile is initialized but not used
* Removed: Public access to formatPath(), rotateVertex(), and convertEllipseToPolygon()
## 2014-09-24: v0.9.0
* Added: Animated tiles! (Thanks to Clean3d)
* Fixed: A crash when a collidable rectangle has no rotation value
* Fixed: Incorrect values given to orthogonal collision objects
## 2014-09-24: v0.8.3
* Added: Map:convertScreenToTile() and Map:convertTileToScreen()
* Added: Map:convertScreenToIsometricTile() and Map:convertIsometricTileToScreen()
* Added: Map:convertScreenToStaggeredTile() and Map:convertStaggeredTileToScreen()
* Fixed: Map:removeLayer() now works properly
* Changed: Tile Objects now use the tile's collision map by default
## 2014-09-22: v0.8.2
* Added: "collidable" property for objects, tiles, and layers
* if collidable is set to true in Tiled, STI will pick it up and set all appropriate entities to collidable objects
* Fixed: Physics module no long required if not needed.
* Fixed: Whitespace discrepencies
* Changed: Map:initWorldCollision() now supports a whole lot more
## 2014-09-21: v0.8.1
* Added: README now lists minimum requirements
* Changed: README updated with new collision system
* Changed: Map:enableCollision() renamed to Map:initWorldCollision()
* Changed: Map:drawCollisionMap() renamed to Map:drawWorldCollision()
* Changed: Updated framework files (still no real Lua/Corona support)
* Changed: Tidied up collision code
* Removed: Map:getCollisionMap()
## 2014-09-20: v0.8.0
* Added: Box2D collision via Map:enableCollision()
* Added: Map:convertEllipseToPolygon()
## 2014-09-17: v0.7.6
* Added: Map:convertScreenToIsometric and Map:convertIsometricToScreen
* Added: Map:setObjectCoordinates
* Added: Map:rotateVertex
* Fixed: Adjusted map positioning for Isometric and Staggered maps
* Fixed: Object positioning in Isometric maps
* Removed: Temporary fix for Tiled 0.9.1
## 2014-08-05: v0.7.5
* Fixed: Properties offset by 1
* Fixed: Drawing a single Layer can now use Layer's name/index
## 2014-04-28: v0.7.4
* Fixed: Canvas resize type
## 2014-04-18: v0.7.3
* Fixed: Canvas using wrong filter
## 2014-04-08: v0.7.2
* Removed: Dependency for LuaJIT's bitwise operations
## 2014-04-08: v0.7.1
* Added: Map:resize(w, h)
* Changed: Map:draw() now takes two optional arguments: ScaleX and ScaleY
* Changed: STI now draws to a Canvas before drawing to screen (fixes scaling oddities)
## 2014-04-07: v0.7.0
* Added: Files for Corona and Pure Lua implementation
* Changed: Restructured sti.lua into several files
* Changed: Library is now LOVE agnostic and should allow for implementation of other frameworks
## 2014-03-1 : v0.6.16
* Changed: Ellipses now use polygons instead of... Not polygons.
## 2014-03-1 : v0.6.15
* Fixed: Tile spacing calculated properly in all cases
## 2014-02-0 : v0.6.14
* Fixed: Tile properties ACTUALLY being added now!
## 2014-01-2 : v0.6.13
* Added: Missing Tile Flag
## 2014-01-2 : v0.6.12
* Added: drawCollisionMap() now supports Isometric and Staggered maps
* Changed: drawCollisionMap() now requires a collision map parameter
* Changed: setCollisionMap() renamed to getCollisionMap()
* Changed: getCollisionMap() now returns the collision map
* Fixed: Tile properties not being added
* Removed: Map.collision table removed
## 2014-01-2 : v0.6.11
* Added: Descriptive error messages
* Fixed: Image filters for scaling
## 2014-01-2 : v0.6.10
* Fixed: Optimized load time
## 2014-01-25: v0.6.9
* Fixed: Parallax Scrolling
## 2014-01-25: v0.6.8
* Changed: Revised and restructured code
* Changed: createCollisionMap() renamed to setCollisionMap()
* Changed: newCustomLayer() renamed to addCustomLayer()
## 2014-01-24: v0.6.7
* Fixed: Number of tiles wasn't calculated properly
## 2014-01-24: v0.6.6
* Fixed: Spacing wasn't calculated properly
## 2014-01-24: v0.6.5
* Added: Staggered Maps
## 2014-01-24: v0.6.4
* Added: Isometric Maps
## 2014-01-20: v0.6.3
* Added: Tile Flags (flip/rotation)
## 2014-01-20: v0.6.2
* Fixed: A scaling bug
## 2014-01-19: v0.6.1
* Fixed: A bug causing the Collision Map to be nil
## 2014-01-19: v0.6.0
* Added: Sprite Batches
## 2014-01-19: v0.5.0
* Added: Draw Range optimization
## 2014-01-18: v0.4.3
* Added: Layer draw offsets
## 2014-01-17: v0.4.2
* Changed: Organized library a little better
## 2014-01-17: v0.4.1
* Fixed: Tiles incorrectly offset
* Fixed: Drawing concave polygons
## 2014-01-17: v0.4.0
* Added: Draw Object Layers
## 2014-01-16: v0.3.3
* Added: Create new Custom Layer
* Added: Callbacks for all layers
* Added: Remove Layer
* Changed: Simplified sti.new()
## 2014-01-16: v0.3.2
* Fixed: Crash if using Tiled 0.9.1
* Changed: Map structure to remove "map" table
## 2014-01-16: v0.3.1
* Added: Update callback to Custom Layers
## 2014-01-16: v0.3.0
* Added: Support for converting layers to Custom Layers
* Changed: sti.new() no longer requires the file extension
## 2014-01-15: v0.2.2
* Added: Support for basic collision layer
## 2014-01-15: v0.2.1
* Added: Support for map instances
* Added: Name alias to layer indices
* Changed: Sandboxed map environment
* Changed: Data structures are more efficient
* Removed: Unnecessary update function
Thanks to JarrettBillingsley for many of these changes
## 2014-01-14: v0.2.0
* Fixed: Drawing Tile Offset
* Changed: Tile Layer data structure is more efficient
* Changed: Simplified Quad generation
## 2014-01-14: v0.1.0
* Initial Commit
* Added: Orthogonal Map support
* Added: Draw Tile Layers
* Added: Draw Image Layers
* Added: Ignore Hidden Layers
* Added: Layer Opacity

26
examples/vendor/sti/LICENSE.md vendored Executable file
View File

@ -0,0 +1,26 @@
# Simple Tiled Implementation
This code is licensed under the [**MIT/X11 Open Source License**][MIT].
Copyright (c) 2014 Landon Manning - LManning17@gmail.com - [LandonManning.com][LM]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
[MIT]: http://www.opensource.org/licenses/mit-license.html
[LM]: http://LandonManning.com

96
examples/vendor/sti/README.md vendored Executable file
View File

@ -0,0 +1,96 @@
# Simple Tiled Implementation
Simple Tiled Implementation is a [**Tiled**][Tiled] map loader and renderer designed for the **\*awesome\*** [**LÖVE**][LOVE] framework. Please read the [**documentation**][dox] to learn how it works!
## Quick Example
```lua
-- This example uses the default Box2D (love.physics) plugin!!
local sti = require "sti"
function love.load()
-- Grab window size
windowWidth = love.graphics.getWidth()
windowHeight = love.graphics.getHeight()
-- Set world meter size (in pixels)
love.physics.setMeter(32)
-- Load a map exported to Lua from Tiled
map = sti.new("assets/maps/map01.lua", { "box2d" })
-- Prepare physics world with horizontal and vertical gravity
world = love.physics.newWorld(0, 0)
-- Prepare collision objects
map:box2d_init(world)
-- Create a Custom Layer
map:addCustomLayer("Sprite Layer", 3)
-- Add data to Custom Layer
local spriteLayer = map.layers["Sprite Layer"]
spriteLayer.sprites = {
player = {
image = love.graphics.newImage("assets/sprites/player.png"),
x = 64,
y = 64,
r = 0,
}
}
-- Update callback for Custom Layer
function spriteLayer:update(dt)
for _, sprite in pairs(self.sprites) do
sprite.r = sprite.r + math.rad(90 * dt)
end
end
-- Draw callback for Custom Layer
function spriteLayer:draw()
for _, sprite in pairs(self.sprites) do
local x = math.floor(sprite.x)
local y = math.floor(sprite.y)
local r = sprite.r
love.graphics.draw(sprite.image, x, y, r)
end
end
end
function love.update(dt)
map:update(dt)
end
function love.draw()
-- Translation would normally be based on a player's x/y
local translateX = 0
local translateY = 0
-- Draw Range culls unnecessary tiles
map:setDrawRange(-translateX, -translateY, windowWidth, windowHeight)
-- Draw the map and all objects within
map:draw()
-- Draw Collision Map (useful for debugging)
love.graphics.setColor(255, 0, 0, 255)
map:box2d_draw()
-- Reset color
love.graphics.setColor(255, 255, 255, 255)
end
```
## Requirements
This library recommends LÖVE 0.9.2 or 0.10.0 and Tiled 0.14.1. If you are updating from an older version of Tiled, please re-export your Lua map files.
## License
This code is licensed under the [**MIT/X11 Open Source License**][MIT]. Check out the LICENSE file for more information.
[Tiled]: http://www.mapeditor.org/
[LOVE]: https://www.love2d.org/
[dox]: http://karai17.github.io/Simple-Tiled-Implementation/
[MIT]: http://www.opensource.org/licenses/mit-license.html

View File

@ -1,56 +0,0 @@
local lf = love.filesystem
local lg = love.graphics
local lm = love.math
local lp = love.physics
local framework = {}
framework.version = "Corona"
function framework.load(file)
return assert(lf.load(file), "File not found: " .. file)
end
function framework.newImage(path)
local image = lg.newImage(path)
image:setFilter("nearest", "nearest")
return image
end
function framework:newCanvas(w, h)
w = w or self.getWidth()
h = h or self.getHeight()
local canvas = lg.newCanvas(w, h)
canvas:setFilter("nearest", "nearest")
return canvas
end
-- Graphics Calls
framework.clear = lg.clear
framework.draw = lg.draw
framework.getHeight = lg.getHeight
framework.getWidth = lg.getWidth
framework.line = lg.line
framework.newSpriteBatch = lg.newSpriteBatch
framework.newQuad = lg.newQuad
framework.polygon = lg.polygon
framework.rectangle = lg.rectangle
framework.setColor = lg.setColor
framework.setCanvas = lg.setCanvas
framework.origin = lg.origin
framework.pop = lg.pop
framework.push = lg.push
-- Math Calls
framework.isConvex = lm.isConvex
framework.triangulate = lm.triangulate
-- Physics Calls
framework.getMeter = lp.getMeter
framework.newBody = lp.newBody
framework.newChainShape = lp.newChainShape
framework.newFixture = lp.newFixture
framework.newPolygonShape = lp.newPolygonShape
return framework

View File

@ -1,62 +0,0 @@
local lf = love.filesystem
local lg = love.graphics
local lm = love.math
local lp = love.physics
local framework = {}
framework.version = "LOVE"
assert(lf, "The love.filesystem module is required for this library.")
assert(lg, "The love.graphics module is required for this library.")
assert(lm, "The love.math module is required for this library.")
function framework.load(file)
return assert(lf.load(file), "File not found: " .. file)
end
function framework.newImage(path)
local image = lg.newImage(path)
image:setFilter("nearest", "nearest")
return image
end
function framework:newCanvas(w, h)
w = w or self.getWidth()
h = h or self.getHeight()
local canvas = lg.newCanvas(w, h)
canvas:setFilter("nearest", "nearest")
return canvas
end
-- Graphics Calls
framework.draw = lg.draw
framework.getCanvas = lg.getCanvas
framework.getHeight = lg.getHeight
framework.getWidth = lg.getWidth
framework.line = lg.line
framework.newSpriteBatch = lg.newSpriteBatch
framework.newQuad = lg.newQuad
framework.polygon = lg.polygon
framework.rectangle = lg.rectangle
framework.setColor = lg.setColor
framework.setCanvas = lg.setCanvas
framework.origin = lg.origin
framework.pop = lg.pop
framework.push = lg.push
-- Math Calls
framework.isConvex = lm.isConvex
framework.triangulate = lm.triangulate
-- Physics Calls
if lp then
framework.getMeter = lp.getMeter
framework.newBody = lp.newBody
framework.newChainShape = lp.newChainShape
framework.newFixture = lp.newFixture
framework.newPolygonShape = lp.newPolygonShape
end
return framework

View File

@ -1,56 +0,0 @@
local lf = love.filesystem
local lg = love.graphics
local lm = love.math
local lp = love.physics
local framework = {}
framework.version = "Lua"
function framework.load(file)
return assert(lf.load(file), "File not found: " .. file)
end
function framework.newImage(path)
local image = lg.newImage(path)
image:setFilter("nearest", "nearest")
return image
end
function framework:newCanvas(w, h)
w = w or self.getWidth()
h = h or self.getHeight()
local canvas = lg.newCanvas(w, h)
canvas:setFilter("nearest", "nearest")
return canvas
end
-- Graphics Calls
framework.clear = lg.clear
framework.draw = lg.draw
framework.getHeight = lg.getHeight
framework.getWidth = lg.getWidth
framework.line = lg.line
framework.newSpriteBatch = lg.newSpriteBatch
framework.newQuad = lg.newQuad
framework.polygon = lg.polygon
framework.rectangle = lg.rectangle
framework.setColor = lg.setColor
framework.setCanvas = lg.setCanvas
framework.origin = lg.origin
framework.pop = lg.pop
framework.push = lg.push
-- Math Calls
framework.isConvex = lm.isConvex
framework.triangulate = lm.triangulate
-- Physics Calls
framework.getMeter = lp.getMeter
framework.newBody = lp.newBody
framework.newChainShape = lp.newChainShape
framework.newFixture = lp.newFixture
framework.newPolygonShape = lp.newPolygonShape
return framework

View File

@ -1,51 +1,33 @@
--[[ --- Simple and fast Tiled map loader and renderer.
------------------------------------------------------------------------------ -- @module sti
Simple Tiled Implementation is licensed under the MIT Open Source License. -- @author Landon Manning
(http://www.opensource.org/licenses/mit-license.html) -- @copyright 2015
------------------------------------------------------------------------------ -- @license MIT/X11
Copyright (c) 2014 Landon Manning - LManning17@gmail.com - LandonManning.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]--
local STI = { local STI = {
_LICENSE = "STI is distributed under the terms of the MIT license. See LICENSE.md.", _LICENSE = "MIT/X11",
_URL = "https://github.com/karai17/Simple-Tiled-Implementation", _URL = "https://github.com/karai17/Simple-Tiled-Implementation",
_VERSION = "0.9.4", _VERSION = "0.14.1.12",
_DESCRIPTION = "Simple Tiled Implementation is a Tiled Map Editor library designed for the *awesome* LÖVE framework." _DESCRIPTION = "Simple Tiled Implementation is a Tiled Map Editor library designed for the *awesome* LÖVE framework.",
cache = {}
} }
local path = ... .. "." -- lol local path = (...):gsub('%.init$', '') .. "."
local Map = require(path .. "map") local Map = require(path .. "map")
local framework
if love then --- Instance a new map.
framework = require(path .. "framework.love") -- @param path Path to the map file.
elseif corona then -- I don't think this works -- @param plugins A list of plugins to load.
framework = require(path .. "framework.corona") -- @param ox Offset of map on the X axis (in pixels)
else -- @param oy Offset of map on the Y axis (in pixels)
framework = require(path .. "framework.pure") -- @return table The loaded Map.
end function STI.new(map, plugins, ox, oy)
-- Check for valid map type
function STI.new(map) local ext = map:sub(-4, -1)
map = map .. ".lua" assert(ext == ".lua", string.format(
"Invalid file type: %s. File must be of type: lua.",
ext
))
-- Get path to map -- Get path to map
local path = map:reverse():find("[/\\]") or "" local path = map:reverse():find("[/\\]") or ""
@ -54,37 +36,18 @@ function STI.new(map)
end end
-- Load map -- Load map
map = framework.load(map) map = love.filesystem.load(map)
setfenv(map, {}) setfenv(map, {})
map = setmetatable(map(), {__index = Map}) map = setmetatable(map(), {__index = Map})
map:init(path, framework) map:init(STI, path, plugins, ox, oy)
return map return map
end end
-- http://wiki.interfaceware.com/534.html --- Flush image cache.
function string.split(s, d) function STI:flush()
local t = {} self.cache = {}
local i = 0
local f
local match = '(.-)' .. d .. '()'
if string.find(s, d) == nil then
return {s}
end
for sub, j in string.gmatch(s, match) do
i = i + 1
t[i] = sub
f = j
end
if i ~= 0 then
t[i+1] = string.sub(s, f)
end
return t
end end
return STI return STI

File diff suppressed because it is too large Load Diff

349
examples/vendor/sti/plugins/box2d.lua vendored Executable file
View File

@ -0,0 +1,349 @@
--- Box2D plugin for STI
-- @module box2d
-- @author Landon Manning
-- @copyright 2015
-- @license MIT/X11
return {
box2d_LICENSE = "MIT/X11",
box2d_URL = "https://github.com/karai17/Simple-Tiled-Implementation",
box2d_VERSION = "2.3.2.1",
box2d_DESCRIPTION = "Box2D hooks for STI.",
--- Initialize Box2D physics world.
-- @param world The Box2D world to add objects to.
-- @return nil
box2d_init = function(map, world)
assert(love.physics, "To use the Box2D plugin, please enable the love.physics module.")
local body = love.physics.newBody(world, map.offsetx, map.offsety)
local collision = {
body = body,
}
local function convertEllipseToPolygon(x, y, w, h, max_segments)
local function calc_segments(segments)
local function vdist(a, b)
local c = {
x = a.x - b.x,
y = a.y - b.y,
}
return c.x * c.x + c.y * c.y
end
segments = segments or 64
local vertices = {}
local v = { 1, 2, math.ceil(segments/4-1), math.ceil(segments/4) }
local m
if love.physics then
m = love.physics.getMeter()
else
m = 32
end
for _, i in ipairs(v) do
local angle = (i / segments) * math.pi * 2
local px = x + w / 2 + math.cos(angle) * w / 2
local py = y + h / 2 + math.sin(angle) * h / 2
table.insert(vertices, { x = px / m, y = py / m })
end
local dist1 = vdist(vertices[1], vertices[2])
local dist2 = vdist(vertices[3], vertices[4])
-- Box2D threshold
if dist1 < 0.0025 or dist2 < 0.0025 then
return calc_segments(segments-2)
end
return segments
end
local segments = calc_segments(max_segments)
local vertices = {}
table.insert(vertices, { x = x + w / 2, y = y + h / 2 })
for i=0, segments do
local angle = (i / segments) * math.pi * 2
local px = x + w / 2 + math.cos(angle) * w / 2
local py = y + h / 2 + math.sin(angle) * h / 2
table.insert(vertices, { x = px, y = py })
end
return vertices
end
local function rotateVertex(v, x, y, cos, sin, oy)
oy = oy or 0
local vertex = {
x = v.x,
y = v.y - oy,
}
vertex.x = vertex.x - x
vertex.y = vertex.y - y
local vx = cos * vertex.x - sin * vertex.y
local vy = sin * vertex.x + cos * vertex.y
return vx + x, vy + y + oy
end
local function addObjectToWorld(objshape, vertices, userdata, object)
local shape
if objshape == "polyline" then
shape = love.physics.newChainShape(false, unpack(vertices))
else
shape = love.physics.newPolygonShape(unpack(vertices))
end
local fixture = love.physics.newFixture(body, shape)
fixture:setUserData(userdata)
if userdata.properties.sensor == "true" then
fixture:setSensor(true)
end
local obj = {
object = object,
shape = shape,
fixture = fixture,
}
table.insert(collision, obj)
end
local function getPolygonVertices(object)
local vertices = {}
for _, vertex in ipairs(object.polygon) do
table.insert(vertices, vertex.x)
table.insert(vertices, vertex.y)
end
return vertices
end
local function calculateObjectPosition(object, tile)
local o = {
shape = object.shape,
x = object.dx or object.x,
y = object.dy or object.y,
w = object.width,
h = object.height,
polygon = object.polygon or object.polyline or object.ellipse or object.rectangle
}
local userdata = {
object = o,
properties = object.properties
}
if o.shape == "rectangle" then
o.r = object.rotation or 0
local cos = math.cos(math.rad(o.r))
local sin = math.sin(math.rad(o.r))
local oy = 0
if object.gid then
local tileset = map.tilesets[map.tiles[object.gid].tileset]
local lid = object.gid - tileset.firstgid
local tile = {}
-- This fixes a height issue
o.y = o.y + map.tiles[object.gid].offset.y
oy = tileset.tileheight
for _, t in ipairs(tileset.tiles) do
if t.id == lid then
tile = t
break
end
end
if tile.objectGroup then
for _, obj in ipairs(tile.objectGroup.objects) do
-- Every object in the tile
calculateObjectPosition(obj, object)
end
return
else
o.w = map.tiles[object.gid].width
o.h = map.tiles[object.gid].height
end
end
o.polygon = {
{ x=o.x+0, y=o.y+0 },
{ x=o.x+o.w, y=o.y+0 },
{ x=o.x+o.w, y=o.y+o.h },
{ x=o.x+0, y=o.y+o.h },
}
for _, vertex in ipairs(o.polygon) do
if map.orientation == "isometric" then
vertex.x, vertex.y = map:convertIsometricToScreen(vertex.x, vertex.y)
end
vertex.x, vertex.y = rotateVertex(vertex, o.x, o.y, cos, sin, oy)
end
local vertices = getPolygonVertices(o)
addObjectToWorld(o.shape, vertices, userdata, tile or object)
elseif o.shape == "ellipse" then
if not o.polygon then
o.polygon = convertEllipseToPolygon(o.x, o.y, o.w, o.h)
end
local vertices = getPolygonVertices(o)
local triangles = love.math.triangulate(vertices)
for _, triangle in ipairs(triangles) do
addObjectToWorld(o.shape, triangle, userdata, tile or object)
end
elseif o.shape == "polygon" then
local vertices = getPolygonVertices(o)
local triangles = love.math.triangulate(vertices)
for _, triangle in ipairs(triangles) do
addObjectToWorld(o.shape, triangle, userdata, tile or object)
end
elseif o.shape == "polyline" then
local vertices = getPolygonVertices(o)
addObjectToWorld(o.shape, vertices, userdata, tile or object)
end
end
for _, tile in pairs(map.tiles) do
local tileset = map.tilesets[tile.tileset]
-- Every object in every instance of a tile
if tile.objectGroup then
if map.tileInstances[tile.gid] then
for _, instance in ipairs(map.tileInstances[tile.gid]) do
for _, object in ipairs(tile.objectGroup.objects) do
object.dx = object.x + instance.x
object.dy = object.y + instance.y
calculateObjectPosition(object, instance)
end
end
end
-- Every instance of a tile
elseif tile.properties and tile.properties.collidable == "true" and map.tileInstances[tile.gid] then
for _, instance in ipairs(map.tileInstances[tile.gid]) do
local object = {
shape = "rectangle",
x = instance.x,
y = instance.y,
width = tileset.tilewidth,
height = tileset.tileheight,
properties = tile.properties
}
calculateObjectPosition(object, instance)
end
end
end
for _, layer in ipairs(map.layers) do
-- Entire layer
if layer.properties.collidable == "true" then
if layer.type == "tilelayer" then
for gid, tiles in pairs(map.tileInstances) do
local tile = map.tiles[gid]
local tileset = map.tilesets[tile.tileset]
for _, instance in ipairs(tiles) do
if instance.layer == layer then
local object = {
shape = "rectangle",
x = instance.x,
y = instance.y,
width = tileset.tilewidth,
height = tileset.tileheight,
properties = tile.properties
}
calculateObjectPosition(object, instance)
end
end
end
elseif layer.type == "objectgroup" then
for _, object in ipairs(layer.objects) do
calculateObjectPosition(object)
end
elseif layer.type == "imagelayer" then
local object = {
shape = "rectangle",
x = layer.x or 0,
y = layer.y or 0,
width = layer.width,
height = layer.height,
properties = layer.properties
}
calculateObjectPosition(object)
end
end
-- Individual objects
if layer.type == "objectgroup" then
for _, object in ipairs(layer.objects) do
if object.properties.collidable == "true" then
calculateObjectPosition(object)
end
end
end
end
map.box2d_collision = collision
end,
--- Remove Box2D fixtures and shapes from world.
-- @param index The index or name of the layer being removed
-- @return nil
box2d_removeLayer = function(map, index)
local layer = assert(map.layers[index], "Layer not found: " .. index)
local collision = map.box2d_collision
-- Remove collision objects
for i=#collision, 1, -1 do
local obj = collision[i]
if obj.object.layer == layer then
obj.fixture:destroy()
table.remove(collision, i)
end
end
end,
--- Draw Box2D physics world.
-- @return nil
box2d_draw = function(map)
local collision = map.box2d_collision
for _, obj in ipairs(collision) do
local points = {collision.body:getWorldPoints(obj.shape:getPoints())}
if #points == 4 then
love.graphics.line(points)
else
love.graphics.polygon("line", points)
end
end
end,
}
--- Custom Properties in Tiled are used to tell this plugin what to do.
-- @table Properties
-- @field collidable set to "true", can be used on any Layer, Tile, or Object
-- @field sensor set to "true", can be used on any Tile or Object that is also collidable

103
examples/vendor/sti/plugins/bump.lua vendored Executable file
View File

@ -0,0 +1,103 @@
--- Bump.lua plugin for STI
-- @module bump.lua
-- @author David Serrano (BobbyJones|FrenchFryLord)
-- @copyright 2016
-- @license MIT/X11
return {
bump_LICENSE = "MIT/X11",
bump_URL = "https://github.com/karai17/Simple-Tiled-Implementation",
bump_VERSION = "3.1.5.2",
bump_DESCRIPTION = "Bump hooks for STI.",
--- Adds each collidable tile to the Bump world.
-- @param world The Bump world to add objects to.
-- @return collidables table containing the handles to the objects in the Bump world.
bump_init = function(map, world)
local collidables = {}
for _, tileset in ipairs(map.tilesets) do
for _, tile in ipairs(tileset.tiles) do
local gid = tileset.firstgid + tile.id
-- Every object in every instance of a tile
if tile.properties and tile.properties.collidable == "true" and map.tileInstances[gid] then
for _, instance in ipairs(map.tileInstances[gid]) do
local t = {properties = tile.properties, x = instance.x + map.offsetx, y = instance.y + map.offsety, width = map.tilewidth, height = map.tileheight, layer = instance.layer }
world:add(t, t.x,t.y, t.width,t.height)
table.insert(collidables,t)
end
end
end
end
for _, layer in ipairs(map.layers) do
-- Entire layer
if layer.properties.collidable == "true" then
if layer.type == "tilelayer" then
for y, tiles in ipairs(layer.data) do
for x, tile in pairs(tiles) do
local t = {properties = tile.properties, x = x * map.tilewidth + tile.offset.x + map.offsetx, y = y * map.tileheight + tile.offset.y + map.offsety, width = tile.width, height = tile.height, layer = layer }
world:add(t, t.x,t.y, t.width,t.height )
table.insert(collidables,t)
end
end
elseif layer.type == "imagelayer" then
world:add(layer, layer.x,layer.y, layer.width,layer.height)
table.insert(collidables,layer)
end
end
-- individual collidable objects in a layer that is not "collidable"
-- or whole collidable objects layer
if layer.type == "objectgroup" then
for _, obj in ipairs(layer.objects) do
if (layer.properties and layer.properties.collidable == "true")
or (obj.properties and obj.properties.collidable == "true") then
if obj.shape == "rectangle" then
local t = {properties = obj.properties, x = obj.x, y = obj.y, width = obj.width, height = obj.height, type = obj.type, name = obj.name, id = obj.id, gid = obj.gid, layer = layer }
if obj.gid then t.y = t.y - obj.height end
world:add(t, t.x,t.y, t.width,t.height )
table.insert(collidables,t)
end -- TODO implement other object shapes?
end
end
end
end
map.bump_collidables = collidables
end,
--- Remove layer
-- @params index to layer to be removed
-- @params world bump world the holds the tiles
-- @return nil
bump_removeLayer = function(map, index, world)
local layer = assert(map.layers[index], "Layer not found: " .. index)
local collidables = map.bump_collidables
-- Remove collision objects
for i=#collidables, 1, -1 do
local obj = collidables[i]
if obj.layer == layer
and (
layer.properties.collidable == "true"
or obj.properties.collidable == "true"
) then
world:remove(obj)
table.remove(collidables, i)
end
end
end,
--- Draw bump collisions world.
-- @params world bump world holding the tiles geometry
-- @return nil
bump_draw = function(map, world)
for k,collidable in pairs(map.bump_collidables) do
love.graphics.rectangle("line",world:getRect(collidable))
end
end
}

View File

@ -525,8 +525,9 @@ function body:setShadowType(type, ...)
{0.0, self.height, 0.0, 1.0} {0.0, self.height, 0.0, 1.0}
} }
if not self.shadowMesh then if not self.shadowMesh then
self.shadowMesh = love.graphics.newMesh(self.shadowVert, self.img, "fan") self.shadowMesh = love.graphics.newMesh(self.shadowVert)
self.shadowMesh:setVertexColors(true) self.shadowMesh:setTexture(self.img)
self.shadowMesh:setAttributeEnabled("VertexColor", true)
end end
else else
self.width = 64 self.width = 64

View File

@ -94,7 +94,7 @@ function post_shader:drawBloom(canvas, args)
util.process(self.back_buffer, {shader = shaders['blurh'][1]}) util.process(self.back_buffer, {shader = shaders['blurh'][1]})
util.process(self.back_buffer, {shader = shaders['contrast'][1]}) util.process(self.back_buffer, {shader = shaders['contrast'][1]})
util.process(canvas, {shader = shaders['contrast'][1]}) util.process(canvas, {shader = shaders['contrast'][1]})
util.drawCanvasToCanvas(self.back_buffer, canvas, {blendmode = "additive", color = {255, 255, 255, (args[2] or 0.25) * 255}}) util.drawCanvasToCanvas(self.back_buffer, canvas, {blendmode = "add", color = {255, 255, 255, (args[2] or 0.25) * 255}})
end end
function post_shader:drawBlur(canvas, args) function post_shader:drawBlur(canvas, args)