I whant it to add 1 to the "click" variable everytime the white squarse are clicked but it is not working help
main.lua
-- things to do
-- finish hitbox
-- start shop
-- make bg
require "coliders"
function love.load()
isMouseNeerTheAxolotl = 0
Clicks = 0
muchPerClick = 1
buttonClick = 1
main_axolotl_img = love.graphics.newImage("happycartoonaxolotlvectorremovebgpreview.png")
HitBox = {}
HitBox.x = 272 - 80
HitBox.y = 172
HitBox.w = 215
HitBox.h = 215
Mw = 5
Mh = 5
shops = {}
Hshops = {}
textn = 0
ShopMoveY = -60
ShopMoveHY = -60
start = 0
stm = 0
loop = 0
text = {10, 1000, 320000, 7600000, 820000000}
for i=1,5 do
textn = textn + 1
shop = {}
shop.w = 250
shop.h = 60
shop.mode = "fill"
ShopMoveY = ShopMoveY + shop.h * 1.5
shop.x = 530
shop.y = ShopMoveY
shop.text = text[textn]
shop.tx = 555
shop.ty = ShopMoveY
stm = stm + 1
if stm == 5 then
start = 1
end
table.insert(shops, shop)
end
end
function love.update(dt)
local Mx, My = love.mouse.getPosition()
if AABB(HitBox.x, HitBox.y, HitBox.w, HitBox.h, Mx, My, Mw, Mh) then
IsMouseNeerTheAxolotl = 1
else
IsMouseNeerTheAxolotl = 0
end
for i,c in ipairs(shops) do
if AABB(c.x, c.y, c.w, c.h, Mx, My, Mw, Mh) then
IsMouseNeerTheAxolotlTest = 1
else
IsMouseNeerTheAxolotlTest = 0
end
end
end
function love.draw()
love.graphics.setColor(1,1,1)
love.graphics.draw(main_axolotl_img, 255 - 80, 155, 0, 0.5, 0.5)
love.graphics.print(Clicks, 370 - 80, 140, 0, 2)
--hitboxes
local Mx, My = love.mouse.getPosition()
if love.keyboard.isDown("g") then
love.graphics.rectangle("line", Mx, My, Mw, Mh)
love.graphics.rectangle("line", HitBox.x, HitBox.y, HitBox.w, HitBox.h)
end
--shop
for i,c in ipairs(shops) do
love.graphics.setColor(1,1,1)
love.graphics.rectangle(c.mode, c.x, c.y, c.w, c.h)
love.graphics.setColor(0,0,0)
love.graphics.print(c.text,c.tx,c.ty)
love.graphics.setColor(1,1,1)
love.graphics.print(c.y,10,10)
end
local Mx, My = love.mouse.getPosition()
end
function love.mousepressed(x, y, button)
if IsMouseNeerTheAxolotl == 1 then
if button == 1 then
Clicks = Clicks + 1
end
end
if IsMouseNeerTheAxolotlTest == 1 then
if button == 1 then
Clicks = Clicks + 1
end
end
end
coliders.lua
function AABB(x1, y1, w1, h1, x2, y2, w2, h2)
return x1 < x2 + w2 and
x1 + w1 > x2 and
y1 < y2 + h2 and
y1 + h1 > y2
end
help me with my game plz
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
help me with my game plz
- Attachments
-
- click.zip
- (113.86 KiB) Downloaded 57 times
-
- click.love
- (113.86 KiB) Downloaded 63 times
Re: help me with my game plz
You iterate over all shops in love.update, but you use the same variable to determine a collision. And this variable gets overwritten in every iteration of the loop. So only the last button will work - and it does.
For this to work you have to make a collision variable for every button. I added a variable called isHovered to each shop in love.load, update this variable in love.update and then use all of those variables in love.mousepressed. Attached is your code with my modification.
For this to work you have to make a collision variable for every button. I added a variable called isHovered to each shop in love.load, update this variable in love.update and then use all of those variables in love.mousepressed. Attached is your code with my modification.
- Attachments
-
- click_with_working_buttons.love
- (113.88 KiB) Downloaded 68 times
Who is online
Users browsing this forum: Bing [Bot], Imnotaplayer and 203 guests