I need help my player can't upgrade a table
I don't know why my player can't advance their table by paying out... I'm using a simple condition that says if they're on the price rectangle and press the spacebar, then it performs a swipe and advances... I don't know why, but it's not working. I think the problem is with the camera, but I don't know how to fix it. Here's the code for the player and the camera... and also the collision function. Thanks for your help.
// player code
initPlayer = function()
Player = class
constructor = function(x,y,w,h,speed,id)
this.x = x
this.y = y
this.w = w
this.h = h
this.speed = speed
this.id = id
this.oldX = 0
this.oldY = 0
this.move = false
this.direction = 0
this.CanMove = true
this.image = "idle"
this.hitbox = object
x = x
y = y
w = 20
h = 20
end
end
end
liste_players = []
liste_players.push(new Player(0,0,32,32,3,"Zac"))
camera = object
x = 0
y = 0
lissage = 0.1
end
end
updatePlayer = function()
if mode == "jeux" then
for p in liste_players
if p.CanMove then
if p.id == "Zac" then
// --- MOUVEMENT ---
if keyboard.UP then
p.y += p.speed
p.image = "up"
p.move = true
p.direction = 1
elsif keyboard.DOWN then
p.y -= p.speed
p.image = "down"
p.move = true
p.direction = -1
elsif keyboard.LEFT then
p.x -= p.speed
p.image = "left"
p.move = true
p.direction = -2
elsif keyboard.RIGHT then
p.x += p.speed
p.image = "right"
p.move = true
p.direction = 2
else
p.move = false
p.image = "idle"
end
local limite = Monde.taille / 2
p.x = clamp(p.x, -limite + p.w/2, limite - p.w/2)
p.y = clamp(p.y, -limite + p.h/2, limite - p.h/2)
camera.x = lerp(p.x, camera.x, camera.lissage)
camera.y = lerp(p.y, camera.y, camera.lissage)
end
end
end
end
end
drawPlayer = function()
if mode == "jeux" then
for p in liste_players
if p.id == "Zac" then
screen.fillRound(p.x,p.y-15,25,10,"rgb(0,0,0,0.5)")
screen.drawSprite("candy_sale/player/zac/" + p.image, p.x, p.y, p.w, p.h)
end
end
end
end
Table code
initTable = function()
Table = class // Utilise une majuscule pour le nom de la classe
constructor = function(x,y,id)
this.x = x
this.y = y
this.w = 96
this.h = 48
this.id = id
this.evolution = 1
this.prix = 100
this.augmentation = 5
this.niveau = 0
this.active = false
this.hitboxP = object
x = x
y = y
w = 60
h = 60
end
end
end
liste_table = []
liste_table.push(new Table(0, 0, 1))
end
updateTable = function()
if mode == "jeux" then
for t in liste_table
t.hitboxP.x = t.x
t.hitboxP.y = t.y + 50
local quelquun_touche = false
for p in liste_players
if checkCollision(p.hitbox, t.hitboxP) then
quelquun_touche = true
break
end
end
// On applique le résultat
t.active = quelquun_touche
if t.active then
if keyboard.press.SPACE then
if global.player_money >= t.prix then
global.player_money -= t.prix
t.prix = floor(t.prix * 1.5) // Augmentation plus douce (1.5x)
t.niveau += 1
end
end
end
end
end
end
drawTable = function()
if mode == "jeux" then
for t in liste_table
screen.drawSprite( "candy_sale/evolution/table/table."+t.niveau, t.x, t.y, t.w, t.h )
end
end
end
and here is my collision fonction
checkCollision = function(o1, o2)
return o1.x - o1.w/2 < o2.x + o2.w/2 and
o1.x + o1.w/2 > o2.x - o2.w/2 and
o1.y - o1.h/2 < o2.y + o2.h/2 and
o1.y + o1.h/2 > o2.y - o2.h/2
end
