1.笔记
代码如下(示例):
def blit_alpha(target,source,location,opacity):
x = location[0]
y = location[1]
temp = pygame.Surface((source.get_width(),source.get_height())).convert()
temp.blit(target , (-x , -y))
temp.blit(source,(0,0))
temp.set_alpha(opacity)
target.blit(temp,location)
########################################主函数###############################################
def main():
pygame.init()
clock = pygame.time.Clock()
# 初始化屏幕
size = (1270,768)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("理工大大富翁 - made by Khalil")
# 读取字体以及有关数据
textColorInMessageBox = (141,146,152)
white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
font = pygame.font.Font('resource\\font\\myfont.ttf',30)
backgroud = pygame.image.load("resource\\pic\\GameMap.png")
chess = pygame.image.load("resource\\pic\\chess.png")
chess_com = pygame.image.load("resource\\pic\\chess1.png")
bigdice_image = pygame.image.load("resource\\pic\\dice.png").convert_alpha()
dice_1 = pygame.image.load("resource\\pic\\dice_1.png")
dice_2 = pygame.image.load("resource\\pic\\dice_2.png")
dice_3 = pygame.image.load("resource\\pic\\dice_3.png")
dice_4 = pygame.image.load("resource\\pic\\dice_4.png")
dice_5 = pygame.image.load("resource\\pic\\dice_5.png")
dice_6 = pygame.image.load("resource\\pic\\dice_6.png")
dices = [dice_1,dice_2,dice_3,dice_4,dice_5,dice_6]
yes = pygame.image.load("resource\\pic\\yes.png")
yes2 = pygame.image.load("resource\\pic\\yes2.png")
no = pygame.image.load("resource\\pic\\no.png")
no2 = pygame.image.load("resource\\pic\\no2.png")
GameStart = pygame.image.load("resource\\pic\\GameStart.png")
StartGameButton = pygame.image.load("resource\\pic\\StartGameButton.png").convert_alpha()
turnover = pygame.image.load("resource\\pic\\turnover.png")
turnover2 = pygame.image.load("resource\\pic\\turnover2.png")
shuaishen = pygame.image.load("resource\\pic\\shuaishen.png").convert_alpha()
tudishen = pygame.image.load("resource\\pic\\tudishen.png").convert_alpha()
caishen = pygame.image.load("resource\\pic\\caishen.png").convert_alpha()
pohuaishen = pygame.image.load("resource\\pic\\pohuaishen.png").convert_alpha()
rollDiceSound = pygame.mixer.Sound("resource\\sound\\rolldicesound.wav")
bgm = pygame.mixer.music.load("resource\\sound\\bgm.ogg")
throwcoin = pygame.mixer.Sound("resource\\sound\\throwcoin.wav")
moneysound = pygame.mixer.Sound("resource\\sound\\moneysound.wav")
aiyo = pygame.mixer.Sound("resource\\sound\\aiyo.wav")
didong = pygame.mixer.Sound("resource\\sound\\didong.wav")
# PlayList 在对象中设置应该播放的声音
playList = [moneysound ,throwcoin ,aiyo]
# 各种Surface的rect
bigdice_rect = bigdice_image.get_rect()
bigdice_rect.left , bigdice_rect.top = 50 , 600
yes_rect = yes.get_rect()
yes_rect.left , yes_rect.top = 500,438
no_rect = no.get_rect()
no_rect.left , no_rect.top = 630,438
button_rect = StartGameButton.get_rect()
button_rect.left , button_rect.top = 1003,30
turnover_rect = turnover.get_rect()
turnover_rect.left , turnover_rect.top = 1035,613
players = []
computers = []
allplayers = []
player_1 = Player(chess , '玩家' , True )
player_com1 = Player(chess_com , '电脑' , False )
players.append(player_1)
computers.append(player_com1)
allplayers.append(player_1)
allplayers.append(player_com1)
gate = Building('大门',1000,200,[1,2])
fountain = Building('喷泉',2000,400,[3,4])
path = Building('小道',800,160,[5])
library = Building('图书馆',2000,400,[6,7])
kongdi1 = Building('空地',0,0,[8])
classroomTen = Building('教十',1200,240,[9,10])
classroomNine = Building('教九',1200,240,[11,12])
resOne = Building('三餐厅',800,160,[13])
resTwo = Building('二餐厅',800,160,[14])
resThree = Building('一餐厅',800,160,[15])
kongdi2 = Building('空地',0,0,[0])
buildings = [gate,fountain,path,library,classroomNine,\
classroomTen,resOne,resThree,resTwo,kongdi1,kongdi2]
MapXYvalue = [(435.5,231.5),(509.5,231.5),(588.5,231.5),(675.5,231.5),(758.5,231.5),\
(758.5,317.0),(758.5,405.5),(758.5,484.5),(758.5,558.5),(679.5,558.5),\
(601.5,558.5),(518.5,556.5),(435.5,556.5),(435.5,479.5),(435.5,399.0),\
(435.5,315.5)
]
MapChessPosition_Player = []
MapChessPosition_Com = []
MapChessPosition_Original = []
MapChessPosition_Payment = []
MapMessageBoxPosition = (474.1 , 276.9)
YesNoMessageBoxPosition = [(500,438) , (630,438)]
StartGameButtonPosition = (1003,30)
TurnOvwrButtonPosition = (1035,613)
for i in range(0,16):
MapChessPosition_Original.append((MapXYvalue[i][0]-50,MapXYvalue[i][1]-80))
MapChessPosition_Player.append((MapXYvalue[i][0]-70,MapXYvalue[i][1]-60))
MapChessPosition_Com.append((MapXYvalue[i][0]-30,MapXYvalue[i][1]-100))
MapChessPosition_Payment.append((MapXYvalue[i][0]-30,MapXYvalue[i][1]-15))
running = True
image_alpha = 255
button_alpha = 255
half_alpha = 30
showdice = True
showYes2 = False
showNo2 = False
showYes_No = False
pressYes = False
whetherYes_NoJudge = False
gameStarted = False
showButton2 = False
pygame.mixer.music.play(100)