-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
97 lines (76 loc) · 2.39 KB
/
main.lua
File metadata and controls
97 lines (76 loc) · 2.39 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
-- This demo demonstrates collision using the built-in spatial hashing.
io.stdout:setvbuf("no")
local entitylove = require("entitylove")
local system = entitylove()
local function drawParticle(self)
if self.collisionShape.type == entitylove.COL_CIRCLE then
love.graphics.circle("fill", self.position.x, self.position.y, self.collisionShape.r)
else
if system:pointInEntity(self, love.mouse.getX(), love.mouse.getY()) then
love.graphics.setColor(1, 0, 0, 1)
if love.mouse.isDown(1) then
system:remove(self)
end
end
love.graphics.rectangle("fill", self.position.x, self.position.y,
self.collisionShape.w, self.collisionShape.h)
end
end
local function createParticle(x, y)
local particle = {}
system:pos(particle, x, y)
if love.math.random(0, 1) == 1 then
system:setRectangleCollision(particle, love.math.random(16, 32), love.math.random(16, 32))
else
system:setCircleCollision(particle, love.math.random(8, 16))
end
particle.draw = drawParticle
particle.solidType = entitylove.SOLID_TYPE_ONEWAY
particle.onewayType = entitylove.ONEWAY_LEFT
return particle
end
local function updatePlayer(self, dt)
local moveDirX, moveDirY = 0, 0
if love.keyboard.isDown("left") then
moveDirX = moveDirX - 1
end
if love.keyboard.isDown("right") then
moveDirX = moveDirX + 1
end
if love.keyboard.isDown("up") then
moveDirY = moveDirY - 1
end
if love.keyboard.isDown("down") then
moveDirY = moveDirY + 1
end
--self.velocity.x = moveDirX * 120 * dt
self.velocity.y = moveDirY * 120 * dt
end
local function drawPlayer(self)
system:drawCollision(self)
end
function createPlayer(x, y)
local player = {}
system:pos(player, x, y)
system:setRectangleCollision(player, 32, 32)
player.update = updatePlayer
player.draw = drawPlayer
player.slopeMode = entitylove.SLOPE_MODE_PLATFORMER
player.gravity = 0.1
player.gravityType = entitylove.GRAVITY_X
return player
end
function love.load()
for i = 1, 100 do
system:add(createParticle(love.math.random(64, love.graphics.getWidth() - 24),
love.math.random(0, love.graphics.getHeight() - 64)))
end
system:add(createPlayer(0, love.graphics.getHeight() / 2))
end
function love.update(dt)
system:update(dt)
end
function love.draw()
system:draw()
love.graphics.print("Arrow keys to move!", 5, love.graphics.getHeight() - 18)
end