def run_level(self): pg.mixer.music.load('song.wav') pg.mixer.music.play(-1) while self.playing: # for bl in self.all_bullets: # bl.kill() # for bl in self.all_superbullets: # bl.kill() self.clock.tick(FPS) self.events() lc.handle_timeout(1) self.update() self.draw() # if self.chef1.is_dead() or self.chef2.is_dead(): # if self.level == 5: # self.running = False # self.playing = False if self.chef1.is_dead(): out = input_t() out.player = 1 out.motion = "dead" lc.publish("TO SERVER", out.encode()) if self.level == 5: self.running = False self.playing = False elif self.chef2.is_dead(): out = input_t() out.player = 2 out.motion = "dead" lc.publish("TO SERVER", out.encode()) if self.level == 5: self.running = False self.playing = False
def show_transition_screen(self): self.waiting = True if self.level == 2: background = pg.image.load("darktransition.png") background = pg.transform.scale(background, (1000, 1000)) self.screen.blit(background, [0, 0]) skip = pg.image.load("continue.PNG") self.screen.blit(skip, [700, 930]) else: background = pg.image.load('transition.png') self.screen.blit(background, [0, 0]) if not self.level == 2: draw_text(self.screen, str(self.level), 55, 550, 375) draw_text(self.screen, str(self.chef2.get_point()), 40, 380, 465) #c2 score draw_text(self.screen, str(self.chef1.get_point()), 40, 600, 465) #c1 score pg.display.update() while self.waiting: lc.handle_timeout(1) for event in pg.event.get(): if event.type == pg.QUIT: pg.quit() mouse = pg.mouse.get_pos() if event.type == pg.MOUSEBUTTONDOWN: if 700 < mouse[0] < 1000 and 900 < mouse[1] < 1000: background = pg.image.load("missing2.png") self.screen.blit(background, [0, 0]) pg.display.update() next = input_t() next.player = 2 next.motion = "start" lc.publish("TO SERVER", next.encode())
def show_start_screen(self): pg.mixer.music.load('song2.wav') pg.mixer.music.play(-1) background = pg.image.load('startscreen.png') self.screen.blit(background, [0, 0]) pg.display.update() click = False # waiting = True #click = pg.mouse.get_pressed() while self.waiting: if click == False: lc.handle_timeout(10) for event in pg.event.get(): if event.type == pg.QUIT: pg.quit() mouse = pg.mouse.get_pos() if 700 < mouse[0] < 800 and 600 < mouse[1] < 850: background = pg.image.load( 'startscreen-select-play.png') self.screen.blit(background, [0, 0]) if event.type == pg.MOUSEBUTTONDOWN: click = True start = input_t() start.motion = "start" start.player = 1 print("client2 click") lc.publish("TO SERVER", start.encode()) #waiting = False elif 212 < mouse[0] < 314 and 862 < mouse[1] < 964: background = pg.image.load( 'startscreen-select-tut.png') self.screen.blit(background, [0, 0]) if event.type == pg.MOUSEBUTTONDOWN: self.tutorial() #waiting = False elif 25 < mouse[0] < 145 and 855 < mouse[1] < 975: background = pg.image.load( 'startscreen-select-creds.png') self.screen.blit(background, [0, 0]) if event.type == pg.MOUSEBUTTONDOWN: self.show_credit_screen() else: background = pg.image.load('startscreen.png') self.screen.blit(background, [0, 0]) pg.display.update() else: lc.handle_timeout(10) print("clicked") print(self.background) background = pg.image.load("missing2.png") self.screen.blit(background, [0, 0]) pg.display.update() for event in pg.event.get(): if event.type == pg.QUIT: pg.quit()
def show_start_screen(self): background = pg.image.load('startscreen.png') self.screen.blit(background, [0,0]) pg.display.update() # waiting = True #click = pg.mouse.get_pressed() while self.waiting: lc.handle_timeout(10) for event in pg.event.get(): if event.type == pg.QUIT: pg.quit() mouse = pg.mouse.get_pos() if event.type == pg.MOUSEBUTTONDOWN: if 700 < mouse[0] < 800 and 600 < mouse[1] < 850: background = pg.image.load("missing2.png") start = input_t() start.player = 1 start.move = "start" lc.publish("CLIENT_INPUT", start.encode()) #waiting = False if 212 < mouse[0] < 314 and 862 < mouse[1] < 964: background = pg.image.load("missing2.png") start = input_t() start.player = 1 start.move = "start" lc.publish("CLIENT_INPUT", start.encode()) #waiting = False if 42 < mouse[0] < 144 and 862 < mouse[1] < 964: background = pg.image.load("missing2.png") start = input_t() start.player = 1 start.move = "start" lc.publish("CLIENT_INPUT", start.encode()) #waiting = False self.screen.blit(background, [0,0]) pg.display.update()
def events(self): for event in pg.event.get(): if event.type == pg.QUIT: # if self.playing: # self.playing = False # self.running = False pg.quit() key = pg.key.get_pressed() sending_out = input_t() sending_out.player = 2 judgeTime = time.time() if key[pg.K_LEFT]: if judgeTime - self.pressTime > 0.1: sending_out.motion = "left" self.release = False lc.publish("TO SERVER", sending_out.encode()) self.pressTime = time.time() elif key[pg.K_RIGHT]: if judgeTime - self.pressTime > 0.1: sending_out.motion = "right" self.release = False lc.publish("TO SERVER", sending_out.encode()) self.pressTime = time.time() elif key[pg.K_UP]: if judgeTime - self.pressTime > 0.1: sending_out.motion = "up" self.release = False lc.publish("TO SERVER", sending_out.encode()) self.pressTime = time.time() elif key[pg.K_DOWN]: if judgeTime - self.pressTime > 0.1: sending_out.motion = "down" self.release = False lc.publish("TO SERVER", sending_out.encode()) self.pressTime = time.time() elif key[pg.K_SPACE]: if judgeTime - self.pressTime > 0.5: sending_out.motion = "shoot" self.release = False lc.publish("TO SERVER", sending_out.encode()) self.pressTime = time.time() else: self.release = True
def events(self): for event in pg.event.get(): if event.type == pg.QUIT: if self.playing: self.playing = False self.running = False key = pg.key.get_pressed() sending_out = input_t() sending_out.player = 1 if key[pg.K_LEFT]: sending_out.move = "left" elif key[pg.K_RIGHT]: sending_out.move = "right" elif key[pg.K_UP]: sending_out.move = "up" elif key[pg.K_DOWN]: sending_out.move = "down" elif key[pg.K_SPACE]: sending_out.move = "shoot" lc.publish("CLIENT_INPUT", sending_out.encode())