Created
May 21, 2016 19:32
-
-
Save SpaceVoyager/9318e3cfffdf66cbf7fed7e11f544314 to your computer and use it in GitHub Desktop.
blocksexample.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scene import * | |
import json | |
import sound | |
background_objects_json_str = ''' | |
[{"x": 500, "y": 62, "w": 50, "h": 80, "img": "plc:Dirt_Block"}, | |
{"x": 500, "y": 100, "w": 50, "h": 80, "img": "plc:Dirt_Block"}, | |
{"x": 500, "y": 150, "w": 50, "h": 50, "img": "plc:Grass_Block"}] | |
''' | |
class GameEnvironment(object): | |
def __init__(self): | |
self.background_speed = 0.3 | |
class MyScene (Scene): | |
def setup(self): | |
self.env = GameEnvironment() | |
self.ground = Node(parent=self) | |
groundimage = 'plf:Ground_SandCenter' | |
w = SpriteNode(groundimage).size.w | |
h = SpriteNode(groundimage).size.h | |
x = 0 | |
while x <= self.size.w + w: | |
tile = SpriteNode(groundimage, position=(x, h/2)) | |
self.ground.add_child(tile) | |
x += w | |
self.background_color = 'midnightblue' | |
self.background_objects = [] | |
json_object = json.loads(background_objects_json_str) | |
for x in json_object: | |
item = SpriteNode(x['img']) | |
item.anchor_point = (0.5, 0) | |
item.position = (x['x'], x['y']) | |
item.size = (x['w'], x['h']) | |
self.add_child(item) | |
self.background_objects.append(item) | |
def update(self): | |
for dirtblock in self.background_objects: | |
pos = dirtblock.position | |
pos.x -= self.env.background_speed | |
dirtblock.position = pos | |
def touch_began(self, touch): | |
pass | |
run(MyScene()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment