def tick(): if g2d.key_pressed("ArrowUp"): turtle.go_up(True) elif g2d.key_released("ArrowUp"): turtle.go_up(False) if g2d.key_pressed("ArrowRight"): turtle.go_right(True) elif g2d.key_released("ArrowRight"): turtle.go_right(False) if g2d.key_pressed("ArrowDown"): turtle.go_down(True) elif g2d.key_released("ArrowDown"): turtle.go_down(False) if g2d.key_pressed("ArrowLeft"): turtle.go_left(True) elif g2d.key_released("ArrowLeft"): turtle.go_left(False) arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): sym, pos = a.symbol(), a.position() g2d.draw_image_clip(sprites, (sym.x, sym.y, sym.w, sym.h), (pos.x, pos.y, pos.w, pos.h))
def update(): arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if isinstance(a, Wall): g2d.fill_rect(a.position()) else: g2d.draw_image_clip(sprites, a.symbol(), a.position())
def tick(): arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if isinstance(a, Wall): g2d.fill_rect(a.position()) else: g2d.draw_image_clip(sprites, a.symbol(), a.position())
def tick(): if g2d.key_pressed("Spacebar"): turtle.jump() elif g2d.key_pressed("ArrowLeft"): turtle.go_left() elif g2d.key_pressed("ArrowRight"): turtle.go_right() elif g2d.key_released("ArrowLeft") or g2d.key_released("ArrowRight"): turtle.stay() arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): g2d.draw_image_clip(sprites, a.symbol(), a.position())
def tick(): if g2d.key_pressed("Spacebar"): mario.jump() elif g2d.key_pressed("ArrowLeft"): mario.go_left() elif g2d.key_pressed("ArrowRight"): mario.go_right() elif (g2d.key_released("ArrowLeft") or g2d.key_released("ArrowRight")): mario.stay() arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if isinstance(a, Wall): g2d.fill_rect(a.position()) else: g2d.draw_image_clip(sprites, a.symbol(), a.position())
def tick(): if g2d.key_pressed("ArrowUp"): hero.jump() elif g2d.key_pressed("ArrowRight"): hero.go_right() elif g2d.key_pressed("ArrowLeft"): hero.go_left() elif (g2d.key_released("ArrowLeft") or g2d.key_released("ArrowRight")): hero.stay() arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if a.symbol() != (0, 0, 0, 0): g2d.draw_image_clip(sprites, a.symbol(), a.position()) else: g2d.fill_rect(a.position())
def tick(): global view_x, view_y arena_w, arena_h = arena.size() if g2d.key_pressed("ArrowUp"): view_y = max(view_y - 10, 0) elif g2d.key_pressed("ArrowRight"): view_x = min(view_x + 10, arena_w - view_w) elif g2d.key_pressed("ArrowDown"): view_y = min(view_y + 10, arena_h - view_h) elif g2d.key_pressed("ArrowLeft"): view_x = max(view_x - 10, 0) g2d.draw_image_clip(background, (view_x, view_y, view_w, view_h), (0, 0, view_w, view_h)) # BG arena.move_all() for a in arena.actors(): x, y, w, h = a.position() g2d.fill_rect((x - view_x, y - view_y, w, h)) # FG
def tick(self): self.handle_keyboard() arena = self._game.arena() arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if a.symbol() != (0, 0, 0, 0): g2d.draw_image_clip(self._sprites, a.symbol(), a.position()) else: g2d.fill_rect(a.position()) lives = "Lives: " + str(self._game.hero().lives()) toplay = "Time: " + str(self._game.remaining_time()) g2d.draw_text(lives + " " + toplay, (0, 0), 24) if self._game.game_over(): g2d.alert("Game over") g2d.close_canvas() elif self._game.game_won(): g2d.alert("Game won") g2d.close_canvas()
def update(): if g2d.key_pressed("ArrowUp"): turtle.go_up() elif g2d.key_pressed("ArrowRight"): turtle.go_right() elif g2d.key_pressed("ArrowDown"): turtle.go_down() elif g2d.key_pressed("ArrowLeft"): turtle.go_left() elif (g2d.key_released("ArrowRight") or g2d.key_released("ArrowDown") or g2d.key_released("ArrowLeft")): turtle.stay() arena.move_all() g2d.clear_canvas() for a in arena.actors(): if a.symbol() != (0, 0, 0, 0): print(a.symbol()) g2d.draw_image_clip(sprites, a.symbol(), a.position()) else: g2d.fill_rect(a.position())
def tick(): arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if isinstance(a, Background): ax, ay, aw, ah = a.position() g2d.draw_image_clip(bg, a.symbol(), (ax, ay, aw, ah)) g2d.draw_image_clip(bg, a.symbol(), (ax + aw, ay, aw, ah)) elif a.symbol() != (0, 0, 0, 0): g2d.draw_image_clip(sprites, a.symbol(), a.position()) else: g2d.fill_rect(a.position())
def draw(self): g2d.clear_canvas() for a in self._arena.actors(): if type(a) in self._game.bg_list: g2d.draw_image_clip(self.background, a.symbol(), a.position()) g2d.draw_image_clip(self.background, a.symbol(), a.second_position()) else: g2d.draw_image_clip(self.sprites, a.symbol(), a.position()) if a.get_state() == 'delete': self._arena.remove(a) g2d.set_color((255, 255, 255)) g2d.draw_text('Remaining time: ' + str(self._game.remaining_time()), (10, 10), 20) g2d.draw_text('Score: ' + str(self._arena.get_score()), (ARENA_W / 2, 10), 20) g2d.draw_text('Lives: ' + str(hero_lives + 1), (ARENA_W - 80, 10), 20)
def update(): terrenoval = B - 100 global contatore, contatore2, contatore3 if g2d.key_pressed("ArrowUp"): turtle.go_up() elif g2d.key_pressed("ArrowRight"): turtle.go_right() elif g2d.key_pressed("ArrowDown"): turtle.go_down() elif g2d.key_pressed("ArrowLeft"): turtle.go_left() elif ( g2d.key_released("ArrowRight") or g2d.key_released("ArrowDown") or g2d.key_released("ArrowLeft")): turtle.stay() arena.move_all() g2d.clear_canvas() # -------------------------------------Sfondo----------------------------------------------------------- '''Disegno 2 volte l'immagine, di cui una volta fuori dallo schermo, quando il decremento è uguale al totale del canvas lo ripristino in modo che il movimento sembri continuo''' g2d.draw_image_clip(image, (0, 0, 512, 128), (0, 0, A, B)) g2d.draw_image_clip(image, (0, 258, 512, 128), (0 - contatore3 // 2, (B - 75) // 3, A, B - (B - 75) // 3)) g2d.draw_image_clip(image, (0, 258, 512, 128), (A - contatore3 // 2, (B - 75) // 3, A, B - (B - 75) // 3)) g2d.draw_image_clip(image, (0, 386, 512, 128), (0 - contatore, terrenoval - 90, A, B - (terrenoval - 90))) g2d.draw_image_clip(image, (0, 386, 512, 128), (A - contatore, terrenoval - 90, A, B - (terrenoval - 90))) g2d.draw_image_clip(image, (0, 513, 512, 128), (0 - contatore2 * 2, terrenoval, A, 100)) g2d.draw_image_clip(image, (0, 513, 512, 128), (A - contatore2 * 2, terrenoval, A, 100)) if contatore == A: contatore = 0 if contatore2 == A // 2: contatore2 = 0 if contatore3 == A * 2: contatore3 = 0 for a in arena.actors(): if a.symbol() != (0, 0, 0, 0): g2d.draw_image_clip(sprites, a.symbol(), a.position()) else: g2d.fill_rect(a.position()) contatore += 1 contatore2 += 1 contatore3 += 1
def tick(self): self.movement() arena = self._game.arena() arena.move_all() g2d.clear_canvas() if 0 < self._current_level < self._total_levels: #se il livello attuale è un livello di gioco, disegna il background inerente self._x_background, self._y_background = self._x_y_background[ self._current_level] g2d.draw_image_clip( self._background, (self._x_background, self._y_background, 512, 424), (0, 32, 512, 424)) if self._game.game_won(): if self._win: #condizioni che peremettono di conoscere il momento in cui si vince self._time_of_win = arena.count() self._win = False if arena.count( ) - self._time_of_win > 90: #se sono passati almeno 90 frame dalla vittoria, cambia livello self._current_level += 1 self._game.levels(self._current_level, self._player1_ready, self._player2_ready) self._win = True if self._game.game_over(): if self._lost: #condizioni che peremettono di conoscere il momento in cui si perde self._time_of_win = arena.count() self._lost = False if arena.count( ) - self._time_of_lost > 90: #se sono passati almeno 90 frame dalla sconfitta, ritorna al menu self._current_level = 0 self._game.levels(self._current_level, self._player1_ready, self._player2_ready) self._lost = True elif self._current_level == 0: #se si è nel menu, disegna il background inerente e se e quale giocatore è pronto g2d.draw_image_clip(self._menu, (0, 0, 512, 424), (0, 32, 512, 424)) if self._player1_ready: g2d.draw_image_clip(self._ready, (0, 0, 100, 18), (312, 284, 100, 16)) else: g2d.draw_image_clip(self._ready, (0, 20, 174, 18), (312, 284, 174, 16)) if self._player2_ready: g2d.draw_image_clip(self._ready, (0, 0, 100, 18), (312, 316, 100, 16)) else: g2d.draw_image_clip(self._ready, (0, 20, 174, 18), (312, 316, 174, 16)) else: g2d.draw_image_clip( self._end, (0, 0, 512, 424), (0, 32, 512, 424)) #disegna il background finale g2d.set_color((0, 0, 0)) g2d.fill_rect((0, 0, 512, 48)) #parte di codice che scrive il punteggio del player 1 e 2 self._numbers_scores1, self._numbers_scores2 = self._game.write_scores( ) self._x1 = 2 for i in self._numbers_scores1: self._x_number1, self._y_number1 = i g2d.draw_image_clip(self._sprites, (self._x_number1, self._y_number1, 8, 7), (self._x1, 32, 12, 12)) g2d.draw_image_clip(self._sprites, (107, 1280, 37, 24), (2, 2, 37, 24)) self._x1 += 12 self._x2 = 450 for h in self._numbers_scores2: self._x_number2, self._y_number2 = h g2d.draw_image_clip(self._sprites, (self._x_number2, self._y_number2, 8, 7), (self._x2, 32, 12, 12)) g2d.draw_image_clip(self._sprites, (267, 1280, 49, 24), (450, 2, 49, 24)) self._x2 += 12 for a in arena.actors(): if a.symbol() != (0, 0, 0, 0): g2d.draw_image_clip(self._sprites, a.symbol(), a.position()) #else: # g2d.fill_rect(a.position()) a.check_actors()
def update(): arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): g2d.draw_image_clip(sprites, vals(a.symbol()), vals(a.position()))
def update(): global playgame if (frog[0].getdeath() == 3): pygame.mixer.music.pause() g2d.fill_canvas((0, 0, 0)) g2d.draw_image(gameover, (20, 10)) g2d.draw_text_centered(("SCORE:" + str(score.count(1) * 1000)), (255, 255, 255), (300, 400), 45) elif (playgame == True): x, y, w, h = frog[0].position() if ((x > 43 and x < 85) and (y > 45 and y < 70) and score[0] != 1): score[0] = 1 frog[0].setposition(0) pygame.mixer.music.play() elif ((x > 175 and x < 205) and (y > 45 and y < 70) and score[1] != 1): score[1] = 1 frog[0].setposition(0) pygame.mixer.music.play() elif ((x > 305 and x < 335) and (y > 45 and y < 70) and score[2] != 1): score[2] = 1 frog[0].setposition(0) pygame.mixer.music.play() elif ((x > 435 and x < 475) and (y > 45 and y < 70) and score[3] != 1): score[3] = 1 frog[0].setposition(0) pygame.mixer.music.play() elif ((x > 560 and x < 590) and (y > 45 and y < 70) and score[4] != 1): score[4] = 1 frog[0].setposition(0) pygame.mixer.music.play() if (score.count(1) == 5): pygame.mixer.music.pause() g2d.fill_canvas((0, 0, 0)) g2d.draw_image(win, (20, 10)) g2d.draw_text_centered(("SCORE:" + str(score.count(1) * 1000)), (255, 255, 255), (300, 400), 45) else: frog[0].setcollideraft() frog[0].setcollidefiume() frog[0].setcollideturtle() frog[0].setcollidecrocodile() arena.move_all() g2d.fill_canvas((255, 255, 255)) g2d.draw_image(background, (0, 0)) g2d.draw_text(("SCORE:" + str(score.count(1) * 1000)), (255, 0, 100), (0, 0), 25) g2d.draw_text(("DEATHS FROG:" + str(frog[0].getdeath())), (255, 0, 100), (150, 0), 25) g2d.draw_text(("LIFE FROG:"), (255, 0, 100), (0, 465), 25) for i in range(0, 3 - frog[0].getdeath()): g2d.draw_image_clip(sprite, (100 + i * 18, 465, 18, 15), (14, 369, 18, 15)) for i in range(0, 15): veicoli[i].move() for i in range(0, 12): raft[i].move() for i in range(0, 12): turtle[i].move() for i in range(0, 4): crocodile[i].move() frog[0].move() for a in arena.actors(): if a != fiume and a != land[0] and a != land[1] and a != land[ 2] and a != land[3] and a != land[4] and a != land[ 5] and a != land[6]: g2d.draw_image_clip(sprite, a.position(), a.symbol()) else: g2d.fill_canvas((0, 0, 0)) g2d.draw_image(logo, (20, 10)) g2d.draw_text_centered(("PRESS ANY KEY"), (255, 255, 255), (300, 240), 25)
def update(): terrenoval = B - 100 global players g2d.clear_canvas() global bucacont, boh, rocciacont, rover2 if arena.stop() is False: if g2d.key_pressed("ArrowUp"): rover.go_up() elif g2d.key_pressed("ArrowDown"): rover.go_down() elif g2d.key_pressed("Spacebar"): x, y, w, h = rover.position() Proiettile(arena, x + (w / 4), y, 0, -5) Proiettile(arena, x + w, y + (h / 2), 5, 0) elif g2d.key_pressed("ArrowRight"): rover.go_right() elif g2d.key_pressed("ArrowLeft"): rover.go_left() elif ( g2d.key_released("ArrowUp") or g2d.key_released("ArrowRight") or g2d.key_released("ArrowLeft")): rover.stay() if players: if g2d.key_pressed("w"): rover2.go_up() elif g2d.key_pressed("s"): rover2.go_down() elif g2d.key_pressed("LeftButton"): x, y, w, h = rover2.position() Proiettile(arena, x + (w / 4), y, 0, -5) Proiettile(arena, x + w, y + (h / 2), 5, 0) elif g2d.key_pressed("d"): rover2.go_right() elif g2d.key_pressed("a"): rover2.go_left() elif ( g2d.key_released("w") or g2d.key_released("d") or g2d.key_released("a")): rover2.stay() arena.move_all() g2d.draw_image_clip(image, (0, 0, 512, 128), (0, 0, A, B)) if random.randint(0, 50) == 0 and \ bucacont >= 30 and \ arena.stop() is False and rocciacont >= 30: Buca(arena, A) bucacont = 0 if random.randint(0, 50) == 0 and \ rocciacont >= 30 and \ arena.stop() is False and bucacont >= 30: choice = bool(random.getrandbits(1)) if choice: Roccia(arena, A, terrenoval - 16, choice) else: Roccia(arena, A, terrenoval - 36, choice) rocciacont = 0 for a in arena.actors(): if a.symbol() != (0, 0, 0, 0): if isinstance(a, Sfondo): # il discriminante tra gli sfondi e tutto il resto è l'immagine da cui prendere le porzioni symbol g2d.draw_image_clip(image, a.symbol(), a.position()) else: g2d.draw_image_clip(sprites, a.symbol(), a.position()) else: g2d.fill_rect(a.position()) bucacont += 1 rocciacont += 1
def update(): arena.move_all() # Game logic g2d.fill_canvas((255, 255, 255)) for a in arena.actors(): g2d.draw_image_clip(sprites, a.position(), a.symbol())