class Gem(Sprite): def on_create(self): self.image = random.choice([ "gem_shiny01.png", "gem_shiny02.png", "gem_shiny03.png", "gem_shiny04.png", "gem_shiny05.png" ]) self.scale = float(0.34) self.goto_random_position() self.y = 600 def on_update(self, dt): self.y -= 5 if is_aabb_collision(self, player): self.delete() player.point += 1 print(player.point) elif self.y <= 0: self.delete() player.point -= 1 print(player.point) def wow(dt): w.create_sprite(Gem) Scheduler.update(wow, delay=1) w.run()
self.image = random.choice( ['1.png', '2.png', '3.png', '4.png', '5.png']) self.goto_random_position() self.y = 50 self.scale = 0.3 self.is_moving = False def on_update(self, dt): if self.is_moving: self.y += 20 if self.touching_any_sprite_with_tag("spaceship"): spaceship.score += 1 print(spaceship.score) score_label.text = "aliens in spaceship=" + str(spaceship.score) self.delete() if self.touching_window_edge(): self.delete() def on_left_click(self): self.is_moving = True def my_custom_update(): window.create_sprite(Aliens) Scheduler.update(my_custom_update, delay=1) window.run()
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 scores.text = "How many Alien have been saved?:" + str( ship.score) self.delete() if self.touching_window_edge(): ship.score -= 1 scores.text = "How many Alien have been saved?:" + str( ship.score) self.delete() def on_left_click(self): self.is_moving_up = True def Alen(dt): w.create_sprite(Alien) Scheduler.update(Alen, delay=1) w.run()
from pycat.window import Window from pycat.sprite import Sprite from pycat.keyboard import KeyCode from pycat.collision import is_aabb_collision from pycat.scheduler import Scheduler from pyglet import window o = Window() s = Scheduler() w = o.create_sprite() w.image = "forest_background.jpg" w.scale = 1.125 w.x = 600 w.y = 325 class Wow(Sprite): def on_create(self): self.image = "owl.png" self.x = 50 self.y = 600 def on_update(self, dt): if o.get_key(KeyCode.W): self.rotation = 90 self.move_forward(10) if o.get_key(KeyCode.S): self.rotation = 270 self.move_forward(10)
class Gem(Sprite): def on_create(self): self.image = "gem_shiny01.png" self.goto_random_position() self.y = w.height self.scale = 0.25 def on_update(self, dt): self.y = self.y - 7 if self.y < 0: self.delete() #if self.touching_any_sprite(): # self.delete() if is_aabb_collision(self, cat): self.delete() filelist = [ "gem_shiny01.png", "gem_shiny02.png", "gem_shiny03.png", "gem_shiny04.png", "gem_shiny05.png" ] def create_gem(dt): w.create_sprite(Gem).image = random.choice(filelist) Scheduler.update(create_gem, delay=1) w.run()
self.x = window.width + self.width / 2 self.scale = 0.5 def on_update(self, dt): self.x -= 10 if self.x < -self.width / 2: self.delete() score.score += 0.5 if self.is_touching_sprite(player): window.close() def create_pipes(): bot_pipe = window.create_sprite(Pipes) top_pipe = window.create_sprite(Pipes) top_pipe.rotation = 180 top_pipe.y = window.height y_offset = randint(-100, 100) bot_pipe.y += y_offset top_pipe.y += y_offset gap_offset = randint(-30, 10) bot_pipe.y -= gap_offset top_pipe.y += gap_offset Scheduler.update(create_pipes, 1) player = window.create_sprite(LittleBird) window.run()
class Alien(Sprite): def on_create(self): self.image = "1.png" self.scale = 0.25 self.goto_random_position() self.y = 70 self.is_moving_up = False def on_update(self, dt): if self.is_moving_up == True: self.y += 10 if self.touching_window_edge(): self.delete() if self.touching_any_sprite_with_tag('spaceship'): s.score += 1 print(s.score) self.delete() def on_left_click(self): self.is_moving_up = True def my_alien(dt): window.create_sprite(Alien) Scheduler.update(my_alien, delay=1) window.run()
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 += 66 if self.touching_any_sprite_with_tag("spaceship"): self.delete() ship.score += 1 print(ship.score) if self.touching_window_edge(): ship.score -= 1 print(ship.score) self.delete() if w.get_key(KeyCode.UP): self.is_moving_up = True def Alen(dt): w.create_sprite(Alien) Scheduler.update(Alen, delay=0.001) w.run()