예제 #1
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()
예제 #2
0
def start_game():
    global SERVER_ADDRESS
    SERVER_ADDRESS = ip_enter.get()

    root.destroy()
    games.init(1600 * SCALE_RATIO, 800 * SCALE_RATIO, 50)

    menu = Menu()
예제 #3
0
def main():
    games.init(1600 * SCALE_RATIO, 850 * SCALE_RATIO, 50, True)
    games.screen.background = load_scaled_image(resource_path('res/bg.png'),
                                                transparent=False)
    #games.music.load(resource_path('res/music.mid'))
    #games.music.play(-1)
    games.screen.add(Player(1))
    games.screen.add(Player2(2))
    games.screen.mainloop()
예제 #4
0
파일: main.py 프로젝트: ProxyPylon/Arbuuuz
def main():
    games.init(screen_width=708, screen_height=800, fps=60)

    wall_image = games.load_image("aska2.jpg", transparent=False)
    games.screen.background = wall_image

    arbuz_img = games.load_image("арбуз_120_recoloRED.png", transparent=True)
    ar_1 = games.Sprite(image=arbuz_img, x=160, y=200, dx=4)

    #txt = games.Text(value="123qweasd", size= 80, color=(255, 30, 40), x=350, y=30)
    txt = New_Text(value="123qweasd",
                   size=80,
                   color=(255, 30, 40),
                   x=350,
                   y=30)

    ar_2 = Water_Melon_rand_jump(image=arbuz_img, x=160, y=500, dx=5, dy=3)

    games.screen.add(ar_1)
    games.screen.add(ar_2)
    games.screen.add(txt)

    games.screen.mainloop()
예제 #5
0
from superwires import games, color
import math

games.init(screen_width=800, screen_height=600, fps=60)


class Blue(games.Sprite):
    image = games.load_image("blue_tank.png")
    NEXT_SHOT = 50

    def __init__(self):
        super(Blue, self).__init__(image=Blue.image,
                                   x=40,
                                   y=games.screen.height / 2)

        self.missile_wait = 0

        self.score = games.Text(value=5,
                                size=50,
                                color=color.blue,
                                x=40,
                                y=40,
                                is_collideable=False)

        games.screen.add(self.score)

    def update(self):
        if games.keyboard.is_pressed(games.K_d):
            self.angle += 1
        if games.keyboard.is_pressed(games.K_a):
            self.angle -= 1
예제 #6
0
from superwires import games

games.init(screen_width=250, screen_height=250, fps=50)
games.screen.mainloop()
예제 #7
0
# Slippery Pizza Program
# Demonstrates testing for sprite collisions

from superwires import games
import random

games.init(screen_width=640, screen_height=480, fps=50)


class Pan(games.Sprite):
    """" A pan controlled by the mouse. """
    def update(self):
        """ Move to mouse position. """
        self.x = games.mouse.x
        self.y = games.mouse.y
        self.check_collide()

    def check_collide(self):
        """ Check for collision with pizza. """
        for pizza in self.overlapping_sprites:
            pizza.handle_collide()


class Pizza(games.Sprite):
    """" A slippery pizza. """
    def handle_collide(self):
        """ Move to a random screen location. """
        self.x = random.randrange(games.screen.width)
        self.y = random.randrange(games.screen.height)

예제 #8
0
#Read Key inputs
#Demonstrates reading the keyboard

from superwires import games

games.init(screen_width=900, screen_height=720, fps=50)


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
예제 #9
0
파일: astro.py 프로젝트: MtzwOsk/astro
# Astro GAME

import pygame
import random
import sys
import os

# from livewires import games, color
from superwires import games, color


games.init(screen_width=640, screen_height=480, fps=50)


PROJECT_ROOT_INDIRECT = os.path.join(os.path.dirname(os.path.realpath(__file__)), './')
PROJECT_ROOT = os.path.realpath(PROJECT_ROOT_INDIRECT)
FILE_SERVING_ROOT = os.path.join(PROJECT_ROOT, 'feat')
print(FILE_SERVING_ROOT)


class Explosion(games.Animation):
    """ Explosion animation """
    sound = games.load_sound(os.path.join(FILE_SERVING_ROOT, 'eksplozja.wav'))
    images = [
        os.path.join(FILE_SERVING_ROOT, "eksplozja1.bmp"),
        os.path.join(FILE_SERVING_ROOT, "eksplozja2.bmp"),
        os.path.join(FILE_SERVING_ROOT, "eksplozja3.bmp"),
        os.path.join(FILE_SERVING_ROOT, "eksplozja4.bmp"),
        os.path.join(FILE_SERVING_ROOT, "eksplozja5.bmp"),
        os.path.join(FILE_SERVING_ROOT, "eksplozja6.bmp"),
        os.path.join(FILE_SERVING_ROOT, "eksplozja7.bmp"),
예제 #10
0
from superwires import games, color
import random
import time

games.init(screen_width=1280, screen_height=850, fps=75)


class Player(games.Sprite):
    """Postać gracza"""
    image = games.load_image("owca.png")

    def __init__(self):
        """Inicjalizacja obiektu gracza"""
        super(Player, self).__init__(image=Player.image,
                                     x=games.mouse.x,
                                     bottom=games.screen.height)
        self.score = games.Text(value=0,
                                size=50,
                                color=color.black,
                                top=5,
                                right=games.screen.width - 10)
        games.screen.add(self.score)

    def update(self):
        """Zmiana pozycji przez mysz"""
        self.x = games.mouse.x

        if self.left < 0:
            self.left = 0
        if self.right > games.screen.width:
            self.right = games.screen.width
예제 #11
0
from superwires import games, color
import random

SCORE = 0

games.init(screen_width=1152, screen_height=648, fps=60)

class Boss(games.Sprite):
    """ A game boss. """
    def update(self):
        if self.right > games.screen.width or self.left < 0:
            self.dx = -self.dx
    def handle_collide(self):
        pass

class Hand(games.Sprite):
    """ A pan controlled by the mouse. """
    def update(self):
        """ Move to mouse cordinates. """
        self.x = games.mouse.x
        #self.y = games.mouse.y
        self.check_collide()
    def check_collide(self):
        """ Check for collision with fireball. """
        for fireball in self.overlapping_sprites:
            fireball.handle_collide()

class Fireball(games.Sprite):

    def update(self):
        global SCORE
    plt.plot(epoch_list, error_list)
    plt.title("Error vs No of epochs")
    plt.xlabel("No of Epochs")
    plt.ylabel("Error")
    plt.show()

    print("Completed")
    print("-------------------------------")
    print("\n")

    da.reconstruct(data)


if __name__ == "__main__":
    games.init(screen_width=1000, screen_height=800, fps=50)
    back_image = games.load_image("white_back.jpg", transparent=False)
    games.screen.background = back_image
    auto_image = games.load_image("auto_arch.jpg")
    the_auto = games.Sprite(image=auto_image,
                            x=games.screen.width / 2,
                            y=games.screen.height / 2)
    games.screen.add(the_auto)
    name = games.Text(value="Autoencoders Architecture",
                      size=40,
                      color=color.black,
                      x=games.screen.width / 2 - 40,
                      y=60)
    games.screen.add(name)
    games.screen.mainloop()
예제 #13
0
def the_game():
    """ Whole code closed in a function to make it possible for calling it from other app. """

    import random, pygame, os
    from superwires import games, color

    #Initializes screen
    games.init(screen_width=600, screen_height=700, fps=100)
    pygame.display.set_caption("SPACE JOURNEY")

    class Collider(games.Sprite):
        def update(self):
            """ 
			Checks for collisions.
			overlapping_sprites is a games. Spirit method that detects if on sprite is on top of another.
			This method works fine but it returns True even when sprites backgrounds overlap.
			To overcome this problem and detect accurate collisions, I'm checking for those sprites if offset value is True.
			If result is True, one life is taken away.
			"""
            if self.overlapping_sprites:
                for sprite in self.overlapping_sprites:
                    offset_x = sprite.get_x() - self.get_x()
                    offset_y = sprite.get_y() - self.get_y()
                    offset = (int(offset_x), int(offset_y))
                    result = self.mask.overlap(sprite.mask, offset)
                    if result:
                        sprite.die()
                        new_bang = Bang(x=sprite.x, y=sprite.y)
                        games.screen.add(new_bang)
                        self.lives -= 1
                        if self.lives <= 0:
                            self.die()

        def die(self):
            """ Delete sprite from screen """
            self.destroy()

    class Background(games.Sprite):
        """
		There is an games. Screen attribute, but it can only be set in place, so I've used non collidable sprite as background.
		It is made of two identical images that are displayed on top of each other and are continuously scrolling down.
		"""
        background_image = games.load_image(os.path.join(
            'images', 'background_image.png'),
                                            transparent=False)
        background_velocity = 2

        def __init__(self, x, y):
            super(Background, self).__init__(image=Background.background_image,
                                             is_collideable=False)
            # x and y coordinates
            self.x = x
            self.y = y

        def update(self):
            """ Checks if one of images is over bottom edge of the screen then places it over top edge of the screen. """

            # value specifying how fast should it scroll down
            self.y += Background.background_velocity

            if self.y == games.screen.height / 2 + games.screen.height:
                self.y = games.screen.height / 2 - games.screen.height

    class Ship(Collider):
        """
		Inherits form Collider class.
		"""
        ship_image = games.load_image(os.path.join('images', 'ship_image.png'))
        ship_velocity = 3

        def __init__(self, game, x, y):
            super(Ship, self).__init__(image=Ship.ship_image)
            self.game = game

            # x and y coordinates
            self.x = x
            self.y = y

            # mask for accurate collision detection
            self.mask = pygame.mask.from_surface(self.image)

            # value specifying times ship can collide
            self.lives = 5

        def update(self):
            """
			In order not to overwrite Collider method, super is used.
			Ship sprite that can be moved around the screen with W, S, A, D keys.
			"""
            super(Ship, self).update()
            if games.keyboard.is_pressed(games.K_a) and self.get_left() > 0:
                self.x -= Ship.ship_velocity
            if games.keyboard.is_pressed(
                    games.K_d) and self.get_right() < games.screen.width:
                self.x += Ship.ship_velocity
            if games.keyboard.is_pressed(games.K_w) and self.get_top() > 0:
                self.y -= Ship.ship_velocity
            if games.keyboard.is_pressed(
                    games.K_s) and self.get_bottom() < games.screen.height:
                self.y += Ship.ship_velocity

            # update lives label
            self.game.lives_label.set_value("Lives: " + str(self.lives))

        def die(self):
            """ Destroy the ship and finish the game. """
            global final_score
            final_score = self.game.score
            self.game.end()
            super(Ship, self).die()

    class Asteroid(games.Sprite):
        """
		Asteroid sprite that is created before entering screen with random x and y coordinates.
		"""
        asteroid_image = games.load_image(
            os.path.join('images', 'asteroid_image.png'))
        asteroid_velocity = 2
        #constant holding amount of asteroids in one level
        span = 0

        def __init__(self, game):
            super(Asteroid, self).__init__(image=Asteroid.asteroid_image)
            self.game = game

            # x and y coordinates
            self.x = random.randint(0, games.screen.width)
            if self.game.level <= 10:
                self.y = random.randint(-games.screen.height * self.game.level,
                                        -100)
            else:
                self.y = random.randint(-games.screen.height * 10, -100)

            # mask for accurate collision detection
            self.mask = pygame.mask.from_surface(self.image)

        def update(self):
            """	After leaving screen it is destroyed."""
            self.y += Asteroid.asteroid_velocity
            if self.get_top() > games.screen.height:
                Asteroid.span -= 1
                self.destroy()
                # add points but only if player has lives and update score label
                if self.game.the_ship.lives:
                    self.game.score += 5 * self.game.level
                    self.game.score_label.set_value("Score: " +
                                                    str(self.game.score))
                    self.game.score_label.right = games.screen.width - 10

            # when there is no asteroids at the level generate new wave
            if Asteroid.span == 0:
                self.game.wave()

        def die(self):
            """ Delete sprite from screen. """
            Asteroid.span -= 1
            self.destroy()

    class Bang(games.Sprite):
        """ Is used for displaying bang_image after collision. """
        bang_image = games.load_image(os.path.join('images', 'bang.png'))

        def __init__(self, x, y):
            super(Bang, self).__init__(image=Bang.bang_image,
                                       x=x,
                                       y=y,
                                       is_collideable=False)

            # value specifying lifespan of this sprite
            self.counter = 3

        def tick(self):
            """
			Similar to update method but it is called every interval frames.
			Counts down before destroying sprite.
			"""
            self.counter -= 1
            if not self.counter:
                self.destroy()

    class Game():
        """ Game itself with its methods. """
        def __init__(self):
            # create level variable
            self.level = 1
            # create score variable
            self.score = 0

            # create visible score label in upper right corner
            self.score_label = games.Text(value="Score: 0",
                                          size=40,
                                          color=color.white,
                                          top=5,
                                          right=games.screen.width - 10,
                                          is_collideable=False)
            games.screen.add(self.score_label)

            # create visible level label in upper middle section
            self.level_label = games.Text(value="Level 1",
                                          size=40,
                                          color=color.white,
                                          x=games.screen.width / 2,
                                          y=20,
                                          is_collideable=False)
            games.screen.add(self.level_label)

            # add ship to the screen and place it in the middle
            self.the_ship = Ship(game=self,
                                 x=games.screen.width / 2,
                                 y=games.screen.height - 200)
            games.screen.add(self.the_ship)

            # create visible lives label in upper left corner
            self.lives_label = games.Text(value=self.the_ship.lives,
                                          size=40,
                                          color=color.white,
                                          x=55,
                                          y=20,
                                          is_collideable=False)
            games.screen.add(self.lives_label)

        def play(self):
            """ Starts the game. """
            self.wave()
            games.screen.mainloop()

        def wave(self):
            """ Creates amount of asteroids appropriate for each level. """
            if self.level <= 10:
                for i in range(self.level * 5):
                    Asteroid.span += 1
            else:
                Asteroid.span = 60

            for i in range(Asteroid.span):  #

                the_asteroid = Asteroid(game=self)
                games.screen.add(the_asteroid)

            # update level label
            self.level_label.set_value("Level " + str(self.level))

            self.level += 1

            # increase velocity of ship and asteroids
            Ship.ship_velocity += 0.2
            Asteroid.asteroid_velocity += 0.4

        def end(self):
            """ Ending message printed when out of lives. """
            end_message = games.Message(value="Game Over",
                                        size=90,
                                        color=color.red,
                                        x=games.screen.width / 2,
                                        y=games.screen.height / 2,
                                        lifetime=3 * games.screen.fps,
                                        after_death=games.screen.quit,
                                        is_collideable=False)

            # add another message, because it is impossible to use \n messages
            score_message = games.Message(value="Your score: " +
                                          str(final_score),
                                          size=90,
                                          color=color.red,
                                          x=games.screen.width / 2,
                                          y=games.screen.height / 1.7,
                                          lifetime=3 * games.screen.fps,
                                          after_death=games.screen.quit,
                                          is_collideable=False)
            games.screen.add(end_message)
            games.screen.add(score_message)

    def add_background():
        """ It concretizes and displays two same background images to the screen. """
        the_background = Background(x=games.screen.width / 2,
                                    y=games.screen.height / 2)
        the_background2 = Background(x=games.screen.width / 2,
                                     y=games.screen.height / 2 -
                                     games.screen.height)
        games.screen.add(the_background)
        games.screen.add(the_background2)

    def main():

        add_background()

        space_journey = Game()

        space_journey.play()

    main()
예제 #14
0
def relay(p1, p2):
    games.init(1600 * SCALE_RATIO, 900 * SCALE_RATIO, 50, True)
    game = Game(p1, p2)
예제 #15
0
from superwires import games, color

games.init(screen_width=1305, screen_height=629, fps=50)


class Ball(games.Sprite):
    time = 100
    tt = 0
    image = games.load_image("ball.png")

    def __init__(self):
        super(Ball, self).__init__(image=self.image, x=650, y=325,
                                   dx=4.5, dy=4.5)
        if Ball.time == 100:
            self.show_time = games.Text(value=Ball.time, size=40,
                                        color=color.red, x=652.5, y=35)
            games.screen.add(self.show_time)

    def update(self):
        if self.bottom > games.screen.height or self.top < 62:
            self.dy = -self.dy
        if self.right > games.screen.width:
            p1.score.value += 10
            p1.score.x -= 1
            self.x = 650
            self.y = 325
        if self.left < 0:
            p2.score.value += 10
            p2.score.x -= 1
            self.x = 650
            self.y = 325
예제 #16
0
# Hayden Whitney
# 5/19
# Minecraft Defenders v1.3.5

from superwires import games
import random
import math

games.init(screen_width=960, screen_height=720, fps=60)


class Wrapper(games.Sprite):
    def update(self):
        if self.top > games.screen.height:
            self.bottom = 0
        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

    def die(self):
        self.destroy()


class Collider(Wrapper):
    def update(self):
        super(Collider, self).update()
        if self.overlapping_sprites:
            for sprite in self.overlapping_sprites:
예제 #17
0
# asteroids 1.0
# nathan Broadbent

# imports
from superwires import games as game
import random

# global variables
game.init(screen_width=640, screen_height=480, fps=60)

# classes


class Asteroid(game.Sprite):
    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

    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]) *
예제 #18
0
"""This module contains classes and functions that are used in star battle game"""

# import
import math
import random
from superwires import games


# initialize game screen
games.init(screen_width=1024, screen_height=768, fps=50)


class Wrapper(games.Sprite):
    """ A model of a sprite that wraps around game screen"""

    def update(self):
        """Wraps sprite around game 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 = games.screen.width

    def die(self):
        """Destroys sprite"""
        self.destroy()

예제 #19
0
# asteroids 1.3
# nathan Broadbent

# imports
from superwires import games as game
import random
import math

# global variables
game.init(screen_width=1000, screen_height=750, fps=60)
SCORE = 0
LIVES = 3

# classes


class Wrapper(game.Sprite):
    def update(self):
        if self.left > game.screen.width:
            self.right = 0
        if self.right < 0:
            self.left = game.screen.width
        if self.top > game.screen.height:
            self.bottom = 0
        if self.bottom < 0:
            self.top = game.screen.height

    def die(self):
        self.destroy()

예제 #20
0
from random import randint

from superwires import games

games.init(screen_width=600, screen_height=377, fps=50)

wall_image = games.load_image('background_1.jpg', transparent=False)
games.screen.background = wall_image
bin_image = games.load_image('bin_1.png')


class BinSprite(games.Sprite):
    def __init__(self, x, type_name):
        self.type_name = type_name
        super(BinSprite, self).__init__(image=bin_image, x=x, y=300)

    def handle_click(self):
        if len(builder.visible_waste) > 0:
            lowest_waste = builder.visible_waste[0]
            if lowest_waste.type_name == self.type_name:
                builder.visible_waste.remove(lowest_waste)
                games.screen.remove(lowest_waste)

    def update(self):
        overlapping_sprites = self.get_overlapping_sprites()

        for sprite in overlapping_sprites:
            if sprite.type_name != self.type_name:
                games.screen.quite()

#astroids
#Jared M.

#imports

from superwires import games
import random, math

#Global info

games.init(screen_width=1280, screen_height=1000, fps=60)

#Classes


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]) *
# Carl Olson   Python
# CSCI-1511
# Project 1:    Playful kitten sprite
#
# A kitten can move about an alleyway


from superwires import games, color
import math
import os
import random
from pygame import *

games.init(screen_width=1200, screen_height=600, fps=50)


def load_images(path):
    """
    Loads all images in directory. The directory must only contain images.

    Args:
        path: The relative or absolute path to the directory to load images from.

    Returns:
        List of images.
    """
    images = []
    for file_name in os.listdir(path):
        each_image = games.load_image(path + os.sep + file_name).convert()
        images.append(each_image)
    return images