develop
huangjielun 3 years ago
commit ce32842dff

@ -0,0 +1,261 @@
import pygame
import os
pygame.init()
pygame.font.init()
#pygame.mixer.init()
#模块###############################
FPS = 60
WIDTH , HEIGHT = 1200 , 800
WIN = pygame.display.set_mode((WIDTH,HEIGHT))
pygame.display.set_caption("Jungle")
SPACE = pygame.transform.scale(pygame.image.load('images/map.png'),(WIDTH,HEIGHT))
chosenChess=None #选择的棋子(将要移动)
coverdChess=None #点击的目标位置(将被覆盖)
currentChess=None #当前点击的棋子
index=0 #记录棋盘上的棋子数量
CHESSSIZE_X=120
CHESSSIZE_Y=100 #棋子大小
R=25
GAP=3 #棋子间距
face_size = int(CHESSSIZE_X * 1.25)
face_pos_x = (WIDTH - face_size) // 2
face_pos_y = (CHESSSIZE_X * 2 - face_size) // 2
##################################################################
###########背景音乐###########
#BGM = pygame.mixer.Sound('audio/BackgroudMusic.mp3')
#Elephant = pygame.mixer.Sound('audio/Elephant.mp3')
#Leopard = pygame.mixer.Sound('audio/Leopard.mp3')
#Lion = pygame.mixer.Sound('audio/Lion.mp3')
#Mouse = pygame.mixer.Sound('audio/Mouse.mp3')
#Start = pygame.mixer.Sound('audio/start.mp3')
#Tiger = pygame.mixer.Sound('audio/Tiger.mp3')
#Wolf = pygame.mixer.Sound('audio/Wolf.mp3')
#Fox = pygame.mixer.Sound('audio/Fox..mp3')
#Eagle = pygame.mixer.Sound('audio/Eagle.mp3')
####################################################
#animals img
#Left
L_mouse = pygame.transform.scale(pygame.image.load('images/animals/left/1MouseLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y))
L_eagle = pygame.transform.scale(pygame.image.load('images/animals/left/2EagleLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y))
L_wolf = pygame.transform.scale(pygame.image.load('images/animals/left/3WolfLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y))
L_leopard = pygame.transform.scale(pygame.image.load('images/animals/left/4LeopardLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y))
L_tiger = pygame.transform.scale(pygame.image.load('images/animals/left/5TigerLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y))
L_lion = pygame.transform.scale(pygame.image.load('images/animals/left/6LionLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y))
L_elephant = pygame.transform.scale(pygame.image.load('images/animals/left/7ElephantLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y))
L_fox = pygame.transform.scale(pygame.image.load('images/animals/left/8FoxLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y))
#Right
R_mouse = pygame.transform.scale(pygame.image.load('images/animals/right/1MouseRight.png'),(CHESSSIZE_X,CHESSSIZE_Y))
R_eagle = pygame.transform.scale(pygame.image.load('images/animals/right/2EagleRight.png'),(CHESSSIZE_X,CHESSSIZE_Y))
R_wolf = pygame.transform.scale(pygame.image.load('images/animals/right/3WolfRight.png'),(CHESSSIZE_X,CHESSSIZE_Y))
R_leopard = pygame.transform.scale(pygame.image.load('images/animals/right/4LeopardRight.png'),(CHESSSIZE_X,CHESSSIZE_Y))
R_tiger = pygame.transform.scale(pygame.image.load('images/animals/right/5TigerRight.png'),(CHESSSIZE_X,CHESSSIZE_Y))
R_lion = pygame.transform.scale(pygame.image.load('images/animals/right/6LionRight.png'),(CHESSSIZE_X,CHESSSIZE_Y))
R_elephant = pygame.transform.scale(pygame.image.load('images/animals/right/7ElephantRight.png'),(CHESSSIZE_X,CHESSSIZE_Y))
R_fox = pygame.transform.scale(pygame.image.load('images/animals/right/8FoxRight.png'),(CHESSSIZE_X,CHESSSIZE_Y))
###############################################################################
#colour###########################################################
BLACK = (0,0,0)
LIGHTBLUE = (40,191,255)
LIGHTBLUE2 = (0,0,255)
BGCOLOR = (230,230,250)
MAGENTA = (255,0,255)
LIGHTYELLOW= (255,225,0)
MYCOLOR = (255,165,0)
WHITE = (255,255,255)
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
Crimson=(220,20,60)
LightPink=(255,182,193)
DeepSkyBlue=(0,191,255)
#############################################################
#TEXT
def print_text(WIN,font,x,y,text,fcolor=WHITE):
imgText = font .render(text,True,fcolor)
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_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))
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():
#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)
status = 0;
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.MOUSEBUTTONDOWN:
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(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()
if __name__ == "__main__":
main()
Loading…
Cancel
Save