diff --git a/src/.DS_Store b/src/.DS_Store index 914e46577560d34d4552a0303d26191df016b735..0b480f9af780aefb879b68d96f8d7f8d2ea79fdd 100755 Binary files a/src/.DS_Store and b/src/.DS_Store differ diff --git a/src/__pycache__/block.cpython-37.pyc b/src/__pycache__/block.cpython-37.pyc index d647440d4e805c4909fef95d783d3e049323cc1a..aeb200eb93a5d41afd121f8983b8fec9cabef60d 100644 Binary files a/src/__pycache__/block.cpython-37.pyc and b/src/__pycache__/block.cpython-37.pyc differ diff --git a/src/__pycache__/game.cpython-37.pyc b/src/__pycache__/game.cpython-37.pyc index ee1e2759134ea0a35898b140dfb86ccb762606ad..5586974a8c9d67698fc2daa9fe635b271fb631a3 100644 Binary files a/src/__pycache__/game.cpython-37.pyc and b/src/__pycache__/game.cpython-37.pyc differ diff --git a/src/block.py b/src/block.py index 5735d560beb40ee4fe7015c80387dc864d03ee5e..f231a44d38e9d365b72d17dd518902b5f24e4f64 100755 --- a/src/block.py +++ b/src/block.py @@ -1,9 +1,26 @@ from pyglet.graphics import TextureGroup from pyglet import image class Block(object): - def __init__(self, coordinates, texturePath): - self.coordinates = [] - self.coordinates.extend(coordinates) - self.coordinates.extend(coordinates) - self.coordinates.extend(coordinates * 4) + def __init__(self, top, bottom, side, size, texturePath): + self.coordinates = self._tex_coords(top, bottom, side, size) self.texture = TextureGroup(image.load(texturePath).get_texture()) + + def _tex_coords(self, top, bottom, side, size): + """ Return a list of the texture squares for the top, bottom and side. + """ + top = self._tex_coord(*top,n = size) + bottom = self._tex_coord(*bottom, n = size) + side = self._tex_coord(*side, n = size) + result = [] + result.extend(top) + result.extend(bottom) + result.extend(side * 4) + return result + + def _tex_coord(self, x, y, n): + """ Return the bounding vertices of the texture square. + """ + m = 1.0 / n + dx = x * m + dy = y * m + return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m diff --git a/src/build.wav b/src/build.wav old mode 100755 new mode 100644 index db9ebc65bdbd09fe31f73617f7f5ad53dab41c2e..7bd809ca82e45cbfe7f0a86fc3bccede1475bd16 Binary files a/src/build.wav and b/src/build.wav differ diff --git a/src/game.py b/src/game.py index 4268a2fde8055ac5303599aa2121b8a4c98dd299..4445c5f80252449c036f6123d458ff5604412477 100755 --- a/src/game.py +++ b/src/game.py @@ -5,7 +5,7 @@ from block import Block from view import View from world import World from mechanism import * - +import os import sys import math import random @@ -43,10 +43,10 @@ if sys.version_info[0] >= 3: if sys.version_info[0] * 10 + sys.version_info[1] >= 38: time.clock = time.process_time -BRICK = Block((0,0,1,0,1,1,0,1),'texture.png') -GRASS = Block((0,0,1,0,1,1,0,1),'texture.png') -SAND = Block((0,0,1,0,1,1,0,1),'texture.png') -STONE = Block((0,0,1,0,1,1,0,1),'texture.png') +BRICK = Block((0, 0), (0, 0), (0, 0), 1, os.path.join("texture","Brick.png")) +GRASS = Block((0, 0), (0, 1), (1, 1), 2, os.path.join("texture","Grass.png")) +STONE = Block((0, 0), (0, 0), (0, 0), 1,os.path.join("texture","Stone.png")) +MARBO = Block((0, 0), (0, 0), (0, 0), 1,os.path.join("texture","Marbo.png")) class Game(pyglet.window.Window): def __init__(self, *args, **kwargs): @@ -87,7 +87,7 @@ class Game(pyglet.window.Window): self.dy = 0 # A list of blocks the player can place. Hit num keys to cycle. - self.inventory = [BRICK, GRASS, SAND] + self.inventory = [BRICK, GRASS, STONE] # The current block the user can place. Hit num keys to cycle. self.block = self.inventory[0] @@ -121,13 +121,13 @@ class Game(pyglet.window.Window): y = 0 # initial y height for x in xrange(-n, n + 1, s): for z in xrange(-n, n + 1, s): - # create a layer STONE.coordinates an GRASS.coordinates everywhere. + # create a layer MARBO.coordinates an GRASS.coordinates everywhere. self.world.add_block((x, y - 2, z), GRASS, immediate=False) - self.world.add_block((x, y - 3, z), STONE, immediate=False) + self.world.add_block((x, y - 3, z), MARBO, immediate=False) if x in (-n, n) or z in (-n, n): # create outer walls. for dy in xrange(-2, 3): - self.world.add_block((x, y + dy, z), STONE, immediate=False) + self.world.add_block((x, y + dy, z), MARBO, immediate=False) # generate the hills randomly o = n - 10 @@ -138,7 +138,7 @@ class Game(pyglet.window.Window): h = random.randint(1, 6) # height of the hill s = random.randint(4, 8) # 2 * s is the side length of the hill d = 1 # how quickly to taper off the hills - t = random.choice([GRASS, SAND, BRICK]) + t = random.choice([GRASS, STONE, BRICK]) for y in xrange(c, c + h): for x in xrange(a - s, a + s + 1): for z in xrange(b - s, b + s + 1): @@ -338,7 +338,7 @@ class Game(pyglet.window.Window): self.buildSound.play() elif button == pyglet.window.mouse.LEFT and curPos: block = self.world.world[curPos] - if block.texture != STONE.texture: + if block.texture != MARBO.texture: self.world.remove_block(curPos) self.destroySound.play() else: diff --git a/src/icon.png b/src/icon.png index efe2c7ebe55df14e3f13ff8358b470a5ddac5dbf..a10a97c20612c0533232ebeabdacaafe06b6050c 100644 Binary files a/src/icon.png and b/src/icon.png differ diff --git a/src/texture/.DS_Store b/src/texture/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8100e247ef30bb2fc4d108d3bf73385c3bb64b88 Binary files /dev/null and b/src/texture/.DS_Store differ diff --git a/src/texture/Brick.png b/src/texture/Brick.png new file mode 100755 index 0000000000000000000000000000000000000000..8108ceec02b37ef5935d744619f226439d1069c6 Binary files /dev/null and b/src/texture/Brick.png differ diff --git a/src/texture/Dirt.png b/src/texture/Dirt.png new file mode 100755 index 0000000000000000000000000000000000000000..4d3449e8756f44d3a499119f355539425b18a9d0 Binary files /dev/null and b/src/texture/Dirt.png differ diff --git a/src/texture/Grass.png b/src/texture/Grass.png new file mode 100755 index 0000000000000000000000000000000000000000..a6efa2f5f43ae61d6499be1476c869f08f265988 Binary files /dev/null and b/src/texture/Grass.png differ diff --git a/src/texture/Marbo.png b/src/texture/Marbo.png new file mode 100755 index 0000000000000000000000000000000000000000..5275f26e2ce7dcac45296a9632a543facd896205 Binary files /dev/null and b/src/texture/Marbo.png differ diff --git a/src/texture/Stone.png b/src/texture/Stone.png new file mode 100755 index 0000000000000000000000000000000000000000..d23ff958d617bf941b898722f4d985f28e0fcaab Binary files /dev/null and b/src/texture/Stone.png differ