forked from nobody5050/Mineshaft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
118 lines (76 loc) · 3.25 KB
/
main.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
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
import pygame
import screeninfo
import os
import random
import pygame_menu
from resources.colors import *
from resources.constants import *
from resources.themes import *
from resources.music import *
class Mineshaft(object):
def __init__(self):
self._pygame_init()
self.currentpanoramapos = [random.randint(-1000, 0),random.randint(-500, 0)]
self.panorama_x_direction = random.randint(0,1)
self.panorama_y_direction = random.randint(0,1)
self.panorama_direction = random.randint(0,1)
self.screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.SCALED | pygame.RESIZABLE)
self.clock = pygame.time.Clock()
self._menu_init(WIDTH, HEIGHT)
MENU1.play(-1)
def _pygame_init(self):
pygame.init()
pygame.display.set_caption("Mineshaft","Mineshaft")
pygame.display.set_icon(pygame.image.load(os.path.join("assets","textures","blocks","Grass.png")))
pygame.mouse.set_visible(False)
def _menu_init(self, width, height):
self.menu = pygame_menu.Menu("", width-100, height-100, theme=MINESHAFT_DEFAULT_THEME)
self.menu.add.button('Start Game', self.menu.toggle)
self.menu.add.button('Quit', pygame_menu.events.EXIT)
monitor = screeninfo.get_monitors()[0]
self.menu.background = pygame.image.load(os.path.join(os.path.abspath(os.getcwd()), "assets", "panorama.jpeg"))
self.menu.background = pygame.transform.scale(self.menu.background, (width*2, height*2))
self.title = pygame.image.load(os.path.join("assets","mineshaft.png"))
self.title = pygame.transform.scale(self.title, (int(width), int(height/9)))
def _update_panorama(self, currentpos):
if currentpos[0]==0:
self.panorama_x_direction = 1
elif currentpos[0]==-600:
self.panorama_x_direction = 0
if currentpos[1]==0:
self.panorama_y_direction = 1
elif currentpos[1]==-500:
self.panorama_y_direction = 0
if self.panorama_x_direction == 0:
currentpos[0]+=1
elif self.panorama_x_direction == 1:
currentpos[0]-=1
if self.panorama_y_direction == 0:
currentpos[1]+=1
elif self.panorama_y_direction == 1:
currentpos[1]-=1
return currentpos
def update_game(self):
events = pygame.event.get()
for event in pygame.event.get():
if event.type == pygame.VIDEORESIZE:
self.screen = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
self._menu_init(event.w, event.h)
continue
elif event.type==pygame.QUIT:
sys.exit(pygame.quit())
if self.menu.is_enabled():
self.currentpanoramapos = self._update_panorama(self.currentpanoramapos)
self.menu.update(events)
def draw_game(self):
self.screen.fill(WHITE)
if self.menu.is_enabled():
self.screen.blit(self.menu.background, self.currentpanoramapos)
self.menu.draw(self.screen)
self.screen.blit(self.title, [0,0])
pygame.display.flip()
self.clock.tick(60)
game = Mineshaft()
while True:
game.update_game()
game.draw_game()