the_lost_digger_v1.py

Created by furicoda

Created on January 14, 2024

15.5 KB


from the_lost_digger_v1_assets import*
menu=True

def updatebombs(s):
  for b in s.bombposlist:
    if (s.PCHX,s.PCHY)==b[0]:
      if ((s.x-b[1][0]*20)**2+(s.y-b[1][1]*20)**2)<225:
        if b[2]:s.dead=1;s.gameover=True
        else:
          texis=getbombtex();f=range
          for x in f(10):
            for y in f(10):
              c=color(198,107,46)
              if texis[x+y*10]==1:c="black"
              if texis[x+y*10]==2:c="yellow"
              set_pixel(b[1][0]*20+5+x,b[1][1]*20+5+y,c)
      else: b[2]=True
def collisionplayer(s,M=[]):
  s.lastx,s.lasty,s.traversable=s.x,s.y,{0,12,13}
  for t in range(4):
    if kd(t):
      s.timerscore+=1
      s.dir,s.indes,d=(3,0,2,1)[t],False,((-1,0,0,1)[t],(0,-1,1,0)[t])
      for sp in range(2,s.speed+2):
        if t==0:c=s.x-sp<1
        if t==1:c=s.y-1<1
        if t==2:c=s.y+11>219
        if t==3:c=s.x+11>319
        if c:
          s.x+=d[0]
          s.y+=d[1]
          s.fuel-=s.consovalue/s.speed
        else:
          tp=[]
          for fyu in range(10):
            if t==0 and 16>int((s.x-sp)/20)>-1 and -1<int((s.y+fyu)/20)<11:tp.append(M[int((s.x-sp)/20)+int((s.y+fyu)/20)*16] in s.traversable)
            if t==1 and -1<int((s.x-sp)/20)<16 and -1<int((s.x+fyu)/20)<16:tp.append(M[int((s.x+fyu)/20)+int((s.y-sp)/20)*16] in s.traversable)
            if t==2 and -1<int((s.y+sp+9)/20)<11 and -1<int((s.x+fyu)/20)<16:tp.append(M[int((s.x+fyu)/20)+int((s.y+sp+9)/20)*16] in s.traversable)
            if t==3 and -1<int((s.x+sp+9)/20)<16 and -1<int((s.y+fyu)/20)<11:tp.append(M[int((s.x+sp+9)/20)+int((s.y+fyu)/20)*16] in s.traversable)
          if not False in tp:
            s.x+=d[0]
            s.y+=d[1]
            s.fuel-=s.consovalue/s.speed
      s.undraw()
      s.draw()


def setvcxy(s,r):
   i=int;sd=s.dir
   if sd==0:vx=i((s.x+5)/20);vy=i(s.y/20)-1-r
   if sd==2:vx=i((s.x+5)/20);vy=i(s.y/20)+1+r
   if sd==1:vx=i(s.x/20)+1+r;vy=i((s.y+5)/20)
   if sd==3:vx=i(s.x/20)-1-r;vy=i((s.y+5)/20)
   return vx,vy
def destruction(s,I,M):
    f=range
    if s.rsclick and not kd(4):s.rsclick=False
    if s.rsclick :return I,M
    if kd(4):
      s.timerscore+=1;s.fuel-=s.consovalue
      if not s.indes:
        s.indes=True;o=0
        for r in f(s.tailleminvalue):
            vx,vy=setvcxy(s,r)
            if -1<vx<16 and -1<vy<11:o+=getlifebloc(M[vx+vy*16])
        s.lifedes=o
      s.rsclick=True;s.lifedes-=s.viminage
      if s.lifedes<=0:
        for r in f(s.tailleminvalue):
            vx,vy=setvcxy(s,r)
            if -1<vx<16 and -1<vy<11: 
                u=vx+vy*16;t=M[u]
                inv=I
                addi=t
                if addi==10:
                  s.fuel+=20
                  if s.fuel>100:s.fuel=100
                elif addi==0:pass
                elif addi==12:pass
                elif s.maxinvplace>sum(inv):inv[addi]+=1
                I=inv
                M[u]=0
                if t!=0:refreshblock(s,vx,vy,M)
        s.indes=False
    return I,M

def generatechunk(s):
  f=range;r=[ran(1,2) for x in f(176)]
  for a in f(ran(10,12)):r[ran(0,175)]=3
  for a in f(ran(8,10)):r[ran(0,175)]=4
  for a in f(ran(6,8)):r[ran(0,175)]=5;r[ran(0,175)]=10
  for a in f(ran(4,6)):r[ran(0,175)]=6
  for a in f(ran(2,4)):r[ran(0,175)]=7
  for a in f(ran(1,2)):r[ran(0,175)]=8
  for s in f(100):
    x=ran(1,14);y=ran(1,9)
    if x+y*16!=88:r[x+y*16]=9;return r
  r[ran(0,175)]=9;return np.array(r)

def affichchunk(posx,posy,s):
  fl(0,220,320,4,"black")
  for xu in range(16):
    for yu in range(11):
      condi=True
      if xu!=15 and mp[str(posx)+"."+str(posy)][xu+1+yu*16]==0:condi=False
      if xu!=0 and mp[str(posx)+"."+str(posy)][xu-1+yu*16]==0:condi=False
      if yu!=10 and mp[str(posx)+"."+str(posy)][xu+(yu+1)*16]==0:condi=False
      if yu!=0 and mp[str(posx)+"."+str(posy)][xu+(yu-1)*16]==0:condi=False
      affitex(xu,yu,condi,mp[str(posx)+"."+str(posy)][xu+yu*16],p)
class Player:
  def __init__(s):
    s.timerscore=0
    s.x=165
    s.y=105
    s.lastx=164
    s.lasty=104
    s.dir=0
    s.indes=False
    s.lifedes=0
    s.rsclick=False
    s.inventoryplpr=10
    s.speedpr=50
    s.fuel=100
    s.money=0
    s.inshop=False
    s.shopallorone=False
    s.shopeleis=False
    s.shopmode=0 
    s.fuelprice=1
    s.viminagepr=100
    s.tailleminpr=1000
    s.tailleminvalue=1
    s.consopr=50
    s.consovalue=0.5
    s.nbofbombs=0
    s.nbofnukes=0
    s.shopbutn=0
    s.viminage=1
    s.speed=1
    s.rsposbomb=False
    s.bombposlist=[]
    s.maxinvplace=10
    s.explolist=[]
    s.gameover=False
    s.dead=0
    s.deltainit=monotonic()
    s.Mape=[]
  def undraw(s):fl(int(s.lastx-1),int(s.lasty-1),12,12,color(198,107,46))
  def draw(s):
    tx,ty=int(s.x),int(s.y)
    if s.dir==0:
      for e in ((1,3,8,7,"red"),(0,3,1,3,"black"),(0,7,1,3,"black"),(9,3,1,3,"black"),(9,7,1,3,"black"),(4,3,2,1,color(0,183,235)),(2,2,6,1,"grey"),(3,1,4,1,"grey"),(4,0,2,1,"grey")):fl(tx+e[0],ty+e[1],e[2],e[3],e[4])
    elif s.dir==1:
      for e in ((0,1,7,8,"red"),(0,0,3,1,"black"),(4,0,3,1,"black"),(0,9,3,1,"black"),(4,9,3,1,"black"),(6,4,1,2,color(0,183,235)),(7,2,1,6,"grey"),(8,3,1,4,"grey"),(9,4,1,2,"grey")):fl(tx+e[0],ty+e[1],e[2],e[3],e[4])
    elif s.dir==2:
      for e in ((1,0,8,7,"red"),(0,0,1,3,"black"),(9,0,1,3,"black"),(0,4,1,3,"black"),(9,4,1,3,"black"),(4,6,2,1,color(0,183,235)),(2,7,6,1,"grey"),(3,8,4,1,"grey"),(4,9,2,1,"grey")):fl(tx+e[0],ty+e[1],e[2],e[3],e[4])
    else:
      for e in ((2,1,7,8,"red"),(2,0,3,1,"black"),(6,0,3,1,"black"),(2,9,3,1,"black"),(6,9,3,1,"black"),(3,4,1,2,color(0,183,235)),(2,2,1,6,"grey"),(1,3,1,4,"grey"),(0,4,1,2,"grey")):fl(tx+e[0],ty+e[1],e[2],e[3],e[4])
    
  def update(s): 
      s.deltatime=monotonic()-s.deltainit
      s.deltainit=monotonic()
      #print(1/s.deltatime)
      global Pcx,Pcy,Inventory
      collisionplayer(s,mp[str(Pcx)+"."+str(Pcy)])
      
      updatebombs(s)
      s.Mape= mp[str(Pcx)+"."+str(Pcy)]
      if len(s.explolist)>0:
        s.Mape=explosion(s,s.Mape,s.explolist[0][0],s.explolist[0][1],s.explolist[0][2])
        s.explolist.pop(0)
        affichchunk(Pcx,Pcy,s)
        s.draw()
      s.Mape= mp[str(Pcx)+"."+str(Pcy)]
      Inventory,s.Mape=destruction(s,Inventory,s.Mape)
      mp[str(Pcx)+"."+str(Pcy)]=s.Mape
      
      if s.rsposbomb and not kd(45):
        s.rsposbomb=False
      if kd(45) and not s.rsposbomb:
        s.rsposbomb=True
        if s.nbofnukes>0:
          s.nbofnukes-=1
          mp[str(Pcx)+"."+str(Pcy)][int(s.x/20)+int(s.y/20)*16]=13
          refreshblock(p,int(s.x/20),int(p.y/20),mp[str(Pcx)+"."+str(Pcy)])
          s.bombposlist.append([(s.PCHX,s.PCHY),(int(s.x/20),int(s.y/20)),False])
      
        elif s.nbofbombs>0:
          s.nbofbombs-=1
          mp[str(Pcx)+"."+str(Pcy)][int(s.x/20)+int(s.y/20)*16]=12
          refreshblock(p,int(s.x/20),int(p.y/20),mp[str(Pcx)+"."+str(Pcy)])
          s.bombposlist.append([(s.PCHX,s.PCHY),(int(s.x/20),int(s.y/20)),False])
      if kd(46):
        for trax in range(16):
          for tray in range(11):
            if mp[str(Pcx)+"."+str(Pcy)][trax+tray*16]==12:
              s.explolist.append((2,(trax,tray),4))
            if mp[str(Pcx)+"."+str(Pcy)][trax+tray*16]==13:
              s.explolist.append((4,(trax,tray),200))
        
        ret=[]
        for bob in s.bombposlist:
          if (s.PCHX,s.PCHY)!=bob[0]:
            ret.append(bob)
        s.bombposlist=ret
      if s.fuel<=0:
        fl(0,0,320,222,"black")
        if 11 in mp[str(Pcx)+"."+str(Pcy)] and  ((150-s.x)**2+(110-s.y)**2)<1600:
            th=0
            iso=0
            for ele in Inventory:
              th+=getvalueitem(iso)*Inventory[iso]
              iso+=1
            if s.money+th>=s.fuelprice:
              s.inshop=True
            else:
              s.fuel=0
              s.gameover=True
        else:
          s.fuel=0
          s.gameover=True
def loadnextchunk(self):
  global Pcx,Pcy,p
  if not str(Pcx)+"."+str(Pcy) in mp.keys():
    mp[str(Pcx)+"."+str(Pcy)]=generatechunk(self)
  if len(list(mp.keys()))==1:
    p.Mape=mp["0.0"]
  affichchunk(Pcx,Pcy,self)
  
  p.draw()
def opti(dx,dy,self):
  global Pcx,Pcy
  if not str(Pcx)+"."+str(Pcy) in mp.keys():
    mp[str(Pcx)+"."+str(Pcy)]=generatechunk(self)
  mp[str(Pcx)+"."+str(Pcy)][dx+int(p.x/20)+(int(p.y/20)+dy)*16]=0
  p.Mape= mp[str(Pcx)+"."+str(Pcy)]
  affichchunk(Pcx,Pcy,self)
  mapencour=list(mp[str(Pcx)+"."+str(Pcy)].copy())
 
  
rsshop=False
rsbut=False
launchscreen()

while not kd(5):
  if menu:
    if kd(4):
      mp={}
      menu=False
      fl(0,0,320,225,color(198,107,46))
      Pcx=0
      Pcy=0
      p=Player()
      loadnextchunk(p)
      mapencour=list(mp[str(Pcx)+"."+str(Pcy)].copy())
      mp[str(Pcx)+"."+str(Pcy)][int(p.x/20)+int(p.y/20)*16]=0
      mp[str(Pcx)+"."+str(Pcy)][int(p.x/20)-1+int(p.y/20)*16]=11
      loadnextchunk(p)
      refreshblock(p,int(p.x//20),int(p.y/20),mp[str(Pcx)+"."+str(Pcy)])
      Inventory=[0 for x in range(14)]
  else:
    if p.gameover:
      
      fl(0,0,320,225,"black");draw_string("Game Over",100,50,"yellow","black");draw_string("Your score:"+str(p.timerscore),100,100,"yellow","black");draw_string("booooom..." if p.dead else "no fuel?",100,150,"yellow","black")
      break
    if rsshop and not kd(37):rsshop=False 
    if rsbut and not kd(1)and not kd(2)and not kd(0)and not kd(3)and not kd(4):rsbut=False
    if kd(37) and not rsshop:
      rsshop=True
      if p.inshop:
        fl(0,0,325,225,color(198,107,46))
        p.inshop=False
        loadnextchunk(p)
      else:
        condi=False
        if Pcx==Pcy==0:
          if 11 in mp["0.0"]:
            if ((150-p.x)**2+(110-p.y)**2)<1600:condi=True
        if condi:
          p.shopallorone=False
          p.shopeleis=1
          fl(0,0,320,222,"black")
          refreshshop(Inventory,p)
          p.inshop=True
    
    if p.inshop:
      if kd(12) and p.shopmode!=0:
        p.shopmode=0
        fl(0,0,320,222,"black")
        refreshshop(Inventory,p)
      if kd(13) and p.shopmode!=1:
        fl(0,0,320,222,"black")
        p.shopmode=1
        refreshshop(Inventory,p)
      if kd(14) and p.shopmode!=2:
        p.shopmode=2
        fl(0,0,320,222,"black")
        refreshshop(Inventory,p)
      if not rsbut and kd(0):
        rsbut=True
        p.shopallorone=not p.shopallorone 
        refreshshop(Inventory,p)
      if not rsbut and kd(3):
        rsbut=True
        p.shopallorone=not p.shopallorone
        refreshshop(Inventory,p)
      if not rsbut and kd(2):
        rsbut=True
        if p.shopmode:
          p.shopbutn+=1
          if p.shopbutn==9:
            p.shopbutn=8
        else:
          p.shopeleis+=1
          if p.shopeleis==10:
            p.shopeleis=9
        refreshshop(Inventory,p)
      if not rsbut and kd(1):
        rsbut=True
        if p.shopmode==1:
          if p.shopbutn!=0:
            p.shopbutn-=1
          refreshshop(Inventory,p) 
        elif p.shopmode==0:
          p.shopeleis-=1
          if p.shopeleis<1:
            p.shopeleis=1
          refreshshop(Inventory,p)
      if not rsbut and kd(4):
        rsbut=True
        if p.shopmode==1:
          if p.shopbutn==0:
            if p.money>=p.fuelprice:
              p.money-=p.fuelprice
              p.fuel+=10
              if p.fuel>100:
                p.fuel=100
              p.fuelprice+=1
              refreshshop(Inventory,p)
          if p.shopbutn==1:
            if p.money>=150:
              p.money-=150
              p.nbofbombs+=1
              refreshshop(Inventory,p)
          if p.shopbutn==2:
            if p.money>=p.viminagepr:
              p.money-=p.viminagepr
              p.viminage+=1
              p.viminagepr+=500
              refreshshop(Inventory,p)
          if p.shopbutn==3:
            if p.money>=p.consopr:
              p.money-=p.consopr
              p.consovalue*=0.5
              p.consopr*=10
              refreshshop(Inventory,p)
          if p.shopbutn==4:
            if p.money>=p.tailleminpr:
              p.money-=p.tailleminpr
              p.tailleminvalue+=1
              p.tailleminpr*=5
              refreshshop(Inventory,p)
          if p.shopbutn==5:
            if p.money>=p.speedpr:
              p.money-=p.speedpr
              p.speed+=1
              p.speedpr*=2
              refreshshop(Inventory,p)
          if p.shopbutn==6:
            if p.money>=p.inventoryplpr:
              p.money-=p.inventoryplpr
              p.maxinvplace+=1
              p.inventoryplpr+=10
              refreshshop(Inventory,p)
          if p.shopbutn==7:
            if p.money>=1000 and Inventory[9]>0:
              p.money-=1000
              p.nbofnukes+=1
              Inventory[9]-=1
              refreshshop(Inventory,p)
          if p.shopbutn==8:
            if Inventory[3]>9:
              p.fuel+=10
              Inventory[3]-=10
              refreshshop(Inventory,p)
          
          continue
        if p.shopallorone:
          if Inventory[p.shopeleis]>0:
            p.money+=getvalueitem(p.shopeleis)*Inventory[p.shopeleis]
            Inventory[p.shopeleis]=0
            refreshshop(Inventory,p)
        else:
          if Inventory[p.shopeleis]>0:
            p.money+=getvalueitem(p.shopeleis)
            Inventory[p.shopeleis]-=1
            refreshshop(Inventory,p)
      continue
   
    
    p.update()
    if p.x<-10:
      if str(Pcx-1)+"."+str(Pcy) in mp.keys():
        condi=True
        for xuu in range(10):
          if -1<int((p.y+xuu)/20)<11:
            if mp[str(Pcx-1)+"."+str(Pcy)][15-int(p.x/20)+int((p.y+xuu)/20)*16]!=0:
              condi=False
        if condi:
            Pcx-=1
            p.Mape= mp[str(Pcx)+"."+str(Pcy)]
            p.x=310
            p.lastx=310
            loadnextchunk(p)
            mapencour=list(mp[str(Pcx)+"."+str(Pcy)].copy())
        else:
            p.x=-5
      else:
        Pcx-=1
        opti(15,0,p)
        p.x=310
        p.lastx=310
        p.draw()
    if p.x>320:
      if str(Pcx+1)+"."+str(Pcy) in mp.keys():
        condi=True
        for xuu in range(10):
          if -1<int((p.y+xuu)/20)<11:
            if mp[str(Pcx+1)+"."+str(Pcy)][-16+int(p.x/20)+int((p.y+xuu)/20)*16]!=0:
              condi=False
        if condi:
            Pcx+=1
            p.Mape= mp[str(Pcx)+"."+str(Pcy)]
            p.x=0
            p.lastx=0
            loadnextchunk(p)
            mapencour=list(mp[str(Pcx)+"."+str(Pcy)].copy())
        else:
            p.x=315
      else:
        Pcx+=1
        opti(-16,0,p)
        p.x=0
        p.lastx=0
        p.draw()
    if p.y>220:
      if str(Pcx)+"."+str(Pcy-1) in mp.keys():
        condi=True
        for xuu in range(10):
          if -1<int((p.x+xuu)/20)<16:
            if mp[str(Pcx)+"."+str(Pcy-1)][int((p.x+xuu)/20)+(int(p.y/20)-11)*16]!=0:
              condi=False
        if condi:
            Pcy-=1
            p.Mape= mp[str(Pcx)+"."+str(Pcy)]
            p.y=0
            p.lasty=0
            loadnextchunk(p)
            mapencour=list(mp[str(Pcx)+"."+str(Pcy)].copy())
        else:
            p.y=215
      else:
        Pcy-=1
        opti(0,-11,p)
        p.y=0
        p.lasty=0
        p.draw()
    if p.y<-10:
      if str(Pcx)+"."+str(Pcy+1) in mp.keys():
        condi=True
        for xuu in range(10):
          if -1<int((p.x+xuu)/20)<16:
            if mp[str(Pcx)+"."+str(Pcy+1)][int((p.x+xuu)/20)+(int(p.y/20)+10)*16]!=0:
              condi=False
        if condi:
            Pcy+=1
            p.Mape= mp[str(Pcx)+"."+str(Pcy)]
            p.y=210
            p.lasty=210
            loadnextchunk(p)
            mapencour=list(mp[str(Pcx)+"."+str(Pcy)].copy())
        else:
            p.y=-5
      else:
        Pcy+=1
        opti(0,10,p)
        p.y=210
        
        p.lasty=210
        p.draw()
        
        
             
    p.PCHX,p.PCHY=Pcx,Pcy


During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.