Develop #4
+34
-14
@@ -29,40 +29,60 @@ function bell.load(game, cam)
|
|||||||
bell_3 = tools.clone_table(body)
|
bell_3 = tools.clone_table(body)
|
||||||
bell_3.x = cam_x + (game.window.width / 4 * 3) - (bell_1.img:getWidth() / body.num_frames / 2)
|
bell_3.x = cam_x + (game.window.width / 4 * 3) - (bell_1.img:getWidth() / body.num_frames / 2)
|
||||||
bell_3.y = bell_1.y
|
bell_3.y = bell_1.y
|
||||||
|
bells = {bell_1, bell_2, bell_3}
|
||||||
|
|
||||||
-- Collisions
|
-- Collisions
|
||||||
local collision_size = body.img:getHeight() / 2
|
collisions.size = 15
|
||||||
collisions.positions = {
|
collisions.positions = {}
|
||||||
{x=100, y=50},
|
collisions.num = 15
|
||||||
{x=500, y=200}
|
collisions.correction = 45
|
||||||
}
|
|
||||||
|
|
||||||
-- Make HC collisions
|
-- Make positions collisions
|
||||||
collisions.hc = {}
|
for i = 1, collisions.num, 1 do
|
||||||
for key, collision in pairs(collisions.positions) do
|
local tem_x, tem_y = tools.cicle_positions(0, 0, bell_1.img:getHeight() / 2, 360 / collisions.num * i)
|
||||||
collisions.hc[key] = HC.circle(collision.x, collision.y, collision_size)
|
collisions.positions[i] = {x=tem_x, y=tem_y}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Add collisions
|
||||||
|
for key, bell in pairs(bells) do
|
||||||
|
bell.collisions = {}
|
||||||
|
for key, collision in pairs(collisions.positions) do
|
||||||
|
bell.collisions[key] = HC.circle(bell.x + collision.x, collision.y, collisions.size)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function bell.update(dt, game, cam)
|
function bell.update(dt, game, cam)
|
||||||
|
-- Update cam position
|
||||||
cam_x, cam_y = cam.gcam:getVisible()
|
cam_x, cam_y = cam.gcam:getVisible()
|
||||||
|
-- Ani bells
|
||||||
bell_1.animation:update(dt)
|
bell_1.animation:update(dt)
|
||||||
bell_2.animation:update(dt)
|
bell_2.animation:update(dt)
|
||||||
bell_3.animation:update(dt)
|
bell_3.animation:update(dt)
|
||||||
|
-- Bells fix pos
|
||||||
bell_1.x = cam_x + (game.window.width / 4) - (bell_1.img:getWidth() / body.num_frames / 2)
|
bell_1.x = cam_x + (game.window.width / 4) - (bell_1.img:getWidth() / body.num_frames / 2)
|
||||||
bell_2.x = cam_x + (game.window.width / 4 * 2) - (bell_1.img:getWidth() / body.num_frames / 2)
|
bell_2.x = cam_x + (game.window.width / 4 * 2) - (bell_1.img:getWidth() / body.num_frames / 2)
|
||||||
bell_3.x = cam_x + (game.window.width / 4 * 3) - (bell_1.img:getWidth() / body.num_frames / 2)
|
bell_3.x = cam_x + (game.window.width / 4 * 3) - (bell_1.img:getWidth() / body.num_frames / 2)
|
||||||
|
-- Collisions fix pos
|
||||||
|
for key, bell in pairs(bells) do
|
||||||
|
for key, collision in pairs(collisions.positions) do
|
||||||
|
bell.collisions[key]:moveTo(collisions.positions[key].x + bell.x + (bell.img:getHeight() / 2) + collisions.correction, collisions.positions[key].y + bell.y + (bell.img:getHeight() / 2))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function bell.draw()
|
function bell.draw()
|
||||||
if bells_enable then
|
if bells_enable then
|
||||||
bell_1.animation:draw(bell_1.img, bell_1.x, bell_1.y)
|
-- Bells
|
||||||
bell_2.animation:draw(bell_2.img, bell_2.x, bell_2.y)
|
for key, bell in pairs(bells) do
|
||||||
bell_3.animation:draw(bell_3.img, bell_3.x, bell_3.y)
|
bell.animation:draw(bell.img, bell.x, bell.y)
|
||||||
|
end
|
||||||
|
-- Collisions
|
||||||
if collision_debug then
|
if collision_debug then
|
||||||
for key, collision in pairs(collisions.hc) do
|
for key, bell in pairs(bells) do
|
||||||
collision:draw('fill')
|
for key, collision in pairs(collisions.positions) do
|
||||||
|
bell.collisions[key]:draw('fill')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -71,4 +71,12 @@ function tools.print_r(t)
|
|||||||
print()
|
print()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Get positions from circle
|
||||||
|
function tools.cicle_positions(x, y, radius, angle)
|
||||||
|
local pos_x, pos_y = nil, nil
|
||||||
|
pos_x = x + radius * math.cos(math.rad(angle))
|
||||||
|
pos_y = y + radius * math.sin(math.rad(angle))
|
||||||
|
return pos_x, pos_y
|
||||||
|
end
|
||||||
|
|
||||||
return tools
|
return tools
|
||||||
Reference in New Issue
Block a user