def __init__(self, window): self.window = window self.play = Animation("./assets/menu/play.png", 2) self.difficulty = Animation("./assets/menu/difc.png", 2) self.rank = Animation("./assets/menu/rank.png", 2) self.quit = Animation("./assets/menu/quit.png", 2) self.difficulty_indicator = Animation( "./assets/menu/difc_indicator.png", 3) self.difficulty_index = 0 self.mouse = Mouse() self.__set_pos() self.__draw()
def __init__(self, janela): self.janela = janela self.mouse = Mouse() self.teclado = janela.get_keyboard() self.titulo = Sprite("assets/dificuldade_titulo.png", 1) self.barra = Sprite("assets/dificuldade_barra.png", 1) self.seletor = Sprite("assets/dificuldade_seletor.png", 1) self.play = Sprite("assets/menu_play.png") self.playHover = Sprite("assets/menu_playhover.png") self.dificuldadePasso = 203 self.set_pos() self._draw()
def __init__(self, janela): self.janela = janela self.distancia = 40 self.play = Sprite("assets/menu_play.png") self.playHover = Sprite("assets/menu_playhover.png") self.dificuldade = Sprite("assets/menu_dificuldade.png") self.dificuldadeHover = Sprite("assets/menu_dificuldadehover.png") self.ranking = Sprite("assets/menu_ranking.png") self.rankingHover = Sprite("assets/menu_rankinghover.png") self.sair = Sprite("assets/menu_sair.png") self.sairHover = Sprite("assets/menu_sairhover.png") self.mouse = Mouse() self.set_pos() self._draw()
def setClique(self): self.mouse = Mouse() if (self.mouse.is_over_object(self.play)): if (self.mouse.is_button_pressed(1)): globais.PAGINA_ATUAL = 1 if (self.mouse.is_over_object(self.dificuldade)): if (self.mouse.is_button_pressed(1)): globais.PAGINA_ATUAL = 2 if (self.mouse.is_over_object(self.rank)): if (self.mouse.is_button_pressed(1)): print("RANK") if (self.mouse.is_over_object(self.quit)): if (self.mouse.is_button_pressed(1)): globais.JOGO_RODANDO = False
def setClique(self): self.mouse = Mouse() if (self.mouse.is_over_object(self.facil)): if (self.mouse.is_button_pressed(1)): globais.DIFICULDADE = 1 globais.PAGINA_ATUAL = 0 if (self.mouse.is_over_object(self.medio)): if (self.mouse.is_button_pressed(1)): globais.DIFICULDADE = 2 globais.PAGINA_ATUAL = 0 if (self.mouse.is_over_object(self.dificil)): if (self.mouse.is_button_pressed(1)): globais.DIFICULDADE = 3 globais.PAGINA_ATUAL = 0
class Dificuldade(object): def __init__(self, window): self.window = window def setDificuldade(self): self.setBotoes() self.setDraw() self.setClique() self.setReturn() def setBotoes(self): self.facil = Sprite("img/FACIL.png") self.facil.set_position((globais.WIDTH / 2) - (self.facil.width / 2), (3 * (globais.HEIGHT / 7))) self.medio = Sprite("img/MEDIO.png") self.medio.set_position((globais.WIDTH / 2) - (self.medio.width / 2), (4 * (globais.HEIGHT / 7))) self.dificil = Sprite("img/DIFICIL.png") self.dificil.set_position( (globais.WIDTH / 2) - (self.dificil.width / 2), (5 * (globais.HEIGHT / 7))) def setDraw(self): self.window.draw_text("Escolha a dificuldade:", (3 * globais.WIDTH / 9), (2 * (globais.HEIGHT / 7)), size=30, color=(255, 255, 255), font_name="Arial", bold=True, italic=False) self.facil.draw() self.medio.draw() self.dificil.draw() def setClique(self): self.mouse = Mouse() if (self.mouse.is_over_object(self.facil)): if (self.mouse.is_button_pressed(1)): globais.DIFICULDADE = 1 globais.PAGINA_ATUAL = 0 if (self.mouse.is_over_object(self.medio)): if (self.mouse.is_button_pressed(1)): globais.DIFICULDADE = 2 globais.PAGINA_ATUAL = 0 if (self.mouse.is_over_object(self.dificil)): if (self.mouse.is_button_pressed(1)): globais.DIFICULDADE = 3 globais.PAGINA_ATUAL = 0 def setReturn(self): self.teclado = Keyboard() if (self.teclado.key_pressed("ESC")): globais.PAGINA_ATUAL = 0 self.window.delay(100)
class Dificuldade(object): def __init__(self): self.window = Window(globais.WIDTH, globais.HEIGHT) self.mouse = Mouse() self.teclado = Keyboard() self.tela = Tela(window) def setDificuldade(self): self.facil = GameImage("img/easy1.png") self.medio = GameImage("img/medium1.png") self.dificil = GameImage("img/hard1.png") self.fundoDificuldade = GameImage("img/fundomenu_ninja.jpg") self.facil.x = self.window.width / 2 - self.facil.width / 2 self.facil.y = self.window.height / 4 - self.facil.height / 2 self.medio.x = self.facil.x self.medio.y = self.facil.y + self.facil.height self.dificil.x = self.facil.x self.dificil.y = self.medio.y + self.medio.height def getDificuldade(self): if self.mouse.is_over_object( self.facil) and self.mouse.is_button_pressed(1): globais.DIFICULDADE = 0 globais.VEL_INIMIGO_H = -100 if self.mouse.is_over_object( self.medio) and self.mouse.is_button_pressed(1): globais.DIFICULDADE = 1 globais.VEL_INIMIGO_H = -200 if self.mouse.is_over_object( self.dificil) and self.mouse.is_button_pressed(1): globais.DIFICULDADE = 2 globais.VEL_INIMIGO_H = -300 def draw(self): self.fundoDificuldade.draw() self.facil.draw() self.medio.draw() self.dificil.draw() def setReturn(self): if (self.teclado.key_pressed("ESC") or self.mouse.is_button_pressed(1) == True): globais.GAME_STATE = 0 self.window.delay(10)
class Menu(object): def __init__(self, janela): self.janela = janela self.distancia = 40 self.play = Sprite("assets/menu_play.png") self.playHover = Sprite("assets/menu_playhover.png") self.dificuldade = Sprite("assets/menu_dificuldade.png") self.dificuldadeHover = Sprite("assets/menu_dificuldadehover.png") self.ranking = Sprite("assets/menu_ranking.png") self.rankingHover = Sprite("assets/menu_rankinghover.png") self.sair = Sprite("assets/menu_sair.png") self.sairHover = Sprite("assets/menu_sairhover.png") self.mouse = Mouse() self.set_pos() self._draw() def set_pos(self): self.play.set_position(self.janela.width / 2 - self.play.width / 2, self.distancia) self.playHover.set_position( self.janela.width / 2 - self.play.width / 2, self.distancia) self.dificuldade.set_position( self.janela.width / 2 - self.dificuldade.width / 2, 2 * self.distancia + self.play.height) self.dificuldadeHover.set_position( self.janela.width / 2 - self.dificuldade.width / 2, 2 * self.distancia + self.play.height) self.ranking.set_position( self.janela.width / 2 - self.ranking.width / 2, 3 * self.distancia + self.ranking.height + self.play.height) self.rankingHover.set_position( self.janela.width / 2 - self.ranking.width / 2, 3 * self.distancia + self.ranking.height + self.play.height) self.sair.set_position( self.janela.width / 2 - self.sair.width / 2, 4 * self.distancia + self.ranking.height + self.play.height + self.ranking.height) self.sairHover.set_position( self.janela.width / 2 - self.sair.width / 2, 4 * self.distancia + self.ranking.height + self.play.height + self.ranking.height) def _draw(self): self.play.draw() self.dificuldade.draw() self.ranking.draw() self.sair.draw() def run(self): self._draw() self.set_pos() if (self.mouse.is_over_object(self.play)): self.playHover.draw() if (self.mouse.is_button_pressed(1)): globals.GAME_STATE = 2 if (self.mouse.is_over_object(self.dificuldade)): self.dificuldadeHover.draw() if (self.mouse.is_button_pressed(1)): globals.GAME_STATE = 3 if (self.mouse.is_over_object(self.ranking)): self.rankingHover.draw() if (self.mouse.is_button_pressed(1)): globals.GAME_STATE = 4 if (self.mouse.is_over_object(self.sair)): self.sairHover.draw() if (self.mouse.is_button_pressed(1)): globals.GAME_STATE = 5
def __init__(self): self.window = Window(globais.WIDTH, globais.HEIGHT) self.mouse = Mouse() self.teclado = Keyboard() self.tela = Tela(window)
class Menu(object): def __init__(self, window): self.window = window #Aqui vamos declarar que a variavel window criada no main.py será enviada ao menu.py, de modo que ela seja igual a janela criada def setMenu(self): #'Nesta parte irá rodar a página menu, teremos outras defs para criar e desenhar os Sprites, mas é nesta def que vamos colocar o que realmente deve rodar no programa' self.setBotoes() self.setDraw() self.setClique() self.setReturn() def setBotoes(self): #'Nesta parte vamos criar todos os sprites e definir suas posições na janela' self.play = Sprite("img/PLAY.png") self.play.set_position(((2 * globais.WIDTH / 5) - self.play.width), ((globais.HEIGHT / 2) - self.play.height)) self.dificuldade = Sprite("img/DIFICULDADE.png") self.dificuldade.set_position( ((4 * globais.WIDTH / 5) - self.play.width), ((globais.HEIGHT / 2) - self.play.height)) self.rank = Sprite("img/RANK.png") self.rank.set_position(((2 * globais.WIDTH / 5) - self.rank.width), ((globais.HEIGHT / 2) + self.rank.height)) self.quit = Sprite("img/QUIT.png") self.quit.set_position(((4 * globais.WIDTH / 5) - self.quit.width), ((globais.HEIGHT / 2) + self.quit.height)) def setDraw(self): #'Nesta parte vamos desenhar todos os sprites que criamos no setBotoes(), mas antes temos que chamar o setBotoes dentro do setDraw para que ele crie as Sprites' self.window.draw_text("Space Invaders", globais.WIDTH / 4, globais.HEIGHT / 4, size=60, color=(255, 255, 255), font_name="Arial", bold=True, italic=False) self.play.draw() self.dificuldade.draw() self.rank.draw() self.quit.draw() def setClique(self): self.mouse = Mouse() if (self.mouse.is_over_object(self.play)): if (self.mouse.is_button_pressed(1)): globais.PAGINA_ATUAL = 1 if (self.mouse.is_over_object(self.dificuldade)): if (self.mouse.is_button_pressed(1)): globais.PAGINA_ATUAL = 2 if (self.mouse.is_over_object(self.rank)): if (self.mouse.is_button_pressed(1)): print("RANK") if (self.mouse.is_over_object(self.quit)): if (self.mouse.is_button_pressed(1)): globais.JOGO_RODANDO = False def setReturn(self): self.teclado = Keyboard() if (self.teclado.key_pressed("ESC")): globais.JOGO_RODANDO = False
class Menu(object): def __init__(self, window): self.window = window self.play = Animation("./assets/menu/play.png", 2) self.difficulty = Animation("./assets/menu/difc.png", 2) self.rank = Animation("./assets/menu/rank.png", 2) self.quit = Animation("./assets/menu/quit.png", 2) self.difficulty_indicator = Animation( "./assets/menu/difc_indicator.png", 3) self.difficulty_index = 0 self.mouse = Mouse() self.__set_pos() self.__draw() def run(self): if self.mouse.is_over_object(self.play): self.play.set_curr_frame(1) if self.mouse.is_button_pressed(1): globals.GAME_STATE = 1 elif self.mouse.is_over_object(self.difficulty): self.difficulty.set_curr_frame(1) if self.mouse.is_button_pressed(1): self.difficulty_index = (self.difficulty_index + 1) % 3 if self.difficulty_index == 0: globals.DIFFICULTY["easy"][0] = True globals.DIFFICULTY["medium"][0] = False globals.DIFFICULTY["hard"][0] = False elif self.difficulty_index == 1: globals.DIFFICULTY["easy"][0] = False globals.DIFFICULTY["medium"][0] = True globals.DIFFICULTY["hard"][0] = False elif self.difficulty_index == 2: globals.DIFFICULTY["easy"][0] = False globals.DIFFICULTY["medium"][0] = False globals.DIFFICULTY["hard"][0] = True globals.PLAY_INIT = True self.window.delay(150) self.difficulty_indicator.set_curr_frame(self.difficulty_index) elif self.mouse.is_over_object(self.rank): self.rank.set_curr_frame(1) if self.mouse.is_button_pressed(1): globals.GAME_STATE = 2 elif self.mouse.is_over_object(self.quit): self.quit.set_curr_frame(1) if self.mouse.is_button_pressed(1): globals.GAME_RUNNING = False else: self.play.set_curr_frame(0) self.difficulty.set_curr_frame(0) self.rank.set_curr_frame(0) self.quit.set_curr_frame(0) self.__draw() def __draw(self): self.play.draw() self.difficulty.draw() self.rank.draw() self.quit.draw() self.difficulty_indicator.draw() def __set_pos(self): self.play.set_position(self.window.width / 2 - self.play.width / 2, self.play.height * 1 + 30 * 1) self.difficulty.set_position( self.window.width / 2 - self.difficulty.width / 2, self.difficulty.height * 2 + 30 * 2, ) self.rank.set_position(self.window.width / 2 - self.rank.width / 2, self.rank.height * 3 + 30 * 3) self.quit.set_position(self.window.width / 2 - self.quit.width / 2, self.quit.height * 4 + 30 * 4) self.difficulty_indicator.set_position( 50, self.window.height - self.difficulty_indicator.height - 50)
class Dificuldade(object): def __init__(self, janela): self.janela = janela self.mouse = Mouse() self.teclado = janela.get_keyboard() self.titulo = Sprite("assets/dificuldade_titulo.png", 1) self.barra = Sprite("assets/dificuldade_barra.png", 1) self.seletor = Sprite("assets/dificuldade_seletor.png", 1) self.play = Sprite("assets/menu_play.png") self.playHover = Sprite("assets/menu_playhover.png") self.dificuldadePasso = 203 self.set_pos() self._draw() def set_pos(self): self.titulo.set_position(self.janela.width/2 - self.titulo.width/2, 25) self.barra.set_position(self.janela.width/2 - self.barra.width/2, self.janela.height/2 - self.barra.height/2) self.seletor.set_position(self.janela.width/2 - self.seletor.width/2, 7 + self.janela.height/2 - self.seletor.height/2) self.play.set_position(self.janela.width/2 - self.play.width/2, self.janela.height/2 + 100) self.playHover.set_position(self.janela.width/2 - self.play.width/2, self.janela.height/2 + 100) def _draw(self): self.titulo.draw() self.barra.draw() self.seletor.draw() self.play.draw() def checarDificuldade(self): if(self.seletor.x == self.janela.width/2 - self.seletor.width/2): dificuldade = 2 elif(self.seletor.x == self.janela.width/2 - self.seletor.width/2 - self.dificuldadePasso): dificuldade = 1 elif(self.seletor.x == self.janela.width/2 - self.seletor.width/2 + self.dificuldadePasso): dificuldade = 3 return dificuldade def run(self): self.janela.set_background_color((0, 0, 0)) self._draw() globals.DIFICULDADE = self.checarDificuldade() if(self.teclado.key_pressed("ESC")): globals.GAME_STATE = 1 if(globals.DIFICULDADE == 2): if(self.teclado.key_pressed("LEFT")): self.seletor.x -= self.dificuldadePasso self.janela.delay(200) if(self.teclado.key_pressed("RIGHT")): self.seletor.x += self.dificuldadePasso self.janela.delay(200) if(globals.DIFICULDADE == 1): if(self.teclado.key_pressed("RIGHT")): self.seletor.x += self.dificuldadePasso self.janela.delay(200) if(globals.DIFICULDADE == 3): if(self.teclado.key_pressed("LEFT")): self.seletor.x -= self.dificuldadePasso self.janela.delay(200) if(self.mouse.is_over_object(self.play)): self.playHover.draw() if(self.mouse.is_button_pressed(1)): globals.GAME_STATE = 2