snake_kart_8_assets_1.py

Created by furicoda

Created on September 19, 2024

13.5 KB


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

class Ballsnick:
  def __init__(self):
    self.speedy=(1-(randint(0,1)*2))*40
    self.speedx=0
    self.x=160
    self.y=120
    self.oldx=self.x
    self.oldy=self.y
  def reset(self):
    fill_rect(0,20,320,210,"gray")
    self.speedx=0
    self.speedy=(1-(randint(0,1)*2))*40
    self.x=160
    self.y=120
  def affich(self):
    fill_rect(int(self.oldx)-4,int(self.oldy)-4,9,9,"gray")
    fill_rect(int(self.x)-4,int(self.y)-4,9,9,"orange")
    self.oldx=self.x
    self.oldy=self.y
  def update(self,Game):
    self.affich()
    if not Game.timerrelaunch>0:return
    cols={}
    for ly in range(11):
      a=get_pixel(int(self.x)-5,int(self.y)+ly-5)
      if a in cols.keys():cols[a]+=1
      else:cols[a]=1
      a=get_pixel(int(self.x)+5,int(self.y)+ly-5)
      if a in cols.keys():cols[a]+=1
      else:cols[a]=1
    for lx in range(9):#cote bas et haut
      a=get_pixel(int(self.x)-5+lx,int(self.y)-5)
      if a in cols.keys():cols[a]+=1
      else:cols[a]=1
      a=get_pixel(int(self.x)-5+lx,int(self.y)+5)
      if a in cols.keys():cols[a]+=1
      else:cols[a]=1
    scoreteam1=0
    scoreteam2=0
    if (255,0,0) in cols.keys():scoreteam1+=cols[(255,0,0)]
    if (0,255,255) in cols.keys():scoreteam2+=cols[(0,255,255)]
    if scoreteam1==scoreteam2:self.speedx=0
    else:self.speedx=(1-(scoreteam1<scoreteam2)*2)*20
    self.x+=self.speedx*Game.deltatime
    self.y+=self.speedy*Game.deltatime
    if self.y>220:
      self.y-=self.speedy*Game.deltatime
      self.speedy*=-1
    if self.y<24:
      self.y-=self.speedy*Game.deltatime
      self.speedy*=-1
    if self.x>320:
      self.x-=self.speedx*Game.deltatime
      self.speedx*=-1
    if self.x<0:
      self.x-=self.speedx*Game.deltatime
      self.speedx*=-1
def racemodemenuprint(butselect,valc,nbofplayers,glonboftour,mapen,tempslimite,courseaelim,nombredebots,aipower,tempsparelim,blueback):
  draw_string("Nombres de joueurs : "+str(nbofplayers),50,valc*3,"orange" if butselect==2 else "red",blueback)
  draw_string("Nombres de tours : "+str(glonboftour),50,valc*4,"orange" if butselect==3 else "red",blueback)
  draw_string("Mape n°"+str(mapen),50,valc*5,"orange" if butselect==4 else "red",blueback)
  draw_string("Temps limite : "+str(tempslimite),50,valc*6,"orange" if butselect==5 else "red",blueback)
  draw_string("Course a elimination : "+str(("non","oui")[courseaelim]),50,valc*7,"orange" if butselect==6 else "red",blueback)
  draw_string("Nombre de bots : "+str(nombredebots),50,valc*8,"orange" if butselect==7 else "red",blueback)
  draw_string("Bots QI : "+str(("nul","facile","normal","dur","extreme","impossible")[aipower]),50,valc*9,"orange" if butselect==8 else "red",blueback)
  draw_string("Temps par elimination : "+str(tempsparelim),50,valc*10,"orange" if butselect==9 else "red",blueback)
def preground(mape):fill_rect(0,40,320,200,(155,79,3))
def write_croix(idi):
  fill_rect(idi*60+20+5,0,15,15,"red")
  for x in range(15):
    set_pixel(idi*60+25+x,x,"white")
    set_pixel(idi*60+39-x,x,"white")
def fillserps(col,classement):
    if len(classement)>1:fill_rect(120,120,4,40,col[classement[1]])
    if len(classement)>0:fill_rect(160,100,4,40,col[classement[0]])
    if len(classement)>2:fill_rect(200,140,4,40,col[classement[2]])
    if len(classement)==4:fill_rect(240,160,4,40,col[classement[3]])
def setselfterritoire(self):
      if self.idi==0:
        self.x=5
        self.y=25
        self.dir=45
        self.tcol=(0,100,0)
        self.gox=randint(10,315)
        self.goy=randint(30,215)
      elif self.idi==1:
        self.x=315
        self.y=216
        self.dir=-135
        self.tcol=(0,0,100)
        self.gox=randint(10,315)
        self.goy=randint(30,215)
      elif self.idi==2:
        self.x=315
        self.y=25
        self.dir=135
        self.tcol=(200,200,0)
        self.gox=randint(10,315)
        self.goy=randint(30,215)
      elif self.idi==3:
        self.x=5
        self.y=216
        self.dir=-45
        self.tcol=(220,69,136)
        self.gox=randint(10,315)
        self.goy=randint(30,215)
      if self.isia:self.dir=angle_to_point(self.x,self.y,self.gox,self.goy)
def getscreenper():
  yu={}
  draw_string("calcul des resultats",20,0,"yellow","black")
  for x in range(320):
    for y in range(20,220):
      a=get_pixel(x,y)
      if a in yu.keys():yu[a]+=1
      else:yu[a]=1
  return yu
def basepodium():
  fill_rect(0,0,320,320,(0,200,200))
  fill_rect(0,190,320,40,"green")
  fill_rect(100,160,40,40,"white")
  fill_rect(140,140,40,60,"white")
  fill_rect(180,180,40,20,"white")
  draw_string("2",117,160,"orange")
  draw_string("1",157,140,"orange")
  draw_string("3",197,180,"orange")
def getmapecode(mapis):
  if mapis==0:return ((21,35,327,53),(48,65,269,81),(269,81,267,178),(267,178,190,90),(190,90,88,183),(88,183,49,64),(262,223,188,140),(188,140,92,230),)
  if mapis==1:return ((173,39,178,155),(180,185,52,172),(139,60,145,182),(179,154,225,41),(251,71,282,126),(282,126,179,185),(251,71,213,166),(53,171,139,60),)
  if mapis==2:return ((44,75,281,75),(281,75,277,182),(277,182,50,178),(50,178,45,75),)
  if mapis==3:return ((29,62,32,192),(59,38,58,62),(29,82,288,85),(59,62,324,65),(326,112,61,110),(31,136,285,142),(322,169,74,169),(32,191,284,194),)
def getcheckcode(mapis):
  if mapis==0:return ((21,56,60),(295,74,60),(277,200,75),(188,113,70),(78,211,65),)
  if mapis==1:return ((155,59,40),(163,168,50),(200,155,40),(245,60,60),(305,132,50),(182,204,45),(24,178,60),(116,55,60),)
  if mapis==2:return ((298,56,50),(299,202,60),(24,197,70),(22,56,60),)
  if mapis==3:return ((42,51,35),(42,73,44),(306,73,40),(304,99,45),(45,97,45),(46,125,45),(304,129,45),(303,157,50),(50,154,60),(52,181,55),(301,183,40),(300,209,50),(16,205,50),(14,50,50),)
def getdecocode(mapis):
  if mapis==0:return ((55,77,1),)
  if mapis==1:return ((253,120,2),(192,72,1),(89,160,1),(124,134,1),)
  if mapis==2:return ((68,97,1),(120,99,1),(167,99,1),(220,99,1),(262,97,1),(64,145,1),(95,131,1),(151,131,1),(126,159,1),(210,122,1),(170,165,1),(246,137,1),(217,167,1),)
  if mapis==3:return ((73,51,1),(94,47,1),(118,50,1),(152,47,1),(196,47,1),(234,48,1),(264,47,1),(299,44,1),)
def decodecode(mape):
  for ele in mape:
    if ele[2]==1:
      fill_rect(ele[0],ele[1],5,10,"brown")
      fill_rect(ele[0]-1,ele[1],7,4,"green")
    if ele[2]==2:fill_rect(ele[0],ele[1],10,5,"gray")
def distance(x1,y1,x2,y2):return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)
def mapdecode(mape):
  for ele in mape:
    stx=ele[0]
    sty=ele[1]
    longa=sqrt(distance(ele[0],ele[1],ele[2],ele[3]))
    for lon in range(longa):
      if int(sty)>39:set_pixel( int(stx),int(sty),(255,60,57))
      stx-=(ele[0]-ele[2])/longa
      sty-=(ele[1]-ele[3])/longa

def angle_to_point(observer_x, observer_y, target_x, target_y):return degrees(atan2(target_y - observer_y, target_x - observer_x))
def launcherwindow():
  inittime=monotonic()
  blueback=(40,60,250)
  fill_rect(0,0,320,320,blueback)
  draw_string("Snake Kart 8",115,50,"red",blueback)
  while monotonic()-inittime<1:
    pass
def refreshaide(Game):
  yee=0
  fill_rect(0,0,320,320,(40,60,250))
  for ele in ["back to menu : click on shift","J1 :(2,1)avancer, (4,0)tourner","J2 :(+,-)avancer, (EXE,division)tourner","J3 :(ln,exp(x))avancer, (shift,sin)tourner","J1 :(virgule,x exp(y))avancer, (x carré,effacer)tourner"]:
    draw_string(ele,0,yee*20,"yellow",(40,60,250))
    yee+=1
def bataillerespawn(self):
        if self.coolres<0:
          self.cango=4
          self.speed=0
          if self.idi==0:
            self.x=5
            self.y=25
            self.dir=45
          if self.idi==1:
            self.x=315
            self.y=215
            self.dir=-135
          if self.idi==2:
            self.x=315
            self.y=25
            self.dir=135
          if self.idi==3:
            self.x=5
            self.y=215
            self.dir=-45
def getsommecol(col,nbteam):
      sommecol=[]
      nb=1
      if nbteam==2:
        if (255,0,0) in col.keys():nb+=col[(255,0,0)]
        sommecol.append(nb)
        nb=1
        if (0,255,255) in col.keys():nb+=col[(0,255,255)]
        sommecol.append(nb)
        return sommecol
      if (0,101,0) in col.keys():nb+=col[(0,101,0)]
      sommecol.append(nb)
      nb=1
      if (0,0,99) in col.keys():nb+=col[(0,0,99)]
      if (0,0,101) in col.keys():nb+=col[(0,0,101)]
      if (0,0,255) in col.keys():nb+=col[(0,0,255)]
      sommecol.append(nb)
      nb=1
      if (206,203,0) in col.keys():nb+=col[(206,203,0)]
      if (82,195,0) in col.keys():nb+=col[(82,195,0)]
      if (255,255,0) in col.keys():nb+=col[(255,255,0)]
      sommecol.append(nb)
      nb=1
      if (222,69,140) in col.keys():nb+=col[(222,69,140)]
      if (82,195,0) in col.keys():nb+=col[(82,195,0)]
      if (255,255,0) in col.keys():nb+=col[(255,255,0)]
      sommecol.append(nb)
      return sommecol
def infoforallset(self):
    self.oldx=self.x
    self.oldy=self.y
    self.olddir=self.dir
    self.speed=0
    self.speedmaxs=(-40,100)
    if self.idi==0:
      self.color="green"
      self.keyso=(KEY_ONE,KEY_TWO,KEY_FOUR,KEY_ZERO,KEY_DOT)
      self.tcolor=(0,100,0)
    if self.idi==1:
      self.color="blue"
      self.keyso=(KEY_MINUS,KEY_PLUS,KEY_EXE,KEY_DIVISION,KEY_ANS)
      self.tcolor=(0,0,100)
    if self.idi==2:
      self.color="yellow"
      self.keyso=(KEY_EXP,KEY_LN,KEY_SHIFT,KEY_SINE,KEY_ALPHA)
      self.tcolor=(200,200,0)
    if self.idi==3:
      self.color="pink"
      self.keyso=(KEY_POWER,KEY_COMMA,KEY_SQUARE,KEY_BACKSPACE,KEY_TOOLBOX)
      self.tcolor=(222,69,140)
    self.chargingstartval=0
    self.cango=-1
    self.preframecos=0
    self.preframesin=0
    self.lastdist=2000
    self.coolres=3
    self.iseliminated=False
def changetimeval(tempslimite,coolclick,refresh):
  if keydown(KEY_RIGHT):
    tempslimite+=10
    refresh=True
    coolclick=monotonic()
  if keydown(KEY_LEFT):
    if tempslimite!=10:
      tempslimite-=10
      refresh=True
      coolclick=monotonic()
  return tempslimite,refresh,coolclick
def getnbofbotchnage(nombredebots,nbofplayers,refresh,coolclick):
  if keydown(KEY_RIGHT):
    if (nombredebots+nbofplayers)==4:
      if nombredebots!=0:
        nombredebots-=1
        nbofplayers+=1
        refresh=True
        coolclick=monotonic()
    else:
      nbofplayers+=1
      refresh=True
      coolclick=monotonic()
  if keydown(KEY_LEFT):
          if nbofplayers!=0:
            if (nombredebots+nbofplayers)!=2:
              nbofplayers-=1
              refresh=True
              coolclick=monotonic()
  return nombredebots,nbofplayers,refresh,coolclick
def startinfo(self):
    if self.chargingstartval>2:
      self.chargingstartval=0
      self.cango=1.5
    elif self.chargingstartval>1.5:
      self.speed=40
      self.chargingstartval=0
    elif self.chargingstartval>1:
      self.speed=20
      self.chargingstartval=0
    elif self.chargingstartval>0.5:
      self.speed=10
      self.chargingstartval=0
def changeaipower(aipower,refresh,coolclick):
  if keydown(KEY_RIGHT):
            if aipower!=5:
              aipower+=1
              refresh=True
              coolclick=monotonic()
  if keydown(KEY_LEFT):
            if aipower!=0:
              aipower-=1
              refresh=True
              coolclick=monotonic()
  return aipower,refresh,coolclick
def speedgeror(self,deltatime):
          if keydown(self.keyso[0]):
            self.speed-=75*deltatime
            if self.speed<self.speedmaxs[0]:self.speed=self.speedmaxs[0]
          if keydown(self.keyso[1]):
            self.speed+=75*deltatime
            if self.speed>self.speedmaxs[1]:self.speed=self.speedmaxs[1]
          if abs(self.speed)>20:
            if keydown(self.keyso[2]):self.dir-=100*deltatime
            if keydown(self.keyso[3]):self.dir+=100*deltatime
def getnbofplayerchnage(nombredebots,nbofplayers,refresh,coolclick):
          if keydown(KEY_RIGHT):
            if (nombredebots+nbofplayers)==4:
              if nbofplayers!=0:
                nbofplayers-=1
                nombredebots+=1
                refresh=True
                coolclick=monotonic()
            else:
              nombredebots+=1
              refresh=True
              coolclick=monotonic()
          if keydown(KEY_LEFT):
            if nombredebots!=0:
              if (nombredebots+nbofplayers)!=2:
                nombredebots-=1
                refresh=True
                coolclick=monotonic()
          return nombredebots,nbofplayers,refresh,coolclick
def changetimeperelim(tempsparelim,refresh,coolclick):
          if keydown(KEY_RIGHT):
              tempsparelim+=1
              refresh=True
              coolclick=monotonic()
          if keydown(KEY_LEFT):
            if tempsparelim!=1:
              tempsparelim-=1
              refresh=True
              coolclick=monotonic()
          return tempsparelim,refresh,coolclick
def snakeresetor(gamescene,nbjperteam,team1,havsetteam):
      for kat in gamescene:
        kat.speed=0
        if nbjperteam==1:
          if kat.idi==0:
            kat.x=5
            kat.y=120
            kat.dir=0
          else:
            kat.x=315
            kat.y=120
            kat.dir=180
        else:
          if kat.idi in team1:
            kat.x=5
            kat.dir=0
            if havsetteam[0]==0:
               havsetteam[0]=1
               kat.y=100
            else:
              kat.y=140
          else:
            kat.x=315
            kat.dir=180
            if havsetteam[1]==0:
               havsetteam[1]=1
               kat.y=100
            else:
              kat.y=140
      kat.oldx=kat.x
      kat.oldy=kat.y
      kat.olddir=kat.dir
      if kat.isia:
        kat.dir=angle_to_point(kat.x,kat.y,kat.gox,kat.goy)

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.