-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygame_only.py
58 lines (52 loc) · 1.42 KB
/
pygame_only.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
__author__ = 'Micah'
import pygame
import sys
import nes
with open("roms/mario.nes", 'rb') as rom:
emu = nes.NES(rom.read())
pygame.init()
screen = pygame.display.set_mode((256, 240))
emu.ppu.display = 0
gamepad1 = {
'up': pygame.K_UP,
'down': pygame.K_DOWN,
'left': pygame.K_LEFT,
'right': pygame.K_RIGHT,
'a': pygame.K_z,
'b': pygame.K_x,
'select': pygame.K_a,
'start': pygame.K_r
}
gamepad2 = {
'up': 0,
'down': 0,
'left': 0,
'right': 0,
'a': 0,
'b': 0,
'select': 0,
'start': 0
}
while 1:
emu.step()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
for button in gamepad1:
if event.key == gamepad1[button]:
emu.parse_input(1, button, 1)
for button in gamepad2:
if event.key == gamepad2[button]:
emu.parse_input(2, button, 1)
elif event.type == pygame.KEYUP:
for button in gamepad1:
if event.key == gamepad1[button]:
emu.parse_input(1, button, 0)
for button in gamepad2:
if event.key == gamepad2[button]:
emu.parse_input(2, button, 0)
if emu.ppu.display == 1:
emu.ppu.display = 0
pygame.surfarray.blit_array(screen, emu.ppu.colors)
pygame.display.update()