-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
119 lines (99 loc) · 3.78 KB
/
main.py
File metadata and controls
119 lines (99 loc) · 3.78 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import pygame, sys
from settings import *
import pygame
from level import Level
from PIL import Image, ImageTk
from tkinter import PhotoImage
from tkinter_menu import *
# from pytmx.util_pygame import load_pygame
from player import main_sound
class Game:
def __init__(self):
# general setup
pygame.init()
self.screen = pygame.display.set_mode ( (WIDTH, HEIGTH) )
pygame.display.set_caption("Treasure Hunt")
self.clock = pygame.time.Clock()
self.bg = pygame.image.load('graphics/background/BackgroundMenu1.png')
DEFAULT_IMAGE_SIZE = (1920, 1080)
self.bg = pygame.transform.scale(self.bg, DEFAULT_IMAGE_SIZE)
self.resume_img = pygame.image.load('graphics/start_menu/resume.png').convert_alpha()
self.exit_img = pygame.image.load('graphics/start_menu/exit.png').convert_alpha()
# self.resume_btn = Button(100,200,self.resume_img)
# self.exit_btn = Button(450,200,self.exit_img)
# global data_tmx
# data_tmx = load_pygame("/home/darshan/college/tiled2_fin/tmx/th.tmx")
self.level = Level()
def draw(self,x,y,image,scale):
action = False
width = image.get_width()
height = image.get_height()
self.image = pygame.transform.scale(image,(int(width *scale),int(height *scale)))
self.rect = self.image.get_rect()
self.rect.topleft=(x,y)
self.screen.blit(self.image , (self.rect.x , self.rect.y))
self.clicked = False
# get mouse pos
pos = pygame.mouse.get_pos()
# print(pos)
# check mouse and clicked conditions
if self.rect.collidepoint(pos):#colliding or not
if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
self.clicked = True
action = True
if pygame.mouse.get_pressed()[0] == 0:
self.clicked = False
return action
def pause(self):
paused = True
while paused:
self.menu_sound = pygame.mixer.Sound('audio/menu_sound.mpeg')
main_sound.set_volume(0)
self.menu_sound.set_volume(0.5)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_c:
paused = False
elif event.type == pygame.K_q:
pygame.quit()
quit()
self.screen.blit(self.bg, (0, 0))
if self.draw(550,365,self.resume_img,0.8):
print("resume")
paused = False
main_sound.set_volume(0.8)
if self.draw(550,545,self.exit_img,0.8):
print('exit')
exit()
# pygame.draw.rect(self.screen,'red',(150,500,100,50))
# debug("paused")
pygame.display.update()
self.clock.tick(5)
def run(self):
while True:
# print("helloooooooo")
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame .quit()
sys.exit()
self.screen.fill('black')
self.level.run()
if(pygame.key.get_pressed()[pygame.K_p]):
# print("thereee")
self.pause()
# debug("hello:)")
pygame.display.update()
self.clock.tick(FPS)
# class Button(self):
if __name__ == '__main__':
# m = Menu()
pygame.mixer.init()
pygame.mixer.music.load('audio/menu_sound.mpeg')
pygame.mixer.music.play(-1)
# m.create_menu()
pygame.mixer.music.stop()
game = Game()
game.run()