aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-08-29 01:46:55 -0400
committerGravatar rcoh <rcoh@mit.edu>2011-08-29 01:46:55 -0400
commit507ca19df23b4e22fc0261bcc6c1275cd2ceef47 (patch)
treeb75411dffe19d181be9ce91a48ab39593a6fcbb7
parent37af70803573d93fd2793d5333fc23a9d8f1e4c2 (diff)
some style changes in tetris.
-rw-r--r--ddrinput.py10
-rw-r--r--renderer.py16
-rw-r--r--tetris.py6
3 files changed, 18 insertions, 14 deletions
diff --git a/ddrinput.py b/ddrinput.py
index f374781..fa31640 100644
--- a/ddrinput.py
+++ b/ddrinput.py
@@ -3,7 +3,7 @@ JOY_EVENT = 7
KEY_EVENT = 2
X = 0
Y = 1
-(LEFT, RIGHT, UP, DOWN, DROP) = range(5)
+(LEFT, RIGHT, UP, DOWN, DROP, DIE) = range(6)
KEY_LEFT = 276
KEY_UP = 273
KEY_DOWN = 274
@@ -15,7 +15,7 @@ KEY_W = 119
KEY_SPACE = 32
KEY_ESC = 27
-DIRECTIONS = {0:'LEFT', 1:'RIGHT', 2:'UP', 3:'DOWN', 5:'DROP'}
+DIRECTIONS = {0:'LEFT', 1:'RIGHT', 2:'UP', 3:'DOWN', 5:'DROP', 6:'DIE'}
class DdrInput(object):
"""
DdrInput is a class to get input from the particular DDR pads and adapters we have. It is not
@@ -36,6 +36,7 @@ class DdrInput(object):
#This is just so that we can get key presses in the demo. remove when we plug it into a ui
screen = pygame.display.set_mode((640, 480))
self.debug_mode = debug_mode
+ self.last_inputs = {}
def init_joysticks(self):
pygame.joystick.init()
@@ -70,6 +71,7 @@ class DdrInput(object):
if self.debug_mode and player_move != None:
print (player_index, player_move)
if player_move != None:
+ self.last_inputs[player_index][player_move] = 1
return (player_index, player_move)
else:
return None
@@ -101,10 +103,10 @@ class DdrInput(object):
player_move = UP
elif event.key == KEY_ESC:
player_index = 2
- player_move = "DIE"
+ player_move = DIE
elif event.key == KEY_SPACE:
player_index = 1
- player_move = "DROP"
+ player_move = DROP
if player_move != None:
return (player_index, player_move)
diff --git a/renderer.py b/renderer.py
index 1e40c7b..e67c6eb 100644
--- a/renderer.py
+++ b/renderer.py
@@ -41,7 +41,7 @@ class PygameRenderer(Renderer):
for (x,y) in game_board:
disp_x = x
if x >= 10:
- disp_x+=3
+ disp_x+=3
x0 = self.OFFSET[0] - self.SCALE/2 - 3
y0 = self.OFFSET[1] - 10
x1 = self.OFFSET[0]+8 + 9*self.SCALE
@@ -79,7 +79,8 @@ class LedRenderer(Renderer):
self.sockets[ip].send(final_packet, 0x00)
except:
print 'failure sending packet'
-
+ def color_deref(self, color):
+ return (255, 0, 0)
def map_to_packets(self, game_board):
"""
Performs the mapping between a game_board and a list of (port,packet) pairs. The port,packet
@@ -93,13 +94,14 @@ class LedRenderer(Renderer):
section_height = 5
for board_x_min in [0, 10]:
packet = []
- for y_start in [20, 15, 10, 5]:
+ for board_y_min in [20, 15, 10, 5]:
strip = zeros((50,3),'ubyte')
index = 0
- for y in range(board_y_min+section_height, board_y_min, -1):
+ for y in range(board_y_min, board_y_min-section_height, -1):
for x in range(board_x_min+section_width, board_x_min, -1):
- strip[index] = self.color_deref(game_board[(x,y)])
+ if (x,y) in game_board:
+ strip[index] = self.color_deref(game_board[(x,y)])
packet.append((1+len(packet), strip))
- packets.append(packet)
-
+ index += 1
+ packets += packet
return packets
diff --git a/tetris.py b/tetris.py
index 7851718..5a0b1d6 100644
--- a/tetris.py
+++ b/tetris.py
@@ -25,7 +25,7 @@ LEVEL_SPEEDS = [800,700,600,500,400,300,200,150,100,70]
MAXX = 10
MAXY = 18
-(LEFT, RIGHT, UP, DOWN) = range(4)
+(LEFT, RIGHT, UP, DOWN, DROP, DIE) = range(6)
COLORS = ["orange", "red", "green", "blue", "purple", "yellow", "magenta"]
LEVEL_COLORS = ["red", "orange red", "orange", "yellow",
@@ -263,14 +263,14 @@ class TetrisGame(object):
if ev:
player,direction = ev
#print "Player",player,direction
- if direction == "DIE": #Exit instruction
+ if direction == DIE: #Exit instruction
game_on = False
pygame.quit()
sys.exit()
if self.gameState.state=="playing":
if self.players[player]!=None:
#DROP is only for debugging purposes for now, to make the game end.
- if direction == "DROP":
+ if direction == DROP:
while self.players[player].handle_move( DOWN ):
pass
else: