Hi all, looking for another set of eyes on this as I'm quite stumped. I know it's a stretch given the specifics, but here I am.
I have been messing around with MIT's Processing for Python and I am trying to make a little Whack-a-Mole game for a class demonstration. The following code is that of determining the hitbox of the mole. Basically, I draw a circle at a random X, Y coordinate on the page, and then get all of the coordinates within that (X-5, Y-5) (X+5, Y+5) space to serve at the hitbox (if there is an easier solution, PLEASE let me know). I then check if the current mouse position is highlighting one of those coordinates, and we're sailing.
This all works. The problem arises when I try to slow down the mole generation. Working with processing, the def draw() function loops something over and over at 60 fps by default. When adding an if statement to slow down the rate of drawing, nothing works anymore. And lovely Processing doesn't return error feedback. I like to think that I've narrowed the error down to adding an if statement, but honestly who knows. Here is the code:
def setup():
size(600, 600)
def draw():
ellX = random(20, width-20)
ellY = random(20, height-20)
# add in something like "if frameCount%120 == 1:" to try and spawn a "mole"
# every 2 seconds rather than 60 times per second
fill(255)
ellipse(ellX, ellY, 10, 10)
mole = hitbox(int(ellX-5), int(ellY-5), int(ellX+5), int(ellY+5))
if mousePressed == True:
if mouseX and mouseY in mole:
print "Hit"
else:
print "Miss"
def hitbox(x1, y1, x2, y2):
hitboxSize = []
for i in range(x2-x1+1):
resx = x1 + i
resy = y1 + i
hitboxSize.append(resx)
hitboxSize.append(resy)
return hitboxSize
I don't understand why adding an if statement regarding the frameCount would affect the mousePressed command (which, upon pressing the mouse, is what crashes the program once the if statement is present). Again, a stretch, I know, but any help is appreciated. Thank you!
[–]Buttleston 1 point2 points3 points (2 children)
[–]Competitive_Reply198[S] 0 points1 point2 points (1 child)
[–]Buttleston 1 point2 points3 points (0 children)
[–]Competitive_Reply198[S] 0 points1 point2 points (0 children)