Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWerder committed Feb 10, 2016
0 parents commit 4da07dd
Show file tree
Hide file tree
Showing 44 changed files with 2,164 additions and 0 deletions.
Empty file added ReadMe.md
Empty file.
152 changes: 152 additions & 0 deletions animation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
--[[
Copyright (c) 2009 Bart Bes
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 anim_mt = {}
anim_mt.__index = anim_mt

function newAnimation(image, fw, fh, delay, frames)
local a = {}
a.img = image
a.frames = {}
a.delays = {}
a.timer = 0
a.position = 1
a.fw = fw
a.fh = fh
a.playing = true
a.speed = 1
a.mode = 1
a.direction = 1
local imgw = image:getWidth()
local imgh = image:getHeight()
if frames == 0 then
frames = imgw / fw * imgh / fh
end
local rowsize = imgw/fw
for i = 1, frames do
local row = math.floor(i/rowsize)
local column = i%rowsize
local frame = love.graphics.newQuad(column*fw, row*fh, fw, fh, imgw, imgh)
table.insert(a.frames, frame)
table.insert(a.delays, delay)
end
return setmetatable(a, anim_mt)
end

function anim_mt:update(dt)
if not self.playing then return end
self.timer = self.timer + dt * self.speed
if self.timer > self.delays[self.position] then
self.timer = self.timer - self.delays[self.position]
self.position = self.position + 1 * self.direction
if self.position > #self.frames then
if self.mode == 1 then
self.position = 1
elseif self.mode == 2 then
self.position = self.position - 1
self:stop()
elseif self.mode == 3 then
self.direction = -1
self.position = self.position - 1
end
elseif self.position < 1 and self.mode == 3 then
self.direction = 1
self.position = self.position + 1
end
end
end

function anim_mt:draw(x, y, angle, sx, sy)
love.graphics.draw(self.img, self.frames[self.position], x, y, angle, sx, sy)
end

function anim_mt:addFrame(x, y, w, h, delay)
local frame = love.graphics.newQuad(x, y, w, h, a.img:getWidth(), a.img:getHeight())
table.insert(self.frames, frame)
table.insert(self.delays, delay)
end

function anim_mt:play()
self.playing = true
end

function anim_mt:stop()
self.playing = false
end

function anim_mt:reset()
self:seek(0)
end

function anim_mt:seek(frame)
self.position = frame
self.timer = 0
end

function anim_mt:getCurrentFrame()
return self.position
end

function anim_mt:getSize()
return #self.frames
end

function anim_mt:setDelay(frame, delay)
self.delays[frame] = delay
end

function anim_mt:setSpeed(speed)
self.speed = speed
end

function anim_mt:getWidth()
return self.frames[self.position]:getWidth()
end

function anim_mt:getHeight()
return self.frames[self.position]:getHeight()
end

function anim_mt:setMode(mode)
if mode == "loop" then
self.mode = 1
elseif mode == "once" then
self.mode = 2
elseif mode == "bounce" then
self.mode = 3
end
end

if Animations_legacy_support then
love.graphics.newAnimation = newAnimation
local oldLGDraw = love.graphics.draw
function love.graphics.draw(item, ...)
if type(item) == "table" and item.draw then
item:draw(...)
else
oldLGDraw(item, ...)
end
end
end
Binary file added assets/Grundschrift-Normal.otf
Binary file not shown.
Binary file added assets/HA-1112-M1LBuchon_flyby.ogg
Binary file not shown.
Binary file added assets/Minimal5x7.ttf
Binary file not shown.
Binary file added assets/anim-boogie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/love-ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/love-big-ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/love-cursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions conf.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function love.conf(t)
--t.console = true
author = "rude, and Codingale for the conversion to 0.9.0"
love_version = "0.10.0"
end
14 changes: 14 additions & 0 deletions examples/001_loading_image.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Example: Loading an Image and displaying it
--[[Description:
Load an image using love.graphics.newImage(image_path)
Draw it using love.graphics.draw
]]

function love.load()
image = love.graphics.newImage("assets/love-ball.png")
end

function love.draw()
love.graphics.draw(image, 400, 300)
end

16 changes: 16 additions & 0 deletions examples/002_mouse_getpos.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Example: Getting the mouse position
--[[Description:
Get the mouse position with love.mouse.getPosition()
Display it with love.graphics.print
]]

function love.load()
love.graphics.setFont(love.graphics.newFont(11))
end

function love.draw()
-- Gets the x- and y-position of the mouse.
local x, y = love.mouse.getPosition()
-- Draws the position on screen.
love.graphics.print("The mouse is at (" .. x .. "," .. y .. ")", 50, 50)
end
23 changes: 23 additions & 0 deletions examples/003_mouse_getx_gety.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Example: Getting the x or y position of the mouse
--[[Description:
Get the mouse position x with love.mouse.getX()
Get the mouse position y with love.mouse.getY()
Display it with love.graphics.print
P.S. I don't see how this is any different from 0002
P.S. I don't see how this is any different from 0002
P.S. I don't see how this is any diffe
Description character limit is löw
]]

function love.load()
love.graphics.setFont(love.graphics.newFont(11))
end

function love.draw()
-- Gets the x- and y-position of the mouse.
local x = love.mouse.getX()
local y = love.mouse.getY()
-- Draws the position on screen.
love.graphics.print("The mouse is at (" .. x .. "," .. y .. ")", 50, 50)
end
16 changes: 16 additions & 0 deletions examples/004_mouse_setpos.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Example: Setting the mouse position

function love.load()
love.graphics.setFont(love.graphics.newFont(11))
end

function love.draw()
love.graphics.print("Press a key to move the mouse to a random point", 50, 50)
end

-- Press a key to move the mouse to
-- some random point.
function love.keypressed(k)
local x, y = math.random(0,800), math.random(0,600)
love.mouse.setPosition(x, y)
end
22 changes: 22 additions & 0 deletions examples/005_mouse_button.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Example: Checking for pressed mouse buttons

function love.load()
love.graphics.setFont(love.graphics.newFont(11))
end

function love.draw()
-- Left mouse button.
if love.mouse.isDown(1) then
love.graphics.print("Left mouse button is down", 50, 50)
end

-- Right mouse button.
if love.mouse.isDown(2) then
love.graphics.print("Right mouse button is down", 50, 100)
end

-- Middle mouse button.
if love.mouse.isDown(3) then
love.graphics.print("Middle mouse button is down", 50, 75)
end
end
22 changes: 22 additions & 0 deletions examples/006_cursor_visibility.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Example: Cursor Visibility

function love.load()
-- Hide mouse on startup.
love.mouse.setVisible(false)
love.graphics.setFont(love.graphics.newFont(11))
end

-- Toggle cursor visibility.
function love.keypressed(k)
if k == "v" then
if love.mouse.isVisible() then
love.mouse.setVisible(false)
else
love.mouse.setVisible(true)
end
end
end

function love.draw()
love.graphics.print("Press V to toggle visibility.", 50, 50)
end
8 changes: 8 additions & 0 deletions examples/007_sleeping.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Example: Sleeping

function love.update(dt)
-- Sleeps 10ms after each udpate. By doing this,
-- CPU time is made available for other processes,
-- and your OS will love you for it.
love.timer.sleep(0.01)
end
13 changes: 13 additions & 0 deletions examples/008_fps_delta.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Example: FPS and delta-time

function love.load()
love.graphics.setFont(love.graphics.newFont(11))
end

function love.draw()
-- Draw the current FPS.
love.graphics.print("FPS: " .. love.timer.getFPS(), 50, 50)
-- Draw the current delta-time. (The same value
-- is passed to update each frame).
love.graphics.print("dt: " .. love.timer.getDelta(), 50, 100)
end
20 changes: 20 additions & 0 deletions examples/009_timing.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Example: Timing code

function love.load()
-- Get time before the code to be timed.
t_start = love.timer.getTime()

-- Load 10 fonts.
for i=13,22 do
local f = love.graphics.newFont(i)
love.graphics.setFont(f)
end

-- Get time after.
t_end = love.timer.getTime()

end

function love.draw()
love.graphics.print("Spent " .. (t_end-t_start) .. " seconds loading 10 fonts.", 50, 50)
end
14 changes: 14 additions & 0 deletions examples/010_key_down.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Example: Checking if a key is down

function love.load()
love.graphics.setFont(love.graphics.newFont(11))
end

function love.draw()
-- Checks whether the return key is down or not.
if love.keyboard.isDown("return") then
love.graphics.print("The return key is down.", 50, 50)
else
love.graphics.print("The return key isn't down.", 50, 50)
end
end
43 changes: 43 additions & 0 deletions examples/011_animation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- Example: Create and use an Animation
require("animation")

function newImagePO2(filename)
local source = love.image.newImageData(filename)
local w, h = source:getWidth(), source:getHeight()

-- Find closest power-of-two.
local wp = math.pow(2, math.ceil(math.log(w)/math.log(2)))
local hp = math.pow(2, math.ceil(math.log(h)/math.log(2)))

-- Only pad if needed:
if wp ~= w or hp ~= h then
local padded = love.image.newImageData(wp, hp)
padded:paste(source, 0, 0)
return love.graphics.newImage(padded)
end

return love.graphics.newImage(source)
end

function love.load()
-- Set a lovely pink background color.
love.graphics.setBackgroundColor(246, 198, 222)

-- Load the source of the animation.
img = newImagePO2("assets/anim-boogie.png")

-- Create an animation with a frame size of 32x32 and
-- 0.1s delay betwen each frame.
animation1 = newAnimation(img, 32, 32, 0.1, 6)
end

function love.update(dt)
-- The animation must be updated so it
-- knows when to change frames.
animation1:update(dt)
end

function love.draw()
-- Draw the animation the center of the screen.
animation1:draw(400, 300, 0, 1, 1)
end
11 changes: 11 additions & 0 deletions examples/012_cursor_change.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Example: Use an Image as cursor

function love.load()
-- Load the "cursor" (with default hot spot 0, 0)
cursor = love.mouse.newCursor("assets/love-cursor.png")

-- Set the cursor
love.mouse.setCursor( cursor )
end


Loading

0 comments on commit 4da07dd

Please sign in to comment.