Example #1
0
class Asteroid(Wrapper):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: game.load_image("img/meteorsmall.png"),
        MEDIUM: game.load_image("img/meteormedium.png"),
        LARGE: game.load_image("img/meteor.png")
    }
    SPEED = 3
    SPAWN = random.randint(2, 4)

    def __init__(self, x, y, size):
        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)
        self.size = size

    def die(self):
        global SCORE
        SCORE += 100 / self.size
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                a = Asteroid(x=self.x, y=self.y, size=self.size - 1)
                game.screen.add(a)
        super(Asteroid, self).die()
class Asteroid(games.Sprite):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("images/astroid_Small.png"),
        MEDIUM: games.load_image("images/astroid_Medium.png"),
        LARGE: games.load_image("images/astroid_large.png"),
    }
    SPEED = 2

    def __init__(self, x, y, size):
        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)
        self.size = size

    def update(self):
        if self.left > games.screen.width:
            self.right = 0

        if self.right < 0:
            self.left = games.screen.width

        if self.bottom < 0:
            self.top = games.screen.height

        if self.top > games.screen.height:
            self.bottom = 0
Example #3
0
class Asteroid(Wrapper):
    """ An asteroid which floats across the screen. """
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("asteroid_small.bmp"),
        MEDIUM: games.load_image("asteroid_med.bmp"),
        LARGE: games.load_image("asteroid_big.bmp")
    }

    SPEED = 2
    SPAWN = 2

    def __init__(self, x, y, size):
        """ Initialize asteroid sprite. """
        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)

        self.size = size

    def die(self):
        """ Destroy asteroid. """
        # if asteroid isn't small, replace with two smaller asteroids
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(x=self.x, y=self.y, size=self.size - 1)
                games.screen.add(new_asteroid)

        super(Asteroid, self).die()
Example #4
0
class Fireball(Wrapper):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    SPAWN = random.randrange(1, 4)
    images = {
        SMALL: games.load_image("Images/asteroid(S).png"),
        MEDIUM: games.load_image("Images/asteroid(M).png"),
        LARGE: games.load_image("Images/asteroid(L).png")
    }
    SPEED = 2

    def __init__(self, x, y, size):
        super(Fireball, self).__init__(
            image=Fireball.images[size],
            x=x,
            y=y,
            dx=random.choice([1, -1]) * Fireball.SPEED * random.random() /
            size,
            dy=random.choice([1, -1]) * Fireball.SPEED * random.random() /
            size,
        )
        self.size = size

    def die(self):
        if self.size != Fireball.SMALL:
            for i in range(Fireball.SPAWN):
                new_fireball = Fireball(x=self.x, y=self.y, size=self.size - 1)
                games.screen.add(new_fireball)
        super(Fireball, self).die()
Example #5
0
class Asteroid(Wrapper):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {SMALL: games.load_image("img/meteorsmall.png"),
              MEDIUM: games.load_image("img/meteormedium.png"),
              LARGE: games.load_image("img/meteor.png")}
    SPEED = 3
    SPAWN = random.randint(2, 4)
    POINTS = 100
    TOTAL = 0

    def __init__(self, game, x, y, size):
        Asteroid.TOTAL += 1
        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) * Asteroid.SPEED * random.random()/size,
                                       dy=random.choice([1, -1]) * Asteroid.SPEED * random.random() / size
                                       )
        self.size = size
        self.game = game

    def die(self):
        Asteroid.TOTAL -= 1
        self.game.score.value += Asteroid.POINTS//self.size
        self.game.score.right = games.screen.width-10
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                a = Asteroid(self.game, x=self.x, y=self.y, size=self.size-1)
                games.screen.add(a)
        if Asteroid.TOTAL == 0:
            self.game.advance()
        self.game.ufocheck()
        super(Asteroid, self).die()
Example #6
0
class Asteroid(games.Sprite):
    small = 1
    medium = 2
    large = 3
    images = {
        small: games.load_image("images2/asteroid3.png"),
        medium: games.load_image("images2/asteroid2.png"),
        large: games.load_image("images2/asteroid1.png")
    }
    speed = 2

    def __init__(self, x, y, size):
        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.speed * random.random() / size,
                                       dy=random.choice([-1, 1]) *
                                       Asteroid.speed * random.random() / size)
        self.size = size

    def update(self):
        if self.left < games.screen.width:
            self.right = 0

        if self.right < 0:
            self.left = games.screen.width

        if self.top > games.screen.height:
            self.bottom = 0

        if self.bottom < 0:
            self.top = games.screen.height
class Asteroid(Collider):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("images/astroid_Small.png"),
        MEDIUM: games.load_image("images/astroid_Medium.png"),
        LARGE: games.load_image("images/astroid_large.png"),
    }
    SPEED = 2
    SPAWN = 2

    def __init__(self, x, y, size):
        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)
        self.size = size

    def die(self):
        super(Asteroid, self).die()
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(x=self.x, y=self.y, size=self.size - 1)
                games.screen.add(new_asteroid)
        self.destroy()
Example #8
0
class Asteroid(Wrapper):
    small = 1
    medium = 2
    large = 3
    images = {
        small: games.load_image("images2/asteroid3.png"),
        medium: games.load_image("images2/asteroid2.png"),
        large: games.load_image("images2/asteroid1.png")
    }
    speed = 2
    spawn = 2

    def __init__(self, x, y, size):
        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.speed * random.random() / size,
                                       dy=random.choice([-1, 1]) *
                                       Asteroid.speed * random.random() / size)
        self.size = size

    def die(self):
        #if asteroid isn't small, replace with two smaller asteroids
        if self.size != Asteroid.small:
            for i in range(Asteroid.spawn):
                new_asteroid = Asteroid(x=self.x, y=self.y, size=self.size - 1)
                games.screen.add(new_asteroid)
        self.destroy()
class Asteroid(games.Sprite):
    """Астероид, прямолинейно движущийся по экрану"""
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {SMALL  : games.load_image("asteroid_small.bmp"),
              MEDIUM : games.load_image("asteroid_med.bmp"),
              LARGE  : games.load_image("asteroid_big.bmp")}
    SPEED = 2

    def __init__(self, x, y, size):
        """Инициализирует спрайт с изображением астероида"""
        super(Asteroid, self).__init__(
            image=Asteroid.images[size],
            x=x, y=y,
            dx=random.choice([1, -1]) * Asteroid.SPEED * random.random()/size,
            dy=random.choice([1, -1]) * Asteroid.SPEED * random.random()/size)
        self.size = size

    def update(self):
        """Заставляет астероид обогнуть экран"""
        if self.top > games.screen.height:
            self.bottom = 0

        if self.bottom < 0:
            self.top = games.screen.height

        if self.left > games.screen.width:
            self.right = 0

        if self.right < 0:
            self.left = games.screen.width
Example #10
0
def main():

    SW = 640
    SH = 480

    games.init(screen_width=SW, screen_height=SH, fps=60)

    #background
    bg_img = games.load_image("sprites/background.jpg", transparent=False)
    games.screen.background = bg_img
    #character
    ch_img = games.load_image("sprites/character.png", transparent=True)
    character = games.Sprite(image=ch_img, x=SW / 3, y=SH / 3)
    games.screen.add(character)

    #present
    present_img = games.load_image("sprites/present.png", transparent=True)

    present = Present(image=present_img,
                      x=SW / 2,
                      y=SH / 2,
                      dx=random.randint(-10, 10),
                      dy=random.randint(-10, 10))
    present2 = Present(image=present_img,
                       x=SW / 2,
                       y=SH / 2,
                       dx=random.randint(-10, 10),
                       dy=random.randint(-10, 10))
    present3 = Present(image=present_img,
                       x=SW / 2,
                       y=SH / 2,
                       dx=random.randint(-10, 10),
                       dy=random.randint(-10, 10))

    #bag
    bag_img = games.load_image("sprites/bag.png", transparent=True)
    bag = Bag(image=bag_img, x=games.mouse.x, y=420)

    #Creating txt object
    score = ScText(value=SCORE,
                   size=60,
                   is_collideable=False,
                   color=color.black,
                   x=550,
                   y=30)

    #Putting objects on screen
    games.screen.add(score)
    games.screen.add(present)
    games.screen.add(present2)
    games.screen.add(present3)
    games.screen.add(bag)

    #makes mouse invisible
    games.mouse.is_visible = False
    #locks screen
    games.screen.event_grab = False

    #starts mainloop
    games.screen.mainloop()
Example #11
0
class Asteroid(Wrapper):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    image = {
        SMALL: games.load_image("img/meteorsmall.png"),
        MEDIUM: games.load_image("img/meteormedium.png"),
        LARGE: games.load_image("img/meteorlarge.png")
    }
    SPEED = 2

    SPAWN = 2

    def __init__(self, x, y, size):
        super(Asteroid, self).__init__(image=Asteroid.image[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)
        self.size = size

    def die(self):
        # if asteroid isn't small, replace with two smaller asteroids
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(x=self.x, y=self.y, size=self.size - 1)
                games.screen.add(new_asteroid)
        self.destroy()
def main():
    nebula_image = games.load_image("nebula.jpg", transparent=False)
    games.screen.background = nebula_image
    ship_image = games.load_image("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()
Example #13
0
def main():
    wall_image = games.load_image(path_to_images + "wall.jpg",
                                  transparent=False)
    games.screen.background = wall_image

    pan_image = games.load_image(path_to_images + "PizzaPan.png")
    the_pan = Pan(image=pan_image, x=games.mouse.x, y=games.mouse.y)
    games.screen.add(the_pan)
    games.mouse.is_visible = False  # mouse pointer is invisible
    games.screen.mainloop()
Example #14
0
    def update(self):
        """Rotates, thrusts and fires missiles based on keys pressed by player"""
        super().update()

        # rotate player's ship based on left and right arrow keys been pressed
        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

        # apply thrust based on up arrow key
        if games.keyboard.is_pressed(games.K_UP):
            Ship.sound.play()

            # change velocity components based on ship's angle
            angle = self.angle * math.pi / 180  # convert into radians
            self.dx += Ship.VELOCITY_STEP * math.sin(angle)
            self.dy += Ship.VELOCITY_STEP * -math.cos(angle)

            # cap velocity in each direction
            self.dx = min(max(self.dx, -Ship.VELOCITY_MAX), Ship.VELOCITY_MAX)
            self.dy = min(max(self.dy, -Ship.VELOCITY_MAX), Ship.VELOCITY_MAX)

            # add jet stream animation
            new_jetstream = JetStream(self.x, self.y, self.angle)
            games.screen.add(new_jetstream)

        # if waiting until the ship can fire next, decrease wait
        if self.missile_wait > 0:
            self.missile_wait -= 1

        # fire missile if space bar is pressed and missile wait is over
        if games.keyboard.is_pressed(games.K_SPACE) and self.missile_wait == 0:
            if self.gun_bonus_is_active:
                missile_image = games.load_image('./res/missile_bonus1.bmp')
            else:
                missile_image = games.load_image('./res/missile.bmp')
            new_missile = Missile(missile_image, self.x, self.y, self.angle)
            games.screen.add(new_missile)
            self.missile_wait = Ship.MISSILE_DELAY

        if self.gun_bonus_time > 0:
            self.gun_bonus_time -= 1
        else:
            self.deactivate_gun_bonus()

        # if waiting until the next bonus, decrease wait
        if self.bonus_wait > 0:
            self.bonus_wait -= 1
        else:
            coords = random_coords(buffer=100, ship_current_x=self.x, ship_current_y=self.y,
                                   screen_width=games.screen.width, screen_height=games.screen.height)
            new_bonus = GunBonus(x=coords[0], y=coords[1])
            games.screen.add(new_bonus)
            self.bonus_wait = Ship.BONUS_DELAY
Example #15
0
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 = False
    games.screen.mainloop()
Example #16
0
def main():
    wall_image = games.load_image("wall.jpg", transparent=False)
    games.screen.background = wall_image
    pizza_image = games.load_image("pizza.bmp")
    the_pizza = Pizza(image=pizza_image,
                      x=games.screen.width/2,
                      y=games.screen.height/2,
                      dx=3,
                      dy=3)
    games.screen.add(the_pizza)
    games.screen.mainloop()
Example #17
0
class Asteroid(Wrapper):
    """Asteroida przelatująca przez ekran"""
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("asteroida_mala.bmp"),
        MEDIUM: games.load_image("asteroida_sred.bmp"),
        LARGE: games.load_image("asteroida_duza.bmp")
    }
    SPEED = 2
    SPAWN = 2
    POINTS = 30
    total = 0

    def __init__(self, game, x, y, size):
        """Inicjalizacja sprite'a asteroidy"""
        Asteroid.total += 1

        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)
        self.game = game
        self.size = size

    def die(self):
        """Zniszcz asteroidę"""
        # jeśli nie jest to mała asteroida, zastąp ją dwoma mniejszymi
        Asteroid.total -= 1

        self.game.score.value += int(Asteroid.POINTS / self.size)
        self.game.score.right = games.screen.width - 10

        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(game=self.game,
                                        x=self.x,
                                        y=self.y,
                                        size=self.size - 1)
                games.screen.add(new_asteroid)

        # jeżeli wszystkie asteroidy zostały zniszczone, przejdź do kolejnego poziomu
        if Asteroid.total == 0:
            self.game.advance()

        super(Asteroid, self).die()
        new_explosion = Explosion(x=self.x, y=self.y)
        games.screen.add(new_explosion)
        self.destroy()
class Asteroid(Wrapper):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("images/astroid_Small.png"),
        MEDIUM: games.load_image("images/astroid_Medium.png"),
        LARGE: games.load_image("images/astroid_large.png")
    }
    SPEED = 2
    SPAWN = 3
    POINTS = 30
    total = 0

    def __init__(self, game, x, y, size):
        """ Initialize asteroid sprite. """
        Asteroid.total += 1

        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)

        self.game = game
        self.size = size

    def die(self):

        Asteroid.total -= 1

        self.game.score.value += int(Asteroid.POINTS / self.size)
        self.game.score.right = games.screen.width - 10

        # if asteroid isn't small, replace with two smaller asteroids
        if self.size == Asteroid.LARGE or self.size == Asteroid.MEDIUM:
            self.size -= 1
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(game=self.game,
                                        x=self.x,
                                        y=self.y,
                                        size=self.size)
                games.screen.add(new_asteroid)
        else:
            self.die

        # if all asteroids are gone, advance to next level
        if Asteroid.total == 0:
            self.game.advance()

        super(Asteroid, self).die()
Example #19
0
class Asteroid(Wrapper):
    """ An asteroid which floats across the screen. """
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("sprites/asteroid3.png"),
        MEDIUM: games.load_image("sprites/asteroid2.png"),
        LARGE: games.load_image("sprites/asteroid1.png")
    }

    SPEED = 2
    SPAWN = 2
    POINTS = 30

    total = 0

    def __init__(self, game, x, y, size):
        """ Initialize asteroid sprite. """
        Asteroid.total += 1

        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)

        self.game = game
        self.size = size

    def die(self):
        """ Destroy asteroid. """
        Asteroid.total -= 1

        self.game.score.value += int(Asteroid.POINTS / self.size)
        self.game.score.right = games.screen.width - 10

        # if asteroid isn't small, replace with two smaller asteroids
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(game=self.game,
                                        x=self.x,
                                        y=self.y,
                                        size=self.size - 1)
                games.screen.add(new_asteroid)

        # if all asteroids are gone, advance to next level
        if Asteroid.total == 0:
            self.game.advance()

        super(Asteroid, self).die()
Example #20
0
def main():
    #loaded img
    bg_img = games.load_image("images/background.png", transparent=False)
    boss_img = games.load_image("images/character.png", transparent=True)
    fireball_img = games.load_image("images/fireball.png", transparent=True)
    hand_img = games.load_image("images/hand.png", transparent=True)

    #added img to bg
    games.screen.background = bg_img

    #create boss
    boss = Boss(image = boss_img,
                x = 550,
                y = 130,
                dx = 6
                )

    #create fireball obj
    fireball = Fireball(image = fireball_img,
                        x=games.screen.width/2,
                        y=games.screen.height/2,
                        dx = random.randint(-10,10),
                        dy = random.randint(-10,10)
                        )
    #create catch obj
    hand = Hand(image = hand_img,
                  x=games.mouse.x,
                  y=580
                  )
    
    #create txt obj
    score = ScText(value=SCORE,
                   is_collideable = False,
                   size = 60,
                   color = color.red,
                   x = 550,
                   y = 30
                   )
    
    #draw objs to screen
    games.screen.add(boss)
    games.screen.add(fireball)
    games.screen.add(hand)
    games.screen.add(score)

    #sets visabilaty of mouse
    games.mouse.is_visible = False
    #locks mouse to screen
    games.screen.event_grab = False
 
    #start mainloop
    games.screen.mainloop()
Example #21
0
def main():
    wall_image = games.load_image(path_to_images + "wall.jpg",
                                  transparent=False)
    games.screen.background = wall_image

    pizza_image = games.load_image(path_to_images + "pizza.png")
    the_pizza = Pizza(image=pizza_image,
                      x=games.screen.width / 2,
                      y=games.screen.height / 2,
                      dx=1,
                      dy=1)
    games.screen.add(the_pizza)
    games.screen.mainloop()
Example #22
0
class Asteroid(Wrapper):

    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("assets/36x36.png"),
        MEDIUM: games.load_image("assets/51x51.png"),
        LARGE: games.load_image("assets/106x106.png")
    }

    SPEED = 2
    SPAWN = 2
    POINTS = 30

    total = 0

    def __init__(self, game, x, y, size):

        Asteroid.total += 1

        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)

        self.game = game
        self.size = size

    def die(self):

        Asteroid.total -= 1

        self.game.score.value += int(Asteroid.POINTS / self.size)
        self.game.score.right = games.screen.width - 10

        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(game=self.game,
                                        x=self.x,
                                        y=self.y,
                                        size=self.size - 1)
                games.screen.add(new_asteroid)

        if Asteroid.total == 0:
            self.game.advance()

        super(Asteroid, self).die()
Example #23
0
def main():
    #load images
    bg_img = games.load_image("images\castle.jpg", transparent=False)
    games.screen.background = bg_img
    target_img = games.load_image("images/target.jfif", transparent=True)
    arrow_img = games.load_image("images\Arrow.jfif", transparent=True)

    #set images
    arrow = Arrow(image=arrow_img,
                  x=games.screen.width / 2,
                  y=games.screen.height / 2,
                  dx=10,
                  dy=-10)
    arrow1 = Arrow(image=arrow_img,
                   x=games.screen.width / 2,
                   y=games.screen.height / 2,
                   dx=-15,
                   dy=15)
    arrow2 = Arrow(image=arrow_img,
                   x=games.screen.width / 2,
                   y=games.screen.height / 2,
                   dx=20,
                   dy=20)
    target = Target(image=target_img, x=games.mouse.x, y=450)

    score = ScText(value=SCORE,
                   is_collideable=False,
                   size=60,
                   color=color.black,
                   x=530,
                   y=30)

    #add images
    games.screen.add(score)
    games.screen.add(arrow)
    games.screen.add(arrow1)
    games.screen.add(arrow2)
    games.screen.add(target)

    games.screen.mainloop()

    # game_over = games.Message(value="Game Over",
    #                           size=100,
    #                           color=color.blue,
    #                           x=games.screen.width/2,
    #                           y=games.screen.height/2,
    #                           lifetime=250,
    #                           after_death=games.screen.quit)
    # games.screen.add(game_over)

    games.screen.mainloop()
class Asteroid(Wrapper):
    """Астероид, прямолинейно движущийся по экрану"""
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("asteroid_small.bmp"),
        MEDIUM: games.load_image("asteroid_med.bmp"),
        LARGE: games.load_image("asteroid_big.bmp")
    }
    SPEED = 2
    SPAWN = 2  # количество новых астероидов, на которые распадается один взорванный
    POINTS = 30
    total = 0

    def __init__(self, game, x, y, size):
        """Инициализирует спрайт с изображением астероида"""
        Asteroid.total += 1

        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)
        self.size = size
        self.game = game

    def die(self):
        """Разрушает астероид"""
        Asteroid.total -= 1

        self.game.score.value += int(Asteroid.POINTS / self.size)
        self.game.score.right = games.screen.width - 10

        # если размеры астероида крупные или средние, заменить его двумя более мелкими астероидами
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(game=self.game,
                                        x=self.x,
                                        y=self.y,
                                        size=self.size - 1)
                games.screen.add(new_asteroid)

        # если больше астероидов не осталось, переходим на следующий уровень
        if Asteroid.total == 0:
            self.game.advance()

        super(Asteroid, self).die()
Example #25
0
class Asteroid(Wrapper):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("asteroida_mala.bmp"),
        MEDIUM: games.load_image("asteroida_sred.bmp"),
        LARGE: games.load_image("asteroida_duza.bmp")
    }

    SPEED = 2
    SPAWN = 2
    POINTS = 30

    total = 0

    def __init__(self, game, x, y, size):
        Asteroid.total += 1

        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)

        self.game = game
        self.size = size

    def die(self):
        Asteroid.total -= 1

        self.game.score.value += int(Asteroid.POINTS / self.size)
        self.game.score.right = games.screen.width - 10

        # jeśli nie jest to mała asteroida, zastąp ją dwoma mniejszymi
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(game=self.game,
                                        x=self.x,
                                        y=self.y,
                                        size=self.size - 1)
                games.screen.add(new_asteroid)

        if Asteroid.total == 0:
            self.game.advance()

        super(Asteroid, self).die()
Example #26
0
class Asteroid(Wrapper):
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    image = {
        SMALL: games.load_image("img/meteorsmall.png"),
        MEDIUM: games.load_image("img/meteormedium.png"),
        LARGE: games.load_image("img/meteorlarge.png")
    }
    SPEED = 2

    SPAWN = 2

    POINTS = 30

    total = 0

    def __init__(self, game, x, y, size):
        Asteroid.total += 1

        super(Asteroid, self).__init__(image=Asteroid.image[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)
        self.size = size
        self.game = game

    def die(self):
        # if asteroid isn't small, replace with two smaller asteroids
        Asteroid.total -= 1
        # add to score
        self.game.score.value += int(Asteroid.POINTS / self.size)
        self.game.score.right = games.screen.width - 10

        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(game=self.game,
                                        x=self.x,
                                        y=self.y,
                                        size=self.size - 1)
                games.screen.add(new_asteroid)
        self.destroy()

        if Asteroid.total == 0:
            self.game.advance()
        super(Asteroid, self).die()
Example #27
0
def main():
    background_image = games.load_image("images/nowhere.png",
                                        transparent=False)
    icon_image = games.load_image("images/icon.png", transparent=False)
    squid_image = Squid()
    nothing_image = Nothing()
    square_image = Square(100)
    games.screen.background = background_image
    add = games.screen.add
    add(squid_image)
    add(nothing_image)
    add(square_image)
    pygame.display.set_caption("The Nowhere Dimension")
    pygame.display.set_icon(icon_image)
    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_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("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 = False
    games.screen.mainloop()
Example #29
0
class Asteroid(games.Sprite):
    """ An asteroid which floats across the screen. """
    SMALL = 1
    MEDIUM = 2
    LARGE = 3
    images = {
        SMALL: games.load_image("asteroid_small.bmp"),
        MEDIUM: games.load_image("asteroid_med.bmp"),
        LARGE: games.load_image("asteroid_big.bmp")
    }

    SPEED = 2
    SPAWN = 2

    def __init__(self, x, y, size):
        """Initialize asteroid sprite. """
        super(Asteroid, self).__init__(image=Asteroid.images[size],
                                       x=x,
                                       y=y,
                                       dx=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size,
                                       dy=random.choice([1, -1]) *
                                       Asteroid.SPEED * random.random() / size)

        self.size = size

    def update(self):
        """ Wrap around screen. """
        if self.top > games.screen.height:
            self.bottom = 0

        if self.bottom < 0:
            self.top = games.screen.height

        if self.left > games.screen.width:
            self.right = 0

        if self.right < 0:
            self.left = 0

    def die(self):
        """ Destroy asteroid. """
        # if asteroid isn't small, replace with two smaller
        if self.size != Asteroid.SMALL:
            for i in range(Asteroid.SPAWN):
                new_asteroid = Asteroid(x=self.x, y=self.y, size=self.size - 1)
                games.screen.add(new_asteroid)
        self.destroy()
Example #30
0
class Ship(games.Sprite):
    ship_image = games.load_image("images/ship.png")

    ROTATION_STEP = 6
    VELOCITY_STEP = .03

    def __init__(self):
        super(Ship, self).__init__(image=Ship.ship_image,
                                   x=games.screen.width / 2,
                                   y=games.screen.height / 2)

    def update(self):

        if games.keyboard.is_pressed(games.K_a) or games.keyboard.is_pressed(
                games.K_LEFT):
            self.angle -= 8
        if games.keyboard.is_pressed(games.K_d) or games.keyboard.is_pressed(
                games.K_RIGHT):
            self.angle += 8
        if games.keyboard.is_pressed(games.K_w) or games.keyboard.is_pressed(
                games.K_UP):
            Ship.sound.play()
            angle = self.angle * math.pi / 180
            self.dx += Ship.VELOCITY_STEP * math.sin(angle)
            self.dy += Ship.VELOCITY_STEP * -math.cos(angle)
Example #31
0
    def play(self):
        """ play """
        print(os.path.join(FILE_SERVING_ROOT, "mglawica.jpg"))
        nebula_image = games.load_image(os.path.join(FILE_SERVING_ROOT, "mglawica.jpg"))
        games.screen.background = nebula_image

        # level 1
        self.advance()

        # play
        games.screen.mainloop()