commit 76c3665cc7053e8c4db965e03522938b9dd4d59f Author: pjht Date: Mon May 11 19:52:50 2020 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/animation/door/0.png b/animation/door/0.png new file mode 100644 index 0000000..2cfdf35 Binary files /dev/null and b/animation/door/0.png differ diff --git a/animation/door/1.png b/animation/door/1.png new file mode 100644 index 0000000..94b2103 Binary files /dev/null and b/animation/door/1.png differ diff --git a/animation/door/2.png b/animation/door/2.png new file mode 100644 index 0000000..942744d Binary files /dev/null and b/animation/door/2.png differ diff --git a/animation/door/3.png b/animation/door/3.png new file mode 100644 index 0000000..b1b741a Binary files /dev/null and b/animation/door/3.png differ diff --git a/animation/furnace/0.png b/animation/furnace/0.png new file mode 100755 index 0000000..a5dde73 Binary files /dev/null and b/animation/furnace/0.png differ diff --git a/animation/furnace/1.png b/animation/furnace/1.png new file mode 100755 index 0000000..31674bc Binary files /dev/null and b/animation/furnace/1.png differ diff --git a/animation/furnace/2.png b/animation/furnace/2.png new file mode 100755 index 0000000..7699012 Binary files /dev/null and b/animation/furnace/2.png differ diff --git a/basictiles.png b/basictiles.png new file mode 100644 index 0000000..9b1de7d Binary files /dev/null and b/basictiles.png differ diff --git a/characters.png b/characters.png new file mode 100644 index 0000000..eac82f3 Binary files /dev/null and b/characters.png differ diff --git a/nails/nails.png b/nails/nails.png new file mode 100644 index 0000000..d6b6563 Binary files /dev/null and b/nails/nails.png differ diff --git a/nails/nails.png.txt b/nails/nails.png.txt new file mode 100644 index 0000000..af9291d --- /dev/null +++ b/nails/nails.png.txt @@ -0,0 +1 @@ +nails_0.png.png 2 4, nails_1.png.png 35 7, nails_2.png.png 69 8, nails_3.png.png 99 11, nails_4.png.png 3 39, nails_5.png.png 35 39, nails_6.png.png 68 42, nails_7.png.png 101 42, nails_8.png.png 2 68, nails_9.png.png 34 68, nails_10.png.png 66 68, nails_11.png.png 98 67, nails_12.png.png 8 101, nails_13.png.png 35 98, nails_14.png.png 73 100, nails_15.png.png 102 100. \ No newline at end of file diff --git a/nails/nails_0.png b/nails/nails_0.png new file mode 100644 index 0000000..eeb17d6 Binary files /dev/null and b/nails/nails_0.png differ diff --git a/nails/nails_1.png b/nails/nails_1.png new file mode 100644 index 0000000..5082a10 Binary files /dev/null and b/nails/nails_1.png differ diff --git a/nails/nails_10.png b/nails/nails_10.png new file mode 100644 index 0000000..448b02f Binary files /dev/null and b/nails/nails_10.png differ diff --git a/nails/nails_11.png b/nails/nails_11.png new file mode 100644 index 0000000..9e63e9f Binary files /dev/null and b/nails/nails_11.png differ diff --git a/nails/nails_12.png b/nails/nails_12.png new file mode 100644 index 0000000..9668333 Binary files /dev/null and b/nails/nails_12.png differ diff --git a/nails/nails_13.png b/nails/nails_13.png new file mode 100644 index 0000000..e8590c8 Binary files /dev/null and b/nails/nails_13.png differ diff --git a/nails/nails_14.png b/nails/nails_14.png new file mode 100644 index 0000000..ec8bf23 Binary files /dev/null and b/nails/nails_14.png differ diff --git a/nails/nails_15.png b/nails/nails_15.png new file mode 100644 index 0000000..40ae7e5 Binary files /dev/null and b/nails/nails_15.png differ diff --git a/nails/nails_2.png b/nails/nails_2.png new file mode 100644 index 0000000..bc72dd7 Binary files /dev/null and b/nails/nails_2.png differ diff --git a/nails/nails_3.png b/nails/nails_3.png new file mode 100644 index 0000000..c0b6293 Binary files /dev/null and b/nails/nails_3.png differ diff --git a/nails/nails_4.png b/nails/nails_4.png new file mode 100644 index 0000000..03c74c6 Binary files /dev/null and b/nails/nails_4.png differ diff --git a/nails/nails_5.png b/nails/nails_5.png new file mode 100644 index 0000000..09888e1 Binary files /dev/null and b/nails/nails_5.png differ diff --git a/nails/nails_6.png b/nails/nails_6.png new file mode 100644 index 0000000..7455028 Binary files /dev/null and b/nails/nails_6.png differ diff --git a/nails/nails_7.png b/nails/nails_7.png new file mode 100644 index 0000000..4d66691 Binary files /dev/null and b/nails/nails_7.png differ diff --git a/nails/nails_8.png b/nails/nails_8.png new file mode 100644 index 0000000..b898e74 Binary files /dev/null and b/nails/nails_8.png differ diff --git a/nails/nails_9.png b/nails/nails_9.png new file mode 100644 index 0000000..a7e256d Binary files /dev/null and b/nails/nails_9.png differ diff --git a/old/.gitignore b/old/.gitignore new file mode 100644 index 0000000..892eb75 --- /dev/null +++ b/old/.gitignore @@ -0,0 +1,4 @@ +__pycache__ +map_*.pkl +serv +client diff --git a/old/blocks.py b/old/blocks.py new file mode 100644 index 0000000..8cfb651 --- /dev/null +++ b/old/blocks.py @@ -0,0 +1,240 @@ +import pygame +import os +import lib.constants as constants +from lib.gameregistry import GameRegistry +from lib.block import Block +from lib.inventory import Inventory +dy_blocks={} + +def make_block(klass_name,name,clear=False,drops=False): + def blk_init(): + pass + def init(self,x,y,screen): + Block.__init__(self,x,y,screen) + self.setTextureName(name) + self.clear=clear + self.drops=drops + self.unlocalisedName=name + attr_table={ + "unlocalisedName":name, + "__init__":init, + "init":blk_init, + } + klass=type(klass_name,(Block,),attr_table) + GameRegistry.registerBlock(klass,name) + Block.registerTexture(name) + glob=globals() + glob[klass_name]=klass + global dy_blocks + dy_blocks[klass_name]=name + return klass + +make_block("BlockStone","stone") +make_block("BlockTree","tree",False,("wood",8)) +make_block("BlockGrass","grass",True) +make_block("BlockWood","wood") +make_block("BlockCoal","coal_ore") +GameRegistry.registerFuel("coal_ore",8) +make_block("BlockIron","iron_ore") +make_block("ItemIronIngot","iron_ingot",False) +#make_block("ItemCoal","coal",False) +class BlockDoor(Block): + unlocalisedName="door" + openDoor=pygame.image.load(os.path.join("tiles","door_open.png")) + + @classmethod + def init(cls): + GameRegistry.registerBlock(cls,cls.unlocalisedName) + Block.registerTexture(cls.unlocalisedName) + + def __init__(self,x,y,screen): + Block.__init__(self,x,y,screen) + self.setTextureName(BlockDoor.unlocalisedName) + self.unlocalisedName=BlockDoor.unlocalisedName + + def interact(self,inv): + self.clear=not self.clear + pygame.mixer.Sound("door.ogg").play().set_volume(0.2) + + def getTexture(self): + if self.clear: + return BlockDoor.openDoor + else: + return False + + def interactData(self): + return {"clear":self.clear} + + def loadData(self,data): + self.clear=data["clear"] + +class BlockWorkbench(Block): + unlocalisedName="workbench" + + @classmethod + def init(cls): + GameRegistry.registerBlock(cls,cls.unlocalisedName) + Block.registerTexture(cls.unlocalisedName) + + def __init__(self,x,y,screen): + Block.__init__(self,x,y,screen) + self.setTextureName(BlockWorkbench.unlocalisedName) + self.unlocalisedName=BlockWorkbench.unlocalisedName + self.inv=Inventory() + + def interact(self,inv): + selected=inv.selected + if selected!="": + inv.remove(selected) + self.inv.addTile(selected,1) + else: + if self.inv.inv in GameRegistry.recipes.values(): + out="" + for outp,reqs in GameRegistry.recipes.items(): + if self.inv.inv==reqs: + out=outp + break + inv.addTile(out,1) + self.inv.clear() + + def interactData(self): + return {"inv":self.inv} + + def loadData(self,data): + self.inv=data["inv"] + +class BlockFurnace(Block): + unlocalisedName="furnace" + frames=[] + + @classmethod + def init(cls): + GameRegistry.registerBlock(cls,cls.unlocalisedName) + Block.registerTexture(cls.unlocalisedName) + for i in range(3): + path=os.path.join("animation",cls.unlocalisedName,"{}.png".format(i)) + img=pygame.image.load(path) + cls.frames.append(img) + + def __init__(self,x,y,screen): + Block.__init__(self,x,y,screen) + self.setTextureName(BlockFurnace.unlocalisedName) + self.unlocalisedName=BlockFurnace.unlocalisedName + self.frameno=0 + self.forward=True + self.burn=False + self.count=0 + self.inp="" + self.inp_amount=0 + self.outp="" + self.outp_amount=0 + self.fuel="" + self.fuel_amount=0 + self.fuel_num=0 + self.originator=True + + def interact(self,inv): + sel=inv.selected + if sel!="": + if sel in GameRegistry.fuels.keys(): + if self.fuel!="" and sel!=self.fuel: + return + self.fuel=sel + self.fuel_num=GameRegistry.fuels[sel] + self.fuel_amount+=1 + if self.inp!="": + if self.burn==False: + self.fuel_amount-=1 + self.burn=True + else: + if self.inp!="" and sel!=self.inp: + return + if not sel in GameRegistry.smelting.keys(): + return + self.inp_amount+=1 + self.inp=sel + if self.burn==False and self.fuel!="": + self.fuel_amount-=1 + self.burn=True + inv.remove(sel) + else: + if self.outp!="": + inv.addTile(self.outp,self.outp_amount) + self.outp="" + self.outp_amount=0 + self.originator=True + + def getTexture(self): + if self.burn: + self.count+=1 + if self.count==10: + self.update() + self.count=0 + img=BlockFurnace.frames[self.frameno] + if self.forward: + self.frameno+=1 + if self.frameno>2: + self.frameno=1 + self.forward=False + else: + self.frameno-=1 + if self.frameno<0: + self.frameno=1 + self.forward=True + return img + else: + return False + self.mp_upd=True + + def update(self): + self.fuel_num-=1 + if self.inp=="": + self.burn=False + return + if self.fuel_num<=0: + if self.fuel_amount<=0: + self.burn=False + self.fuel="" + return + else: + self.fuel_amount-=1 + self.fuel_num=GameRegistry.fuels[self.fuel] + if self.inp!="": + if self.inp in GameRegistry.smelting: + self.inp_amount-=1 + self.outp=GameRegistry.smelting[self.inp] + self.outp_amount+=1 + if self.inp_amount<=0: + self.inp="" + if self.originator: + self.mp_upd=True + + def loadData(self,data): + self.frameno=data["frameno"] + self.forward=data["forward"] + self.burn=data["burn"] + self.count=data["count"] + self.inp=data["inp"] + self.inp_amount=data["inp_amount"] + self.outp=data["outp"] + self.outp_amount=data["outp_amount"] + self.fuel=data["fuel"] + self.fuel_amount=data["fuel_amount"] + self.fuel_num=data["fuel_num"] + self.originator=False + + def interactData(self): + self.mp_upd=False + return { + "frameno":self.frameno, + "forward":self.forward, + "burn":self.burn, + "count":self.count, + "inp":self.inp, + "inp_amount":self.inp_amount, + "outp":self.outp, + "outp_amount":self.outp_amount, + "fuel":self.fuel, + "fuel_amount":self.fuel_amount, + "fuel_num":self.fuel_num + } diff --git a/old/client.py b/old/client.py new file mode 100644 index 0000000..9350d11 --- /dev/null +++ b/old/client.py @@ -0,0 +1,292 @@ +import pygame +import os +import random +import recipes +import sys +import select +import blocks +import socket +import pickle +import lib.constants as constants +from lib.gameregistry import GameRegistry +from lib.map import Map +from lib.character import Character +from lib.block import Block +from lib.player import Player +from lib.player_img import PlayerImg +from showstep import show_step +from time import sleep +import pprint + +pp=pprint.PrettyPrinter(indent=2) + +def recv_str(sock,print_str=True): + str="" + ch="" + while True: + ch=sock.recv(1).decode("utf-8") + if ch=="\n": + break + str+=ch + if print_str: + pass + # print("Got string: "+str) + return str + +def send_str(sock,str): + # print("Sending string: "+str) + sock.send((str+"\n").encode("utf-8")) + +def recv_hash(sock): + hash={} + len=int(recv_str(sock,False)) + for _ in range(len): + key=recv_str(sock,False) + val=recv_str(sock,False) + hash[key]=val + # print("Got hash: "+pp.pformat(hash)) + return hash + +def recvall(sock): + BUFF_SIZE=4096 + data=b'' + while True: + part=sock.recv(BUFF_SIZE) + data+=part + if len(part) [count]") + for event in pygame.event.get(): + if event.type==pygame.QUIT: + running=False + elif event.type==pygame.KEYDOWN: + print("DOWN") + print(event.key) + if event.key==pygame.K_PERIOD: + coords=player.facingTile() + if coords!=False: + tile=map.tileAt(coords[0],coords[1]) + name=tile.unlocalisedName + if name=="grass": + to_place=player.inv.selected + if to_place!="": + send_str(sock,"PLACE_BLOCK_AT") + send_str(sock,str(my_uid)) + send_str(sock,str(coords[0])) + send_str(sock,str(coords[1])) + send_str(sock,str(to_place)) + player.interact() + else: + player.interact() + tile=map.tileAt(coords[0],coords[1]) + data=tile.interactData() + if data!=None: + send_str(sock,"INTERACT_BLOCK_AT") + send_str(sock,str(my_uid)) + send_str(sock,str(coords[0])) + send_str(sock,str(coords[1])) + data_string=pickle.dumps(data) + sock.send(data_string) + if event.key==pygame.K_SLASH: + player.attack() + facing=player.facingTile() + print(facing) + if facing!=False: + print("BREAK") + x=facing[0] + y=facing[1] + send_str(sock,"BREAK_BLOCK_AT") + send_str(sock,str(my_uid)) + send_str(sock,str(x)) + send_str(sock,str(y)) + if event.key==pygame.K_j: + player.inv.selPrev() + if event.key==pygame.K_k: + player.inv.clearSel() + if event.key==pygame.K_l: + player.inv.selNext() + if event.key==pygame.K_e: + inv=not inv + if event.key==pygame.K_i: + dy_blocks=blocks.dy_blocks + Block.textures={} + Block.init() + for klass,unName in dy_blocks.items(): + Block.registerTexture(unName) + elif event.key in key_to_dir.keys(): + move=True + dir=key_to_dir[event.key] + elif event.type==pygame.KEYUP: + move=False + player.frame=1 + if move: + player.move(dir) + send_str(sock,"SET_POS_FOR_UID") + send_str(sock,str(my_uid)) + send_str(sock,str(player.x)) + send_str(sock,str(player.y)) + send_str(sock,player.dir) + if inv: + screen.fill([255,255,255]) + text=[] + label=[] + for item, count in player.inv.inv.items(): + text.append("{} {}".format(count,item)) + for line in text: + label.append(helvetica_neue.render(line, True, (0,0,0))) + for line in range(len(label)): + screen.blit(label[line],(1,(line*constants.FONTSIZE)+(2*line))) + pygame.display.flip() + else: + screen.fill([0,0,0]) + map.draw(player.x,player.y) + player.draw() + selected=player.inv.selected + if selected!="": + texture=Block.textures[selected] + screen.blit(texture,(0*constants.TILESIZE,constants.PORTHEIGHT*constants.TILESIZE)) + topleftx=player.x-constants.CENTERX + toplefty=player.y-constants.CENTERY + x=topleftx + y=toplefty + while True: + other=None + for uname,o in others.items(): + if o.x==x and o.y==y: + other=o + break + if other: + other.draw(x-topleftx,y-toplefty) + x+=1 + if x==topleftx+constants.PORTWIDTH: + x=topleftx + y+=1 + if y==toplefty+constants.PORTHEIGHT: + break + pygame.display.flip() + sleep(0.1) +send_str(sock,"CLOSE") +send_str(sock,UNAME) +sock.close() diff --git a/old/dist_all b/old/dist_all new file mode 100755 index 0000000..b7135d5 --- /dev/null +++ b/old/dist_all @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +./dist_client +./dist_serv diff --git a/old/dist_client b/old/dist_client new file mode 100755 index 0000000..45af281 --- /dev/null +++ b/old/dist_client @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +rm -rf client +mkdir client +mkdir client/code +cp -r lib sprites tiles animation blocks.py recipes.py showstep.py client/code +cp client.py client/code +echo "#!/usr/bin/env bash +cd code +python3 client.py +cd .." > client/run +chmod u+x client/run diff --git a/old/dist_serv b/old/dist_serv new file mode 100755 index 0000000..7e4dc9b --- /dev/null +++ b/old/dist_serv @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +rm -rf serv +mkdir serv +mkdir serv/code +mkdir serv/worlds +cp -r lib blocks.py recipes.py serv/code +cp serv.py serv/code +echo "#!/usr/bin/env bash +python3 code/serv.py" > serv/run +chmod u+x serv/run diff --git a/old/door.ogg b/old/door.ogg new file mode 100644 index 0000000..fc7fe88 Binary files /dev/null and b/old/door.ogg differ diff --git a/old/lib/__init__.py b/old/lib/__init__.py new file mode 100644 index 0000000..d1eb679 --- /dev/null +++ b/old/lib/__init__.py @@ -0,0 +1,2 @@ +from . import block,constants,gameregistry,map,character,inventory,player,player_img +__all__=["block","gameregistry","map","character","inventory","player","player_img"] diff --git a/old/lib/block.py b/old/lib/block.py new file mode 100644 index 0000000..9d14285 --- /dev/null +++ b/old/lib/block.py @@ -0,0 +1,55 @@ +from pygame.sprite import Sprite +import pygame.image +import os +from time import sleep +from . import constants +class Block(Sprite): + textures={} + background=pygame.image.load(os.path.join("tiles","{}.png".format(constants.BACKGROUND))) + @classmethod + def init(cls): + subclasses=cls.__subclasses__() + for klass in subclasses: + klass.init() + + def __init__(self,x,y,screen): + super().__init__() + self.x=x + self.y=y + self.screen=screen + self.tname=None + self.clear=False + self.unlocalisedName="" + self.drops=False + self.mp_upd=False + + def draw(self,x,y): + # print("DRAW BLOCK") + if self.tname==None: + raise Exception("No texture name for block. Did you forget to call setTextureName()?".format()) + self.screen.blit(Block.background,(x*constants.TILESIZE,y*constants.TILESIZE)) + texture=self.getTexture() + if texture==False: + texture=Block.textures[self.tname] + self.screen.blit(texture,(x*constants.TILESIZE,y*constants.TILESIZE)) + # sleep(0.05) + def setTextureName(self,name): + if not name in Block.textures.keys(): + raise Exception("{} is not a valid texture. Did you forget to call registerTexture(\"{}\")?".format(name,name)) + self.tname=name + + @classmethod + def registerTexture(cls,name): + Block.textures[name]=pygame.image.load(os.path.join("tiles","{}.png".format(name))) + + def interact(self,inv): + pass + + def getTexture(self): + return False + + def interactData(self): + return None + + def loadData(self,data): + pass diff --git a/old/lib/character.py b/old/lib/character.py new file mode 100644 index 0000000..21bd49d --- /dev/null +++ b/old/lib/character.py @@ -0,0 +1,53 @@ +from pygame.sprite import Sprite +import pygame.image +import os +from . import constants +class Character(Sprite): + @staticmethod + def loadFrames(type): + frames={} + dirs=["up","down","left","right"] + num_frames=3 + for dir in dirs: + frame_array=[0,0,0] + i=0 + while i2: + self.frame=0 + tile=self.map.tileAt(self.x,self.y) + if not tile.clear: + self.x=old_x + self.y=old_y diff --git a/old/lib/constants.py b/old/lib/constants.py new file mode 100644 index 0000000..d39dcac --- /dev/null +++ b/old/lib/constants.py @@ -0,0 +1,12 @@ +TILESIZE=16 +MAPWIDTH=64 +MAPHEIGHT=64 +PORTHEIGHT=32 +PORTWIDTH=32 +EXTRAROWS=1 +CENTERX=15 +CENTERY=15 +WINDWIDTH=PORTWIDTH*TILESIZE +WINDHEIGHT=(PORTHEIGHT+EXTRAROWS)*TILESIZE +BACKGROUND="grass" +FONTSIZE=30 diff --git a/old/lib/gameregistry.py b/old/lib/gameregistry.py new file mode 100644 index 0000000..cfcf95a --- /dev/null +++ b/old/lib/gameregistry.py @@ -0,0 +1,25 @@ +class GameRegistry: + block_classes={} + recipes={} + smelting={} + fuels={} + + @classmethod + def registerBlock(cls,klass,name): + if not klass in cls.block_classes.keys(): + cls.block_classes[name]=klass + + @classmethod + def registerCrafting(cls,reqs,result): + if not result in cls.recipes.keys(): + cls.recipes[result]=reqs + + @classmethod + def registerSmelting(cls,inp,outp): + if not inp in cls.smelting.keys(): + cls.smelting[inp]=outp + + @classmethod + def registerFuel(cls,name,amount): + if not name in cls.fuels.keys(): + cls.fuels[name]=amount diff --git a/old/lib/inventory.py b/old/lib/inventory.py new file mode 100644 index 0000000..f2a3fe6 --- /dev/null +++ b/old/lib/inventory.py @@ -0,0 +1,51 @@ +class Inventory: + def __init__(self): + self.inv={} + self.selected="" + + def addTile(self,name,amount): + if name in self.inv.keys(): + self.inv[name]+=amount + else: + self.inv[name]=amount + self.selected=name + + def remove(self,name,num=1): + if not name in self.inv: + raise Exception("No {} in inventory".format(name)) + amount=self.inv[name] + amount-=num + if amount<0: + raise Exception("Attempted to remove more {} than avalible".format(name)) + self.inv[name]=amount + if amount==0: + del self.inv[name] + self.selected="" + + def selPrev(self): + newsel="" + for item, count in self.inv.items(): + if item==self.selected: + break + newsel=item + if newsel!="": + self.selected=newsel + + def clearSel(self): + self.selected="" + + def selNext(self): + newsel="" + ok_next=False + for item, count in self.inv.items(): + if ok_next: + newsel=item + break + if item==self.selected: + ok_next=True + if newsel!="": + self.selected=newsel + + def clear(self): + self.inv={} + self.selected="" diff --git a/old/lib/map.py b/old/lib/map.py new file mode 100644 index 0000000..0da77bf --- /dev/null +++ b/old/lib/map.py @@ -0,0 +1,107 @@ +import pygame +import random +from pygame.sprite import Group +from . import block,gameregistry +from . import constants +from .gameregistry import GameRegistry +from .block import Block +import pickle +class Map: + def __init__(self,screen,sock=None,uid=None): + super().__init__() + self.tiles={} + self.screen=screen + self.sock=sock + self.uid=uid + self.generate() + + def send_str(self,sock,str): + # print(str) + sock.send((str+"\n").encode("utf-8")) + + def recvall(self,sock): + BUFF_SIZE=4096 + data=b'' + while True: + part=sock.recv(BUFF_SIZE) + data+=part + if len(part)constants.MAPWIDTH-1: + return False + if x<0: + return False + if y>constants.MAPHEIGHT-1: + return False + if y<0: + return False + return (x,y) + + def interact(self): + coords=self.facingTile() + if coords==False: + return + tile=self.map.tileAt(coords[0],coords[1]) + name=tile.unlocalisedName + if name=="grass": + to_place=self.inv.selected + if to_place=="": + return + self.map.tiles[(coords[0],coords[1])]=None + self.map.addTile(to_place,coords[0],coords[1]) + self.inv.remove(to_place) + else: + tile.interact(self.inv) + + def attack(self): + coords=self.facingTile() + if coords==False: + return + tile=self.map.tileAt(coords[0],coords[1]) + name=tile.unlocalisedName + if name=="grass": + return + self.map.tiles[(coords[0],coords[1])]=None + self.map.addTile("grass",coords[0],coords[1]) + if tile.drops==False: + self.inv.addTile(name,1) + else: + drop=tile.drops[0] + amount=tile.drops[1] + self.inv.addTile(drop,amount) + + def draw(self): + oldx=self.x + oldy=self.y + self.x=constants.CENTERX + self.y=constants.CENTERY + super().draw() + self.x=oldx + self.y=oldy diff --git a/old/lib/player_img.py b/old/lib/player_img.py new file mode 100644 index 0000000..3d66c51 --- /dev/null +++ b/old/lib/player_img.py @@ -0,0 +1,33 @@ +from pygame.sprite import Sprite +import pygame.image +import os +import lib.constants as constants +class PlayerImg(Sprite): + @staticmethod + def loadFrames(type): + frames={} + dirs=["up","down","left","right"] + num_frames=3 + for dir in dirs: + frame_array=[0,0,0] + i=0 + while i0: + if cmd[0]=="stop": + s.close() + f=open("worlds/map_{}.pkl".format(map_name),"wb") + pickle.dump(map,f) + f.close() + exit(1) + +def exit_cleanup(signal,frame): + s.close() + f=open("worlds/map_{}.pkl".format(map_name),"wb") + pickle.dump(map,f) + f.close() + +Block.init() +files=glob.glob("worlds/map_*.pkl") +if len(files)==0: + new="y" +else: + new=input("New world?").lower() +if new=="n" or new=="no": + i=1 + map_map=[] + for name in files: + name=name.split("_") + name.pop(0) + name="_".join(name) + name,_=os.path.splitext(name) + print("{}. {}".format(i,name)) + map_map.append(name) + i+=1 + map_name=map_map[int(input("Which world?"))-1] + f=open("worlds/map_{}.pkl".format(map_name),"rb") + map=pickle.load(f) + f.close() +else: + map_name=input("World name:") + map=Map(None) + +s=socket.socket() +s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +host="localhost" +port=2000 +s.bind((host, port)) +s.listen(5) +_thread.start_new_thread(handle_cmds,()) +signal.signal(signal.SIGINT, exit_cleanup) +while True: + c,addr=s.accept() + _thread.start_new_thread(on_new_client,(c,)) diff --git a/old/showstep.py b/old/showstep.py new file mode 100644 index 0000000..60e9825 --- /dev/null +++ b/old/showstep.py @@ -0,0 +1,3 @@ +def show_step(step): + print(step) + input("Press enter to proceed") diff --git a/sprites/player/down_0.png b/sprites/player/down_0.png new file mode 100644 index 0000000..6b1cae0 Binary files /dev/null and b/sprites/player/down_0.png differ diff --git a/sprites/player/down_1.png b/sprites/player/down_1.png new file mode 100644 index 0000000..3d7724b Binary files /dev/null and b/sprites/player/down_1.png differ diff --git a/sprites/player/down_2.png b/sprites/player/down_2.png new file mode 100644 index 0000000..7d7085c Binary files /dev/null and b/sprites/player/down_2.png differ diff --git a/sprites/player/left_0.png b/sprites/player/left_0.png new file mode 100644 index 0000000..4da3051 Binary files /dev/null and b/sprites/player/left_0.png differ diff --git a/sprites/player/left_1.png b/sprites/player/left_1.png new file mode 100644 index 0000000..40b786f Binary files /dev/null and b/sprites/player/left_1.png differ diff --git a/sprites/player/left_2.png b/sprites/player/left_2.png new file mode 100644 index 0000000..8aa3e89 Binary files /dev/null and b/sprites/player/left_2.png differ diff --git a/sprites/player/right_0.png b/sprites/player/right_0.png new file mode 100644 index 0000000..e2e0b73 Binary files /dev/null and b/sprites/player/right_0.png differ diff --git a/sprites/player/right_1.png b/sprites/player/right_1.png new file mode 100644 index 0000000..c7e91d4 Binary files /dev/null and b/sprites/player/right_1.png differ diff --git a/sprites/player/right_2.png b/sprites/player/right_2.png new file mode 100644 index 0000000..20e15ba Binary files /dev/null and b/sprites/player/right_2.png differ diff --git a/sprites/player/up_0.png b/sprites/player/up_0.png new file mode 100644 index 0000000..88ca813 Binary files /dev/null and b/sprites/player/up_0.png differ diff --git a/sprites/player/up_1.png b/sprites/player/up_1.png new file mode 100644 index 0000000..962c39d Binary files /dev/null and b/sprites/player/up_1.png differ diff --git a/sprites/player/up_2.png b/sprites/player/up_2.png new file mode 100644 index 0000000..7230655 Binary files /dev/null and b/sprites/player/up_2.png differ diff --git a/sprites/player_local/down_0.png b/sprites/player_local/down_0.png new file mode 100644 index 0000000..5a3c29a Binary files /dev/null and b/sprites/player_local/down_0.png differ diff --git a/sprites/player_local/down_1.png b/sprites/player_local/down_1.png new file mode 100644 index 0000000..6823682 Binary files /dev/null and b/sprites/player_local/down_1.png differ diff --git a/sprites/player_local/down_2.png b/sprites/player_local/down_2.png new file mode 100644 index 0000000..8d563fb Binary files /dev/null and b/sprites/player_local/down_2.png differ diff --git a/sprites/player_local/left_0.png b/sprites/player_local/left_0.png new file mode 100644 index 0000000..b9aee28 Binary files /dev/null and b/sprites/player_local/left_0.png differ diff --git a/sprites/player_local/left_1.png b/sprites/player_local/left_1.png new file mode 100644 index 0000000..ac63bb0 Binary files /dev/null and b/sprites/player_local/left_1.png differ diff --git a/sprites/player_local/left_2.png b/sprites/player_local/left_2.png new file mode 100644 index 0000000..c5d647a Binary files /dev/null and b/sprites/player_local/left_2.png differ diff --git a/sprites/player_local/right_0.png b/sprites/player_local/right_0.png new file mode 100644 index 0000000..dd94883 Binary files /dev/null and b/sprites/player_local/right_0.png differ diff --git a/sprites/player_local/right_1.png b/sprites/player_local/right_1.png new file mode 100644 index 0000000..43c5415 Binary files /dev/null and b/sprites/player_local/right_1.png differ diff --git a/sprites/player_local/right_2.png b/sprites/player_local/right_2.png new file mode 100644 index 0000000..c0fd312 Binary files /dev/null and b/sprites/player_local/right_2.png differ diff --git a/sprites/player_local/up_0.png b/sprites/player_local/up_0.png new file mode 100644 index 0000000..32cbcb1 Binary files /dev/null and b/sprites/player_local/up_0.png differ diff --git a/sprites/player_local/up_1.png b/sprites/player_local/up_1.png new file mode 100644 index 0000000..fcb6c6c Binary files /dev/null and b/sprites/player_local/up_1.png differ diff --git a/sprites/player_local/up_2.png b/sprites/player_local/up_2.png new file mode 100644 index 0000000..d0b12d2 Binary files /dev/null and b/sprites/player_local/up_2.png differ diff --git a/sprites/slime/down_0.png b/sprites/slime/down_0.png new file mode 100644 index 0000000..fa205be Binary files /dev/null and b/sprites/slime/down_0.png differ diff --git a/sprites/slime/down_1.png b/sprites/slime/down_1.png new file mode 100644 index 0000000..4ca4bd6 Binary files /dev/null and b/sprites/slime/down_1.png differ diff --git a/sprites/slime/down_2.png b/sprites/slime/down_2.png new file mode 100644 index 0000000..0328ba0 Binary files /dev/null and b/sprites/slime/down_2.png differ diff --git a/sprites/slime/left_0.png b/sprites/slime/left_0.png new file mode 100644 index 0000000..e50a9c0 Binary files /dev/null and b/sprites/slime/left_0.png differ diff --git a/sprites/slime/left_1.png b/sprites/slime/left_1.png new file mode 100644 index 0000000..8045c51 Binary files /dev/null and b/sprites/slime/left_1.png differ diff --git a/sprites/slime/left_2.png b/sprites/slime/left_2.png new file mode 100644 index 0000000..c884dfd Binary files /dev/null and b/sprites/slime/left_2.png differ diff --git a/sprites/slime/right_0.png b/sprites/slime/right_0.png new file mode 100644 index 0000000..7bc5749 Binary files /dev/null and b/sprites/slime/right_0.png differ diff --git a/sprites/slime/right_1.png b/sprites/slime/right_1.png new file mode 100644 index 0000000..8d46baa Binary files /dev/null and b/sprites/slime/right_1.png differ diff --git a/sprites/slime/right_2.png b/sprites/slime/right_2.png new file mode 100644 index 0000000..bcbd689 Binary files /dev/null and b/sprites/slime/right_2.png differ diff --git a/sprites/slime/up_0.png b/sprites/slime/up_0.png new file mode 100644 index 0000000..021b547 Binary files /dev/null and b/sprites/slime/up_0.png differ diff --git a/sprites/slime/up_1.png b/sprites/slime/up_1.png new file mode 100644 index 0000000..416171f Binary files /dev/null and b/sprites/slime/up_1.png differ diff --git a/sprites/slime/up_2.png b/sprites/slime/up_2.png new file mode 100644 index 0000000..cd8deff Binary files /dev/null and b/sprites/slime/up_2.png differ diff --git a/things.png b/things.png new file mode 100644 index 0000000..b0de579 Binary files /dev/null and b/things.png differ diff --git a/tiles/bed_bot.png b/tiles/bed_bot.png new file mode 100644 index 0000000..eb18a65 Binary files /dev/null and b/tiles/bed_bot.png differ diff --git a/tiles/bed_top.png b/tiles/bed_top.png new file mode 100644 index 0000000..2068a7e Binary files /dev/null and b/tiles/bed_top.png differ diff --git a/tiles/brick.png b/tiles/brick.png new file mode 100644 index 0000000..6e0aa79 Binary files /dev/null and b/tiles/brick.png differ diff --git a/tiles/chest.png b/tiles/chest.png new file mode 100644 index 0000000..d46b947 Binary files /dev/null and b/tiles/chest.png differ diff --git a/tiles/chest_open.png b/tiles/chest_open.png new file mode 100644 index 0000000..529ec1d Binary files /dev/null and b/tiles/chest_open.png differ diff --git a/tiles/coal_ore.png b/tiles/coal_ore.png new file mode 100644 index 0000000..5e855c0 Binary files /dev/null and b/tiles/coal_ore.png differ diff --git a/tiles/cobblestone.png b/tiles/cobblestone.png new file mode 100644 index 0000000..7202db4 Binary files /dev/null and b/tiles/cobblestone.png differ diff --git a/tiles/door.png b/tiles/door.png new file mode 100644 index 0000000..389583e Binary files /dev/null and b/tiles/door.png differ diff --git a/tiles/door_open.png b/tiles/door_open.png new file mode 100644 index 0000000..049f01b Binary files /dev/null and b/tiles/door_open.png differ diff --git a/tiles/furnace.png b/tiles/furnace.png new file mode 100644 index 0000000..0b7920e Binary files /dev/null and b/tiles/furnace.png differ diff --git a/tiles/grass.png b/tiles/grass.png new file mode 100644 index 0000000..dfca6ea Binary files /dev/null and b/tiles/grass.png differ diff --git a/tiles/iron_ingot.png b/tiles/iron_ingot.png new file mode 100644 index 0000000..88237de Binary files /dev/null and b/tiles/iron_ingot.png differ diff --git a/tiles/iron_ore.png b/tiles/iron_ore.png new file mode 100644 index 0000000..3308e10 Binary files /dev/null and b/tiles/iron_ore.png differ diff --git a/tiles/stone.png b/tiles/stone.png new file mode 100644 index 0000000..cd7d473 Binary files /dev/null and b/tiles/stone.png differ diff --git a/tiles/texture10.png b/tiles/texture10.png new file mode 100644 index 0000000..98e938d Binary files /dev/null and b/tiles/texture10.png differ diff --git a/tiles/texture11.png b/tiles/texture11.png new file mode 100644 index 0000000..1e2c2c6 Binary files /dev/null and b/tiles/texture11.png differ diff --git a/tiles/texture12.png b/tiles/texture12.png new file mode 100644 index 0000000..dfca6ea Binary files /dev/null and b/tiles/texture12.png differ diff --git a/tiles/texture13.png b/tiles/texture13.png new file mode 100644 index 0000000..78d57fa Binary files /dev/null and b/tiles/texture13.png differ diff --git a/tiles/texture14.png b/tiles/texture14.png new file mode 100644 index 0000000..a11d326 Binary files /dev/null and b/tiles/texture14.png differ diff --git a/tiles/texture15.png b/tiles/texture15.png new file mode 100644 index 0000000..d787a45 Binary files /dev/null and b/tiles/texture15.png differ diff --git a/tiles/texture16.png b/tiles/texture16.png new file mode 100644 index 0000000..92fb7a8 Binary files /dev/null and b/tiles/texture16.png differ diff --git a/tiles/texture18.png b/tiles/texture18.png new file mode 100644 index 0000000..342d360 Binary files /dev/null and b/tiles/texture18.png differ diff --git a/tiles/texture19.png b/tiles/texture19.png new file mode 100644 index 0000000..0a05c29 Binary files /dev/null and b/tiles/texture19.png differ diff --git a/tiles/texture20.png b/tiles/texture20.png new file mode 100644 index 0000000..8e951ed Binary files /dev/null and b/tiles/texture20.png differ diff --git a/tiles/texture21.png b/tiles/texture21.png new file mode 100644 index 0000000..42ef5bc Binary files /dev/null and b/tiles/texture21.png differ diff --git a/tiles/texture22.png b/tiles/texture22.png new file mode 100644 index 0000000..36dc41b Binary files /dev/null and b/tiles/texture22.png differ diff --git a/tiles/texture23.png b/tiles/texture23.png new file mode 100644 index 0000000..04dfb4a Binary files /dev/null and b/tiles/texture23.png differ diff --git a/tiles/texture24.png b/tiles/texture24.png new file mode 100644 index 0000000..3423a4b Binary files /dev/null and b/tiles/texture24.png differ diff --git a/tiles/texture25.png b/tiles/texture25.png new file mode 100644 index 0000000..477aa28 Binary files /dev/null and b/tiles/texture25.png differ diff --git a/tiles/texture26.png b/tiles/texture26.png new file mode 100644 index 0000000..d1a3521 Binary files /dev/null and b/tiles/texture26.png differ diff --git a/tiles/texture27.png b/tiles/texture27.png new file mode 100644 index 0000000..bfeca9d Binary files /dev/null and b/tiles/texture27.png differ diff --git a/tiles/texture28.png b/tiles/texture28.png new file mode 100644 index 0000000..43408d9 Binary files /dev/null and b/tiles/texture28.png differ diff --git a/tiles/texture29.png b/tiles/texture29.png new file mode 100644 index 0000000..f646d84 Binary files /dev/null and b/tiles/texture29.png differ diff --git a/tiles/texture30.png b/tiles/texture30.png new file mode 100644 index 0000000..b0f8587 Binary files /dev/null and b/tiles/texture30.png differ diff --git a/tiles/texture31.png b/tiles/texture31.png new file mode 100644 index 0000000..c1f10db Binary files /dev/null and b/tiles/texture31.png differ diff --git a/tiles/texture32.png b/tiles/texture32.png new file mode 100644 index 0000000..762e1ba Binary files /dev/null and b/tiles/texture32.png differ diff --git a/tiles/texture33.png b/tiles/texture33.png new file mode 100644 index 0000000..6a19463 Binary files /dev/null and b/tiles/texture33.png differ diff --git a/tiles/texture34.png b/tiles/texture34.png new file mode 100644 index 0000000..50c7aca Binary files /dev/null and b/tiles/texture34.png differ diff --git a/tiles/texture35.png b/tiles/texture35.png new file mode 100644 index 0000000..1b265ad Binary files /dev/null and b/tiles/texture35.png differ diff --git a/tiles/texture38.png b/tiles/texture38.png new file mode 100644 index 0000000..792fbc5 Binary files /dev/null and b/tiles/texture38.png differ diff --git a/tiles/texture39.png b/tiles/texture39.png new file mode 100644 index 0000000..4902856 Binary files /dev/null and b/tiles/texture39.png differ diff --git a/tiles/texture40.png b/tiles/texture40.png new file mode 100644 index 0000000..14a36c8 Binary files /dev/null and b/tiles/texture40.png differ diff --git a/tiles/texture41.png b/tiles/texture41.png new file mode 100644 index 0000000..e73276a Binary files /dev/null and b/tiles/texture41.png differ diff --git a/tiles/texture42.png b/tiles/texture42.png new file mode 100644 index 0000000..d03a23f Binary files /dev/null and b/tiles/texture42.png differ diff --git a/tiles/texture43.png b/tiles/texture43.png new file mode 100644 index 0000000..e06fd01 Binary files /dev/null and b/tiles/texture43.png differ diff --git a/tiles/texture44.png b/tiles/texture44.png new file mode 100644 index 0000000..cc8ca02 Binary files /dev/null and b/tiles/texture44.png differ diff --git a/tiles/texture46.png b/tiles/texture46.png new file mode 100644 index 0000000..8cabbb1 Binary files /dev/null and b/tiles/texture46.png differ diff --git a/tiles/texture47.png b/tiles/texture47.png new file mode 100644 index 0000000..f0c3c1a Binary files /dev/null and b/tiles/texture47.png differ diff --git a/tiles/texture49.png b/tiles/texture49.png new file mode 100644 index 0000000..b3bb710 Binary files /dev/null and b/tiles/texture49.png differ diff --git a/tiles/texture50.png b/tiles/texture50.png new file mode 100644 index 0000000..c9342be Binary files /dev/null and b/tiles/texture50.png differ diff --git a/tiles/texture51.png b/tiles/texture51.png new file mode 100644 index 0000000..bdea999 Binary files /dev/null and b/tiles/texture51.png differ diff --git a/tiles/texture52.png b/tiles/texture52.png new file mode 100644 index 0000000..e6d251f Binary files /dev/null and b/tiles/texture52.png differ diff --git a/tiles/texture55.png b/tiles/texture55.png new file mode 100644 index 0000000..f24573c Binary files /dev/null and b/tiles/texture55.png differ diff --git a/tiles/texture56.png b/tiles/texture56.png new file mode 100644 index 0000000..f88ef8f Binary files /dev/null and b/tiles/texture56.png differ diff --git a/tiles/texture57.png b/tiles/texture57.png new file mode 100644 index 0000000..c2c8b97 Binary files /dev/null and b/tiles/texture57.png differ diff --git a/tiles/texture58.png b/tiles/texture58.png new file mode 100644 index 0000000..b336f12 Binary files /dev/null and b/tiles/texture58.png differ diff --git a/tiles/texture59.png b/tiles/texture59.png new file mode 100644 index 0000000..4bd555b Binary files /dev/null and b/tiles/texture59.png differ diff --git a/tiles/texture6.png b/tiles/texture6.png new file mode 100644 index 0000000..cd73593 Binary files /dev/null and b/tiles/texture6.png differ diff --git a/tiles/texture60.png b/tiles/texture60.png new file mode 100644 index 0000000..8d10d4c Binary files /dev/null and b/tiles/texture60.png differ diff --git a/tiles/texture61.png b/tiles/texture61.png new file mode 100644 index 0000000..db490ae Binary files /dev/null and b/tiles/texture61.png differ diff --git a/tiles/texture62.png b/tiles/texture62.png new file mode 100644 index 0000000..a2796f3 Binary files /dev/null and b/tiles/texture62.png differ diff --git a/tiles/texture63.png b/tiles/texture63.png new file mode 100644 index 0000000..065b396 Binary files /dev/null and b/tiles/texture63.png differ diff --git a/tiles/texture64.png b/tiles/texture64.png new file mode 100644 index 0000000..5377634 Binary files /dev/null and b/tiles/texture64.png differ diff --git a/tiles/texture65.png b/tiles/texture65.png new file mode 100644 index 0000000..495d3df Binary files /dev/null and b/tiles/texture65.png differ diff --git a/tiles/texture66.png b/tiles/texture66.png new file mode 100644 index 0000000..dfd8af4 Binary files /dev/null and b/tiles/texture66.png differ diff --git a/tiles/texture67.png b/tiles/texture67.png new file mode 100644 index 0000000..1a90b42 Binary files /dev/null and b/tiles/texture67.png differ diff --git a/tiles/texture68.png b/tiles/texture68.png new file mode 100644 index 0000000..6880cbd Binary files /dev/null and b/tiles/texture68.png differ diff --git a/tiles/texture69.png b/tiles/texture69.png new file mode 100644 index 0000000..5798156 Binary files /dev/null and b/tiles/texture69.png differ diff --git a/tiles/texture70.png b/tiles/texture70.png new file mode 100644 index 0000000..98c0913 Binary files /dev/null and b/tiles/texture70.png differ diff --git a/tiles/texture71.png b/tiles/texture71.png new file mode 100644 index 0000000..c94dcd2 Binary files /dev/null and b/tiles/texture71.png differ diff --git a/tiles/texture72.png b/tiles/texture72.png new file mode 100644 index 0000000..5f092a2 Binary files /dev/null and b/tiles/texture72.png differ diff --git a/tiles/texture73.png b/tiles/texture73.png new file mode 100644 index 0000000..dc1d1f6 Binary files /dev/null and b/tiles/texture73.png differ diff --git a/tiles/texture74.png b/tiles/texture74.png new file mode 100644 index 0000000..5529d67 Binary files /dev/null and b/tiles/texture74.png differ diff --git a/tiles/texture75.png b/tiles/texture75.png new file mode 100644 index 0000000..4dc44f1 Binary files /dev/null and b/tiles/texture75.png differ diff --git a/tiles/texture76.png b/tiles/texture76.png new file mode 100644 index 0000000..fd2c975 Binary files /dev/null and b/tiles/texture76.png differ diff --git a/tiles/texture77.png b/tiles/texture77.png new file mode 100644 index 0000000..a640c18 Binary files /dev/null and b/tiles/texture77.png differ diff --git a/tiles/texture78.png b/tiles/texture78.png new file mode 100644 index 0000000..a7bb37d Binary files /dev/null and b/tiles/texture78.png differ diff --git a/tiles/texture79.png b/tiles/texture79.png new file mode 100644 index 0000000..cd30635 Binary files /dev/null and b/tiles/texture79.png differ diff --git a/tiles/texture80.png b/tiles/texture80.png new file mode 100644 index 0000000..651f5b0 Binary files /dev/null and b/tiles/texture80.png differ diff --git a/tiles/texture81.png b/tiles/texture81.png new file mode 100644 index 0000000..9ec6119 Binary files /dev/null and b/tiles/texture81.png differ diff --git a/tiles/texture82.png b/tiles/texture82.png new file mode 100644 index 0000000..9d87d6e Binary files /dev/null and b/tiles/texture82.png differ diff --git a/tiles/tree.png b/tiles/tree.png new file mode 100644 index 0000000..8e60ada Binary files /dev/null and b/tiles/tree.png differ diff --git a/tiles/wood.png b/tiles/wood.png new file mode 100644 index 0000000..0b8219b Binary files /dev/null and b/tiles/wood.png differ diff --git a/tiles/workbench.png b/tiles/workbench.png new file mode 100644 index 0000000..7da7981 Binary files /dev/null and b/tiles/workbench.png differ