A game for the Ipad made with pyhton in the app pythonista.
Nessun elemento selezionato Vai ai contenuti Utilizzo di Gmail con gli screen reader 1 di 55.569 Aria def Posta in arrivo Giovanni Gatto <[email protected]> Allegati 18:29 (32 minuti fa) a Giovanni, me Un allegato • Scansione eseguita da Gmail Scrivi: Nuovo messaggio Riduci a iconaSeparaChiudi Destinatari Oggetto import scene import sound import random import motion import ui class Brick(scene.SpriteNode): def __init__(self, position, *args, **kwargs): super().__init__(*args, **kwargs) self.position = position self.size = (80, 40) self.color = random.choice(['#ff8989', '#88eeac', '#9bd8ff', '#fff1bf', '#ff92ae', '#addfff']) class Ball(scene.SpriteNode): def __init__(self, position, velocity, *args, **kwargs): super().__init__(*args, **kwargs) self.position = position self.size = (20, 20) self.color = '#fbffa4' self.velocity = velocity # texture = scene.Texture(ui.Image.named('iob:ios7_circle_outline_24')) # self.texture = texture class Arkanoid(scene.Scene): def setup(self): self.background_color = '#000000' motion.start_updates() self.paddle = scene.SpriteNode(color='white') self.paddle.size = (100, 20) self.paddle.position = (self.size.w / 2, 50) self.add_child(self.paddle) self.balls = [] self.create_ball() self.bricks = [] self.create_bricks() self.score = 0 self.score_label = scene.LabelNode(f'Score: {self.score}', position=(50, self.size.h - 30)) self.add_child(self.score_label) self.level = 1 self.level_label = scene.LabelNode(f'Level: {self.level}', position=(self.size.w - 50, self.size.h - 30)) self.add_child(self.level_label) self.lives = 3 self.lives_label = scene.LabelNode(f'Lives: {self.lives}', position=(self.size.w / 2, self.size.h - 30)) self.add_child(self.lives_label) self.paddle_speed = 0 self.max_speed = 10 def create_ball(self): if len(self.balls) < 2: ball = Ball(position=(self.size.w / 2, 100), velocity=scene.Point(4, 4)) self.add_child(ball) self.balls.append(ball) def create_bricks(self): for brick in self.bricks: brick.remove_from_parent() self.bricks.clear() rows = 5 cols = int(self.size.w // 90) for row in range(rows): for col in range(cols): brick = Brick(position=(col * 90 + 45, self.size.h - (row * 50 + 100))) self.add_child(brick) self.bricks.append(brick) def update(self): tilt = motion.get_gravity()[0] self.paddle_speed = -tilt * self.max_speed*6 new_x = self.paddle.position.x + self.paddle_speed new_x = max(self.paddle.size.w / 2, min(new_x, self.size.w - self.paddle.size.w / 2)) self.paddle.position = (new_x, 50) for ball in self.balls[:]: ball.position += ball.velocity if ball.position.x <= 10 or ball.position.x >= self.size.w - 10: ball.velocity.x *= -1 if ball.position.y >= self.size.h - 10: ball.velocity.y *= -1 if ball.frame.intersects(self.paddle.frame): ball.velocity.y *= -1 sound.play_effect('game:Woosh_1') for brick in self.bricks[:]: if ball.frame.intersects(brick.frame): brick.remove_from_parent() self.bricks.remove(brick) ball.velocity.y *= -1 self.score += 10 self.score_label.text = f'Score: {self.score}' sound.play_effect('game:Ding_3') if ball.position.y <= 0: self.balls.remove(ball) ball.remove_from_parent() if not self.balls: self.lives -= 1 self.lives_label.text = f'Lives: {self.lives}' if self.lives > 0: self.create_ball() else: self.game_over() if random.random() < 0.001: # 0.1% chance each frame to spawn a new ball self.create_ball() if not self.bricks: self.level += 1 self.level_label.text = f'Level: {self.level}' self.create_bricks() for ball in self.balls: ball.velocity *= 1.1 # Increase velocity by 10% def game_over(self): self.paused = True game_over_label = scene.LabelNode('Game Over', position=(self.size.w/2, self.size.h/2 + 50)) self.add_child(game_over_label) restart_button = scene.SpriteNode(color='green') restart_button.size = (100, 50) restart_button.position = (self.size.w/2, self.size.h/2 - 50) self.add_child(restart_button) restart_label = scene.LabelNode('Restart', position=restart_button.position) self.add_child(restart_label) def touch_began(self, touch): if self.paused: if touch.location in self.children['SpriteNode'].frame: # Check if restart button is tapped self.restart_game() def restart_game(self): for child in self.children: child.remove_from_parent() self.setup() self.paused = False if __name__ == '__main__': scene.run(Arkanoid(), show_fps=False) arkanoid.py Visualizzazione di arkanoid.py.
https://www.tiktok.com/@johnstarfire/video/7402662957332679968?is_from_webapp=1&sender_device=pc
Subscribe to the newsletter for updates
Tkinter templatesTwitter: @pythonprogrammi - python_pygame
Claude's Games
1. Memory gameVideos
Speech recognition gamePygame's Platform Game