def __init__(self, name="", image="", attackSound="", specialSound="", xPos=450, yPos=250, dX=0, dY=1): # Initialize Sprite super(Monster, self).__init__(image=games.load_image(image), x=xPos, y=yPos, dx=dX, dy=dY) # General Variables self.name = name.title() self.health = randint(20, 53) self.money = dice.roll(20) # Roll d20 for amount of coins owned self.alive = True self.moving = False # Attack Variables self.attacking = False self.attackDelay = 0 self.attackBonus = 0 self.defenseBonus = 10 # Sounds self.attackSound = games.load_sound(attackSound) self.specialSound = games.load_sound(specialSound) self.deathSound = games.load_sound("sounds/dragon_death.wav") # Sprite to show damage was inflicted self.damageSprite = games.Sprite(image=games.load_image("sprites/damage.png"), x=self.x, y=self.y) self.damageSpriteCounter = -1 # Sprite to show health info above head self.healthLabel = games.Text(value="HP: " + str(self.health), size=30, x=self.x, y=self.top - 20, color=color.white) games.screen.add(self.healthLabel)
def __init__(self, name, classType="Player", image="", attackSound="", specialSound=""): super(Player, self).__init__(image=games.load_image(image), x=150, y=350, dx=0, dy=0) self.name = name.title() self.status = "Alive" self.health = randint(20, 45) self.money = 0 self.type = classType # Sounds self.attackSound = games.load_sound(attackSound) self.specialSound = games.load_sound(specialSound) self.deathSound = games.load_sound("sounds/death.wav") self.alive = True self.moving = False self.attacking = False self.attackDelay = 0 # Sprite to show damage was inflicted self.damageSprite = games.Sprite(image=games.load_image("sprites/damage.png"), x=self.x, y=self.y) self.damageSpriteCounter = -1 # label for health info self.lblHP = games.Text(value="HP: " + str(self.health), size=30, x=self.x, y=self.top - 20, color=color.white) games.screen.add(self.lblHP)
def main(): nebula_image = games.load_image("../Res/nebula.jpg", transparent=False) games.screen.background = nebula_image ship_image = games.load_image("../Res/ship.bmp") the_ship = Ship(image=ship_image, x=games.screen.width / 2, y=games.screen.height / 2) games.screen.add(the_ship) games.screen.mainloop()
def main(): wall_image = games.load_image("wall.jpg", transparent=False) games.screen.background = wall_image pizza_image = games.load_image("pizza.png") the_pizza = Pizza(image = pizza_image, x = games.screen.width/2, y = games.screen.width/2, dx = 1, dy = 1) games.screen.add(the_pizza) games.screen.mainloop()
def __init__(self, color, x, y): self.default = games.load_image("Sprites/" + color + ".png", transparent=False) super(Square, self).__init__(image=self.default, x=x, y=y) games.screen.add(self) self.flashImage = games.load_image("Sprites/" + color + "1.png", transparent=False) self.flashTimer = 0 self.flashing = False
def main(): wall_image = games.load_image("wall.jpg", transparent=False) games.screen.background = wall_image pan_image = games.load_image("pan.bmp") the_pan = Pan(image=pan_image, x=games.mouse.x, y=games.mouse.y) games.screen.add(the_pan) games.mouse.is_visible = False games.screen.event_grab = True games.screen.mainloop()
def main(): nebula_image = games.load_image("nebula.jpg") games.screen.background = nebula_image ship_image = games.load_image("ship.png") the_ship = Ship(image = ship_image, x = games.screen.width/2, y = games.screen.height/2) games.screen.add(the_ship) games.screen.mainloop()
def __init__(self, unit): if(unit.getPlayer() == 0): super(Unit, self).__init__(image=games.load_image("img/f"+unit.getImage()), x = unit.getX() * CONST_TILE_SIZE + CONST_TILE_SIZE/2 + CONST_SIDE_PANELS, y = unit.getY() * CONST_TILE_SIZE + CONST_TILE_SIZE/2) else: super(Unit, self).__init__(image=games.load_image("img/"+unit.getImage()), x = unit.getX() * CONST_TILE_SIZE + CONST_TILE_SIZE/2 + CONST_SIDE_PANELS, y = unit.getY() * CONST_TILE_SIZE + CONST_TILE_SIZE/2) self.unit = unit self.enemy = None self.dest_x = None self.dest_y = None
def __init__(self): super(Game, self).__init__(image=Game.image, x=0, y=0) # Instructions Labels self.instructions = games.Text(value="Shoot as many ducks as possible in 1 minute!", size=35, x=650, y=150, color=color.white) self.instructions2 = games.Text(value="Press \"P\" To Pause", size=35, x=650, y=190, color=color.white) games.screen.add(self.instructions) games.screen.add(self.instructions2) # Paused Game Sprite self.paused = games.Sprite(image=games.load_image("Sprites/paused.png"), x=650, y=350, dx=0, dy=0) # Final Results Labels self.results = games.Text(value="", size=35, x=420, y=300, color=color.white) # How many ducks were hit self.results2 = games.Text(value="", size=35, x=420, y=340, color=color.white)# Accuracy # Counters to delay events self.spawnCounter = 0 self.menuCounter = 0 self.keyDelay = 0 self.keyDelayStart = False self.playing = False # Set to true after instructions go away # Create the timer for the game self.gameTimer = Clock() games.screen.add(self.gameTimer)
class Arrangement(games.Sprite): image = games.load_image('img/car8.png') def __init__(self, y=-200, speed=5, odds_change=200): super(Arrangement, self).__init__(image=Arrangement.image, x=games.screen.width / 2, y=y, dx=speed) self.odds_change = odds_change self.time_til_drop = 0 self.score = games.Text(value=0, size=40, right=games.screen.width - 15, color=color.white, top=5) games.screen.add(self.score) def update(self): if self.left < 0 or self.right > games.screen.width: self.dx = -self.dx elif random.randrange(self.odds_change) == 0: self.dx = -self.dx self.check_drop() def check_drop(self): if self.time_til_drop > 0: self.time_til_drop -= 1 else: new_obstacle = Obstacles(x=self.x, rand1=random.randint(3, 8), speed1=random.randrange(2, 4)) games.screen.add(new_obstacle) self.score.value += 1 self.time_til_drop = random.randint(90, 100)
def play(classType): # Create and set the background image games.screen.background = games.load_image("dd60_background.jpg", transparent=False) # Create the correct class Type if classType == 1: player = Knight("knight", image="sprites\knight.png") elif classType == 2: player = Cleric("Cleric", image="sprites\cleric.png") elif classType == 3: player = Thief("Thief", image="sprites\thief.png") games.screen.add(player) # Create the Dragon object dragon = Red_Dragon("Dragon", image="sprites\dragon.png") games.screen.add(dragon) # Create Labels knightLabel = games.Text(value="Health: " + str(player.health), size=40, x=150, y=200, color=color.white) games.screen.add(knightLabel) dragonLabel = games.Text(value="Health: " + str(dragon.health), size=40, x=450, y=100, color=color.white) games.screen.add(dragonLabel) games.screen.mainloop()
class Ball(games.Sprite): VELOCITY_FACTOR = 4 SIZE_FACTOR = 2 image = games.load_image('ball.png') def __init__(self, game, x, y): super(Ball, self).__init__(image=Ball.image, x=x, y=y) self.dx = self.VELOCITY_FACTOR self.dy = self.VELOCITY_FACTOR self.game = game def __str__(self): return 'Ball' def update(self): if self.right > games.screen.width + self.SIZE_FACTOR: self.right = games.screen.width + self.SIZE_FACTOR self.game.advance() if self.top < -self.SIZE_FACTOR: self.top = -self.SIZE_FACTOR self.dy = -self.dy if self.left < -self.SIZE_FACTOR: self.left = -self.SIZE_FACTOR self.game.advance() if self.bottom > games.screen.height + self.SIZE_FACTOR: self.bottom = games.screen.height + self.SIZE_FACTOR self.dy = -self.dy if self.overlapping_sprites: for sprite in self.overlapping_sprites: self.dx = -self.dx
class Chef(games.Sprite): """Chef whom throw pizza move left - right""" image = games.load_image('chef.bmp') speed = 2 def __init__(self, y=55, speed=speed, odds_change=200): """init object Chef""" super().__init__(image=Chef.image, x=games.screen.width / 2, y=y, dx=speed) self.odds_change = odds_change self.time_til_drop = 0 def update(self): """Defined got change course""" if self.left < 0 or self.right > games.screen.width: # Если ставить условие на равно, может быть баг что повар застрянет в углу self.dx = -self.dx elif random.randrange(self.odds_change) == 0: self.dx = -self.dx self.check_drop() def check_drop(self): """Reduce interval expectation on one or drop next pizza and recover initial interval""" if self.time_til_drop > 0: self.time_til_drop -= 1 else: new_pizza = Pizza(x=self.x) games.screen.add(new_pizza) self.time_til_drop = int(new_pizza.height * 1.3)
class Pan(games.Sprite): """A pan controlled by player to catch falling pizzas.""" image = games.load_image("pan.bmp") # NOTE: Static/Class varieble def __init__(self): """ Initialize Pan object and create Text object for score. """ super(Pan, self).__init__(image=Pan.image, x=games.mouse.x, bottom=games.screen.height) self.score = games.Text(value=0, size=25, color=color.black, top=5, right=games.screen.width - 10) games.screen.add(self.score) def update(self): """ Move to mouse x position. """ self.x = games.mouse.x if self.left < 0: self.left = 0 if self.right > games.screen.width: self.right = games.screen.width self.check_catch() def check_catch(self): """ Check if catch pizzas. """ for pizza in self.overlapping_sprites: self.score.value += 10 self.score.right = games.screen.width - 10 pizza.handle_caught()
class Missile(Collider): """Ракеты коробля""" image = games.load_image("missile.bmp") sound = games.load_sound("missile.wav") BUFFER = 40 VELOCITY_FACTOR = 7 LIFETIME = 40 def __init__(self, ship_x, ship_y, ship_angle): """Инициализация ракеты""" Missile.sound.play() angle = ship_angle * math.pi / 180 buffer_x = Missile.BUFFER * math.sin(angle) buffer_y = Missile.BUFFER * -math.cos(angle) x = ship_x + buffer_x y = ship_y + buffer_y dx = Missile.VELOCITY_FACTOR * math.sin(angle) dy = Missile.VELOCITY_FACTOR * -math.cos(angle) super(Missile, self).__init__(image=Missile.image, x=x, y=y, dx=dx, dy=dy) self.lifetime = Missile.LIFETIME def update(self): """ Перемещает ракету""" super(Missile, self).update() self.lifetime -= 1 if self.lifetime == 0: self.destroy()
class Koles(games.Sprite): #unikajacy zderzen sprzatacz image = games.load_image("Pics/koles.jpg") score = games.Text(value=0, size=75, color=color.pink, top=5, right=games.screen.width - 20) def __init__(self): super(Koles, self).__init__(image=Koles.image, x=games.mouse.x, bottom=games.screen.height) games.screen.add(self.score) def update(self): #zmien pozycje na wyznaczona przez wspolrzedna x myszy. self.x = games.mouse.x if self.left < 0: self.left = 0 if self.right > games.screen.width: self.right = games.screen.width self.check_crash() def check_crash(self): #sprawdz, czy nie doszlo do kolizjii z papierem toaletowym for paper in self.overlapping_sprites: Papier.handle_crash(Papier)
class Papier(games.Sprite): #papier, ktory spada na ziemie image = games.load_image("Pics/papier.jpg") speed = 1 def __init__(self, x, y=50): super(Papier, self).__init__(image=Papier.image, x=x, y=y, dy=Papier.speed) def update(self): #sprawdz, czy dolny brzeg papieru dotknal dolu ekranu if self.bottom > games.screen.height: Koles.score.value += 10 self.destroy() def handle_crash(self): #co sie stanie kiedy papier zetknie sie z kolesiem self.end_game(Koles) games.screen.quit() def end_game(self): #zakoncz gre end_msg = games.Message(value="Przegrana!", size=120, color=color.black, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=5 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_msg)
def main(): games.screen.background = games.load_image("bj.png", transparent=False) game = Game() game.add_bird() game.add_pillar() game.add_ground(192) games.screen.mainloop()
class Skillet(games.Sprite): image = games.load_image("Images/skillet.png") def __init__(self, screen, x, y): self.init_sprite(screen, x=x, y=y, image=Skillet.image) self.score_value = 0 self.score_text = games.Text(screen=self.screen, x=650, y=20, text="Score: 0", size=25, colour=colour.black) def moved(self): """Moves the skillet to mouse position only sideways""" x, y = self.screen.mouse_pos() self.move_to(x, self.getypos()) if self.get_left() < 0: self.set_left(0) if self.get_right() > screen_width: self.set_right(screen_width) self.check_for_catch() def check_for_catch(self): for pizza in self.overlapping_objects(): self.handle_caught() pizza.handle_caught() def handle_caught(self): """Increase and display score.""" self.score_value += 10 self.score_text.set_text("Score: " + str(self.score_value))
class Plant(games.Sprite): image = games.load_image("plant.bmp") def __init__(self): super(Plant, self).__init__(image = Plant.image, x = games.mouse.x, bottom = games.screen.height) self.score = games.Text(value = 0, size = 25, color = color.black, top = 5, right = games.screen.width - 10) games.screen.add(self.score) def update(self): """ Move to mouse x position. """ self.x = games.mouse.x if self.left < 0: self.left = 0 if self.right > games.screen.width: self.right = games.screen.width self.check_catch() def check_catch(self): for water in self.overlapping_sprites: self.score.value += 10 self.score.right = games.screen.width - 10 water.handle_caught()
class Water_Man(games.Sprite): image = games.load_image("water_man.png") def __init__(self, y = 55, speed = 5, odds_change = 200): super(Water_Man, self).__init__(image = Water_Man.image, x = games.screen.width / 2, y = y, dx = speed) self.odds_change = odds_change self.time_til_drop = 0 def update(self): """ Determine if direction needs to be reversed. """ if self.left < 0 or self.right > games.screen.width: self.dx = -self.dx elif random.randrange(self.odds_change) == 0: self.dx = -self.dx self.check_drop() def check_drop(self): if self.time_til_drop > 0: self.time_til_drop -= 1 else: new_water_drop = Water(x = self.x) games.screen.add(new_water_drop) self.time_til_drop = int(new_water_drop.height * 1.3 / Water.speed) + 1
class Ship(Collider): """ The Player's Ship """ image = games.load_image("ship.png") ROTATION_STEP = 3 VELOCITY_STEP = .03 MISSILE_DELAY = 25 sound = games.load_sound("thrust.wav") def __init__(self, x, y): """ Initialise the ship """ super(Ship, self).__init__(image=Ship.image, x=x, y=y) self.missile_wait = 0 def update(self): """ Rotate based on keys pressed """ # Inputs if games.keyboard.is_pressed(games.K_LEFT): self.angle -= Ship.ROTATION_STEP if games.keyboard.is_pressed(games.K_RIGHT): self.angle += Ship.ROTATION_STEP if games.keyboard.is_pressed(games.K_UP): Ship.sound.play() angle = self.angle * math.pi / 180 # radians self.dx += Ship.VELOCITY_STEP * math.sin(angle) self.dy += Ship.VELOCITY_STEP * -math.cos(angle) # Firing missiles is more complex if games.keyboard.is_pressed(games.K_SPACE) and self.missile_wait == 0: new_missile = Missile(self.x, self.y, self.angle) games.screen.add(new_missile) self.missile_wait = Ship.MISSILE_DELAY super(Ship, self).update() if self.missile_wait > 0: self.missile_wait -= 1
class Water(games.Sprite): image = games.load_image("water.bmp") speed = 2 def __init__(self, x, y = 90): super(Water, self).__init__(image = Water.image, x = x, y = y, dy = Water.speed ) def update(self): """ Check if bottom edge has reached screen bottom. """ if self.bottom > games.screen.height: self.end_game() self.destroy() def handle_caught(self): """ Destroy self if caught. """ self.destroy() def end_game(self): """ End the game. """ end_message = games.Message(value = "Game Over", size = 90, color = color.red, x = games.screen.width/2, y = games.screen.height/2, lifetime = 5 * games.screen.fps, after_death = games.screen.quit) games.screen.add(end_message)
def main(): games.screen.background = games.load_image("bj.png",transparent = False) game = Game() game.add_bird() game.add_pillar() game.add_ground(192) games.screen.mainloop()
def main(): wall_image = games.load_image("wall.jpg", transparent = False) games.screen.background = wall_image pizza_image = games.load_image("pizza.bmp") pizza = Pizza(image = pizza_image, x = 320, y = 240, dx = 1, dy = 1) games.screen.add(pizza) pan_image = games.load_image("pan.bmp") the_pan = Pan(image = pan_image, x = games.mouse.x, y = games.mouse.y) games.screen.add(the_pan) games.mouse.is_visible = False games.screen.event_grab = True games.screen.mainloop()
class Burger(games.Sprite): """ бургеры, падающие на землю. """ image = games.load_image("burger_syrom_fri.png") speed = 1 def __init__(self, x, y=90): """ Инициализирует объект Burger """ super(Burger, self).__init__(image=Burger.image, x=x, y=y, dy=Burger.speed) def update(self): """ Проверяет, не коснулась ли нижняя кромка спрайта нижней границы экрана """ if self.bottom > games.screen.height: self.end_game() self.destroy() def handle_caught(self): """ Разрушает объект, пойманный игроком. """ self.destroy() def end_game(self): """ Завершает игру. """ end_message = games.Message(value="Вільна каса", size=90, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=5 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message)
class Przeciwnik(games.Sprite): #przeciwnik, rzucajacy papierem na oslep! image = games.load_image("Pics/zly_czlowiek.png") def __init__(self, y=65, speed=2, odds_change=150): super(Przeciwnik, self).__init__(image=Przeciwnik.image, x=games.screen.width / 2, y=y, dx=speed) self.odds_change = odds_change self.time_till_drop = 0 def update(self): if self.left < 0 or self.right > games.screen.width: self.dx = -self.dx elif random.randrange(self.odds_change) == 0: self.dx = -self.dx self.check_drop() def check_drop(self): #zmniejsz licznik odliczajacy czas lub rzuc papierem i zresetuj odliczanie if self.time_till_drop > 0: self.time_till_drop -= 1 else: new_paper = Papier(x=self.x) #spadnie na wysokosci przeciwnika games.screen.add(new_paper) self.time_till_drop = int( new_paper.height * 1.5 / Papier.speed) + 1
class Chef(games.Sprite): image = games.load_image("kucharz.bmp") def __init__(self, y=55, speed=2, odds_change=200): super(Chef, self).__init__(image=Chef.image, x=games.screen.width / 2, y=y, dx=speed) self.odds_change = odds_change self.time_til_drop = 0 self.pizza_speed = 1 self.pizza_height = 90 def update(self): if self.left < 0 or self.right > games.screen.width: self.dx = -self.dx elif random.randrange(self.odds_change) == 0: self.dx = -self.dx self.check_drop() if Game.difficult >= 1: self.pizza_speed = 2 if Game.difficult >= 2: self.pizza_height = 180 def check_drop(self): if self.time_til_drop > 0: self.time_til_drop -= 1 else: new_pizza = Pizza(x=self.x, dy=self.pizza_speed, y=self.pizza_height) games.screen.add(new_pizza) #self.time_til_drop = int(new_pizza.height*1.3/self.pizza_speed)+1 self.time_til_drop = int(new_pizza.height * 1.3 / 1) + 1
class Deska(games.Sprite): image = games.load_image("deska.bmp", transparent=False) def __init__(self): """ Initialize Pan object and create Text object for score. """ super(Deska, self).__init__(x=games.mouse.x, bottom=games.screen.height, image=Deska.image) self.score = games.Text(value=0, size=25, color=color.black, top=5, right=games.screen.width - 10) games.screen.add(self.score) def update(self): """ Zmień pozycję na wyznaczoną przez współrzędną x myszy. """ self.x = games.mouse.x if self.left < 0: self.left = 0 if self.right > games.screen.width: self.right = games.screen.width self.check_catch() def check_catch(self): """ Sprawdź, czy nie zostały złapane jakieś pizze. """ for ball in self.overlapping_sprites: self.score.value += 10 self.score.right = games.screen.width - 10 ball.ball_hit(self.x)
class Pizza(games.Sprite): """A pizza which falls to the ground.""" image = games.load_image("pizza.bmp") speed = 1 def __init__(self, x, y=90): """ Initialize a Pizza object. """ super(Pizza, self).__init__(image=Pizza.image, x=x, y=y, dy=Pizza.speed) def update(self): """ Check if bottom edge has reached screen bottom. """ if self.bottom > games.screen.height: self.end_game() self.destroy() def handle_caught(self): """ Destroy self if caught. """ self.destroy() def end_game(self): """ End the game. """ end_message = games.Message(value="Game Over", size=90, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=5 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message)
def play(self): # This loads the background image background = games.load_image("bg.jpg") games.screen.background = background # This progresses the game to level 1 and begins the screen's main loop self.newlevel() games.screen.mainloop()
class Caterpillar(games.Sprite): # A caterpillar that moves left and right dropping mouses. image=games.load_image("mouseHole.png") def __init__(self, y=20, speed=3, odds_change=200): # Initialise the caterpillar object. super(Caterpillar, self).__init__( image=Caterpillar.image, x=games.screen.width/2, y=y, dx=speed) self.odds_change = odds_change self.time_til_drop = 0 def update(self): # Check if direction should be reversed if self.left < 0 or self.right > games.screen.width: self.dx = -self.dx elif random.randrange(self.odds_change) == 0: self.dx = -self.dx self.check_drop() def check_drop(self): # Decrease countdown or drop mouse and reset countdown. if self.time_til_drop > 0: self.time_til_drop -= 1 else: new_mouse = Mouse(x=self.x) games.screen.add(new_mouse) # Set buffer to 20% of mouse height self.time_til_drop = int(new_mouse.height * 1.2 / Mouse.speed) + 1
class Missile(Collider): image = games.load_image('pocisk.bmp') sound = games.load_sound('pocisk.wav') BUFFER = 40 VELOCITY_FACTOR = 7 LIFETIME = 40 def __init__(self, ship_x, ship_y, ship_angle): Missile.sound.play() angle = ship_angle * math.pi / 180 buffer_x = Missile.BUFFER * math.sin(angle) buffer_y = Missile.BUFFER * -math.cos(angle) x = ship_x + buffer_x y = ship_y + buffer_y dx = Missile.VELOCITY_FACTOR * math.sin(angle) dy = Missile.VELOCITY_FACTOR * -math.cos(angle) super(Missile, self).__init__(image=Missile.image, x=x, y=y, dx=dx, dy=dy) self.lifetime = Missile.LIFETIME def update(self): super(Missile, self).update() self.lifetime -= 1 if self.lifetime == 0: self.destroy()
def main(): wall_image = games.load_image("images/wall.jpg", transparent = False) games.screen.background = wall_image pizza_image = games.load_image("images/pizza.bmp") pizza_x = random.randrange(games.screen.width) pizza_y = random.randrange(games.screen.height) the_pizza = Pizza(image = pizza_image, x = pizza_x, y = pizza_y) games.screen.add(the_pizza) pan_image = games.load_image("images/pan.bmp") the_pan = Pan(image = pan_image, x = games.mouse.x, y = games.mouse.y) games.screen.add(the_pan) games.mouse.is_visible = False games.screen.event_grab = True games.screen.mainloop()
class Net(games.Sprite): #a paddle Net controlled by the player. image = games.load_image('Paddle.png') def __init__(self): super(Net, self).__init__( image=Net.image,\ x=games.mouse.x,\ bottom=games.screen.height) self.score = games.Text(value=0, size=25, color=color.black, top=5, right=games.screen.width - 10) games.screen.add(self.score) def update(self): #Move to mouse x position. self.x = games.mouse.x if self.left < 0: self.left = 0 if self.right > games.screen.width: self.right = games.screen.width self.check_catch() def check_catch(self): #Check if ball is caught. for ball in self.overlapping_sprites: self.score.value += 10 self.score.right = games.screen.width - 10 ball.handle_caught()
class Net(games.Sprite): # An owl net controlled by the player. image=games.load_image("flyingOwl.png") def __init__(self): # Initialise the net object and create text object for the score. super(Net, self).__init__( image=Net.image, x=games.mouse.x, \ bottom=games.screen.height) self.score=games.Text(value=0, size=25, color=color.black, top=5, right=games.screen.width - 10) games.screen.add(self.score) def update(self): # Move to mouse x position. self.x=games.mouse.x if self.left < 0: self.left = 0 if self.right > games.screen.width: self.right = games.screen.width self.check_catch() def check_catch(self): for owl in self.overlapping_sprites: self.score.value += 10 self.score.right = games.screen.width - 10 owl.handle_caught()
def play(self): # Метод запускающий игру games.music.load('theme.mid') # Загружает в память музыку games.music.play(-1) # Начинает ее проигрывать nebula_image = games.load_image('nebula.jpg', transparent = False) # Создает фон games.screen.background = nebula_image # Загружает фон self.advance() # Толкает игру на уровень 1 , создается астероид, на экране появляется надпись о первом уровне games.screen.mainloop()
def main(): #add a background of clouds background = games.load_image("cloud.jpeg", transparent=False) games.screen.background = background #add the bird bird = Bird() games.screen.add(bird) #add four grasses that overlap so that there aren't any gaps. grass = Screen_Bottom(x=0) games.screen.add(grass) grass1 = Screen_Bottom(x=200) games.screen.add(grass1) grass2 = Screen_Bottom(x=500) games.screen.add(grass2) grass3 = Screen_Bottom(x=800) games.screen.add(grass3) #add the initial tube with a random height tube = Tube(top=random.randrange(300, 550)) games.screen.add(tube) #kick it off! games.mouse.is_visible = True games.screen.event_grab = True games.screen.mainloop()
def setPokeball(dx, dy): PosX = games.screen.width / 2 PosY = 0 pokeballImage = games.load_image("pokeball.png", transparent=True) pokeball = Pokeball(image=pokeballImage, x=PosX, y=PosY, dx=dx, dy=dy) games.screen.add(pokeball)
class Missile(Collider): # Класс ракет """Rocket, which may shoot space ship player""" image = games.load_image('missile.bmp') # Загрузка изображения ракет sound = games.load_sound('missile.wav') # Загружаем звук BUFFER = 40 # растояние в пикселях появления ракеты VELOCITY_FACTOR = 7 # скорость движения ракеты LIFETIME = 40 # время в кадрах жизни ракеты def __init__(self, ship_x, ship_y, ship_angle): # Передаются параметры от корабля """Init sprite with image missile""" Missile.sound.play() # проигрывается звук запуска ракет angle = ship_angle * math.pi / 180 # Высчитывается угол сопоставимый с отметкой на корабле buffer_x = Missile.BUFFER * math.sin(angle) # Высчитывается точка появления ракеты по абциссе в 40 писселях от корабля buffer_y = Missile.BUFFER * -math.cos(angle) # Высчитывается точка появления ракеты по ординате в 40 писселях от корабля x = ship_x + buffer_x # Высчитывается точка появления ракеты по абциссе в 40 писселях от корабля y = ship_y + buffer_y # Высчитывается точка появления ракеты по ординате в 40 писселях от корабля dx = Missile.VELOCITY_FACTOR * math.sin(angle) # Задается скорость ракеты по абцисе dy = Missile.VELOCITY_FACTOR * -math.cos(angle) # Задается скорость ракеты по ординате super().__init__(Missile.image, x = x, y = y, # Хер поймешь зачем такие сложные высчеты, надо разбираться в начальной математике dx = dx, dy = dy) # self.lifetime = Missile.LIFETIME # def update(self): """Moves rocket""" super().update() # Наследование от Collider ( 1 - переход при попадание на край экрана # 2 - проверка на столкновения с другими объектами (астероидами) self.lifetime -= 1 # при каждом кадре жизнь выстрела становится меньше на 1 if self.lifetime == 0: # Если она равна 1: self.destroy() # выстрел уничтожается
def load(self): # load and set background backgroundImage = games.load_image("images/background.png", transparent = False) games.screen.background = backgroundImage # start play games.screen.mainloop()
def main(): ship_image = games.load_image("missile.bmp") the_ship = Ship(image = ship_image, x = games.screen.width/2, y = games.screen.height/2) games.screen.add(the_ship) games.screen.mainloop()
class Chef(games.Sprite): """A chef which moves left and right, dropping pizzas.""" image = games.load_image("chef.bmp") def __init__(self, y=55, speed=2, odds_change=200): """ Initialize the Chef object. """ super(Chef, self).__init__(image=Chef.image, x=games.screen.width / 2, y=y, dx=speed) self.odds_change = odds_change self.time_til_drop = 0 def update(self): """ Determine if direction needs to be reversed. """ if self.left < 0 or self.right > games.screen.width: self.dx = -self.dx elif random.randrange(self.odds_change) == 0: self.dx = -self.dx self.check_drop() def check_drop(self): """ Decrease countdown or drop pizza and reset countdown. """ if self.time_til_drop > 0: self.time_til_drop -= 1 else: new_pizza = Pizza(x=self.x) games.screen.add(new_pizza) # set buffer to approx 30% of pizza height, regardless of pizza speed self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed) + 1
def __init__(self): super(Game, self).__init__(image=Game.image, x=0, y=0) # Instructions Labels self.instructions = games.Text(value="Shoot as many ducks as possible in 1 minute!", size=35, x=320, y=100, color=color.white) self.instructions2 = games.Text(value="Press \"P\" To Pause", size=35, x=320, y=140, color=color.white) games.screen.add(self.instructions) games.screen.add(self.instructions2) # Paused Game Sprite self.paused = games.Sprite(image=games.load_image("Sprites/paused.png"), x=320, y=240, dx=0, dy=0) # Final Results Labels self.results = games.Text(value="", size=35, x=320, y=100, color=color.white) # How many ducks were hit self.results2 = games.Text(value="", size=35, x=320, y=140, color=color.white)# Accuracy # Counters to delay events self.spawnCounter = 0 self.menuCounter = 0 self.keyDelay = 0 self.keyDelayStart = False self.playing = False # Set to true after instructions go away # Create the timer for the game self.gameTimer = Clock() games.screen.add(self.gameTimer)
class PingPongBall(games.Sprite): # A bouncing Ping Pong Ball image = games.load_image('PingPongBall.png') speed = 3 def __init__(self, x=70, y=70): #initialise a ping pong ball object. super(PingPongBall,self).__init__(image=PingPongBall.image,\ x=x, y=y, dx=PingPongBall.speed, \ dy=PingPongBall.speed) def update(self): #Check if the bottom edge of the ping pong ball sprite #has reached the screen bottom. if self.right > games.screen.width or self.left < 0: self.dx = -self.dx if self.top > games.screen.height or self.top < 0: self.dy = -self.dy if self.bottom > games.screen.height: self.end_game() self.destroy() def handle_caught(self): #rebound of the paddle self.dy = -self.dy def end_game(self): #End The Game! end_message=games.Message(value='Game Over!', size=90,\ color=color.black, x=games.screen.width/2, y=games.screen.height/2, lifetime=5*games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message)
def __init__(self): # Load Sprites self.LEFTSPRITE = games.load_image("sprites\superman\superman_left.png", transparent=True) self.RIGHTSPRITE = games.load_image("sprites\superman\superman_right.png", transparent=True) super(Superman, self).__init__(image=self.RIGHTSPRITE, x=games.mouse.x, y=410, dx=0, dy=0) self.timer = 0 self.facing = 1 self.time_til_drop = 0 self.dead = False self.playing = False # Used to tell if the instructions have been displayed yet # Display game Instructions self.lbl_instructs = games.Text(value="Avoid The Kryptonite", size=80, x=320, y=250, color=color.white) games.screen.add(self.lbl_instructs)
def __init__(self, user, enemy): self.user = user self.enemy = enemy Image = games.load_image(enemy.Image) super(opponent, self).__init__(image = Image, x = enemy.enemyX, y = enemy.enemyY) self.count = 10
def play(self): # load background ground_image = games.load_image("dirt.jpg") games.screen.background = ground_image # start play games.screen.mainloop()
def __init__(self, classType): super(Game, self).__init__(image=games.load_image("sprites\game.png"), x=0, y=0) # Create the correct class Type if classType == 1: self.player = Knight() elif classType == 2: self.player = Cleric() elif classType == 3: self.player = Thief() # Create the enemy enemy = randint(1, 3) if enemy == 1: self.enemy = Red_Dragon() elif enemy == 2: self.enemy = White_Dragon() elif enemy == 3: self.enemy = Goblin() # Add the player and the enemy to the screen games.screen.add(self.enemy) games.screen.add(self.player) # Labels and Variables to show controls self.controlsOnScreen = False self.controlsCounter = 0 self.lblControls_Attack = games.Text(value="a - Attack", size=40, x=100, y=30, color=color.white) self.lblControls_Special = games.Text(value="s - Special Ability", size=40, x=155, y=70, color=color.white) self.lblControls_Help = games.Text(value="F1 - Help", size=40, x=95, y=110, color=color.white) self.lblControls_Exit = games.Text(value="Esc - Exit", size=40, x=100, y=150, color=color.white)
def play(classType): # Create and set the background image games.screen.background = games.load_image("background.jpg", transparent=False) mainGame = Game(classType) games.screen.add(mainGame) games.screen.mainloop()
def play(self): """ Play the game. """ games.music.load("theme.mid") games.music.play(-1) wall_image = games.load_image("background.bmp") games.screen.background = wall_image self.advance() games.screen.mainloop()
def play(self): EoS_background = games.load_image("EoS_Background.bmp") games.screen.background = E0S_background self_advance() games.screen.mainloop()
def player2Select(self): playerSelect_background = games.load_image("graphics/menuCharSelect.png", transparent = False) games.screen.background = playerSelect_background for i in range(4): char = CharacterIcon(x = 125 + (200 * i), y = 295, character = i + 1) games.screen.add(char) selector = PlayerSelector(game = self, x= 125, y = 294, selector = 2) games.screen.add(selector)
def main(): """ Playing the game""" #background wall_image = games.load_image("lrg_back.jpg", transparent = False) games.screen.background = wall_image #inserting new bricks ''' insert the first level of brick pattern here ''' ## Group of bricks bricks = [] ##Locations bricks.append(Brick(70, 50)) bricks.append(Brick(140, 50)) ## add bricks to window #for brick in bricks: #games.screen.add(brick) brick1 = Brick(300, 200) games.screen.add(brick1) #the ball ball_image = games.load_image("ball.bmp") the_ball = Ball(image = ball_image, x = games.screen.width/2, y = games.screen.height/2 + 120, dx = 2, dy = -2) games.screen.add(the_ball) #the paddle the_paddle = Paddle() games.screen.add(the_paddle) games.mouse.is_visible = False games.screen.event_grab = True games.screen.mainloop()
def play(self): """start the game""" games.music.load("sounds/StarFr_title.mp3") games.music.play(-1) background = games.load_image("pic/space.jpg") games.screen.background = background #start with level 1 self.newLevel() games.screen.mainloop()
def __init__(self): """ Cursor Initializer """ super(Cursor, self).__init__(image=games.load_image("Sprites/cursor.png"), x=games.mouse.x, y=games.mouse.y) self.mouseClicked = False self.mouseCounter = 0 # Load gunshot sound self.gunShotSound = games.load_sound("Sounds/shot.wav")
def playerSelect(self): charSelectBackground = games.load_image("graphics/menuCharSelect.png") games.screen.background = charSelectBackground for i in range(4): char = CharacterIcon(x = 125 + (200 * i), y = 295, character = i + 1) games.screen.add(char) p1Selector = PlayerSelector(x = 125, y = 294) games.screen.add(p1Selector)
def __init__(self, name, minHP=20, maxHP=53, image="", x=450, y=250, dx=0, dy=1): self.name = name.title() self.status = "Alive" self.health = randint(minHP, maxHP) self.alive = True self.moving = False self.attacking = False self.attackDelay = 0 super(Monster, self).__init__(image=games.load_image(image, transparent=True), x=x, y=y, dx=dx, dy=dy) self.damageSprite = games.Sprite(games.load_image("sprites/damage.png"), x=self.x, y=self.y) self.damageSpriteCounter = -1 # Health label self.lblHP = games.Text(value="HP: " + str(self.health), size=30, x=self.x, y=self.top - 20, color=color.white) games.screen.add(self.lblHP)
def play(self): games.music.load("theme.mid") games.music.play(-1) background_image = games.load_image("background.bmp") games.screen.background = background_image # games.screen.add(Invader(game = self, x = games.screen.width/2, y = games.screen.height/2)) games.screen.mainloop()