def draw_construction_interface(): # snap to nearest grid position mouse = inverse_adjust_for_cam( # TODO: this offset is wrong when rotated MOUSE + Vec2d(BLOCK_SIZE / 2, BLOCK_SIZE / 2) * SPACE.scale) if not SPACE.camera_lock(): return cam = SPACE.camera_lock()._body.position a = SPACE.camera_lock()._body.angle _ = (mouse - cam) _.angle -= a _ %= Vec2d(BLOCK_SIZE, BLOCK_SIZE) _.angle += a mouse -= _ # create a collision object CONSTRUCTION_BLOCK._body.position = mouse CONSTRUCTION_BLOCK._body.angle = SPACE.camera_lock()._body.angle # check if stuff is near it valid_welds = [] for block in SPACE.camera_lock().construction: dist = round((block._body.position - mouse).length) if dist == 0: valid_welds = [] break elif dist == BLOCK_SIZE: valid_welds.append(block) CONSTRUCTION_BLOCK.valid_welds = valid_welds # draw it CONSTRUCTION_BLOCK.draw()
def update(dt): [b._upkeep() for b in SPACE.controllable_blocks] # update scale smoothly SPACE.scale += (SPACE.target_scale - SPACE.scale) * .25 # upkeep on various entities for p in SPACE.projectiles.copy(): p.upkeep() for r in SPACE.resources.copy(): r.upkeep() for e in SPACE.explosions: e.upkeep() # Run the simulation SPACE.step(dt) # Update the camera's last valid position if SPACE.camera_lock(): SPACE.last_pos = Vec2d(SPACE.camera_lock()._body.position)
def on_mouse_press(x, y, button, modifiers): try: if not SPACE.camera_lock(): return if not CONSTRUCTION_BLOCK or not CONSTRUCTION_BLOCK.valid_welds: return # TODO: any block type new_block = Block(CONSTRUCTION_BLOCK._body.position) new_block._body.angle = CONSTRUCTION_BLOCK.valid_welds[0]._body.angle for block in CONSTRUCTION_BLOCK.valid_welds: new_block.weld_to(block) # TODO: link the cockpit as the master block except Exception as e: print e
def collide(t1, t2, func): SPACE.add_collision_handler(COLLISION_TYPES[t1], COLLISION_TYPES[t2], begin=func)
def on_key_release(symbol, modifiers): if SPACE.camera_lock(): SPACE.camera_lock().on_key_release(symbol)
def on_key_press(symbol, modifiers): if SPACE.camera_lock(): SPACE.camera_lock().on_key_press(symbol)