Skip to content

Commit

Permalink
Switched to sprites!
Browse files Browse the repository at this point in the history
  • Loading branch information
rdvonz committed Jan 27, 2012
1 parent ea06dcb commit cccf215
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
6 changes: 3 additions & 3 deletions game/interaction.py
Expand Up @@ -64,14 +64,14 @@ def grid_interaction(self, (x,y), button):
#and the tile is a solution
if tile.is_tile:
#Change the color to black
tile.vertex_list.colors[:12] = (0, 0, 0) * 4
tile.change_image('clicked')
else:
tile.is_clicked = True

elif self.hover(tile, (x,y), button) == self.RIGHT:
if not(tile.is_marked):
tile.vertex_list.colors[:12] = (255, 0, 0) * 4
tile.change_image('marked')
tile.is_marked = True
elif tile.is_marked:
tile.vertex_list.colors[:12] = (255, 255, 255) * 4
tile.change_image('normal')
tile.is_marked = False
25 changes: 20 additions & 5 deletions game/level.py
Expand Up @@ -10,6 +10,7 @@
from itertools import izip_longest
from numpy import array
import window
import resources


def grouper(n, iterable, fillvalue=None):
Expand All @@ -36,9 +37,9 @@ def __init__(self, image):
self.grid = self.get_grid()
self.column_grid = self.get_column(self.grid)
self.row_numbers = self.get_numbers(self.grid)
self.column_numbers = self.get_numbers(self.column_grid)
self.column_numbers = self.get_numbers(self.column_grid)

#Some default parameters of the tiles:
#Some default parameters of the tiles DEPRECATED:
self.tile_width = 20
self.tile_height = 20

Expand Down Expand Up @@ -89,8 +90,7 @@ def draw_grid(self):

x = self.pos_x
for tile in tiles:
tile_list.append(Tile(self.tile_width, self.tile_height,
x, y, tile))
tile_list.append(Tile_Sprite(tile, x, y, batch=window.batch))

x += self.tile_spacing
y += self.tile_spacing
Expand Down Expand Up @@ -159,7 +159,8 @@ def get_numbers(self, grid):

class Tile(object):

def __init__(self, width, height, x, y, is_tile, group=None):
def __init__(self, width, height, x, y, is_tile, group = None):

#Width attribute is a must to get mouse detection
self.width = width
self.height = height
Expand Down Expand Up @@ -192,6 +193,20 @@ def __init__(self, width, height, x, y, is_tile, group=None):
indices,
('v2f', vertices),
('c3B', self.base_color * 4))

class Tile_Sprite(pyglet.sprite.Sprite):
def __init__(self, is_tile, x, y, batch=None):
super(Tile_Sprite, self).__init__(img = resources.tile, x = x, y = y, batch=batch)
self.is_tile = is_tile
self.is_clicked = 0
self.is_marked = 0
def change_image(self, state):
if state == 'clicked':
self.image = resources.clicked
elif state == 'marked':
self.image = resources.marked
elif state == 'normal':
self.image = resources.tile

class Numbers(pyglet.text.Label):
'''
Expand Down
16 changes: 13 additions & 3 deletions game/resources.py
Expand Up @@ -12,8 +12,18 @@
img.path = ['resources/']

img.reindex()

cursor = img.image('pencil.png')
tile = img.image('tile.png')
clicked = img.image('clicked.png')
marked = img.image('marked.png')

def center(image):
image.anchor_y = image.height/2
image.anchor_x = image.width/2

center(cursor)

center(tile)

cursor.anchor_y = 0
cursor.anchor_x = cursor.height
center(clicked)
center(marked)
3 changes: 2 additions & 1 deletion game/window.py
Expand Up @@ -10,4 +10,5 @@
import pyglet

window = pyglet.window.Window(width=800, height=600)
batch = pyglet.graphics.Batch()
batch = pyglet.graphics.Batch()
grid = pyglet.graphics.Batch()
Binary file added resources/clicked.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/marked.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/tile.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cccf215

Please sign in to comment.