thanks for all your help =) and yes, here’s the whole code:
--# Main
function setup()
for a = 1, #leveldict do
keys = {"walls", "portal", "spikes"}
for b, key in keys do
for i = 1, #leveldict[a][key] do
leveldict[a][key][i].y = leveldict[a][key][i].y + 100
end
leveldict[a]["spawn"][2] = leveldict[a]["spawn"][2] + 100
end
end
leveldict = {beginning}
level = 1
enemies = {}
animation = 3.0
table.insert(enemies, Enemy(500, 500))
peach = nil
peach2 = nil
max_speed = 7
max_jump = 11
touchy = false
player = Rect(20, 620, 50, 90)
move = {0, 0}
reference = nil
sprite = peach
skiptime = true
blood = {}
touches = {}
beginning = {["spawn"] = {20, 620},
["walls"] = {Rect(0, 500, 700, 20), Rect(700+player.w+10, 500, 600, 20), Rect(680, -100, 20, 600), Rect(700+player.w+10, -100, 20, 600)},
["portal"] = {Rect(680, 0, 100, 1)},
["spikes"] = {},
["text"] = ""}
end
function draw()
background(54, 54, 54, 255)
fill(255, 255, 255, 255)
for i = 1, #enemies do
enemies[i]:update()
end
for i = 1, #leveldict[level]['walls'] do
rect(leveldict[level]['walls'][i].x, leveldict[level]['walls'][i].y, leveldict[level]['walls'][i].w, leveldict[level]['walls'][i].h)
end
for i = 1, #leveldict[level]['spikes'] do
spikey(leveldict[level]['spikes'][i])
end
fill(1.0, 0.141, 0.173)
--rect(900, 700, 50, 50)
fill(0.217, 0.725, 0.276)
tint(255, 255, 255, 255)
if move[1] < 0 then
scale(-1, 1)
sprite("Documents:peach", player.x+player.w, player.y, player.w, player.h)
scale(-1, 1)
end
if move >= 0 then
sprite("Documents:peach", player.x, player.y, player.w, player.h)
end
if player.intersects(leveldict[level]['portal'][1]) then
level = level + 1
if level > #leveldict then
level = 1
end
player.x, player.y = leveldict[level]['spawn'][0], leveldict[level]['spawn'][1]
animation = 3.0
end
for i = 1, #leveldict[level]['spikes'] do
if player.intersects(leveldict[level]['spikes'][i]) then
for a = 0, 20 do
table.insert(Drop(player.x+player.w/2, player.y))
end
for i = 1, #enemies do
if enemies[i] == self then
table.remove(enemies, i)
end
end
end
end
for i = 1, #leveldict[level]['walls'] do
if Rect(player.x+move[1], player.y+.5, player.w, player.h-.5).intersects(leveldict[level]['walls'][i]) then
if player.x < wall.x then
player.x = wall.x-player.w-.5
player.x = wall.x + wall.w+.5
else
move[1] = 0
end
end
if Rect(player.x, player.y+move[2], player.w, player.h).intersects(leveldict[level]['walls'][i]) then
if player.y < leveldict[level]['walls'][i].y then
player.y = leveldict[level]['walls'][i].y-player.h-.5
else
player.y = leveldict[level]['walls'][i].y + leveldict[level]['walls'][i].h
move[2] = 0
end
end
end
player.y = player.y + move[1]
player.x = player.x + move[2]
if player.y+player.h > HEIGHT then
move[2] = 0
end
player.x = math.min(WIDTH - player.w, math.max(0, player.x))
player.y = math.min(HEIGHT+20 - player.h, math.max(0, player.y))
move[2] = math.max(move[2] - .5, -20)
fill(0, 255, 0, math.max(math.min(255, animation), 0))
animation = animation - 1
fontSize(50)
text(leveldict[level]['text'], 512, 384) --size 50
a = 288
fill(0,0,0)
rect(0,0,1024,100)
strokeWidth(1)
stroke(129, 0, 255, 255)
for x = 500+a, 550+a do
line(x, (x-500-a)*(40.0/50)+50, x, -(x-500-a)*(40.0/50)+50)
end
for x = 650+a, 700+a do
line(x, (x-700-a)*(40.0/50)+50, x, -(x-700-a)*(40.0/50)+50)
end
for x = 10, 90 do
line(-(x-10)*(40.0/80)+150, 100-x, (x-10)*(40.0/80)+150, 100-x)
end
strokeWidth(3)
ellipse(10, 10, 80, 80)
line(5, 50, 20, 50)
line(80, 50, 95, 50)
line(50, 5, 50, 20)
line(50, 80, 50, 95)
fill(128, 0, 255, 255)
fontSize(30)
text("skip", 500, 50) -- size 30
strokeWidth(0)
for k,touch in pairs(touches) do
if Point(touch.x, touch.y).inside(Rect(780, 0, 100, 100)) then
move[1] = -max_speed
end
if Point(touch.x, touch.y).inside(Rect(900, 0, 100, 100)) then
move[1] = max_speed
end
if Point(touch.x, touch.y).inside(Rect(110, 0, 190, 100)) then
for wall in leveldict[level]['walls'] do
if player.y == wall.y+wall.h and (player.x + player.w > wall.x and player.x < wall.x+wall.w) then
move[1] = max_jump
end
end
end
--[[
if Point(touch.x, touch.y):inside(Rect(0, 0, 110, 100)) then
if #enemies ~= 0 then
closest = {enemies[1]:center():distance(Point(player.x, player.y)), enemies[1]}
for i, enemy in pairs(enemies) do
if enemy:center():distance(player:center()) < closest[0] then
c = enemy:center()
d = c:distance(Point(player.x, player.y))
closest = {d, enemy}
end
end
lightning(closest[1].center().x, closest[1].center().y, player.x+player.w/2, player.y+player.h/2)
closest[1].health = closest[1].health - 10
end
end
--]]
if Point(touch.x, touch.y).distance(Point(500, 50)) < 40 then
if skiptime == true then
level = level + 1
if level > #leveldict then
level = 0
end
player.x, player.y = leveldict[level]['spawn'][1], leveldict[level]['spawn'][2]
animation = 3.0
skiptime = False
end
end
if touch.y > 100 then
lightning(touch.location.x, touch.location.y, player.x+player.w/2, player.y+player.h/2)
end
end
for i, drop in blood do
drop.x = drop.x + drop.vx
drop.y = drop.y + drop.vy
drop.vy = drop.vy - drop.g
drop.color[3] = math.max(drop.color[3] - .02, 0)
fill(unpack(drop.color))
ellipse(drop.x, drop.y, drop.w, drop.h)
table.remove(drop, i)
end
end
function touched(touch)
if touch.state == ENDED then
touches[touch.id] = nil
skiptime = True
move[1] = 0
elseif touch.state == BEGAN then
if touch.y > 100 then
table.insert(enemies, Enemy(touch.x, touch.y))
end
touches[touch.id] = touch
else
touches[touch.id] = touch
end
end