Skip to content
Snippets Groups Projects
Commit e13e2243 authored by Sida Wang's avatar Sida Wang :juggling_tone1:
Browse files

texture pack and game setup updated

parent 100b98c3
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
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
src/build.wav 100755 → 100644
No preview for this file type
......@@ -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:
......
src/icon.png

62.5 KiB | W: | H:

src/icon.png

105 KiB | W: | H:

src/icon.png
src/icon.png
src/icon.png
src/icon.png
  • 2-up
  • Swipe
  • Onion skin
File added
src/texture/Brick.png

2.87 KiB

src/texture/Dirt.png

35.8 KiB

src/texture/Grass.png

57.1 KiB

src/texture/Marbo.png

2.53 KiB

src/texture/Stone.png

2.21 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment