예제 #1
0
from rstem.button import Button
from rstem.mcpi import minecraft, control, block
from rstem.mcpi.vec3 import Vec3
import time
from math import sin, cos, radians

control.show(hide_at_exit=True)
mc = minecraft.Minecraft.create()
button = Button(7)

while True:
    if button.presses():
        heading = control.get_heading(mc)
        x_delta = sin(radians(heading))
        z_delta = cos(radians(heading))
        pos = mc.player.getPos() - Vec3(0, 1, 0)
        for i in range(100):
            pos += Vec3(x_delta, 0, z_delta)
            mc.setBlock(pos, block.STONE)

    time.sleep(0.01)

예제 #2
0
    block.STONE,
    block.BRICK_BLOCK,
    block.OBSIDIAN,
    block.DIAMOND_BLOCK,
    ]
block_types = cycle(block_types)
blk = next(block_types)

cursor = mc.player.getTilePos()
cursor.y = mc.getHeight(cursor.x, cursor.z)

BLINK_TIME = 0.3
start = time.time()
cursor_on = True
while True:
    if select.presses():
        blk = next(block_types)

    if place.presses():
        mc.setBlock(cursor, blk)
        cursor.y += 1

    old_cursor = cursor.clone()
    cursor += Vec3(0, 0, right.presses())
    cursor += Vec3(0, 0, -left.presses())
    cursor += Vec3(up.presses(), 0, 0)
    cursor += Vec3(-down.presses(), 0, 0)
    if old_cursor != cursor:
        mc.setBlock(old_cursor, block.AIR)
        cursor.y = mc.getHeight(cursor.x, cursor.z)
        start = 0
예제 #3
0
ALIENS_STEP_TIME = 0.8

missile_x, missile_y = -1, -1

MISSILE_COLOR = 10
MISSILE_STEP_TIME = 0.1

TILT_FORCE = 0.1
SPACESHIP_STEP = 0.1

while True:
    # ########################################
    # Get inputs
    # ########################################
    presses = fire_button.presses()
    x_force, y_force, z_force = accel.forces()
    now = time.time()

    # ########################################
    # Change the World
    # ########################################

    if missile_x >= 0 and now - missile_start_time > MISSILE_STEP_TIME:
        # Missile already launched - move it up
        missile_y += 1
        if missile_y >= fb.height:
            missile_x, missile_y = -1, -1
        missile_start_time = now
    elif presses:
        # Button was pressed - launch missile
예제 #4
0
from rstem.button import Button
from rstem.mcpi import minecraft, control, block
from rstem.mcpi.vec3 import Vec3
import time

control.show(hide_at_exit=True)
mc = minecraft.Minecraft.create()

left = Button(23)
right = Button(14)
up = Button(18)
down = Button(15)

cursor = mc.player.getTilePos()
cursor.y = mc.getHeight(cursor.x, cursor.z)

while True:
    old_cursor = cursor.clone()
    cursor += Vec3(0, 0, right.presses())
    cursor += Vec3(0, 0, -left.presses())
    cursor += Vec3(up.presses(), 0, 0)
    cursor += Vec3(-down.presses(), 0, 0)
    if old_cursor != cursor:
        mc.setBlock(old_cursor, block.AIR)
        cursor.y = mc.getHeight(cursor.x, cursor.z)

    mc.setBlock(cursor, block.STONE)

    time.sleep(0.01)
예제 #5
0
    Sprite(arrow15deg).rotate(270),
    Sprite(arrow30deg).rotate(270),
    Sprite(arrow45deg).rotate(270),
    Sprite(arrow60deg).rotate(270),
    Sprite(arrow75deg).rotate(270),
]


def vector_angle(start, end):
    return degrees(atan2(end.x - start.x, end.z - start.z))


compass = Button(24)
fb = FrameBuffer()
while block.Block(mc.getBlock(gold_pos)) == block.GOLD_BLOCK:
    if compass.presses():
        heading = control.get_heading(mc)
        angle_to_gold = vector_angle(mc.player.getPos(), gold_pos)
        compass_angle = 90 + (angle_to_gold - heading)
        fb.erase()
        arrow_index = round(compass_angle / 15) % 24
        fb.draw(arrows[arrow_index])
        fb.show()

    for button, action in keymap.items():
        if button.is_pressed():
            action()
        else:
            action(release=True)

    x, y, z = accel.forces()
    Sprite(arrow30deg).rotate(90),
    Sprite(arrow45deg).rotate(90),
    Sprite(arrow60deg).rotate(90),
    Sprite(arrow75deg).rotate(90),
    Sprite(arrow0deg).rotate(180),
    Sprite(arrow15deg).rotate(180),
    Sprite(arrow30deg).rotate(180),
    Sprite(arrow45deg).rotate(180),
    Sprite(arrow60deg).rotate(180),
    Sprite(arrow75deg).rotate(180),
    Sprite(arrow0deg).rotate(270),
    Sprite(arrow15deg).rotate(270),
    Sprite(arrow30deg).rotate(270),
    Sprite(arrow45deg).rotate(270),
    Sprite(arrow60deg).rotate(270),
    Sprite(arrow75deg).rotate(270),
    ]

compass = Button(24)
fb = FrameBuffer()
while True:
    if compass.presses():
        heading = control.get_heading(mc)
        fb.erase()
        arrow_index = round(heading/15) % 24
        fb.draw(arrows[arrow_index])
        fb.show()

    time.sleep(0.01)

예제 #7
0
bomb = Button(7)
up = Button(18)
down = Button(15)


def detonate(mc, pos, radius=1):
    r_vector = Vec3(radius, radius, radius)
    mc.setBlocks(pos - r_vector, pos + r_vector, block.AIR)
    bomb_sound.play()


place_mode = True
radius = 1
while True:
    if place_mode:
        if bomb.presses():
            control.hit()
        hits = mc.events.pollBlockHits()
        if hits:
            tnt_pos = hits[0].pos
            mc.setBlock(tnt_pos, block.TNT)
            place_mode = False

    else:
        if bomb.presses():
            detonate(mc, tnt_pos, radius)
            place_mode = True

    radius += up.presses()
    radius -= down.presses()
    radius = max(min(9, radius), 0)