tape_taupe.py

Created by antarctus

Created on April 21, 2022

6.1 KB

Jeux du tape-taupe !
Vous avez neufs carrés où apparaissent des taupes, taper dessus pour les faire disparaitre !
Les taupes accélèrent, vous arriverez à en avoir combien ?
Un combat de boss est présent, le roi des taupes aura votre peau (ou l’inverse) en trois phases.
Un vote avait été ouvert pour choisir les modèles des taupes, se référer à ceci.


from random import *
from kandinsky import *
from ion import *
from time import *

models=[[
(0,0,50,50,(160,60,20)),
(0,0,50,12,(0,80,0)),
(0,0,6,20,(0,80,0)),
(44,0,6,20,(0,80,0)),
(0,4,50,4,(0,180,0)),
(2,0,2,20,(0,180,0)),
(15,0,2,12,(0,180,0)),
(33,0,2,12,(0,180,0)),
(46,0,2,20,(0,180,0)),
(8,13,15,15,(255,)*3),
(27,13,15,15,(255,)*3),
(11,16,9,9,(0,)*3),
(30,16,9,9,(0,)*3),
(8,32,34,8,(40,)*3),
( 8,32,8,14,(40,)*3),
(36,32,8,14,(40,)*3),
],[
(0,0,50,50,(160,60,20)),
(5,5,15,15,(255,)*3),
(30,5,15,15,(255,)*3),
(8,6,9,9,(0,)*3),
(33,6,9,9,(0,)*3),
(10,38,30,5,(40,)*3),
(10,30,5,12,(40,)*3),
],[
(0,0,50,50,(160,60,20)),
(3,5,20,20,(255,)*3),
(27,5,20,20,(255,)*3),
(7,7,14,14,(0,)*3),
(29,7,14,14,(0,)*3),
(13,9,6,6,(240,)*3),
(31,9,6,6,(240,)*3),
(17,30,16,16,(40,)*3),
(21,30,8,8,(220,)*3),
(24,32,2,6,(100,)*3),
],[
( 0,7,50,43,(160,60,20)),
( 8,15,10,10,(255,0,0)),
(32,15,10,10,(255,0,0)),
(5,5,40,5,(255,200,0)),
(0,0,10,10,(150,100,0)),
(20,0,10,10,(150,100,0)),
(40,0,10,10,(150,100,0)),
(8,28,34,8,(40,)*3),
(12,30,8,16,(220,)*3),
(30,30,8,16,(220,)*3),
],[
( 0,10,50,40,(110,60,170)),
( 8,15,10,10,(205,0,150)),
(32,15,10,10,(205,0,150)),
(0,5,50,5,(205,200,150)),
(0,0,10,10,(150,150,150)),
(20,0,10,10,(150,150,150)),
(40,0,10,10,(150,150,150)),
(8,28,34,8,(0,40,190)),
(12,31,8,16,(170,220,250)),
(30,31,8,16,(170,220,250)),
],[
(0,0,50,50,(160,60,20)),
(5,5,15,15,(255,)*3),
(30,5,15,15,(255,)*3),
(8,8,9,9,(0,)*3),
(33,8,9,9,(0,)*3),
(8,37,34,8,(40,)*3),
(12,27,8,16,(220,)*3),
(30,27,8,16,(220,)*3),
],[
(0,0,50,50,(160,60,20)),
(3,5,17,17,(255,)*3),
(30,5,17,17,(255,)*3),
(10,7,8,8,(0,)*3),
(32,7,8,8,(0,)*3),
(8,27,10,18,(40,)*3),
],[
(0,0,50,50,(160,60,20)),
( 4,14,18,5,(40,)*3),
(28,14,18,5,(40,)*3),
(18,10,4,8,(40,)*3),
(28,10,4,8,(40,)*3),
(17,30,16,16,(40,)*3),
(21,30,8,8,(220,)*3),
(24,32,2,6,(100,)*3),
],[
(0,0,50,50,(0,200,0)),
(30,40,6,6,(0,100,0)),
(3,5,17,17,(255,)*3),
(30,5,17,17,(255,)*3),
(12,7,6,6,(0,)*3),
(32,10,10,10,(0,)*3),
(9,30,8,12,(40,)*3),
(9,30,32,8,(40,)*3),
],[
( 0,10,50,40,(160,60,20)),
( 8,15,3,3,(40,)*3),
(32,15,3,3,(40,)*3),
(14,15,3,3,(40,)*3),
(38,15,3,3,(40,)*3),
(11,18,3,3,(40,)*3),
(35,18,3,3,(40,)*3),
( 8,21,3,3,(40,)*3),
(32,21,3,3,(40,)*3),
(14,21,3,3,(40,)*3),
(38,21,3,3,(40,)*3),
(0,5,50,5,(255,200,0)),
(0,0,10,10,(150,100,0)),
(20,0,10,10,(150,100,0)),
(40,0,10,10,(150,100,0)),
(8,28,34,8,(40,)*3),
(12,30,8,16,(220,)*3),
(30,30,8,16,(220,)*3),
]]

def draw_model(model,x,y,scale=50):
  coef=scale/50
  for m in model:
    fill_rect(x+int(m[0]*coef),y+int(m[1]*coef),int(m[2]*coef),int(m[3]*coef),m[4])


moles=[0,]*9
modes=""
count_=0
minus=0.007
act_moles=[4]


t=2*(1-minus)**count_
moles_model=[0,]*9
easy_model_ids=[0,1,2,5,6,7]

decors=[]
for i in range(6):
  decors+=[randint(0,1)]

def get_moles():
  n=randint(0,8)
  while n in act_moles:
    n=randint(0,8)
  return n

def timer():
  fill_rect(120,96,80,30,(100,)*3)
  for i in range(3):
    fill_rect(125+25*i,101,20,20,(0,)*3)
  for i in range(2):
    fill_rect(125+25*i,101,20,20,(255,255,0))
    sleep(1)
  for i in range(3):
    fill_rect(125+25*i,101,20,20,(0,255,0))
  sleep(1)

def draw_back(color):
  cr,cg,cb=color[0]/255,color[1]/255,color[2]/255
  for i in range(50):
    fill_rect(0,i*2,320,2,(int(cr*250-i*5),int(cg*250-i*5),int(cb*250-i*5)))


def draw_box(number=False):
  fill_rect(60,11,200,200,(80,30,10))
  for x in range(3):
    for y in range(3):
      fill_rect(x*70+65,y*70+16,50,50,(0,)*3)
      if number:
        draw_string(str((2-y)*3+x+1),x*70+85,y*70+32,(100,)*3,(0,)*3)


def boss(model,c=(255,0,0)):
  draw_all(c)
  for i in range(30,-1,-1):
    draw_box()
    draw_model(model,65+int(19/6*(30-i)),16+int(19/6*(30-i)),int(19/3*i))
    sleep(0.1)


def draw_all(back=(0,255,255)):
  fill_rect(0,0,320,160,(0,)*3)
  fill_rect(0,160,320,62,(160,60,20))
  draw_back(back)
  models=[
  [
  (5,10,10,10,(110,40,12)),
  (2,2,16,12,(0,150,0))
  ],[
  (3,6,14,14,(20,)*3),
  (4,7,12,12,(180,)*3)
  ]]

  for i in range(3):
    fill_rect(i*20,120-i*40,20,122+i*40,(160,60,20))
    fill_rect(i*20,120-i*40,20,20,(0,255,0))
    draw_model(models[decors[i]],i*20,100-i*40,50)

    fill_rect(260+(2-i)*20,120-i*40,20,122+i*40,(160,60,20))
    fill_rect(260+(2-i)*20,120-i*40,20,20,(0,255,0))
    draw_model(models[decors[i]],260+(2-i)*20,100-i*40,50)

  draw_string("Score:",0,150,(0,)*3,(160,60,20))
  draw_string("{:>3}".format(str(count_)),0,170,(0,)*3,(160,60,20))
  draw_box(True)

draw_all()

run=True

timer()
draw_box(True)


moles[4]=monotonic()

while run:
  for i in range(9):
    if moles[i]!=0:
      w=int(25/t*(monotonic()-moles[i]))
      draw_model(models[moles_model[i]],(i%3)*70+90-w,(i//3)*70+41-w,2*w)

      if keydown([KEY_SEVEN,KEY_EIGHT,KEY_NINE,KEY_FOUR,KEY_FIVE,KEY_SIX,KEY_ONE,KEY_TWO,KEY_THREE][i]):
        fill_rect((i%3)*70+65,(i//3)*70+16,50,50,(0,)*3)
        if moles_model[i]==4:
          act_moles.remove(i)
          moles[i]=0
          continue

        t*=(1-minus)
        count_+=1        

        if count_==80:
          boss(models[3],(255,0,0))
          moles_model=[3,]*9
        if count_==140:
          boss(models[9],(0,255,255))

        if 119<count_<=140:
          draw_box()
          act_moles=[]
          moles=[0,]*9

        if 119<count_<140:
          act_moles=[i]
          for ii in range(3):
            act_moles+=[get_moles()]
            moles[act_moles[ii+1]]=monotonic()
            moles_model[act_moles[ii+1]]=[3,4,4][ii]
          del act_moles[0]

          draw_string("{:>3}".format(str(count_)),0,170,(0,)*3,(160,60,20))
          if count_!=140:
            continue

        if len(act_moles)<=[1,2][100<=count_<119]:
          act_moles+=[get_moles()]
          moles[act_moles[-1]]=monotonic()
          moles_model[act_moles[-1]]=[choice(easy_model_ids),3][80<=count_<139]

        if 100<=count_<119 and len(act_moles)<3:
          act_moles+=[get_moles()]
          moles[act_moles[-1]]=monotonic()

        if count_!=140:
          act_moles.remove(i)
          moles[i]=0

        draw_string("{:>3}".format(str(count_)),0,170,(0,)*3,(160,60,20))
        continue

      if monotonic()-moles[i]>t:
        run=False
        draw_model(models[moles_model[i]],60+5,11+5,190)