Exemplo n.º 1
0
class Spaceship(object):
    def __init__(self, window):
        self.window = window
        self.spaceship = Sprite("./assets/images/spaceship.png")
        self.velocity = 0
        self.__set_pos()

    def run(self):
        self.__draw()
        self.move(self.velocity)

    def move(self, velocity):
        if keyboard.key_pressed("left"):
            self.velocity = -GVar.SPACESHIP_VELOCITY
        elif keyboard.key_pressed("right"):
            self.velocity = GVar.SPACESHIP_VELOCITY
        else:
            self.velocity = 0

        if self.spaceship.x >= (GVar.WIDTH - self.spaceship.width):
            self.spaceship.set_position(GVar.WIDTH - self.spaceship.width - 1, GVar.HEIGHT - self.spaceship.height - 10)

        if self.spaceship.x <= 0:
            self.spaceship.set_position(0.5, GVar.HEIGHT - self.spaceship.height - 10)
        
        self.spaceship.x += velocity * self.window.delta_time()

    def __draw(self):
        self.spaceship.draw()
    
    def __set_pos(self):
        self.spaceship.set_position(GVar.WIDTH/2 - self.spaceship.width/2, GVar.HEIGHT - self.spaceship.height - 10)
Exemplo n.º 2
0
class Menu(object):
    def __init__(self, window):
        self.window = window
        self.play = Sprite("./assets/images/play.png")
        self.difc = Sprite("./assets/images/difc.png")
        self.rank = Sprite("./assets/images/rank.png")
        self.quit = Sprite("./assets/images/quit.png")
        self.mouse = Mouse()
        self.__set_pos()
        self.__draw()

    def run(self):
        if self.mouse.is_over_object(
                self.play) and self.mouse.is_button_pressed(1):
            GVar.STATE = 1

        if self.mouse.is_over_object(
                self.difc) and self.mouse.is_button_pressed(1):
            GVar.STATE = 2

        if self.mouse.is_over_object(
                self.rank) and self.mouse.is_button_pressed(1):
            GVar.STATE = 3

        if self.mouse.is_over_object(
                self.quit) and self.mouse.is_button_pressed(1):
            GVar.STATE = 4

        self.__draw()

    def __draw(self):
        self.play.draw()
        self.difc.draw()
        self.rank.draw()
        self.quit.draw()

    def __set_pos(self):
        button_distance = (GVar.HEIGHT - 4 * self.play.height) / 5
        self.play.set_position(GVar.WIDTH / 2 - self.play.width / 2,
                               button_distance)
        self.difc.set_position(GVar.WIDTH / 2 - self.play.width / 2,
                               2 * button_distance + self.play.height)
        self.rank.set_position(GVar.WIDTH / 2 - self.play.width / 2,
                               3 * button_distance + 2 * self.play.height)
        self.quit.set_position(GVar.WIDTH / 2 - self.play.width / 2,
                               4 * button_distance + 3 * self.play.height)
Exemplo n.º 3
0
class Difficulty(object):
    def __init__(self, window):
        self.window = window
        self.easy_button = Sprite("./assets/images/easy.png")
        self.norm_button = Sprite("./assets/images/norm.png")
        self.hard_button = Sprite("./assets/images/hard.png")
        self.__set_pos()

    def run(self):
        self.__draw()
        self.set_difficulty()


    def set_difficulty(self):
        if mouse.is_over_object(self.easy_button) and mouse.is_button_pressed(1):
            GVar.DIFC = 1 * GVar.DIFC_MULTIPLIER
            GVar.DIFC_CHOSEN = True
            GVar.STATE = 1
        if mouse.is_over_object(self.norm_button) and mouse.is_button_pressed(1):
            GVar.DIFC = 2 * GVar.DIFC_MULTIPLIER
            GVar.DIFC_CHOSEN = True
            GVar.STATE = 1
        if mouse.is_over_object(self.hard_button) and mouse.is_button_pressed(1):
            GVar.DIFC = 3 * GVar.DIFC_MULTIPLIER
            GVar.DIFC_CHOSEN = True
            GVar.STATE = 1

    def __draw(self):
        self.easy_button.draw()
        self.norm_button.draw()
        self.hard_button.draw()
    
    def __set_pos(self):
        button_distance = (GVar.HEIGHT - 3 * self.easy_button.height)/4
        self.easy_button.set_position(GVar.WIDTH/2 - self.easy_button.width/2, button_distance)
        self.norm_button.set_position(GVar.WIDTH/2 - self.easy_button.width/2, self.easy_button.height + 2 * button_distance)
        self.hard_button.set_position(GVar.WIDTH/2 - self.easy_button.width/2, 2 * self.easy_button.height + 3 * button_distance)