from pycat.window import Window from pycat.sprite import Sprite from pycat.keyboard import KeyCode from pycat.scheduler import Scheduler from pycat.collision import is_aabb_collision from pycat.label import Label import random window = Window(background_image="underwater_04.png") score_label = Label("aliens in spaceship=0") window.add_label(score_label) score_label.x = 550 score_label.y = 600 class Spaceship(Sprite): def on_create(self): self.image = "saucer.png" self.y = 500 self.scale = 0.3 self.score = 0 self.add_tag("spaceship") def on_update(self, dt): self.move_forward(8) if self.touching_window_edge(): self.rotation += 180 spaceship = window.create_sprite(Spaceship)
self.y = 490 self.scale = float(0.25) self.rotation_mode = RotationMode.RIGHT_LEFT self.add_tag("spaceship") def on_update(self, dt): self.move_forward(4) if self.touching_window_edge(): self.rotation += 180 ship = w.create_sprite(Ship) scores = Label("How many Alien have been saved?:", x=400, y=600) ship.score = 0 w.add_label(scores) class Alien(Sprite): def on_create(self): self.image = random.choice(["1.png", "2.png", "3.png", "5.png"]) self.scale = float(0.25) self.goto_random_position() self.y = 46 self.is_moving_up = False def on_update(self, dt): if self.is_moving_up: self.y += 10 if self.touching_any_sprite_with_tag("spaceship"): ship.score += 1
if sprite1.image == sprite2.image: sprite1.delete() sprite2.delete() button.score += 1 score_label.text = 'BEST MATCH: ' + str(button.score) else: sprite1.is_visible = False sprite2.is_visible = False cL_sprite.clear() button = w.create_sprite(Button) button.score = 0 score_label = Label("BEST MATCH: 0", x=1000, y=400) w.add_label(score_label) p1 = w.create_sprite(Card, x=200, y=100, image="avatar_01.png", scale=float(1.6)) p2 = w.create_sprite(Card, x=200, y=220, image="avatar_02.png", scale=float(1.6)) p3 = w.create_sprite(Card, x=200, y=340, image="avatar_03.png",