# HG changeset patch # User Simon Cross # Date 1315771218 -7200 # Node ID 646bb61c9ea6b40fe4601837b6638acc77f5df66 # Parent 2b50fd1e4ca1bbbe51236147de7817284bfc602a The snake is a li(n)e! diff -r 2b50fd1e4ca1 -r 646bb61c9ea6 mamba/snake.py --- a/mamba/snake.py Sun Sep 11 21:47:44 2011 +0200 +++ b/mamba/snake.py Sun Sep 11 22:00:18 2011 +0200 @@ -2,20 +2,24 @@ from pygame.sprite import Group from pygame.locals import BLEND_MULT +from pygame.draw import aalines -from mamba.sprites import BaseSprite +from mamba.sprites import BaseSprite, tile_sizify from mamba import mutators class Snake(object): UP, DOWN, LEFT, RIGHT = [(0, -1), (0, 1), (-1, 0), (1, 0)] + SPEED = 20.0 # pixels / s def __init__(self, tile_pos, orientation): self.segments = self.create_segments(tile_pos, orientation) self.segment_group = Group() self.segment_group.add(*self.segments) self.set_orientation(orientation) + self.pos = tile_sizify(tile_pos) + self.length = 3.0 head = property(fget=lambda self: self.segments[0]) tail = property(fget=lambda self: self.segments[-1]) @@ -29,17 +33,21 @@ ] def draw(self, surface): - self.segment_group.draw(surface) + # self.segment_group.draw(surface) + x, y = self.pos + aalines(surface, (0, 0, 255), False, [(x, y), (x + 60, y)]) def update(self, dt): - pass + x, y = self.pos + ox, oy = self.orientation + ds = self.SPEED * dt + self.pos = (x + ox * ds, y + oy * ds) def set_orientation(self, orientation): self.orientation = orientation #self.orientation = orientation #for segment in self.segments: # segment.set_orientation(self) - print orientation class Segment(BaseSprite):