-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworld.lua
More file actions
62 lines (52 loc) · 1.79 KB
/
world.lua
File metadata and controls
62 lines (52 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function world_load()
--set up world
love.graphics.setMode(1024, 768, false, true, 16)
love.physics.setMeter(100)
world = love.physics.newWorld(0,0,true)
world:setCallbacks(beginContact, endContact, preSolve, postSolve)
width = love.graphics.getWidth()
height = love.graphics.getHeight()
player_create()
score = 0
asteroid_freq = 5
asteroid_timer = 0
end
function world_update(dt)
if asteroid_timer >= asteroid_freq then
asteroid_create("big", math.random(width, width + 1), math.random(height, height + 1))
asteroids[#asteroids].body:applyForce(math.random(-10000, 10000), math.random(-10000, 10000))
asteroid_timer = 0
else
asteroid_timer = asteroid_timer + dt
end
end
--collisions
function beginContact(a, b, coll)
debugText = debugText .. "collision" .. "\n"
--bullet vs asteroid
if a:getUserData() == "bullet" and b:getUserData() == "asteroid" then
debugText = debugText .. a:getUserData() .. " Collision " .. b:getUserData() .. "\n"
a:setUserData("bullet_D")
b:setUserData("asteroid_D")
end
if b:getUserData() == "bullet" and a:getUserData() == "asteroid" then
debugText = debugText .. b:getUserData() .. " Collision " .. a:getUserData() .. "\n"
b:setUserData("bullet_D")
a:setUserData("asteroid_D")
end
--player vs asteroid
if a:getUserData() == "player" and b:getUserData() == "asteroid" then
debugText = debugText .. a:getUserData() .. " Collision " .. b:getUserData() .. "\n"
a:setUserData("player_D")
end
if b:getUserData() == "player" and a:getUserData() == "asteroid" then
debugText = debugText .. b:getUserData() .. " Collision " .. a:getUserData() .. "\n"
b:setUserData("player_D")
end
end
function endContact(a, b, coll)
end
function preSolve(a, b, coll)
end
function postSolve(a, b, coll)
end