0

Ive been messing around with get_ticks() and its been working sort of well besides the fact that i cant;

  1. Stop and reset the var = var - tick counter
  2. I cant do if var >= tick + 10 anyone know how to stop the variable or count ahead for it? im trying to add events that trigger after a set time Heres my code if it helps
import pygame, random, time
import pygame_textinput
import prompts

pygame.init()
textinput = pygame_textinput.TextInputVisualizer()
black = ("225, 225, 225")
font = pygame.font.SysFont("Comicsansms", 55)

display = pygame.display.set_mode((575, 375))
pygame.display.set_caption("Game")
clock = pygame.time.Clock()

pygame.key.set_repeat(200, 25)

room = pygame.image.load("assets/images/room.png")
stick = pygame.image.load("assets/images/sticky.png")
dark = pygame.image.load("assets/images/dark.png")
dark1 = pygame.image.load("assets/images/dark1.png")
lighti = pygame.image.load("assets/images/light.png")
mel = pygame.image.load("assets/images/waterelo.png")
tablet = pygame.image.load("assets/images/3.png")
cam1 = pygame.image.load("assets/images/cam1.png")
cam2 = pygame.image.load("assets/images/cam2.png")
fan1 = pygame.image.load("assets/images/fanbutton.png")
wing1 = pygame.image.load("assets/images/wing.png")
corn = pygame.image.load("assets/images/corner.png")
broken = pygame.image.load("assets/images/broken.png")
bat = pygame.image.load("assets/images/battery.png")
cell1 = pygame.image.load("assets/images/cell.png")
cell2 = pygame.image.load("assets/images/cell.png")
cell3 = pygame.image.load("assets/images/cell.png")
cell4 = pygame.image.load("assets/images/cell.png")

def wait(seconds):
  time.sleep(seconds)

def watermelon(x, r):
  if x <= 0 and r == False:
    Wc1 = True
    x = 20

def camera(g, cname):
  if g == 0:
    display.blit(tablet, (-75, -75))
    display.blit(cam1, (450, 240))
    display.blit(cam2, (450, 190))
  elif g == 1:
    display.blit(cname, (0, 0))
    display.blit(cam1, (450, 240))
    display.blit(cam2, (450, 190))

def powerdis(gg):
  display.blit(bat, (0, 0))
  if int(gg) in range(76, 100):
    display.blit(cell1, (5, 1))
    display.blit(cell2, (45, 1))
    display.blit(cell3, (85, 1))
    display.blit(cell4, (120, 1))
  elif int(gg) in range(51, 75):
    display.blit(cell1, (5, 1))
    display.blit(cell2, (45, 1))
    display.blit(cell3, (85, 1))
  elif int(gg) in range(26, 50):
    display.blit(cell1, (5, 1))
    display.blit(cell2, (45, 1))
  elif int(gg) in range(1, 25):
    display.blit(cell1, (5, 1))
  elif gg <= 0:
    outage = True

Wmove = 20
Wmovement = True
batt = 100
heat = 60
outage = False
power = True
q = False
light = False
wing = False
hall = False
flash = False
Wc1 = False
Wc2 = False
Cheats = True
while True:
    display.fill((225, 225, 225))
    display.blit(room, (0, 0))
    events = pygame.event.get()
    textinput.update(events)
    gobalcounter = pygame.time.get_ticks() / 10000

    for event in events:
        if event.type == pygame.QUIT:
            exit()
        elif event.type == pygame.KEYDOWN:
          if event.key == pygame.K_q:
            if outage == False:
              flash = not flash
          if event.key == pygame.K_SPACE:
            if outage == False:
              q = not q
          if event.key == pygame.K_z:
            light = not light
        elif event.type == pygame.MOUSEBUTTONDOWN and q == True:
          cam1_rect = cam1.get_rect(topleft = (450, 240))
          cam2_rect = cam2.get_rect(topleft = (450, 190))
          if cam1_rect.collidepoint(event.pos):
            wing = not wing
            hall = False
          elif cam2_rect.collidepoint(event.pos):
            hall = not hall
            wing = False  
    if q == True:
      camera(0, tablet)
    elif flash == True and outage == False:
      display.blit(lighti, (70, 60))

    if light == True and q == False and flash == False:
      display.blit(dark1, (207, 100))
    elif light == False and q == False and flash == False:
      display.blit(dark, (80, 55))

    if wing == True and q == True:
      camera(1, wing1)
      if Wc1 == True:
        display.blit(mel, (200, 150))
    elif hall == True and q == True:
      camera(1, corn)
      if Wc2 == True:
        pass

    if q == True or flash == True:
      tick = pygame.time.get_ticks() / 599999
      batt = batt - tick
    elif light == True:
      lamptick = pygame.time.get_ticks() / 999999999
      batt = batt - lamptick

    ##Problem area
    if Wmovement == True and Wc1 == False and Wc2 == False:
      timer = pygame.time.get_ticks() / 999
      counter = Wmove - timer
      if counter <= 0:
        Wc2 = True
        Wmovement == False
    
    if q == False:
      powerdis(batt)

    if outage == True:
      q = False
      flash = False
    
    pygame.display.update()
    clock.tick(60)
Stoat
  • 13
  • 3

0 Answers0