coup_ahoo_beta_3.py

Created by mathieu-croslacoste

Created on January 03, 2025

8.22 KB

Beta version of “Coup Ahoo” by antthiaavikko (https://anttihaavikko.itch.io/coup-ahoo). Try it, it is amazing.


from random import randint as R,choice
from kandinsky import*
from ion import keydown as K
from math import*
from time import*
def pa():wait_vblank();sleep(.1)
try:from os import*
except ImportError:
 def pa():sleep(.15)
def T(t,y,c1,c2,x=0):
 i=len(t)//2;o=len(t)%2
 for j in W(i+1):
  D(t[i-j],160-j*10-o*5+x,y,c1,c2)
  if j+o<i+o:D(t[i+j+o],160+j*10+o*5+x,y,c1,c2);sleep(.03)
pcl,ecl=[[1,1],[4,1],[9,1]],[[1,1],[8,1],[9,1]]
pipes=("","4","26","048","0268","02468","023568","0234568","01235678","012345678")
cd=((235,)*3,(220,100,30),(175,)*3)
cols=((180,90,30),(238,125,164),(220,50,220))
d=((-30,-20,cols[0]),(0,0,cols[1]),(15,15,cols[2]))
txt=[["Navigator","an extra reroll"],["Mate","extra events"],["Bard","boosted crew"]]
pd,ed=[],[]
pc,ec=[],[]
pt=[]
def ell(x,y,rx,ry,c=(0,)*3):
 for h in range(-int(ry),int(ry)+1):w=sqrt(max(0,rx*rx*(1-h*h/ry/ry)));x1,x2=int(x-w),int(x+w);yc=int(y+h);set_pixel(x1,yc,c);set_pixel(x2,yc,c)
 for w in range(-int(rx),int(rx)+1):h=sqrt(max(0,ry*ry*(1-w*w/rx/rx)));y1,y2=int(y-h),int(y+h);xc=int(x+w);set_pixel(xc,y1,c);set_pixel(xc,y2,c)
def f_ell(x,y,rx,ry,c=(0,)*3):
 for h in range(-int(ry),int(ry)+1):w=sqrt(max(0,rx*rx*(1-h*h/ry/ry)));fill_rect(int(x-w),int(y+h),int(2*w),1,c)
def dice(x,y,v,t=0):
 p=pipes[v];F(x,y,27,27,(0,)*3);F(x+2,y+2,23,23,cd[t])
 for j in p:i=int(j);x2,y2=x+7+6*(i%3),y+7+6*(i//3);f_ell(x2,y2,3,3,(0,)*3)
def roll(f,x,y,a):
 v=R(0,f-1)
 if a:dice(x,y,v+(f==6));sleep(.01)
 return v
def atk(nb,pos):
 sum=0
 for i in W(nb):sum+=roll(3,170*pos+(i%5)*30,160+i//5*30,i<16);sleep(.05*(i<19))
 return sum
def cargo(x,y,d,c):
 for i in W(len(c)):
  if i<9:dice(x+(75+25*(i//3))*d-25*(d==1),y+16-25*(i%3),c[i][0],c[i][1])
def boat(x,y,d,l,c,f):
 for i in W(15):F(x+i*d,y+42+i*2,(l-i)*d,2,3*(0,)if i%5==0 else(160,60,20+(100*(i>8))))
 F(x+50*d-7*(d==1),y,7,42,(160,60,20))
 for i in W(10):F(x+(50+i*3)*d,y+4*i,-3*i*d,4,f)
 cargo(x,y,d,c)
def c_boat(x,y,d,l):F(x+40*d,y-42,(l-40)*d,42,bg);F(x,y,l*d,72,bg)
def sea():
 F(0,140,320,83,(140,130,255));c=[(140,130,255),(180,167,255),(200,180,255)]
 for i in W(45):s=R(3,8);F(int(i*7.5)+R(5,12+i//2),125+R(1,30),s,s,choice(c))
def button(o,x,c=(240,)*3,c2=(0,)*3):F(x,190,84,23,c2);F(x+2,192,80,19,c);D(o,x+42-len(o)*5,193,(0,)*3,c)
def crew(x,y,c,a=""):
 f_ell(x,y,9,18);f_ell(x,y,8,17,c)
 for j in ci:F(x+j[0],y+j[1],j[2],j[3],(0,)*3)
def boost(c,id):
 b=0
 for i in c:
  if i[0]==9:b+=i[1]
 t=0
 for i in c:
  if i[0]==id:t+=i[1]+b
 return t
def menu(b):
 s=0
 while(K(4)|K(52))^1:
  for i in W(len(b)):button(b[i],235-85*i,c2=(200*(s==i),130*(s==i),0))
  while(K(4)|K(52)|K(0)|K(3))^1:0
  s=(s+K(0)-K(3))%len(b)
  while K(0)|K(3):0
 return s
def dd(c):
 for i in W(len(c)):dice(275-25*i,115,c[i][0],c[i][1])
def gd(nb):return[[R(1,6),R(0,3)==3]for i in W(nb)]
def drop(nb):
 for i in W(boost(pc,1)+1):
  c=gd(nb);dd(c);s=menu(["Keep","Reroll"])
  if s:c2=gd(nb);c=[[c2[i][0],c[i][1]]for i in W(len(c2))]
  else:break
 while K(4)|K(52):0
 while(K(4)|K(52))^1:
  dd(c);x,y=275-25*s,115
  for i in((0,0,25,2),(0,25,27,2),(25,0,2,25),(0,2,2,23)):F(x+i[0],y+i[1],i[2],i[3],(230,230,0))
  while(K(4)|K(52)|K(0)|K(3))^1:0
  s=(s+K(0)-K(3))%len(c)
  while K(0)|K(3)|K(1)|K(2):0
 return c[s]
def dp():boat(115,80,-1,100+50*(len(pd)>6),pd,(210,)*3);dpc()
def de():boat(210,80,1,100+50*(len(ed)>6),ed,(210,)*3);dec()
def cp():c_boat(215,80,1,100+50*(len(ed)>6))
def ce():c_boat(115,80,-1,100+50*(len(pd)>6))
def dpc():
 for c in pc:id=pc.index(c);crew(87+d[id][0],103+d[id][1],d[id][2])
def dec():
 for c in ec:id=ec.index(c);crew(87+d[id][0],103+d[id][1],d[id][2])
def cs():F(0,0,320,222,bg);sea()
def da():cs();crew(87,103,(200,)*3);dp();de()
def fight():
 global ed,ec,pc
 for i in W(lv+1):ed.append([R(1,6),choice([0]*5+[1])])
 for i in W(P[lv]):
  n=choice(ecl)
  while n in ec:n=choice(ecl)
  ec.append(n)
 for i in ec:
  if i[0]==0:0
 da();msg=choice(["Victory or the deep","There's no parley in sight"]);T(msg,5,(0,)*3,bg);button("Shoot !",235,c2=(200,130,0));hnt=1
 while(K(4)|K(52))^1:0
 while len(pd)and len(ed):
  da();rn,dmg=1+boost(pc,1),boost(pc,2)-boost(ec,3)
  if hnt:a=atk(len(pd),0)+dmg
  for i in W(rn*hnt):
   D(" "*(15+a//10),90,30,(0,)*3,bg);T("Total: "+str(a)+" damage",30,(0,)*3,bg);s=menu(["Keep","Reroll"])
   if s:a=atk(len(pd),0)+dmg
   else:break
  if a==13 or hnt==0:T("Unlucky 13 !",10,(0,)*3,bg);sleep(.3);a=0
  ted=[i[0]for i in ed]
  if a>=max(ted):ed.remove(ed[ted.index(min(ted))])
  elif len(ted)==1:ed[0][0]-=a
  else:ed[ted.index(min([i for i in ted if i>a]))][0]-=a
  sleep(.2);hnt=1
  if sum([i[0]for i in ed])==13:T("Unlucky 13 !",10,(0,)*3,bg);sleep(.3);hnt=0
  cs();da();rn,dmg=1+boost(ec,1),boost(ec,2)-boost(pc,3)
  if len(ed)and hnt:
   tpd=[i[0]for i in pd];a=atk(len(ed),1)+dmg
   for i in W(rn):
    sleep(.1)
    if a<len(ed)and a<max(tpd):a=atk(len(ed),1)+dmg
   if a:T("Incoming "+str(a)+" damage",30,(0,)*3,bg)
   t=0;sleep(.2)
   if len(pd)>1 and a:
    T("Select cargo taking the hit",1,(0,)*3,bg,10)
    while K(4)|K(52):0
    while(K(4)|K(52))^1:
     cargo(115,80,-1,pd);x,y=115-75-25*(t//3),80+16-25*(t%3)
     for i in((0,0,25,2),(0,25,27,2),(25,0,2,25),(0,2,2,23)):F(x+i[0],y+i[1],i[2],i[3],(230,230,0))
     while(K(4)|K(52)|K(0)|K(3)|K(1)|K(2))^1:0
     t=max(min(t+K(1)-K(2)+3*K(0)-3*K(3),len(pd)-1),0)
     while K(0)|K(3)|K(1)|K(2):0
     msg=[str(pd[t][0]),["N","S","P"][pd[t][1]]]
     for i in("V=","T="):h="T"in i;D(i+msg[h],0,18*h,(0,)*3,bg)
   cs()
   if pd[t][0]==1:pd.remove(pd[t])
   elif pd[t][1]==2:pd[t][0]-=1
   elif pd[t][0]>a:pd[t][0]-=a
   else:pd.remove(pd[t])
  hnt=1
  if sum([i[0]for i in pd])==13:hnt=0
 T("Die, bastard !",10,(0,)*3,bg);sleep(.3);ec=[];return len(pd)
def anim(bc,cc,c2c,dc2,bd):
 for i in W(52+8*(len(bd)>6)):
  cs();boat(210-6*i,80,1,100+50*(len(bd)>6),bd,bc);crew(215-6*i,103,cc)
  if dc2:crew(265-6*i,103,c2c)
  dp();pa()
def enc():
 while K(4):0
 o=R(1,100)
 bc,cc,bd=(R(50,255),R(50,255),R(50,255)),(R(150,230),R(120,170),R(140,190)),[[R(1,6),choice([0]*5+[1]*3+[2]*1)]for i in range(lv)]
 cs();dp()
 while o<36 and len(pc)==5:o=R(1,100)
 if"Mark"in pt and R(0,10)>6:o=100
 if"Cross"in pt and R(0,10)>6 and len(pc)<5:o=R(20,36)
 if o<13:
  c=choice(pcl)
  while c in pc:c=choice(pcl)
  c[1]+="Parasite"in pt;id=pcl.index(c)
  boat(215,80,1,100,[],bc);crew(215,103,cc);crew(265,103,cols[id])
  T("Want to hire this "+txt[id][0]+"?",0,(0,)*3,bg)
  T("He'll give you "+txt[id][1],16,(0,)*3,bg)
  s=menu(["Yeah","Nope"])
  if s:ec.append(ecl[id])
  else:pc.append(c)
  anim(bc,cc,cols[id],s,[])
 elif o<19:
  c,c2=choice(pcl),choice(pcl)
  while c in pc:c=choice(pcl)
  while c2 in pc or c==c2:c=choice(pcl)
  c[1]+="Parasite"in pt;id=pcl.index(c)
  c2[1]+="Parasite"in pt;id2=pcl.index(c2)
  boat(215,80,1,100,[],bc);crew(215,103,cc);crew(265,103,cols[id]);crew(285,103,cols[id2])
  T("Want to hire this "+txt[id][0]+" or "+txt[id2][0]+"?",0,(0,)*3,bg)
  s=menu(["Yeah","Nope"])
  if s:ec.append(ecl[id]);ec.append(ecl[id2])
  else:
   cs();dp()
   boat(215,80,1,100,[],bc);crew(215,103,cc);crew(265,103,cols[id]);crew(285,103,cols[id2])
   s2=menu([txt[id][0],txt[id2][0]])
   pc.append([c,c2][s2])
   T("He'll give you "+txt[[id,id2][s2]][1],0,(0,)*3,bg)
   ec.append(ecl[[id,id2][1-s2]])
  anim(bc,cc,cols[id],s,[])
F,D,W=fill_rect,draw_string,range
bg=(216,252,240)
ci=((-6,-5,4,4),(2,-5,4,4),(-7,12,2,9),(4,12,2,9),(-12,0,3,2),(8,0,3,2))
P=(0,0,0,0,0,0,0,1,1,1,2,2,4)
sea()
boat(115,80,-1,100,[[8,2],[2,0],[0,1],[9,1],[1,1]],(210,)*3)
D("Total: "+str(atk(10,0))+" damage.",10,0,(0,)*3,bg)
button("Yo !",200)
sleep(1)
while 1:
 bg=(216,252,240)
 pd=[[3,1],[9,0],[7,2],[9,2]]
 lv=0;pc=[];z=1;ed,ec=[],[]
 while z:
  m,n=R(-2,2),R(-1,1);sea();boat(115+m,80+n,-1,100+50*(len(pd)>6),pd,(210,)*3);boat(210+m,80+n,1,100+50*(len(ed)>6),[],(210,)*3);crew(87+m,103+n,(200,)*3);pa();F(0,126,320,96,bg);c_boat(115+m,80+n,-1,100+50*(len(pd)>6));c_boat(215+m,80+n,1,100+50*(len(ed)>6));z=fight()
  if z:
   lv+=1;cs();dp();pd.append(drop(lv+1));enc()
   while R(-10,100)*boost(pc,4)>60:enc()
 cs();D("Down to Davy Jones' Locker !",20,10,(0,)*3,bg)
 for i in W(43):m=R(-2,2);sea();boat(115+m,80+int(i*2.5+i),-1,100,[],(210,)*3);dpc();pa();F(0,126,320,96,bg);c_boat(115+m,80+int(i*2.5+i),-1,100)
 for i in W(161):F(i,0,1,222,(0,)*3);F(320-i,0,1,222,(0,)*3);sleep(.01)
 D("Press [OK]",110,103,(255,0,0),(0,)*3)
 while(K(4)|K(52))^1:0
 for i in W(161):F(160-i,0,1,222,bg);F(160+i,0,1,222,bg);sleep(.01)

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.