We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying out a simple target practice game (click on a rectangle) using the cursor and mouse button. If the mouse is within the borders of the rectangle, it will turn green and if there is a mouseclick, you receive a point and an explosion occurs AND the rectangle disappears. The rectangle moves randomly around the screen every 5 seconds.
Two problems so far:
1) I cannot for the life of me get the explosion to be timed. I tried and tried and even though I managed to get the rectangle appearance at 5 seconds, getting the explosion to be time delayed escapes me. I commented out the code at the location I tried it, but unfortunately, me time delay doesn't work.
2) The rectangle appears every 5 seconds. If there is an explosion, the rectangle disappears and a new one appears in a random location. BUT it seems to interfere with the 5 second delay (continually running) which causes flashing. For example, if at 4 seconds, you hit the target, it will disappear. A new one will appear - but only for 1 seconds because the timer is still counting 5 seconds! It flashes and a new one will appear.
Ok, here is what I have so far:
def setup(): global score, x, y, img, count score=0 count=0 timer=0 size(400, 400) noStroke() fill(0) background(255) # white textSize(20) img=loadImage("explosionsmall.jpg") x=random(10, 360) y=random(10, 360) def draw(): #cursor(CROSS) background(255) # white fill(0,0,0) text("SCORE :", 10, 390) # this is a label for the count text(score, 150, 390) # this is the actual variable for the count time_delay() def laser(): ellipse(200,360, x, y) def time_delay(): global count, timer, x, y if count<10: count=count+1 timer=millis() else: random_placement() if millis() > timer + 5000: count=0 x=random(10, 360) y=random(10, 360) def random_placement(): fill(0) rect(x,y,5,5) if (mouseX >x) and (mouseX < x+5) and (mouseY > y) and (mouseY < y+5): fill(0,255,0) rect(x,y,5,5) def mouseClicked(): keepscore() def keepscore(): global score, x, y, count, timer if (mouseX >x) and (mouseX < x+5) and (mouseY > y) and (mouseY < y+5): score=score+1 explosion() #if count<10: # count=count+1 # timer=millis() #else: # explosion() # if millis() > timer + 2000: # count=0 def explosion(): global x, y image(img,x-5,y-5) x=random(10, 360) y=random(10, 360)