the whole game
This commit is contained in:
309
project/raspberry/Makefile
Executable file
309
project/raspberry/Makefile
Executable file
@@ -0,0 +1,309 @@
|
||||
MODULE := minecraftpi
|
||||
SOURCES := ../../src/main.cpp \
|
||||
../../src/main_rpi.cpp \
|
||||
../../src/platform/input/Controller.cpp \
|
||||
../../src/platform/input/Keyboard.cpp \
|
||||
../../src/platform/input/Mouse.cpp \
|
||||
../../src/platform/input/Multitouch.cpp \
|
||||
../../src/platform/time.cpp \
|
||||
../../src/platform/CThread.cpp \
|
||||
../../src/NinecraftApp.cpp \
|
||||
../../src/Performance.cpp \
|
||||
../../src/SharedConstants.cpp \
|
||||
../../src/client/IConfigListener.cpp \
|
||||
../../src/client/Minecraft.cpp \
|
||||
../../src/client/Options.cpp \
|
||||
../../src/client/OptionStrings.cpp \
|
||||
../../src/client/OptionsFile.cpp \
|
||||
../../src/client/MouseHandler.cpp \
|
||||
../../src/client/gamemode/CreatorMode.cpp \
|
||||
../../src/client/gamemode/GameMode.cpp \
|
||||
../../src/client/gamemode/CreativeMode.cpp \
|
||||
../../src/client/gamemode/SurvivalMode.cpp \
|
||||
../../src/client/gui/components/Button.cpp \
|
||||
../../src/client/gui/components/ImageButton.cpp \
|
||||
../../src/client/gui/components/GuiElement.cpp \
|
||||
../../src/client/gui/components/GuiElementContainer.cpp \
|
||||
../../src/client/gui/components/ItemPane.cpp \
|
||||
../../src/client/gui/components/InventoryPane.cpp \
|
||||
../../src/client/gui/components/LargeImageButton.cpp \
|
||||
../../src/client/gui/components/NinePatch.cpp \
|
||||
../../src/client/gui/components/RolledSelectionListH.cpp \
|
||||
../../src/client/gui/components/RolledSelectionListV.cpp \
|
||||
../../src/client/gui/components/ScrolledSelectionList.cpp \
|
||||
../../src/client/gui/components/ScrollingPane.cpp \
|
||||
../../src/client/gui/components/SmallButton.cpp \
|
||||
../../src/client/gui/components/Slider.cpp \
|
||||
../../src/client/gui/components/OptionsItem.cpp \
|
||||
../../src/client/gui/components/OptionsGroup.cpp \
|
||||
../../src/client/gui/components/OptionsPane.cpp \
|
||||
../../src/client/gui/Font.cpp \
|
||||
../../src/client/gui/Gui.cpp \
|
||||
../../src/client/gui/GuiComponent.cpp \
|
||||
../../src/client/gui/Screen.cpp \
|
||||
../../src/client/gui/screens/ScreenChooser.cpp \
|
||||
../../src/client/gui/screens/ArmorScreen.cpp \
|
||||
../../src/client/gui/screens/ChatScreen.cpp \
|
||||
../../src/client/gui/screens/ConfirmScreen.cpp \
|
||||
../../src/client/gui/screens/ChestScreen.cpp \
|
||||
../../src/client/gui/screens/crafting/PaneCraftingScreen.cpp \
|
||||
../../src/client/gui/screens/crafting/StonecutterScreen.cpp \
|
||||
../../src/client/gui/screens/crafting/WorkbenchScreen.cpp \
|
||||
../../src/client/gui/screens/crafting/CraftingFilters.cpp \
|
||||
../../src/client/gui/screens/DeathScreen.cpp \
|
||||
../../src/client/gui/screens/ChooseLevelScreen.cpp \
|
||||
../../src/client/gui/screens/SimpleChooseLevelScreen.cpp \
|
||||
../../src/client/gui/screens/FurnaceScreen.cpp \
|
||||
../../src/client/gui/screens/InBedScreen.cpp \
|
||||
../../src/client/gui/screens/IngameBlockSelectionScreen.cpp \
|
||||
../../src/client/gui/screens/JoinGameScreen.cpp \
|
||||
../../src/client/gui/screens/MouseUnlockedScreen.cpp \
|
||||
../../src/client/gui/screens/OptionsScreen.cpp \
|
||||
../../src/client/gui/screens/PauseScreen.cpp \
|
||||
../../src/client/gui/screens/ProgressScreen.cpp \
|
||||
../../src/client/gui/screens/RenameMPLevelScreen.cpp \
|
||||
../../src/client/gui/screens/SelectWorldScreen.cpp \
|
||||
../../src/client/gui/screens/StartMenuScreen.cpp \
|
||||
../../src/client/gui/screens/TextEditScreen.cpp \
|
||||
../../src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.cpp \
|
||||
../../src/client/gui/screens/touch/TouchJoinGameScreen.cpp \
|
||||
../../src/client/gui/screens/touch/TouchSelectWorldScreen.cpp \
|
||||
../../src/client/gui/screens/touch/TouchStartMenuScreen.cpp \
|
||||
../../src/client/gui/screens/UploadPhotoScreen.cpp \
|
||||
../../src/client/model/ChickenModel.cpp \
|
||||
../../src/client/model/CowModel.cpp \
|
||||
../../src/client/model/HumanoidModel.cpp \
|
||||
../../src/client/model/PigModel.cpp \
|
||||
../../src/client/model/QuadrupedModel.cpp \
|
||||
../../src/client/model/SheepModel.cpp \
|
||||
../../src/client/model/SheepFurModel.cpp \
|
||||
../../src/client/model/geom/Cube.cpp \
|
||||
../../src/client/model/geom/ModelPart.cpp \
|
||||
../../src/client/model/geom/Polygon.cpp \
|
||||
../../src/client/particle/Particle.cpp \
|
||||
../../src/client/particle/ParticleEngine.cpp \
|
||||
../../src/client/player/LocalPlayer.cpp \
|
||||
../../src/client/player/RemotePlayer.cpp \
|
||||
../../src/client/player/input/KeyboardInput.cpp \
|
||||
../../src/client/player/input/touchscreen/TouchscreenInput.cpp \
|
||||
../../src/client/renderer/Chunk.cpp \
|
||||
../../src/client/renderer/EntityTileRenderer.cpp \
|
||||
../../src/client/renderer/GameRenderer.cpp \
|
||||
../../src/client/renderer/ItemInHandRenderer.cpp \
|
||||
../../src/client/renderer/LevelRenderer.cpp \
|
||||
../../src/client/renderer/RenderChunk.cpp \
|
||||
../../src/client/renderer/RenderList.cpp \
|
||||
../../src/client/renderer/Tesselator.cpp \
|
||||
../../src/client/renderer/Textures.cpp \
|
||||
../../src/client/renderer/TileRenderer.cpp \
|
||||
../../src/client/renderer/gles.cpp \
|
||||
../../src/client/renderer/culling/Frustum.cpp \
|
||||
../../src/client/renderer/entity/ArrowRenderer.cpp \
|
||||
../../src/client/renderer/entity/ChickenRenderer.cpp \
|
||||
../../src/client/renderer/entity/EntityRenderDispatcher.cpp \
|
||||
../../src/client/renderer/entity/EntityRenderer.cpp \
|
||||
../../src/client/renderer/entity/FallingTileRenderer.cpp \
|
||||
../../src/client/renderer/entity/HumanoidMobRenderer.cpp \
|
||||
../../src/client/renderer/entity/ItemRenderer.cpp \
|
||||
../../src/client/renderer/entity/ItemSpriteRenderer.cpp \
|
||||
../../src/client/renderer/entity/MobRenderer.cpp \
|
||||
../../src/client/renderer/entity/PaintingRenderer.cpp \
|
||||
../../src/client/renderer/entity/PlayerRenderer.cpp \
|
||||
../../src/client/renderer/entity/SheepRenderer.cpp \
|
||||
../../src/client/renderer/entity/TntRenderer.cpp \
|
||||
../../src/client/renderer/entity/TripodCameraRenderer.cpp \
|
||||
../../src/client/renderer/ptexture/DynamicTexture.cpp \
|
||||
../../src/client/renderer/tileentity/ChestRenderer.cpp \
|
||||
../../src/client/renderer/tileentity/SignRenderer.cpp \
|
||||
../../src/client/renderer/tileentity/TileEntityRenderDispatcher.cpp \
|
||||
../../src/client/renderer/tileentity/TileEntityRenderer.cpp \
|
||||
../../src/client/sound/Sound.cpp \
|
||||
../../src/client/sound/SoundEngine.cpp \
|
||||
../../src/locale/I18n.cpp \
|
||||
../../src/nbt/Tag.cpp \
|
||||
../../src/network/command/CommandServer.cpp \
|
||||
../../src/network/ClientSideNetworkHandler.cpp \
|
||||
../../src/network/NetEventCallback.cpp \
|
||||
../../src/network/Packet.cpp \
|
||||
../../src/network/RakNetInstance.cpp \
|
||||
../../src/network/ServerSideNetworkHandler.cpp \
|
||||
../../src/server/CreatorLevel.cpp \
|
||||
../../src/server/ServerLevel.cpp \
|
||||
../../src/server/ServerPlayer.cpp \
|
||||
../../src/util/DataIO.cpp \
|
||||
../../src/util/Mth.cpp \
|
||||
../../src/util/StringUtils.cpp \
|
||||
../../src/util/PerfTimer.cpp \
|
||||
../../src/util/PerfRenderer.cpp \
|
||||
../../src/world/Direction.cpp \
|
||||
../../src/world/entity/AgableMob.cpp \
|
||||
../../src/world/entity/Entity.cpp \
|
||||
../../src/world/entity/EntityFactory.cpp \
|
||||
../../src/world/entity/FlyingMob.cpp \
|
||||
../../src/world/entity/HangingEntity.cpp \
|
||||
../../src/world/entity/Mob.cpp \
|
||||
../../src/world/entity/MobCategory.cpp \
|
||||
../../src/world/entity/Motive.cpp \
|
||||
../../src/world/entity/Painting.cpp \
|
||||
../../src/world/entity/PathfinderMob.cpp \
|
||||
../../src/world/entity/SynchedEntityData.cpp \
|
||||
../../src/world/entity/ai/control/MoveControl.cpp \
|
||||
../../src/world/entity/animal/Animal.cpp \
|
||||
../../src/world/entity/animal/Chicken.cpp \
|
||||
../../src/world/entity/animal/Cow.cpp \
|
||||
../../src/world/entity/animal/Pig.cpp \
|
||||
../../src/world/entity/animal/Sheep.cpp \
|
||||
../../src/world/entity/animal/WaterAnimal.cpp \
|
||||
../../src/world/entity/item/FallingTile.cpp \
|
||||
../../src/world/entity/item/ItemEntity.cpp \
|
||||
../../src/world/entity/item/PrimedTnt.cpp \
|
||||
../../src/world/entity/item/TripodCamera.cpp \
|
||||
../../src/world/entity/monster/Creeper.cpp \
|
||||
../../src/world/entity/monster/Monster.cpp \
|
||||
../../src/world/entity/monster/PigZombie.cpp \
|
||||
../../src/world/entity/monster/Skeleton.cpp \
|
||||
../../src/world/entity/monster/Spider.cpp \
|
||||
../../src/world/entity/monster/Zombie.cpp \
|
||||
../../src/world/entity/projectile/Arrow.cpp \
|
||||
../../src/world/entity/projectile/Throwable.cpp \
|
||||
../../src/world/entity/player/Inventory.cpp \
|
||||
../../src/world/entity/player/Player.cpp \
|
||||
../../src/world/food/SimpleFoodData.cpp \
|
||||
../../src/world/inventory/BaseContainerMenu.cpp \
|
||||
../../src/world/inventory/ContainerMenu.cpp \
|
||||
../../src/world/inventory/FillingContainer.cpp \
|
||||
../../src/world/inventory/FurnaceMenu.cpp \
|
||||
../../src/world/item/ArmorItem.cpp \
|
||||
../../src/world/item/BedItem.cpp \
|
||||
../../src/world/item/DyePowderItem.cpp \
|
||||
../../src/world/item/Item.cpp \
|
||||
../../src/world/item/ItemInstance.cpp \
|
||||
../../src/world/item/HangingEntityItem.cpp \
|
||||
../../src/world/item/HatchetItem.cpp \
|
||||
../../src/world/item/HoeItem.cpp \
|
||||
../../src/world/item/PickaxeItem.cpp \
|
||||
../../src/world/item/ShovelItem.cpp \
|
||||
../../src/world/item/crafting/Recipe.cpp \
|
||||
../../src/world/item/crafting/ArmorRecipes.cpp \
|
||||
../../src/world/item/crafting/Recipes.cpp \
|
||||
../../src/world/item/crafting/FurnaceRecipes.cpp \
|
||||
../../src/world/item/crafting/OreRecipes.cpp \
|
||||
../../src/world/item/crafting/StructureRecipes.cpp \
|
||||
../../src/world/item/crafting/ToolRecipes.cpp \
|
||||
../../src/world/item/crafting/WeaponRecipes.cpp \
|
||||
../../src/world/level/Explosion.cpp \
|
||||
../../src/world/level/Level.cpp \
|
||||
../../src/world/level/LightLayer.cpp \
|
||||
../../src/world/level/LightUpdate.cpp \
|
||||
../../src/world/level/MobSpawner.cpp \
|
||||
../../src/world/level/Region.cpp \
|
||||
../../src/world/level/TickNextTickData.cpp \
|
||||
../../src/world/level/biome/Biome.cpp \
|
||||
../../src/world/level/biome/BiomeSource.cpp \
|
||||
../../src/world/level/chunk/LevelChunk.cpp \
|
||||
../../src/world/level/dimension/Dimension.cpp \
|
||||
../../src/world/level/levelgen/CanyonFeature.cpp \
|
||||
../../src/world/level/levelgen/DungeonFeature.cpp \
|
||||
../../src/world/level/levelgen/LargeCaveFeature.cpp \
|
||||
../../src/world/level/levelgen/LargeFeature.cpp \
|
||||
../../src/world/level/levelgen/RandomLevelSource.cpp \
|
||||
../../src/world/level/levelgen/feature/Feature.cpp \
|
||||
../../src/world/level/levelgen/synth/ImprovedNoise.cpp \
|
||||
../../src/world/level/levelgen/synth/PerlinNoise.cpp \
|
||||
../../src/world/level/levelgen/synth/Synth.cpp \
|
||||
../../src/world/level/material/Material.cpp \
|
||||
../../src/world/level/pathfinder/Path.cpp \
|
||||
../../src/world/level/storage/ExternalFileLevelStorage.cpp \
|
||||
../../src/world/level/storage/ExternalFileLevelStorageSource.cpp \
|
||||
../../src/world/level/storage/FolderMethods.cpp \
|
||||
../../src/world/level/storage/LevelData.cpp \
|
||||
../../src/world/level/storage/LevelStorageSource.cpp \
|
||||
../../src/world/level/storage/RegionFile.cpp \
|
||||
../../src/world/level/tile/BedTile.cpp \
|
||||
../../src/world/level/tile/ChestTile.cpp \
|
||||
../../src/world/level/tile/CropTile.cpp \
|
||||
../../src/world/level/tile/DoorTile.cpp \
|
||||
../../src/world/level/tile/EntityTile.cpp \
|
||||
../../src/world/level/tile/FurnaceTile.cpp \
|
||||
../../src/world/level/tile/GrassTile.cpp \
|
||||
../../src/world/level/tile/HeavyTile.cpp \
|
||||
../../src/world/level/tile/LightGemTile.cpp \
|
||||
../../src/world/level/tile/MelonTile.cpp \
|
||||
../../src/world/level/tile/Mushroom.cpp \
|
||||
../../src/world/level/tile/NetherReactor.cpp \
|
||||
../../src/world/level/tile/NetherReactorPattern.cpp \
|
||||
../../src/world/level/tile/StairTile.cpp \
|
||||
../../src/world/level/tile/StemTile.cpp \
|
||||
../../src/world/level/tile/StoneSlabTile.cpp \
|
||||
../../src/world/level/tile/TallGrass.cpp \
|
||||
../../src/world/level/tile/Tile.cpp \
|
||||
../../src/world/level/tile/TrapDoorTile.cpp \
|
||||
../../src/world/level/tile/entity/ChestTileEntity.cpp \
|
||||
../../src/world/level/tile/entity/NetherReactorTileEntity.cpp \
|
||||
../../src/world/level/tile/entity/SignTileEntity.cpp \
|
||||
../../src/world/level/tile/entity/TileEntity.cpp \
|
||||
../../src/world/level/tile/entity/FurnaceTileEntity.cpp \
|
||||
../../src/world/phys/HitResult.cpp
|
||||
|
||||
#
|
||||
# Build environment
|
||||
#
|
||||
CC:=g++
|
||||
SHELL:=/bin/bash
|
||||
|
||||
#
|
||||
# Setup default vars and paths
|
||||
#
|
||||
CFLAGS:=-mfloat-abi=hard -march=armv6j -mfpu=vfp -DRPI -DPOSIX -DGFX_SMALLER_CHUNKS -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads
|
||||
|
||||
OBJECTS:=$(SOURCES:%.cpp=%.o)
|
||||
DEPS:=$(SOURCES:%.cpp=%.d)
|
||||
|
||||
OBJDIR=.
|
||||
SRCDIR=.
|
||||
|
||||
#
|
||||
# Build mode specifics
|
||||
#
|
||||
ifeq ($(BUILD),release)
|
||||
CFLAGS+=-Os -g -DNDEBUG -DPUBLISH
|
||||
OBJDIR=obj/release/d1/d2
|
||||
OBJECTS:=$(patsubst %,$(OBJDIR)/%,$(OBJECTS))
|
||||
else
|
||||
CFLAGS+=-O0 -g
|
||||
OBJDIR=obj/debug/d1/d2
|
||||
OBJECTS:=$(patsubst %,$(OBJDIR)/%,$(OBJECTS))
|
||||
endif
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
LDFLAGS:=-L/opt/vc/lib/ -lGLESv1_CM -lEGL -lbcm_host -lpng -lSDL -L. libRakNet_static_O1.a
|
||||
|
||||
|
||||
#
|
||||
# Targets
|
||||
#
|
||||
all: $(MODULE)
|
||||
|
||||
-include $(DEPS)
|
||||
|
||||
release:
|
||||
make "BUILD=release"
|
||||
|
||||
#$(CC) -MM $(CFLAGS) $*.cpp > $*.d
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
@mkdir -p $(@D)
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
$(CC) -MM -MT $*.o $(CFLAGS) $*.cpp > $*.d
|
||||
@cp -f $*.d $*.d.tmp
|
||||
@rm -f $*.d.tmp
|
||||
|
||||
#@sed -e 's/.*://' -e 's/\$$//' < $*.d.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
|
||||
|
||||
$(MODULE): $(OBJECTS)
|
||||
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS) $(DEPS) $(MODULE)
|
||||
BIN
project/raspberry/libRakNet.so
Executable file
BIN
project/raspberry/libRakNet.so
Executable file
Binary file not shown.
BIN
project/raspberry/libRakNet_static.a
Executable file
BIN
project/raspberry/libRakNet_static.a
Executable file
Binary file not shown.
BIN
project/raspberry/minecraftpi
Executable file
BIN
project/raspberry/minecraftpi
Executable file
Binary file not shown.
BIN
project/raspberry/py/__pycache__/api.cpython-312.pyc
Executable file
BIN
project/raspberry/py/__pycache__/api.cpython-312.pyc
Executable file
Binary file not shown.
BIN
project/raspberry/py/__pycache__/apiutil.cpython-312.pyc
Executable file
BIN
project/raspberry/py/__pycache__/apiutil.cpython-312.pyc
Executable file
Binary file not shown.
BIN
project/raspberry/py/__pycache__/event.cpython-312.pyc
Executable file
BIN
project/raspberry/py/__pycache__/event.cpython-312.pyc
Executable file
Binary file not shown.
BIN
project/raspberry/py/__pycache__/vec3.cpython-312.pyc
Executable file
BIN
project/raspberry/py/__pycache__/vec3.cpython-312.pyc
Executable file
Binary file not shown.
100
project/raspberry/py/api.py
Executable file
100
project/raspberry/py/api.py
Executable file
@@ -0,0 +1,100 @@
|
||||
import socket, select
|
||||
import apiutil
|
||||
from vec3 import Vec3
|
||||
from event import TileEvent
|
||||
|
||||
comm = None
|
||||
def connect(address, port=4711):
|
||||
global comm
|
||||
comm = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
comm.connect((address, 4711))
|
||||
|
||||
connect("localhost")
|
||||
|
||||
def drainSocket(s):
|
||||
while True:
|
||||
read, w, x = select.select([s], [], [], 0.0)
|
||||
if len(read) == 0: break
|
||||
s.recv(1500)
|
||||
|
||||
def generateFunc(name, unpack=None):
|
||||
def _inner(*l):
|
||||
s = apiutil.call(name,*l)
|
||||
drainSocket(comm)
|
||||
comm.send(s)
|
||||
if not unpack: return
|
||||
|
||||
r = comm.recv(1024)
|
||||
if r != "Fail\n":
|
||||
return unpack(r)
|
||||
return _inner
|
||||
|
||||
def unpackArrayTo(func, f=lambda x:x):
|
||||
"""Calling func with unpacked array element arguments"""
|
||||
def _inner(s): return [func(*map(f, e.split(","))) for e in s.split("|") if e.strip()]
|
||||
return _inner
|
||||
|
||||
def unpackTo(func, f=lambda x:x):
|
||||
"""Calling func with unpacked arguments"""
|
||||
def _inner(s): return func(*map(f, s.split(",")))
|
||||
return _inner
|
||||
|
||||
def postMessageLoop():
|
||||
n = 0
|
||||
while 1:
|
||||
postMessage(n)
|
||||
n += 1
|
||||
|
||||
def Print(s):
|
||||
print(s)
|
||||
|
||||
def readV3(s): return unpackTo(Vec3, float)(s)
|
||||
def readV3ints(s): return unpackTo(Vec3, lambda x:int(float(x)))(s)
|
||||
|
||||
class Holder:
|
||||
pass
|
||||
|
||||
# Block, world
|
||||
world = Holder()
|
||||
world.setBlock = generateFunc("world.setBlock")
|
||||
world.getBlock = generateFunc("world.getBlock", int)
|
||||
world.setBlocks = generateFunc("world.setBlocks")
|
||||
world.getHeight = generateFunc("world.getHeight", int)
|
||||
world.getPlayerIds = generateFunc("world.getPlayerIds", unpackArrayTo(int))
|
||||
world.setting = generateFunc("world.setting")
|
||||
|
||||
# Checkpoint
|
||||
world.checkpoint = Holder()
|
||||
world.checkpoint.save = generateFunc("world.checkpoint.save")
|
||||
world.checkpoint.restore= generateFunc("world.checkpoint.restore")
|
||||
# = generateFunc("entity.getType
|
||||
|
||||
# Player
|
||||
player = Holder()
|
||||
player.setTile = generateFunc("player.setTile")
|
||||
player.getTile = generateFunc("player.getTile", readV3ints)
|
||||
player.setPos = generateFunc("player.setPos")
|
||||
player.getPos = generateFunc("player.getPos", readV3)
|
||||
player.setting = generateFunc("player.setting")
|
||||
|
||||
# Camera
|
||||
camera = Holder()
|
||||
camera.setNormal = generateFunc("camera.mode.setNormal")
|
||||
#camera.setThirdPerson = generateFunc("camera.mode.setThirdPerson")
|
||||
camera.setFixed = generateFunc("camera.mode.setFixed")
|
||||
camera.setFollow = generateFunc("camera.mode.setFollow")
|
||||
camera.setPos = generateFunc("camera.setPos")
|
||||
#setCameraFollow1 = generateFunc("camera.mode.setFollowWithPosition")
|
||||
#setCameraFollow2 = generateFunc("camera.mode.setFollowWithRotation")
|
||||
|
||||
# Events
|
||||
events = Holder()
|
||||
events.block = Holder()
|
||||
events.block.hits = generateFunc("events.block.hits", unpackArrayTo(TileEvent.Hit, int))
|
||||
#pollChat = generateFunc("events.chat", unpackArrayTo(TileEvent.Hit, int))
|
||||
# Chat
|
||||
chat = Holder()
|
||||
chat.post = generateFunc("chat.post")
|
||||
|
||||
from functools import partial
|
||||
setAutojump = partial(player.setting, "autojump")
|
||||
13
project/raspberry/py/apiutil.py
Executable file
13
project/raspberry/py/apiutil.py
Executable file
@@ -0,0 +1,13 @@
|
||||
import collections
|
||||
|
||||
def flatten(l):
|
||||
for e in l:
|
||||
if isinstance(e, collections.Iterable) and not isinstance(e, basestring):
|
||||
for ee in flatten(e): yield ee
|
||||
else: yield e
|
||||
|
||||
def toParameters(l):
|
||||
return ",".join(map(str, flatten(l)))
|
||||
|
||||
def call(name, *l):
|
||||
return "%s(%s)\n"%(name, toParameters(l))
|
||||
19
project/raspberry/py/event.py
Executable file
19
project/raspberry/py/event.py
Executable file
@@ -0,0 +1,19 @@
|
||||
from vec3 import Vec3
|
||||
|
||||
class TileEvent:
|
||||
HIT = 0
|
||||
|
||||
def __init__(self, type, x, y, z, face, entityId):
|
||||
self.type = type
|
||||
self.pos = Vec3(x, y, z)
|
||||
self.face = face
|
||||
self.entityId = entityId
|
||||
|
||||
def __str__(self):
|
||||
types = {TileEvent.HIT: "Hit"}
|
||||
return "TileEvent(%s @ %s:%d by %d)"%(types.get(self.type, 0),
|
||||
self.pos, self.face, self.entityId);
|
||||
|
||||
@staticmethod
|
||||
def Hit(x, y, z, face, entityId):
|
||||
return TileEvent(TileEvent.HIT, x, y, z, face, entityId)
|
||||
199
project/raspberry/py/game_snake.py
Executable file
199
project/raspberry/py/game_snake.py
Executable file
@@ -0,0 +1,199 @@
|
||||
import time, random
|
||||
import api, kbhelp
|
||||
from vec3 import Vec3
|
||||
|
||||
class BlockType:
|
||||
AIR = 0
|
||||
ROCK = 1
|
||||
DIRT = 3
|
||||
SANDSTONE = 24
|
||||
CLOTH = 35
|
||||
CACTUS = 81
|
||||
|
||||
class ClothColor:
|
||||
WHITE = 0
|
||||
RED = 14
|
||||
|
||||
@staticmethod
|
||||
def dark(x): return x + 8 if x < 8 else x
|
||||
def bright(x): return x - 8 if x >= 8 else x
|
||||
|
||||
class Level:
|
||||
Wall = BlockType.DIRT
|
||||
Food = BlockType.SANDSTONE
|
||||
|
||||
def __init__(self, w, h, pos=Vec3(0,0,0)):
|
||||
self.w = w
|
||||
self.h = h
|
||||
self.pos = pos
|
||||
self.m = [0] * (w * h)
|
||||
|
||||
def setup(self, numApples):
|
||||
size = Vec3(self.w-1, 0, self.h-1)
|
||||
margin = Vec3(1, 0, 1)
|
||||
api.world.setBlocks(self.pos - margin + Vec3.down(3), self.pos + size + margin, BlockType.ROCK)
|
||||
api.world.setBlocks(self.pos, self.pos + size + Vec3.up(8), BlockType.AIR)
|
||||
|
||||
for i in random.sample(range(self.w * self.h), numApples):
|
||||
xx = i % self.w
|
||||
yy = i / self.w
|
||||
self.m[i] = Level.Food
|
||||
api.world.setBlock(xx, self.pos.y, yy, Level.Food)
|
||||
|
||||
def getTile(self, x, y):
|
||||
return self.m[y * self.w + x] if self.inRange(x, y) else None
|
||||
|
||||
def clearTile(self, x, y):
|
||||
if self.inRange(x, y): self.m[y * self.w + x] = 0
|
||||
|
||||
def isFood(self, x, y):
|
||||
return self.inRange(x, y) and Level.Food == self.getTile(x, y)
|
||||
|
||||
def isWall(self, x, y):
|
||||
return (not self.inRange(x, y)) or Level.Wall == self.getTile(x, y)
|
||||
|
||||
def inRange(self, x, y):
|
||||
return x >= 0 and y >= 0 and x < self.w and y < self.h
|
||||
|
||||
def countApples(self):
|
||||
return self.m.count(Level.Food)
|
||||
|
||||
class Snake:
|
||||
def __init__(self, pos=Vec3(0,0,0), length=5):
|
||||
self.dir = Vec3(1, 0, 0)
|
||||
self.seg = [pos]
|
||||
self.dead = False
|
||||
self.growTicks = 0
|
||||
|
||||
for i in range(length-1):
|
||||
self._add()
|
||||
|
||||
def left(self): self.dir.rotateLeft()
|
||||
def right(self): self.dir.rotateRight()
|
||||
|
||||
def next(self):
|
||||
return self.head() + self.dir
|
||||
|
||||
def head(self):
|
||||
return self.seg[-1]
|
||||
|
||||
def tick(self):
|
||||
self._add()
|
||||
if self.growTicks == 0: self._remove()
|
||||
if self.growTicks > 0: self.growTicks -= 1
|
||||
|
||||
def _add(self):
|
||||
n = self.next()
|
||||
if n in self.seg:
|
||||
self.kill()
|
||||
return
|
||||
self.seg.append( n )
|
||||
api.world.setBlock(n.x, n.y, n.z, 45)
|
||||
|
||||
def _remove(self):
|
||||
h, self.seg = self.seg[0], self.seg[1:]
|
||||
api.world.setBlock(h.x, h.y, h.z, 0)
|
||||
|
||||
def grow(self, ticks):
|
||||
self.growTicks = ticks
|
||||
|
||||
def kill(self):
|
||||
for p in self.seg:
|
||||
api.world.setBlock(p.x, p.y, p.z, BlockType.CLOTH, 14)
|
||||
self.dead = True
|
||||
|
||||
class SnakeGame:
|
||||
def __init__(self, numSnakes):
|
||||
self.numSnakes = numSnakes
|
||||
self.snakes = []
|
||||
self.level = None
|
||||
self.noActionTicks = 10
|
||||
|
||||
def startLevel(self, level, numApples=8):
|
||||
self.level = level
|
||||
self.level.setup(numApples)
|
||||
self.snakes = [Snake(Vec3(3, 0, 3)) for x in range(self.numSnakes)]
|
||||
self.noActionTicks = 10
|
||||
for s in self.snakes:
|
||||
for t in s.seg: self.level.clearTile(t.x, t.z)
|
||||
api.camera.setFixed()
|
||||
api.camera.setPos(Vec3((level.w-1)/2.0, 10, level.h/2.0 - 1))
|
||||
|
||||
def tick(self):
|
||||
if self.noActionTicks > 0:
|
||||
self.noActionTicks -= 1
|
||||
return
|
||||
|
||||
for s in self.snakes:
|
||||
self.tickSnake(s)
|
||||
|
||||
def tickSnake(self, snake):
|
||||
if snake.dead: return
|
||||
self.onTile(snake, snake.next())
|
||||
if not snake.dead: snake.tick()
|
||||
|
||||
def isFinished(self):
|
||||
return self.isWon() or self.allSnakesDead()
|
||||
|
||||
def isWon(self):
|
||||
#print self.level.countApples()
|
||||
return self.level.countApples() == 0
|
||||
|
||||
def allSnakesDead(self):
|
||||
for s in self.snakes:
|
||||
if not s.dead: return False
|
||||
return True
|
||||
|
||||
def onTile(self, snake, pos):
|
||||
x, y = pos.x, pos.z
|
||||
if self.level.isWall(x, y): snake.kill()
|
||||
if self.level.isFood(x, y): snake.grow(2)
|
||||
self.level.clearTile(x, y)
|
||||
|
||||
def run():
|
||||
kb = kbhelp.KeyboardInput()
|
||||
keys = (('a', 'd'),
|
||||
('4', '6'))
|
||||
|
||||
numSnakes = 1
|
||||
|
||||
def play(level, numApples, tickDelay):
|
||||
g = SnakeGame(numSnakes)
|
||||
g.startLevel(Level(16, 12), numApples)
|
||||
api.chat.post("Snake - level %d"%level)
|
||||
|
||||
while 1:
|
||||
# Update input
|
||||
if kb.hasChar():
|
||||
key = kb.readChar()
|
||||
for i in range(min(len(g.snakes), len(keys))):
|
||||
LeftKey, RightKey = keys[i]
|
||||
s = g.snakes[i]
|
||||
if key == LeftKey: s.left()
|
||||
if key == RightKey: s.right()
|
||||
# Update game
|
||||
g.tick()
|
||||
time.sleep(tickDelay)
|
||||
|
||||
if g.isFinished():
|
||||
return g.isWon()
|
||||
|
||||
delay = 0.15
|
||||
level = 0
|
||||
apples = 5
|
||||
|
||||
while 1:
|
||||
level += 1
|
||||
apples += 1
|
||||
won = play(level, apples, delay)
|
||||
if not won:
|
||||
api.chat.post("Snake - Game over! [ level %d ]!"%level)
|
||||
return
|
||||
|
||||
delay -= 0.01
|
||||
if delay < 0.04:
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
38
project/raspberry/py/image.py
Executable file
38
project/raspberry/py/image.py
Executable file
@@ -0,0 +1,38 @@
|
||||
import Image
|
||||
import apiutil
|
||||
|
||||
def hexToRgb(hex):
|
||||
return (hex >> 16) & 255, (hex >> 8) & 255, hex & 255
|
||||
|
||||
cgaColors = map(hexToRgb, (
|
||||
0x000000,
|
||||
0x0000A8,
|
||||
0x00A800,
|
||||
0x00A8A8,
|
||||
0xFF0000,
|
||||
0xA800A8,
|
||||
0xA85400,
|
||||
0xA8A8A8,
|
||||
0x545454,
|
||||
0x5454FE,
|
||||
0x54FE54,
|
||||
0x54FEFE,
|
||||
0xFE5454,
|
||||
0xFE54FE,
|
||||
0xFEFE54,
|
||||
0xFEFEFE))
|
||||
|
||||
cgaPalette = apiutil.flatten(cgaColors)
|
||||
|
||||
def _padPalette(values, count):
|
||||
v = tuple(values)
|
||||
return v + (0, 0, 0) * (count - len(v))
|
||||
|
||||
def imageToCga(im):
|
||||
p = Image.new("P", (1,1))
|
||||
p.putpalette(_padPalette(cgaPalette, 256))
|
||||
return im.convert("RGB").quantize(palette=p, kmeans=255)
|
||||
|
||||
def imageToWool(im, (w, h)):
|
||||
cga = imageToCga(im.resize((w, h)))
|
||||
|
||||
60
project/raspberry/py/kbhelp.py
Executable file
60
project/raspberry/py/kbhelp.py
Executable file
@@ -0,0 +1,60 @@
|
||||
try:
|
||||
import msvcrt
|
||||
|
||||
"""Win32 implementation of a keyboard input reader"""
|
||||
class KeyboardInput_win32:
|
||||
def __init__(self):
|
||||
self.setBlocking(True)
|
||||
|
||||
def clear(self):
|
||||
while 1:
|
||||
if self.readChar_nonblocking() is None:
|
||||
break
|
||||
|
||||
def setBlocking(self, block):
|
||||
self.readChar = self.readChar_blocking if block else \
|
||||
self.readChar_nonblocking
|
||||
|
||||
def hasChar(self):
|
||||
return msvcrt.kbhit()
|
||||
|
||||
def readChar_blocking(self):
|
||||
return msvcrt.getch()
|
||||
|
||||
def readChar_nonblocking(self):
|
||||
if not msvcrt.kbhit(): return None
|
||||
return msvcrt.getch()
|
||||
|
||||
KeyboardInput = KeyboardInput_win32
|
||||
|
||||
except:
|
||||
try:
|
||||
class KeyboardInput_unix:
|
||||
def hasChar(self):
|
||||
import sys, tty, termios
|
||||
from select import select
|
||||
fd = sys.stdin.fileno()
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
try:
|
||||
tty.setraw(sys.stdin.fileno())
|
||||
[i, o, e] = select([sys.stdin.fileno()], [], [], 5)
|
||||
if i: ch = True
|
||||
else: ch = False
|
||||
finally:
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
return ch
|
||||
|
||||
def readChar(self):
|
||||
import sys, tty, termios
|
||||
from select import select
|
||||
fd = sys.stdin.fileno()
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
try:
|
||||
tty.setraw(sys.stdin.fileno())
|
||||
ch = sys.stdin.read(1)
|
||||
finally:
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
return ch
|
||||
|
||||
KeyboardInput = KeyboardInput_unix
|
||||
except: pass
|
||||
BIN
project/raspberry/py/mojang_cga.png
Executable file
BIN
project/raspberry/py/mojang_cga.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
80
project/raspberry/py/vec3.py
Executable file
80
project/raspberry/py/vec3.py
Executable file
@@ -0,0 +1,80 @@
|
||||
class Vec3:
|
||||
def __init__(self, x=0, y=0, z=0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
|
||||
def __add__(self, rhs):
|
||||
c = self.clone()
|
||||
c += rhs
|
||||
return c
|
||||
|
||||
def __iadd__(self, rhs):
|
||||
self.x += rhs.x
|
||||
self.y += rhs.y
|
||||
self.z += rhs.z
|
||||
return self
|
||||
|
||||
def clone(self):
|
||||
return Vec3(self.x, self.y, self.z)
|
||||
|
||||
def __neg__(self):
|
||||
return Vec3(-self.x, -self.y, -self.z)
|
||||
|
||||
def __sub__(self, rhs):
|
||||
return self.__add__(-rhs)
|
||||
|
||||
def __isub__(self, rhs):
|
||||
return self.__iadd__(-rhs)
|
||||
|
||||
def __repr__(self):
|
||||
return "Vec3(%s,%s,%s)"%(self.x,self.y,self.z)
|
||||
|
||||
def __iter__(self):
|
||||
return iter((self.x, self.y, self.z))
|
||||
|
||||
def _map(self, func):
|
||||
self.x = func(self.x)
|
||||
self.y = func(self.y)
|
||||
self.z = func(self.z)
|
||||
|
||||
def __cmp__(self, rhs):
|
||||
dx = self.x - rhs.x
|
||||
if dx != 0: return dx
|
||||
dy = self.y - rhs.y
|
||||
if dy != 0: return dy
|
||||
dz = self.z - rhs.z
|
||||
if dz != 0: return dz
|
||||
return 0
|
||||
|
||||
def iround(self): self._map(lambda v:int(v+0.5))
|
||||
def ifloor(self): self._map(int)
|
||||
|
||||
def rotateLeft(self): self.x, self.z = self.z, -self.x
|
||||
def rotateRight(self): self.x, self.z = -self.z, self.x
|
||||
|
||||
@staticmethod
|
||||
def y(n=1): return Vec3(0, n, 0)
|
||||
@staticmethod
|
||||
def up(n=1): return Vec3.y(n)
|
||||
@staticmethod
|
||||
def down(n=1): return Vec3.y(-n)
|
||||
|
||||
def testVec3():
|
||||
# Note: It's not testing everything
|
||||
|
||||
# 1.1 Test initialization
|
||||
it = Vec3(1, -2, 3)
|
||||
assert it.x == 1
|
||||
assert it.y == -2
|
||||
assert it.z == 3
|
||||
|
||||
# 2.1 Test cloning and equality
|
||||
clone = it.clone()
|
||||
assert it == clone
|
||||
it.x += 1
|
||||
assert it != clone
|
||||
|
||||
# Test repr
|
||||
e = eval(repr(it))
|
||||
assert e == it
|
||||
Reference in New Issue
Block a user