vendredi 8 mai 2020

How can you make the previous line disappear in python?

I'm making a constellation that starts from (0,0). The previous line has to disappear after a two second delay and when the left is clicked within the two second delay, white circles should appear. I don't why my timer isn't working and I'm not sure how to make the line disappear. Also the circles don't appear. This is my code

from pygame import * 
import random
init()
size = width, height = 700, 700
screen = display.set_mode(size)
button = 0

BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0,0,255)
WHITE = (255,255,255)
colors = (RED,GREEN,BLUE)
time.set_timer(USEREVENT, 2000)
mx = 0
my = 0

def drawScene(screen, button):
 if button == 1:
  draw.circle(screen,RED,(mx,my), 5)
  draw.line(screen,RED,(mx,my),(lx,ly),2)
  draw.circle(screen,RED,(lx,ly), 5)
  display.flip()
 if button == 3:
  draw.line(screen,random.choice(colors),(mx,my),(lx,ly),2)
  draw.circle(screen,random.choice(colors),(lx,ly), 5)
  display.flip()


running = True
myClock = time.Clock()
start = time.get_ticks()
# Game Loop
while running:
 lx = mx
 ly = my 
 for evnt in event.get():             # checks all events that happen
  if evnt.type == QUIT:
   running = False
  if evnt.type == MOUSEBUTTONDOWN:
   mx,my = evnt.pos
   button = evnt.button
   cx,cy = mouse.get_pos()
   draw.circle(screen,WHITE,(cx,cy),5)
  if evnt.type == USEREVENT:
   my_event = event.Event(USEREVENT)
   time.set_timer(my_event , 2000)   
 drawScene(screen, button)

 myClock.tick(60)                     # waits long enough to have 60 fps



quit()

Aucun commentaire:

Enregistrer un commentaire