def on_create(self): self.image = "pipe.png" self.scale = 0.7 self.x = window.width + self.width/2 def on_update(self, dt): self.x -= 4 if self.x < -self.width/2: self.delete() def makes_pipe (): bottom_pipe = window.create_sprite(Pipe) top_pipe = window.create_sprite(Pipe) top_pipe.y = window.height top_pipe.rotation += 180 a = int(bottom_pipe.height/2) offset = random.randint(-a,a) bottom_pipe.y += offset top_pipe.y += offset class Score(Label): def on_create(self): self.text = "score" Scheduler.update(makes_pipe ,1.6) window.create_sprite(Pipe) window.create_label(Score) window.run()
enemy = w.create_sprite(Enemy) Enemy.speed *= 2 self.x -= Enemy.speed class Projectile(Sprite): def on_create(self): self.scale = 20 self.color = Color.AZURE self.goto(player) self.add_tag("projectile") def on_update(self, dt): self.x += 10 if self.is_touching_any_sprite_with_tag("enemy"): enemy.x += 50 self.delete() if self.is_touching_window_edge(): self.delete() def key_press(key: KeyEvent): if label.is_current(key.character): p = w.create_sprite(Projectile) player = w.create_sprite(Player) w.subscribe(on_key_press=key_press) label = w.create_label(TypingLabel) enemy = w.create_sprite(Enemy) w.run()
return word verbs = get_words_from_file('verbs.txt') nouns = get_words_from_file('nouns.txt') adjectives = get_words_from_file('adjectives.txt') class GameMode(Enum): Noun = 1 Verb = 2 Adjective = 3 state = GameMode.Noun goal_label = window.create_label(text=str(state)) score = 0 score_label = window.create_label(text='0', x=400) class Word(Sprite): def on_create(self): self.image = '1.png' self.x = random.randint(100, 1100) self.y = 800 self.label = window.create_label(font_size=30) self.label.text = random.choice(verbs + nouns + adjectives)
self.x = 600 def on_update(self, dt: float): if game_manager.timer < 2: self.text = "Get Ready" elif game_manager.timer < 3: self.text = "3" elif game_manager.timer < 4: self.text = "2" elif game_manager.timer < 5: self.text = "1" elif game_manager.timer < 6: self.is_visible = False countdown_label = window.create_label(TimeLabel) class WinLabel(Label): def on_create(self): self.is_visible = False self.text = "You Win!" self.x = 600 self.y = 400 self.font_size = 100 def on_update(self, dt: float): if game_manager.timer > 180: if game_manager.timer < 186: self.is_visible = True
from pycat.base.color import Color from pycat.core import KeyCode, Sprite, Window, Label from pyglet.image import create from pyglet.window.key import W w = Window(background_image = "beach.jpg") w.create_label() class PlayerOneScore(Label): def on_create(self): self.score = 0 self.text = "player one score: " + str(self.score) self.x = 150 self.y = 600 self.font_size = 30 self.color = Color.CHARTREUSE self.font = 'Comic Sans MS' def update_label(self): self.text = "player one score: " + str(self.score) def on_update(self, dt: float): if player_two_score.score>=3: self.text = "you lose " self.x = 150 self.y = 600 self.font_size = 50 self.color = Color.RED self.font = 'Comic Sans MS' game_over()
class Pipe(Sprite): def on_create(self): self.image = "pipe.png" self.x = w.width + self.width / 2 def on_update(self, dt): self.x -= 2 if self.x < -self.width / 2: self.delete() class Score(Label): def on_create(self): self.text = "Score:" def make_pipe(dt): buttom_pipe = w.create_sprite(Pipe) top_pipe = w.create_sprite(Pipe) a = int(buttom_pipe.height / 2) offset = random.randint(-a, a) buttom_pipe.y += offset top_pipe.y = w.height + offset top_pipe.rotation += 180 Scheduler.update(make_pipe, 5) w.create_label(Score) w.create_sprite(Player) w.run()
w.set_clear_color(126, 200, 80) class Health(Label): def on_create(self): self.health = 99 self.font_size = 40 self.color = Color.RED self.x = 36 self.y = 628 def on_update(self, dt: float): self.text = ("Health:" + str(self.health)) playerhp = w.create_label(Health) class Player(Sprite): def on_create(self): self.scale = 0.24 self.image = "slimee.png" self.position = w.center self.speed = 9 self.add_tag("player") def on_update(self, dt): if w.is_key_pressed(KeyCode.W): self.y += self.speed if w.is_key_pressed(KeyCode.S):
Tword.score += 1 score.text = ("Catched Word : " + str(Tword.score)) elif nstate == State.WEAPONS and self.lw.text in weapons: self.delete() self.lw.delete() Tword.score += 1 score.text = ("Catched Word : " + str(Tword.score)) else: self.delete() self.lw.delete() Tword.score -= 1 score.text = ("Catched Word : " + str(Tword.score)) def wordr(): word = w.create_sprite(Tword) word.sposition(choice(ccword), randint(100, 1200), w.height) Scheduler.update(wordr, delay=0.9) score = w.create_label() score.text = ("Catched Word : " + str(0)) score.color = Color.BLACK lstate = w.create_label() lstate.text = (str(nstate)) lstate.y = score.y - score.content_height lstate.color = Color.BLACK w.run()
from pycat.core import Window, Sprite w = Window() my_list = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg'] text_list = ["bus", "bus stop", "bus_number2", "wood_plartform", "Plants"] label = w.create_label() label.text = text_list[0] class Button(Sprite): def on_create(self): self.image = 'button_next.png' self.scale = 0.5 self.x = w.width / 2 self.y = 200 self.img_num = 0 def on_left_click(self): self.img_num += 1 if self.img_num == len(my_list): w.close() return w.background_image = my_list[self.img_num] label.text = text_list[self.img_num] class Up(Sprite): def on_create(self): self.image = 'thumbs_up.png' self.scale = 0.5
class Score(Label): def on_create(self): self.current = 0 self.x = w.width/2 self.file = path.dirname(__file__)+"/highscore.txt" self.high = int(get_data(self.file)[0]) self.text = "High Score: "+ str(self.high) def check_high(self): if self.current > self.high: self.high = self.current self.text = "High Score: "+ str(self.high) write_data(self.file, str(self.high)) score = w.create_label(Score) class State(Enum): SPORTS = 0 CARS = 1 ANIMALS = 2 states = [State.SPORTS, State.CARS, State.ANIMALS] current_state = choice(states) def change_state(): global current_state current_state = choice(states) print(current_state) Scheduler.update(change_state, delay=3)
n = get_words(file_1) adj = get_words(file_2) v = get_words(file_3) all = n + adj + v class State(Enum): N = 0 V = 1 ADJ = 2 states = [State.N, State.V, State.ADJ] current_state = random.choice(states) state_label = w.create_label() class Word(Sprite): def on_create(self): self.color = Color.RED self.label = w.create_label() def setup(self, x, y, t): self.x = x self.y = y self.label.text = t self.width = self.label.content_width self.height = self.label.content_height self.label.y = self.y + self.height / 2 self.label.x = self.x - self.width / 2
if self.touching_window_edge(): self.delete() if self.touching_window_edge(): self.delete() player.health -= 1 scllabel.text = "HEALTH: " +str(player.health) elif self.touching_any_sprite_with_tag("bb"): self.delete() elif self.touching_any_sprite_with_tag('aa'): self.delete() player.health -= 1 scllabel.text = "HEALTH: " +str(player.health) sclabel = Label("POINT: 0",x=200,y=600) w.create_label(sclabel) scllabel = Label("HEALTH: 100",x=20,y=600) w.create_label(scllabel) li01 = Label("You LOSE!",x=600,y=600) li02 = Label("You WIN!",x=600,y=600) player = w.create_sprite(Duck) EM = Emeny def spawn_enemy(): w.create_sprite(Emeny) Scheduler.update(spawn_enemy, delay=0.99)