diff options
author | Peter Ward <peteraward@gmail.com> | 2009-09-28 10:51:50 +1000 |
---|---|---|
committer | Peter Ward <peteraward@gmail.com> | 2009-09-28 10:51:50 +1000 |
commit | 494e519103aa8bde7a8c28e02ae8178cb69d7a17 (patch) | |
tree | 38494ddcbc225556b85de953c3b3eb0a8a71d9b0 | |
parent | 91da0245b57ebe54f9168fdbc1c97d5981232198 (diff) |
Started drawing snakes.
-rw-r--r-- | images/eyes.png | bin | 0 -> 4037 bytes | |||
-rwxr-xr-x[-rw-r--r--] | snake.py | 23 |
2 files changed, 18 insertions, 5 deletions
diff --git a/images/eyes.png b/images/eyes.png Binary files differnew file mode 100644 index 0000000..643158c --- /dev/null +++ b/images/eyes.png @@ -1,3 +1,5 @@ +#!/usr/bin/env python + from __future__ import division import string @@ -68,9 +70,12 @@ class SnakeEngine(object): xscale = self.board_width / self.columns yscale = self.board_height / self.rows - image = Sprites.APPLE - new_size = scale_aspect(image.get_size(), (xscale, yscale)) - self.apple = pygame.transform.smoothscale(image, new_size) + def load_image(image): + new_size = scale_aspect(image.get_size(), (xscale, yscale)) + return pygame.transform.smoothscale(image, new_size) + + self.apple = load_image(Sprites.APPLE) + self.eyes = load_image(Sprites.EYES) def add_bot(self, bot): """ @@ -82,7 +87,6 @@ class SnakeEngine(object): return random.choice('RULD') """ letter = self.letters.pop() - self.bots[letter] = bot for i in xrange(self.rows * self.columns): x, y = self.get_random_position() @@ -91,7 +95,9 @@ class SnakeEngine(object): else: raise KeyError, "Could not insert snake into the board." - self.board[y][x] = letter + colour = (255, 0, 0) + self.bots[letter] = (bot, (x, y), colour) + self.board[y][x] = letter.upper() return letter def remove_bot(self, letter): @@ -118,6 +124,13 @@ class SnakeEngine(object): if cell == Squares.APPLE: self.surface.blit(self.apple, r.topleft) + elif cell.isalpha(): # Snake... + colour = self.bots[cell.lower()][2] + self.surface.fill(colour, r) + + if cell.isupper(): # Snake head + self.surface.blit(self.eyes, r.topleft) + def run(self): # Draw the board. self.draw_board() |