From 68fb8fd3b2a62bf51cbda05ea0528e18c5e3dc4d Mon Sep 17 00:00:00 2001 From: huangjielun <2872405629@qq.com> Date: Fri, 26 Aug 2022 08:26:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=A3=8B=E5=AD=90=E7=9A=84?= =?UTF-8?q?=E6=91=86=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/main.py | 89 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 31cd7f0..ca2cc74 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Jungle +主要功能在main.py函数中 diff --git a/src/main.py b/src/main.py index bc66a19..54feb2f 100644 --- a/src/main.py +++ b/src/main.py @@ -81,14 +81,54 @@ 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() def main(): - fox = pygame.Rect(155,130,CHESSSIZE_Y,CHESSSIZE_Y) + + #animals rect + 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 +139,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()