Need help with limiting mouse clicks
- PlatinumFaceGirl2
- Prole
- Posts: 4
- Joined: Sat Jan 04, 2014 5:18 pm
Need help with limiting mouse clicks
I am currently working on a game, memory game, almost done, everything working fine by now, but I have little problem and needs to be fixed. Everyone has seen a memory game before, you need to click 2 items, and if they match they go away, if they don't match they stay and you continue... My problem here is that when 2 objects are clicked , program checks only those in that moment if they match or not,but the time when they are open until they flip back again (love.timer.getTime()+1) if you click fast in that one second you can open probably 4-5 more . The program does not react to them , it has only the 2 first clicked in the memory. Can someone help me fixing this problem? Maybe by limiting mouse clicks when 2 items are already clicked? And how to do that? I will appreciate every answer back. Thank you
Re: Need help with limiting mouse clicks
Try having a game state variable. That is a string that contains information about the current state of the game. In the beginning when the game is waiting for the player to click it could have the value "waitingForFirst" then when the player clicks onto an image, it changes to "waitingForSecond" and when the player clicks onto another one (which is different from the first one) then it should change to "comparing". While in the state "comparing" clicks just do nothing and after a second or so, the two images are removed or put back and the state goes to "waitingForFirst" again.
Check out my blog on gamedev
Re: Need help with limiting mouse clicks
In a simple case like this one, you can also add to your mouse-click handler a check that measures the number of items clicked and simply refuses to do anything if there is already two open. (For larger projects, micha's suggestion is a better one though!)
Pseudocode:
Pseudocode:
Code: Select all
function love.mousepressed( x, y, button )
if tilesOpen() >= 2 then
return false
end
openClickedTile()
end
- PlatinumFaceGirl2
- Prole
- Posts: 4
- Joined: Sat Jan 04, 2014 5:18 pm
Re: Need help with limiting mouse clicks
Code: Select all
local clicked = love.mouse.isDown( "l" )
if game.scene.mode == 1 or game.scene.mode == 2 then -----choose 2 to check
for i = #objects.cards,1,-1 do
local c = objects.cards[i]
if mx > c.sprite.rect[1] and mx < c.sprite.rect[1] + c.sprite.rect[3]
and my > c.sprite.rect[2] and my < c.sprite.rect[2] + c.sprite.rect[4] then -- mouse is over an object
if clicked and love.mouse.wasDown == false then
if c.state == 1...
Code: Select all
function getFullCardLayout()
local cardLayout = {}
---
cardLayout[1] = {407,84}
cardLayout[2] = {494,84}
cardLayout[3] = {581,79}
cardLayout[4] = {669,74}
cardLayout[5] = {760,73}
cardLayout[6] = {853,74}
Code: Select all
local all_cards_flipped = true
for i = 1,#objects.cards,1 do
local c = objects.cards[i]
if c.state ~= 3 then
all_cards_flipped = false ---one pair is active for checking
break
end
end
if all_cards_flipped then --all cards are closed
Code: Select all
function love.mousepressed( x, y, button )
if clicked == '1' and ? then
return false
end
all_cards_flipped ?
end
Re: Need help with limiting mouse clicks
Does that mean you have solved the problem or do you have a specific question?
Check out my blog on gamedev
- PlatinumFaceGirl2
- Prole
- Posts: 4
- Joined: Sat Jan 04, 2014 5:18 pm
Re: Need help with limiting mouse clicks
yeah, i got it, i had little trouble while forming it right, but now its fine. Thank you Plu and micha
Who is online
Users browsing this forum: No registered users and 5 guests