-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·87 lines (76 loc) · 2.02 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
#!/usr/bin/env python3
from os import environ
environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import pygame
import importlib
import os
import modules
# map inputs to "pressed" strings
def mapKeyInput(key):
if key == pygame.K_UP:
return 'up'
if key == pygame.K_DOWN:
return 'down'
if key == pygame.K_LEFT:
return 'left'
if key == pygame.K_RIGHT:
return 'right'
if key == pygame.K_z:
return 'a'
if key == pygame.K_x:
return 'b'
if key == pygame.K_a:
return 'x'
if key == pygame.K_s:
return 'y'
if key == pygame.K_RETURN:
return 'start'
if key == pygame.K_ESCAPE:
return 'back'
if key == pygame.K_PAGEUP:
return 'l'
if key == pygame.K_PAGEDOWN:
return 'r'
pygame.init()
screen = pygame.display.set_mode((320, 240), pygame.HWSURFACE | pygame.DOUBLEBUF, 32)
world = pygame.Surface((320, 240), pygame.SRCALPHA, 32)
pygame.event.set_allowed([pygame.QUIT, pygame.KEYDOWN, pygame.KEYUP])
pygame.display.set_caption("Pakémon")
pygame.mixer.init()
clock = pygame.time.Clock()
modules.setup()
oldTime = 0
font = pygame.font.SysFont(None, 24)
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN:
try:
button = mapKeyInput(event.key)
if button:
modules.modules[modules.current].pressed(button, event)
except AttributeError:
pass
if event.type == pygame.KEYUP:
try:
button = mapKeyInput(event.key)
if button:
modules.modules[modules.current].released(button, event)
except AttributeError:
pass
try:
time = pygame.time.get_ticks()
dt = time - oldTime
oldTime = time
modules.modules[modules.current].draw(world, time, dt)
except AttributeError:
pass
# display fps
# world.blit(font.render(str(int(clock.get_fps())), True, (255, 255, 255)), (0, 0))
screen.fill((0, 0, 0))
screen.blit(world, pygame.rect.Rect(0, 0, 320, 240))
pygame.display.flip()
clock.tick(60)
pygame.quit()