-
Notifications
You must be signed in to change notification settings - Fork 0
/
person.py
142 lines (128 loc) · 4.24 KB
/
person.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'''person.py'''
import os
import sys
import signal
from board import BOARD
from config import MARIO_B
from bullet import BULLET_LIST, Bullet
from getch import _getChUnix as getChar
from alarm_exception import AlarmException
CHECKPOINT = [
[
25, 2], [
21, 66], [
25, 115], [
25, 140], [
25, 155], [
25, 180], [
25, 250], [
16, 396], [
25, 450], [
18, 430], [
25, 550]]
class Person():
'''code for mario'''
def __init__(self, xpos, ypos, jump, sym):
self.xpos = xpos
self.ypos = ypos
self.jump = jump
self.sym = sym
BOARD.mat[self.xpos][self.ypos] = sym
# check any obstacle in jump
def checkjump(self):
'''jump of mario'''
for i in range(self.xpos, self.xpos - self.jump, -1):
if BOARD.checkstar(
i - 2,
self.ypos) is 1 or BOARD.checkstar(
i - 2,
self.ypos - 1) is 1:
self.jump = self.xpos - i + 1
break
def moveup(self):
'''move up'''
oldxpos = self.xpos
if BOARD.checkstar(
oldxpos + 1,
self.ypos) is 1 or BOARD.checkstar(
oldxpos + 1,
self.ypos - 1) is 1:
self.checkjump()
# print(self.jump)
if BOARD.mat[self.xpos + 1][self.ypos] == '-':
self.jump = 12
self.xpos = self.xpos - self.jump
return self.xpos
def movedown(self, key):
'''movedown'''
# come down until there is no surface
# if(BOARD.mat[self.xpos+1][self.ypos] != '*' and
# BOARD.mat[self.xpos+1][self.ypos] != '-'):
if BOARD.checkstar(
self.xpos + 1,
self.ypos) != 1 and BOARD.checkstar(
self.xpos + 1,
self.ypos - 1) != 1:
self.xpos += 1
if key == 'd' and BOARD.checkstar(self.xpos, self.ypos + 1) != 1:
self.ypos += 1
if key == 'a' and BOARD.checkstar(self.xpos, self.ypos - 2) != 1:
self.ypos -= 1
def moveright(self):
'''moveright'''
if BOARD.checkstar(self.xpos, self.ypos + 1) != 1:
self.ypos += 1
def moveleft(self, i):
'''moveleft'''
if BOARD.checkstar(self.xpos, self.ypos -
2) != 1 and self.ypos > i + 1:
self.ypos -= 1
def print_on_board(self, xps, yps):
'''print mario on board'''
BOARD.mat[xps - 1][yps] = self.sym
BOARD.mat[xps - 1][yps - 1] = self.sym
BOARD.mat[xps][yps] = '\\'
BOARD.mat[xps][yps - 1] = '/'
def move(self, i):
'''move'''
def alarmhandler(signum, frame):
''' input method '''
if signum and frame:
pass
raise AlarmException
def user_input(timeout=0.1):
''' input method '''
signal.signal(signal.SIGALRM, alarmhandler)
signal.setitimer(signal.ITIMER_REAL, timeout)
try:
text = getChar()()
signal.alarm(0)
return text
except AlarmException:
pass
signal.signal(signal.SIGALRM, signal.SIG_IGN)
return ''
key = user_input()
self.jump = 8
if key == 'q':
os.system('pkill -kill aplay')
sys.exit(0)
# left
if key == 'd':
self.moveright()
# right
if key == 'a':
self.moveleft(i)
# up
if key == 'w':
self.moveup()
# print(self.xpos)
os.system('aplay -q ./smb_jump-small.wav&')
# cheat-code
if key == 'p':
self.sym = 'M'
# bullets
if key == 'x' and self.sym == 'M':
BULLET_LIST.append(Bullet(PERSON.xpos, PERSON.ypos + 1, 1, MARIO_B))
self.movedown(key)
PERSON = Person(25, 3, 8, 'm')