-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
91 lines (69 loc) · 2.65 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
import pygame
import player
import tile
pygame.init()
BLACK = (0, 0, 0)
pxsize = 2
size = [256 * pxsize, 240 * pxsize]
screen = pygame.display.set_mode(size)
font = pygame.font.SysFont("consolas", 20)
tile.load(pxsize)
pygame.display.set_caption("pysmb1")
campos = 0
clock = pygame.time.Clock()
end = False
debugging = False
frameadvance = False
def printtext(msg, color=BLACK, pos=(50, 50)):
textsurface = font.render(msg, True, pygame.Color(color), None)
textrect = textsurface.get_rect()
textrect.topleft = pos
screen.blit(textsurface, textrect)
mario = pygame.image.load("resource/player.png")
player = player.Player(left=pygame.K_a, right=pygame.K_d, up=pygame.K_w, down=pygame.K_s, a=pygame.K_k, b=pygame.K_j)
while not end:
# set framerate
clock.tick(60)
# event check
for event in pygame.event.get():
if event.type == pygame.QUIT:
end = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_F1 and not debugging:
debugging = True
elif event.key == pygame.K_F1 and debugging:
debugging = False
if debugging and event.key == pygame.K_F2 and not frameadvance:
frameadvance = True
elif debugging and event.key == pygame.K_F2 and frameadvance:
frameadvance = False
if event.key == pygame.K_SPACE and frameadvance:
keys = pygame.key.get_pressed()
player.advance_frame(keys)
if event.key == pygame.K_ESCAPE:
end = True
# get keyboard input
keys = pygame.key.get_pressed()
if not frameadvance:
player.advance_frame(keys)
while player.pxxpos - campos > 116:
campos += 1
# draw background
screen.fill([227, 255, 250])
for collision in tile.tile_draw("0x11", campos, screen, pxsize):
player.collision_check(collision, campos, pxsize)
# print debug info
if debugging:
printtext("pxxpos: " + str(player.pxxpos), BLACK, (50, 50))
printtext("pxypos: " + str(player.pxypos), BLACK, (50, 70))
printtext("hexxpos: " + player.hexxpos, BLACK, (50, 90))
printtext("hexypos: " + player.hexypos, BLACK, (50, 110))
printtext("hexxspeed: " + player.hexxspeed, BLACK, (50, 130))
printtext("hexyspeed: " + player.hexyspeed, BLACK, (50, 150))
printtext("oncampxxpos: " + str(player.pxxpos - campos), BLACK, (250, 50))
printtext("frameadvace: " + str(frameadvance), BLACK, (250, 70))
# draw player
screen.blit(mario, ((player.pxxpos - campos) * pxsize, player.pxypos * pxsize))
pygame.display.flip()
pygame.quit()
exit(0)