-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg.py
78 lines (64 loc) · 2.37 KB
/
bg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sys
import pygame
from pygame.locals import *
from path import *
from player import *
from enemy import *
from projectile import *
# draw backgroud
def drawWindow(bgX, bgX2):
DISPLAYSURF.blit(bg,(bgX,0))
DISPLAYSURF.blit(bg,(bgX2,0))
#draw icon setting
# bghowTG = pygame.image.load("data/images/bg_desert.png")
# bghowTG = pygame.transform.scale(bghowTG,(WINDOWWIDTH,WINDOWHEIGHT))
def drawController():
imgController = pygame.image.load("data\images\controller.png")
imgController = pygame.transform.scale(imgController,(400,250))
DISPLAYSURF.blit(imgController, (WINDOWWIDTH * 0.25, WINDOWHEIGHT /2 )) # vẽ hình setting lên screen
# draw icon volume
def drawVolume():
imgVolume = pygame.image.load("data\images\olume.png")
imgVolume = pygame.transform.scale(imgVolume,(80,80))
DISPLAYSURF.blit(imgVolume, (WINDOWWIDTH * 0.86, WINDOWHEIGHT * 0.85))
#button là ảnh
def image_button(img,x,y,c,d):
pause = False
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if(x + c) > mouse[0] > x and y + d > mouse[1] > y:
if click[0] == 1:
if pause == False:
pygame.mixer.music.pause()
pause == True
if pause == True:
pygame.mixer.music.unpause()
pause == False
#đối tượng chữ
def text_obj(text,font,color):
textSur = font.render(text,True,color)
return textSur,textSur.get_rect()
#hiển thị chữ
def message_display(text,color):
largeText = pygame.font.Font('freesansbold.ttf',100)
TextSur, TextRect = text_obj(text, largeText,color)
TextRect.center = ((WINDOWWIDTH /2),(WINDOWHEIGHT /2))
DISPLAYSURF.blit(TextSur, TextRect)
pygame.display.update()
time.sleep(2)
# game_intro()
#button cho hình khối
def game_button(te,x,y,c,d,bef,aft,action = None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if(x + c) > mouse[0] > x and y + d > mouse[1] > y:
pygame.draw.rect(DISPLAYSURF,aft,(x,y,c,d))
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(DISPLAYSURF,bef,(x,y,c,d))
#vẽ chữ vào nút
smallText = pygame.font.Font("freesansbold.ttf",30)
textSur, textRect = text_obj(te, smallText,BROWN)
textRect.center = ( (x+(c/2)), (y+(d/2)) )
DISPLAYSURF.blit(textSur, textRect)