coup_ahoo_beta_6_1.py

Created by mathieu-croslacoste

Created on September 15, 2025

8.83 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 as C
from kandinsky import*
from ion import keydown as K
from math import*
from time import sleep as P
bg=(216,252,240)
def pa():wait_vblank();wait_vblank();P(.1)
def B(x,y,r,c):draw_circle(x,y,r,c)
try:from os import*
except ImportError:
 def pa():P(.17)
 def B(x,y,r,c):F(x,y,r,r,c)
def E():
 while K(4)|K(52):0
def T(t,y,c1="k",c2=bg,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);P(.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=(("Navi","extra reroll(s)"),("Mate","extra events"),("Bard","boosted crew"),("Canoneer","extra shot(s)"))
pd,ed=[],[]
pc,ec=[],[]
pt=[]
def ell(x,y,rx,ry,c="k"):
 for h in W(-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 W(-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="k"):
 for h in W(-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,"k");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,"k")
def roll(f,x,y,a):
 v=R(0,f-1)
 if a:dice(x,y,v+(f==6));P(.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);P(.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,e=0):
 b=(160,60,20)
 for i in W(15):F(x+i*d,y+42+i*2,(l-i)*d,2,"k"if i%5==0 else(160,60,20+(100*(i>8))))
 F(x+50*d-7*(d==1),y,7,42,b)
 for i in W(10):F(x+(50+i*3)*d,y+4*i,-3*i*d,4,f)
 if d==1:F(x+43,y,7,42,b);D("14",x-l-90,y+44,"w",b,1)
 elif e:F(x-50,y,7,42,b);D(str(13-lv),x+l+70,y+44,"w",b,1)
 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(2,5);B(int(i*7.5)+R(5,12+i//2),125+R(1,30),s,C(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],"k")
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):
 E();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(i*2,nb*2-1)>=nb*2-2]for i in W(nb)]
def drop(nb):
 c=gd(nb)
 for i in W(boost(pc,1)+1):
  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
 E()
 while(K(4)|K(52))^1:
  dd(c);x,y=275-25*s,115;co=(230,230,0);F(x,y,25,2,co);F(x,y+25,27,2,co);F(x+25,y,2,25,co);F(x,y+2,2,23,co)
  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,1);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 rs():F(0,121,320,34,bg);sea()
def da():cs();crew(87,103,(200,)*3);dp();de()
def fight():
 global ed,ec,pc
 for i in W(lv+1+3*boost(ec,8)):ed.append([R(1,6),C([0]*5+[1])])
 for i in W(ceInf[lv]):
  n=C(ecl)
  while n in ec:n=C(ecl)
  ec.append(n)
 for i in ec:
  if i[0]==0:0
 da();msg=C(["Victory or the deep","There's no parley in sight"]);T(msg,5,"k",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,"k",bg);T("Total: "+str(a)+" damage",30,"k",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,"k",bg);P(.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
  P(.2);hnt=1
  if sum([i[0]for i in ed])==13:T("Unlucky 13 !",10,"k",bg);P(.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):
    P(.1)
    if a<len(ed)and a<max(tpd):a=atk(len(ed),1)+dmg
   if a:T("Incoming "+str(a)+" damage",30,"k",bg)
   t=0;P(.2)
   if len(pd)>1 and a:
    T("Select cargo taking the hit",1,"k",bg,10);E()
    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,"k",bg);P(.3);ec=[];return len(pd)
def anim(bc,cc,bd,c2c="k",dc2=0):
 for i in W(28+4*(len(bd)>6)):
  cs();boat(210-12*i,80,1,100+50*(len(bd)>6),bd,bc);crew(215-12*i,103,cc)
  if dc2:crew(265-12*i,103,c2c)
  dp();pa()
def enc():
 while K(4):0
 bc,cc=(R(50,255),R(50,255),R(50,255)),(R(150,230),R(120,170),R(140,190));bd=gd(lv*(lv<9)+8*(lv>8));cs();dp()
 if"Mark"in pt and R(0,10)>6:o=100
 elif"Cross"in pt and R(0,10)>6 and len(pc)<5:o=R(25,46)
 else:o=R(1,100)
 while o<47 and len(pc)==5:o=R(1,100)
 if o<26:
  c=C(pcl)
  while c in pc:c=C(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);T("He'll give you "+txt[id][1],16);s=menu(["Yeah","Nope"])
  if s:ec.append(ecl[id])
  else:pc.append(c)
  anim(bc,cc,[],cols[id],s)
 elif o<47:
  c,c2=C(pcl),C(pcl)
  while c in pc:c=C(pcl)
  while c2 in pc or c==c2:c=C(pcl)
  id=pcl.index(c);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,"k",bg);s=menu(["Yeah","Nope"])
  if s:ec.append(ecl[id]);ec.append(ecl[id2])
  else:c[1]+="Parasite"in pt;c2[1]+="Parasite"in pt;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);ec.append(ecl[[id,id2][1-s2]])
  anim(bc,cc,[],cols[id],s)
 elif o<58:
  boat(215,80,1,100+50*(len(bd)>6),bd,bc);crew(215,103,cc);T("I could plate 1 of your cargo.",20);T("It'll only take 1 dmg at a time",43);s=menu(["Yes","No"]);l=[i for i in pd if i[1]==0]
  if s==0 and len(l):pd[pd.index(C(l))][1]=2
  anim(bc,cc,bd)
F,D,W=fill_rect,draw_string,range
F(0,0,320,222,bg)
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))
ceInf=(0,0,0,0,0,0,0,1,1,1,2,2,4)
button("Yo !",200)
P(1)
def Start():
 E();D("Coup Ahoo",115,14,(175,130,25),bg);F(110,10,100,4,"k");F(110,32,100,4,"k");F(110,14,4,18,"k");F(206,14,4,18,"k");F(111,7,98,2,"r");F(107,11,2,24,"r");F(211,11,2,24,"r");dice(3,2,R(1,6),R(0,1));dice(23,4,R(1,6),2);dice(2,25,R(1,6),R(0,1));dice(48,3,R(1,6),R(0,1));dice(292,2,R(1,6),R(0,1));dice(272,4,R(1,6),2);dice(293,25,R(1,6),R(0,1));dice(247,3,R(1,6),R(0,1));rs();T("A game by anttihaavikko",40);F(45,58,230,2,"r");T("Python Edition 0.6",60)
 while(K(4)|K(52))^1:rs();pa()
 E()
while 1:
 Start();bg=(216,252,240);pd=[[3,1],[9,0],[7,2],[9,2]];lv=0;pc=[];z=1;ed,ec=[],[]
 while z:
  cs()
  for i in W(5):m,n=R(-2,2),R(-1,1);rs();boat(115+m,80+n,-1,100+50*(len(pd)>6),pd,(210,)*3);crew(87+m,103+n,(200,)*3);pa();c_boat(115+m,80+n,-1,100+50*(len(pd)>6))
  z=fight()
  if z:
   lv+=1;cs();dp();pd.append(drop((lv+1)*(lv<5)+6*(lv>4)));enc()
   while R(-10,100)*boost(pc,4)>60:enc()
 cs();D("Down to Davy Jones' Locker !",20,10,"k",bg)
 for i in W(43):m=R(-2,2);rs();boat(115+m,80+int(i*2.5+i),-1,100,[],(210,)*3);dpc();pa();c_boat(115+m,80+int(i*2.5+i),-1,100)
 for i in W(81):F(i*2,0,2,222,"k");F(320-i*2,0,2,222,"k");P(.01)
 D("Press [OK]",110,103,(255,0,0),"k")
 while(K(4)|K(52))^1:0
 for i in W(81):F(160-2*i,0,2,222,bg);F(160+i*2,0,2,222,bg);P(.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.