Skip to content

Commit 4da07dd

Browse files
committed
Initial Commit
0 parents  commit 4da07dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2164
-0
lines changed

ReadMe.md

Whitespace-only changes.

animation.lua

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
--[[
2+
Copyright (c) 2009 Bart Bes
3+
4+
Permission is hereby granted, free of charge, to any person
5+
obtaining a copy of this software and associated documentation
6+
files (the "Software"), to deal in the Software without
7+
restriction, including without limitation the rights to use,
8+
copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
OTHER DEALINGS IN THE SOFTWARE.
24+
]]
25+
26+
local anim_mt = {}
27+
anim_mt.__index = anim_mt
28+
29+
function newAnimation(image, fw, fh, delay, frames)
30+
local a = {}
31+
a.img = image
32+
a.frames = {}
33+
a.delays = {}
34+
a.timer = 0
35+
a.position = 1
36+
a.fw = fw
37+
a.fh = fh
38+
a.playing = true
39+
a.speed = 1
40+
a.mode = 1
41+
a.direction = 1
42+
local imgw = image:getWidth()
43+
local imgh = image:getHeight()
44+
if frames == 0 then
45+
frames = imgw / fw * imgh / fh
46+
end
47+
local rowsize = imgw/fw
48+
for i = 1, frames do
49+
local row = math.floor(i/rowsize)
50+
local column = i%rowsize
51+
local frame = love.graphics.newQuad(column*fw, row*fh, fw, fh, imgw, imgh)
52+
table.insert(a.frames, frame)
53+
table.insert(a.delays, delay)
54+
end
55+
return setmetatable(a, anim_mt)
56+
end
57+
58+
function anim_mt:update(dt)
59+
if not self.playing then return end
60+
self.timer = self.timer + dt * self.speed
61+
if self.timer > self.delays[self.position] then
62+
self.timer = self.timer - self.delays[self.position]
63+
self.position = self.position + 1 * self.direction
64+
if self.position > #self.frames then
65+
if self.mode == 1 then
66+
self.position = 1
67+
elseif self.mode == 2 then
68+
self.position = self.position - 1
69+
self:stop()
70+
elseif self.mode == 3 then
71+
self.direction = -1
72+
self.position = self.position - 1
73+
end
74+
elseif self.position < 1 and self.mode == 3 then
75+
self.direction = 1
76+
self.position = self.position + 1
77+
end
78+
end
79+
end
80+
81+
function anim_mt:draw(x, y, angle, sx, sy)
82+
love.graphics.draw(self.img, self.frames[self.position], x, y, angle, sx, sy)
83+
end
84+
85+
function anim_mt:addFrame(x, y, w, h, delay)
86+
local frame = love.graphics.newQuad(x, y, w, h, a.img:getWidth(), a.img:getHeight())
87+
table.insert(self.frames, frame)
88+
table.insert(self.delays, delay)
89+
end
90+
91+
function anim_mt:play()
92+
self.playing = true
93+
end
94+
95+
function anim_mt:stop()
96+
self.playing = false
97+
end
98+
99+
function anim_mt:reset()
100+
self:seek(0)
101+
end
102+
103+
function anim_mt:seek(frame)
104+
self.position = frame
105+
self.timer = 0
106+
end
107+
108+
function anim_mt:getCurrentFrame()
109+
return self.position
110+
end
111+
112+
function anim_mt:getSize()
113+
return #self.frames
114+
end
115+
116+
function anim_mt:setDelay(frame, delay)
117+
self.delays[frame] = delay
118+
end
119+
120+
function anim_mt:setSpeed(speed)
121+
self.speed = speed
122+
end
123+
124+
function anim_mt:getWidth()
125+
return self.frames[self.position]:getWidth()
126+
end
127+
128+
function anim_mt:getHeight()
129+
return self.frames[self.position]:getHeight()
130+
end
131+
132+
function anim_mt:setMode(mode)
133+
if mode == "loop" then
134+
self.mode = 1
135+
elseif mode == "once" then
136+
self.mode = 2
137+
elseif mode == "bounce" then
138+
self.mode = 3
139+
end
140+
end
141+
142+
if Animations_legacy_support then
143+
love.graphics.newAnimation = newAnimation
144+
local oldLGDraw = love.graphics.draw
145+
function love.graphics.draw(item, ...)
146+
if type(item) == "table" and item.draw then
147+
item:draw(...)
148+
else
149+
oldLGDraw(item, ...)
150+
end
151+
end
152+
end

assets/Grundschrift-Normal.otf

15.3 KB
Binary file not shown.

assets/HA-1112-M1LBuchon_flyby.ogg

547 KB
Binary file not shown.

assets/Minimal5x7.ttf

14.2 KB
Binary file not shown.

assets/anim-boogie.png

902 Bytes
Loading

assets/love-ball.png

2.12 KB
Loading

assets/love-big-ball.png

3.99 KB
Loading

assets/love-cursor.png

1.25 KB
Loading

conf.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function love.conf(t)
2+
--t.console = true
3+
author = "rude, and Codingale for the conversion to 0.9.0"
4+
love_version = "0.10.0"
5+
end

examples/001_loading_image.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Example: Loading an Image and displaying it
2+
--[[Description:
3+
Load an image using love.graphics.newImage(image_path)
4+
Draw it using love.graphics.draw
5+
]]
6+
7+
function love.load()
8+
image = love.graphics.newImage("assets/love-ball.png")
9+
end
10+
11+
function love.draw()
12+
love.graphics.draw(image, 400, 300)
13+
end
14+

examples/002_mouse_getpos.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Example: Getting the mouse position
2+
--[[Description:
3+
Get the mouse position with love.mouse.getPosition()
4+
Display it with love.graphics.print
5+
]]
6+
7+
function love.load()
8+
love.graphics.setFont(love.graphics.newFont(11))
9+
end
10+
11+
function love.draw()
12+
-- Gets the x- and y-position of the mouse.
13+
local x, y = love.mouse.getPosition()
14+
-- Draws the position on screen.
15+
love.graphics.print("The mouse is at (" .. x .. "," .. y .. ")", 50, 50)
16+
end

examples/003_mouse_getx_gety.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Example: Getting the x or y position of the mouse
2+
--[[Description:
3+
Get the mouse position x with love.mouse.getX()
4+
Get the mouse position y with love.mouse.getY()
5+
Display it with love.graphics.print
6+
7+
P.S. I don't see how this is any different from 0002
8+
P.S. I don't see how this is any different from 0002
9+
P.S. I don't see how this is any diffe
10+
Description character limit is löw
11+
]]
12+
13+
function love.load()
14+
love.graphics.setFont(love.graphics.newFont(11))
15+
end
16+
17+
function love.draw()
18+
-- Gets the x- and y-position of the mouse.
19+
local x = love.mouse.getX()
20+
local y = love.mouse.getY()
21+
-- Draws the position on screen.
22+
love.graphics.print("The mouse is at (" .. x .. "," .. y .. ")", 50, 50)
23+
end

examples/004_mouse_setpos.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Example: Setting the mouse position
2+
3+
function love.load()
4+
love.graphics.setFont(love.graphics.newFont(11))
5+
end
6+
7+
function love.draw()
8+
love.graphics.print("Press a key to move the mouse to a random point", 50, 50)
9+
end
10+
11+
-- Press a key to move the mouse to
12+
-- some random point.
13+
function love.keypressed(k)
14+
local x, y = math.random(0,800), math.random(0,600)
15+
love.mouse.setPosition(x, y)
16+
end

examples/005_mouse_button.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Example: Checking for pressed mouse buttons
2+
3+
function love.load()
4+
love.graphics.setFont(love.graphics.newFont(11))
5+
end
6+
7+
function love.draw()
8+
-- Left mouse button.
9+
if love.mouse.isDown(1) then
10+
love.graphics.print("Left mouse button is down", 50, 50)
11+
end
12+
13+
-- Right mouse button.
14+
if love.mouse.isDown(2) then
15+
love.graphics.print("Right mouse button is down", 50, 100)
16+
end
17+
18+
-- Middle mouse button.
19+
if love.mouse.isDown(3) then
20+
love.graphics.print("Middle mouse button is down", 50, 75)
21+
end
22+
end

examples/006_cursor_visibility.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Example: Cursor Visibility
2+
3+
function love.load()
4+
-- Hide mouse on startup.
5+
love.mouse.setVisible(false)
6+
love.graphics.setFont(love.graphics.newFont(11))
7+
end
8+
9+
-- Toggle cursor visibility.
10+
function love.keypressed(k)
11+
if k == "v" then
12+
if love.mouse.isVisible() then
13+
love.mouse.setVisible(false)
14+
else
15+
love.mouse.setVisible(true)
16+
end
17+
end
18+
end
19+
20+
function love.draw()
21+
love.graphics.print("Press V to toggle visibility.", 50, 50)
22+
end

examples/007_sleeping.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Example: Sleeping
2+
3+
function love.update(dt)
4+
-- Sleeps 10ms after each udpate. By doing this,
5+
-- CPU time is made available for other processes,
6+
-- and your OS will love you for it.
7+
love.timer.sleep(0.01)
8+
end

examples/008_fps_delta.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Example: FPS and delta-time
2+
3+
function love.load()
4+
love.graphics.setFont(love.graphics.newFont(11))
5+
end
6+
7+
function love.draw()
8+
-- Draw the current FPS.
9+
love.graphics.print("FPS: " .. love.timer.getFPS(), 50, 50)
10+
-- Draw the current delta-time. (The same value
11+
-- is passed to update each frame).
12+
love.graphics.print("dt: " .. love.timer.getDelta(), 50, 100)
13+
end

examples/009_timing.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Example: Timing code
2+
3+
function love.load()
4+
-- Get time before the code to be timed.
5+
t_start = love.timer.getTime()
6+
7+
-- Load 10 fonts.
8+
for i=13,22 do
9+
local f = love.graphics.newFont(i)
10+
love.graphics.setFont(f)
11+
end
12+
13+
-- Get time after.
14+
t_end = love.timer.getTime()
15+
16+
end
17+
18+
function love.draw()
19+
love.graphics.print("Spent " .. (t_end-t_start) .. " seconds loading 10 fonts.", 50, 50)
20+
end

examples/010_key_down.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Example: Checking if a key is down
2+
3+
function love.load()
4+
love.graphics.setFont(love.graphics.newFont(11))
5+
end
6+
7+
function love.draw()
8+
-- Checks whether the return key is down or not.
9+
if love.keyboard.isDown("return") then
10+
love.graphics.print("The return key is down.", 50, 50)
11+
else
12+
love.graphics.print("The return key isn't down.", 50, 50)
13+
end
14+
end

examples/011_animation.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- Example: Create and use an Animation
2+
require("animation")
3+
4+
function newImagePO2(filename)
5+
local source = love.image.newImageData(filename)
6+
local w, h = source:getWidth(), source:getHeight()
7+
8+
-- Find closest power-of-two.
9+
local wp = math.pow(2, math.ceil(math.log(w)/math.log(2)))
10+
local hp = math.pow(2, math.ceil(math.log(h)/math.log(2)))
11+
12+
-- Only pad if needed:
13+
if wp ~= w or hp ~= h then
14+
local padded = love.image.newImageData(wp, hp)
15+
padded:paste(source, 0, 0)
16+
return love.graphics.newImage(padded)
17+
end
18+
19+
return love.graphics.newImage(source)
20+
end
21+
22+
function love.load()
23+
-- Set a lovely pink background color.
24+
love.graphics.setBackgroundColor(246, 198, 222)
25+
26+
-- Load the source of the animation.
27+
img = newImagePO2("assets/anim-boogie.png")
28+
29+
-- Create an animation with a frame size of 32x32 and
30+
-- 0.1s delay betwen each frame.
31+
animation1 = newAnimation(img, 32, 32, 0.1, 6)
32+
end
33+
34+
function love.update(dt)
35+
-- The animation must be updated so it
36+
-- knows when to change frames.
37+
animation1:update(dt)
38+
end
39+
40+
function love.draw()
41+
-- Draw the animation the center of the screen.
42+
animation1:draw(400, 300, 0, 1, 1)
43+
end

examples/012_cursor_change.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Example: Use an Image as cursor
2+
3+
function love.load()
4+
-- Load the "cursor" (with default hot spot 0, 0)
5+
cursor = love.mouse.newCursor("assets/love-cursor.png")
6+
7+
-- Set the cursor
8+
love.mouse.setCursor( cursor )
9+
end
10+
11+

0 commit comments

Comments
 (0)