diff --git a/src/main1.py b/src/main1.py index 3e3dfac..a37f29f 100644 --- a/src/main1.py +++ b/src/main1.py @@ -81,14 +81,142 @@ def print_text(WIN,font,x,y,text,fcolor=WHITE): WIN.blit(imgText,(x,y)) ###################################### +def draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox): + WIN.blit(L_elephant,(l_elephant.x,l_elephant.y)) + WIN.blit(L_eagle, (l_eagle.x, l_eagle.y)) + WIN.blit(L_wolf, (l_wolf.x, l_wolf.y)) + WIN.blit(L_lion, (l_lion.x, l_lion.y)) + WIN.blit(L_leopard, (l_leopard.x, l_leopard.y)) + WIN.blit(L_mouse, (l_mouse.x, l_mouse.y)) + WIN.blit(L_fox, (l_fox.x, l_fox.y)) -def draw_window(fox): +def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox): + WIN.blit(R_elephant, (r_elephant.x, r_elephant.y)) + WIN.blit(R_eagle, (r_eagle.x, r_eagle.y)) + WIN.blit(R_wolf, (r_wolf.x,r_wolf.y)) + WIN.blit(R_lion, (r_lion.x, r_lion.y)) + WIN.blit(R_leopard, (r_leopard.x, r_leopard.y)) + WIN.blit(R_mouse, (r_mouse.x, r_mouse.y)) + WIN.blit(R_fox, (r_fox.x, r_fox.y)) + + + + + +def draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox): WIN.blit(SPACE,(0,0)) - WIN.blit(L_fox,(fox.x,fox.y)) + draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox) + draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) + #WIN.blit(L_fox,(fox.x,fox.y)) pygame.display.update() +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, text, color, x=None, y=None, **kwargs): + self.surface = font.render(text, 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.y = 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()): + return True + if exit_button.check_click(pygame.mouse.get_pos()): + return False def main(): - fox = pygame.Rect(155,130,CHESSSIZE_Y,CHESSSIZE_Y) + + #animals rect + game_status = starting_screen() + if not game_status: + return True + l_elephant = pygame.Rect(281,10,CHESSSIZE_Y,CHESSSIZE_Y) + l_eagle = pygame.Rect(157,120,CHESSSIZE_Y,CHESSSIZE_Y) + l_wolf = pygame.Rect(284,229,CHESSSIZE_Y,CHESSSIZE_Y) + l_lion = pygame.Rect(292,343,CHESSSIZE_Y,CHESSSIZE_Y) + l_leopard = pygame.Rect(285,450,CHESSSIZE_Y,CHESSSIZE_Y) + l_mouse = pygame.Rect(285,665,CHESSSIZE_Y,CHESSSIZE_Y) + l_fox = pygame.Rect(157,557,CHESSSIZE_Y,CHESSSIZE_Y) + + r_elephant = pygame.Rect(795,673,CHESSSIZE_Y,CHESSSIZE_Y) + r_eagle = pygame.Rect(925,570,CHESSSIZE_Y,CHESSSIZE_Y) + r_wolf = pygame.Rect(803,458,CHESSSIZE_Y,CHESSSIZE_Y) + r_lion = pygame.Rect(802,347,CHESSSIZE_Y,CHESSSIZE_Y) + r_leopard = pygame.Rect(796,232,CHESSSIZE_Y,CHESSSIZE_Y) + r_fox = pygame.Rect(920,123,CHESSSIZE_Y,CHESSSIZE_Y) + r_mouse = pygame.Rect(793,16,CHESSSIZE_Y,CHESSSIZE_Y) + ############################################# run = True clock = pygame.time.Clock() font1 = pygame.font.SysFont('kaiti',40) @@ -99,31 +227,32 @@ def main(): if event.type == pygame.QUIT: run = False elif event.type == pygame.MOUSEBUTTONDOWN: - mouse_x , mouse_y= event.pos - x = int(mouse_x / WIDTH * 9) + 1 - y = int(mouse_y / HEIGHT * 7) + 1 - b1,b2,b3 = pygame.mouse.get_pressed() - print(mouse_x,mouse_y) - if status == 1: - if mouse_x >=800: - fox.x = int((x-1) / 9 * WIDTH) - 10 - fox.y = int((y-1) / 7 * HEIGHT) - elif mouse_x >=600: - fox.x = int((x - 1) / 9 * WIDTH) - fox.y = int((y - 1) / 7 * HEIGHT) - else: - fox.x = int((x - 1) / 9 * WIDTH) + 15 - fox.y = int((y - 1) / 7 * HEIGHT) - if mouse_y >= 500: - fox.y -= 15 - status = 0 - else : - status = 1 + b1, b2, b3 = pygame.mouse.get_pressed() + if b1 and not b3: + mouse_x , mouse_y= event.pos + x = int(mouse_x / WIDTH * 9) + 1 + y = int(mouse_y / HEIGHT * 7) + 1 + print(mouse_x,mouse_y) + '''if status == 1: + if mouse_x >=800: + fox.x = int((x-1) / 9 * WIDTH) - 10 + fox.y = int((y-1) / 7 * HEIGHT) + elif mouse_x >=600: + fox.x = int((x - 1) / 9 * WIDTH) + fox.y = int((y - 1) / 7 * HEIGHT) + else: + fox.x = int((x - 1) / 9 * WIDTH) + 15 + fox.y = int((y - 1) / 7 * HEIGHT) + if mouse_y >= 500: + fox.y -= 15 + status = 0 + else : + status = 1''' #fox.x+=1 - draw_window(fox) + draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) pygame.quit()