Merge branch 'an_branch' of https://bdgit.educoder.net/pahiq8bnc/Jungle into an_branch
commit
79a7312cc3
@ -0,0 +1,86 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
display_width = 1200
|
||||||
|
display_height = 800
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
RED = (255, 0, 0)
|
||||||
|
|
||||||
|
screen = pygame.display.set_mode((display_width,display_height))
|
||||||
|
bg = pygame.image.load('./images/map.png')
|
||||||
|
#begin = pygame.image.load('./images/begin.png')
|
||||||
|
bg = pygame.transform.scale(bg, (display_width,display_height))
|
||||||
|
pygame.init()
|
||||||
|
font_addr = pygame.font.get_default_font()
|
||||||
|
font = pygame.font.Font(font_addr, 36)
|
||||||
|
|
||||||
|
|
||||||
|
class Button(object):
|
||||||
|
def __init__(self, png, color, x=None, y=None, **kwargs):
|
||||||
|
self.surface = font.render(png, True, color)
|
||||||
|
|
||||||
|
self.WIDTH = self.surface.get_width()
|
||||||
|
self.HEIGHT = self.surface.get_height()
|
||||||
|
|
||||||
|
if 'centered_x' in kwargs and kwargs['centered_x']:
|
||||||
|
self.x = display_width // 2 - self.WIDTH // 2
|
||||||
|
else:
|
||||||
|
self.x = x
|
||||||
|
|
||||||
|
if 'centered_y' in kwargs and kwargs['centered_y']:
|
||||||
|
self.x = display_height //2 - self.HEIGHT // 2
|
||||||
|
else:
|
||||||
|
self.y = y
|
||||||
|
|
||||||
|
def display(self):
|
||||||
|
screen.blit(self.surface, (self.x, self.y))
|
||||||
|
|
||||||
|
def check_click(self,position):
|
||||||
|
x_match = (position[0] > self.x) and (position[0] < self.x + self.WIDTH)
|
||||||
|
y_match = (position[1] > self.y) and (position[1] < self.y + self.HEIGHT)
|
||||||
|
if x_match and y_match:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def starting_screen():
|
||||||
|
screen.blit(bg, (0, 0))
|
||||||
|
|
||||||
|
game_title = font.render('Starting Screen', True, WHITE)
|
||||||
|
|
||||||
|
screen.blit(game_title, (display_width//2 - game_title.get_width()//2, 150))
|
||||||
|
|
||||||
|
play_button = Button('Play!', WHITE, None, 350, centered_x=True)
|
||||||
|
exit_button = Button('Exit!', WHITE, None, 400, centered_x=True)
|
||||||
|
|
||||||
|
play_button.display()
|
||||||
|
exit_button.display()
|
||||||
|
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
if play_button.check_click(pygame.mouse.get_pos()):
|
||||||
|
play_button = Button('Play', RED, None, 350, centered_x=True)
|
||||||
|
else:
|
||||||
|
play_button = Button('Play', WHITE, None, 350, centered_x=True)
|
||||||
|
|
||||||
|
if exit_button.check_click(pygame.mouse.get_pos()):
|
||||||
|
exit_button = Button('Exit', RED, None, 400, centered_x=True)
|
||||||
|
else:
|
||||||
|
exit_button = Button('Exit', WHITE, None, 400, centered_x=True)
|
||||||
|
|
||||||
|
play_button.display()
|
||||||
|
exit_button.display()
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
raise SystemExit
|
||||||
|
if pygame.mouse.get_pressed()[0]:
|
||||||
|
if play_button.check_click(pygame.mouse.get_pos()):
|
||||||
|
break
|
||||||
|
if exit_button.check_click(pygame.mouse.get_pos()):
|
||||||
|
break
|
||||||
|
|
||||||
|
starting_screen()
|
Loading…
Reference in new issue