snake_kart_8_war_and_ball.py

Created by furicoda

Created on September 19, 2024

13.4 KB


from snake_kart_8_assets_1 import*
class gamegeror:
  def __init__(self):
    self.gamemode=2
    self.menuin=0
    self.refresh=True
    self.deltatime=0
    self.deltainit=0
    self.nbofplayers=1
    self.butselect=0
    self.coolclick=-1
    self.tempslimite=60
    self.nombredebots=3
    self.aipower=2
    self.timerrelaunch=0
    self.nbjperteam=1
    self.typofteam=0
    self.scoreteam1=0
    self.scoreteam2=0
    self.oldscore1=-1
    self.oldscore2=-1
def initmap(Game):
  Game.gamescene=[]
  Game.timer=-5
  Game.classement=[]
  Game.timerrelaunch=-5
  Game.scoreteam1=0
  Game.scoreteam2=0
  Game.oldscore1=-1
  Game.oldscore2=-1
  if Game.gamemode==1 or Game.gamemode==2:
    fill_rect(0,0,320,20,"black")
    fill_rect(0,20,320,210,"gray")
  cp=0
  for add in range(Game.nbofplayers):
    Game.gamescene.append(Kart(idi=cp,ai=False,Game=Game))
    cp+=1
  for add in range(Game.nombredebots):
    Game.gamescene.append(Kart(idi=cp,ai=True,Game=Game))
    cp+=1
  if Game.gamemode==2:
    if Game.nbjperteam==1:
      if len(Game.gamescene)>2:
        Game.gamescene=[Game.gamescene[0],Game.gamescene[1]]
    team1=(0,1)
    if Game.typofteam==1:
        team1=(0,2)
    if Game.typofteam==2:
        team1=(0,3)
    havsetteam=[0,0]
    Game.balle=Ballsnick()
    snakeresetor(Game.gamescene,Game.nbjperteam,team1,havsetteam)
def gameupdate(Game):
  Game.timer+=Game.deltatime
  Game.timerrelaunch+=Game.deltatime
  if Game.gamemode==1:
    if Game.timer>=0:
      draw_string(str(round(Game.timer,3)),270,0,"yellow","black")
    elif Game.timer>=-3.5:
      nb=abs(floor(Game.timer))
      if nb>3:
        nb=3
      draw_string(str(nb),270,0,"orange","black")
  else:
    if Game.timerrelaunch>=0:
      var=(Game.timer>Game.tempslimite) and (Game.scoreteam1==Game.scoreteam2)
      draw_string(str(floor(Game.timer)),160,0,"red" if var else "yellow","black")
    elif Game.timerrelaunch>=-3.5:
      nb=abs(floor(Game.timerrelaunch))
      if nb>3:
        nb=3
      fill_rect(160,0,30,15,"black")
      draw_string(str(nb),160,0,"orange","black")
  if Game.gamemode==1:
    if  Game.timer>Game.tempslimite:
      Game.classement=[]
      Game.menuin=3  
      Game.col=getscreenper()
      Game.sommecol=getsommecol(Game.col,Game.nbjperteam)
      if Game.nbjperteam==2:
        Game.classement=Game.sommecol
      if Game.nbjperteam==1:
        temp=Game.sommecol.copy()
        for x in range(Game.nbofplayers+Game.nombredebots):
          Game.classement.append(Game.sommecol.index(max(Game.sommecol)))
          Game.sommecol[Game.sommecol.index(max(Game.sommecol))]=-1
        Game.sommecol=temp
  elif Game.gamemode==2:
    if  Game.timer>Game.tempslimite:
      if Game.scoreteam1!=Game.scoreteam2:
        Game.menuin=0
    team1=(0,1)
    if Game.typofteam==1:
      team1=(0,2)
    if Game.typofteam==2:
      team1=(0,3)
    havsetteam=[0,0]
    Game.scoreteam1+=Game.balle.x>315
    Game.scoreteam2+=Game.balle.x<5
    if Game.balle.x>315 or Game.balle.x<5:
      Game.balle.reset()
      Game.timerrelaunch=-5
      snakeresetor(Game.gamescene,Game.nbjperteam,team1,havsetteam)
    if Game.oldscore1!=Game.scoreteam1:
      Game.oldscore1=Game.scoreteam1
      draw_string(str(Game.scoreteam1),80,0,(255,0,0),"black")
    if Game.oldscore2!=Game.scoreteam2: 
      Game.oldscore2=Game.scoreteam2
      draw_string(str(Game.scoreteam2),240,0,(0,255,255),"black")
    Game.balle.update(Game)
  for ele in Game.gamescene:
    ele.update(Game)
    ele.affich(Game)
def podiumupdate(Game):
  if keydown(KEY_SHIFT):
    Game.menuin=0
    refreshmenu(Game)
class Kart:
  def __init__(self,idi,ai,Game):
    self.idi=idi
    self.isia=ai
    self.x=0
    self.y=0
    self.dir=0
    if Game.gamemode==1:
      setselfterritoire(self)
    if Game.gamemode==2:
      self.x=10
      self.y=100
      if self.idi==0:
        self.gox=randint(10,315)
        self.goy=randint(30,215)
      elif self.idi==1:
        self.gox=randint(10,315)
        self.goy=randint(30,215)
      elif self.idi==2:
        self.gox=randint(10,315)
        self.goy=randint(30,215)
      elif self.idi==3:
        self.gox=randint(10,315)
        self.goy=randint(30,215)
    infoforallset(self)
  def affich(self,Game):
    if Game.gamemode==1 or Game.gamemode==2:
      if Game.nbjperteam==1:
        if Game.gamemode==2:
          if self.idi ==0:
            fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,(255,0,0))
          else:
            fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,(0,255,255))
        else:
          fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,self.tcolor)
      else:
        colorteam1=(255,0,0)
        colorteam2=(0,255,255)
        if Game.typofteam==0:
          if self.idi in (0,1):
            fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,colorteam1)
          else:
            fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,colorteam2)
        if Game.typofteam==1:
          if self.idi in (0,2):
            fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,colorteam1)
          else:
            fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,colorteam2)
        if Game.typofteam==2:
          if self.idi in (0,3):
            fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,colorteam1)
          else:
            fill_rect(int(self.oldx-5),int(self.oldy-5),11,11,colorteam2)
    predirval=0.01745329251994329*self.dir
    precosval=cos(predirval)
    presinval=sin(predirval)
    stx=0
    sty=0
    for x in (0,1,2,3,4,5,6,7,8,9):
      stx+=precosval
      sty+=presinval
      set_pixel(int(self.x+stx),int(self.y+sty),self.color)
    self.oldx=self.x
    self.oldy=self.y
    self.olddir=self.dir
  def update(self,Game):
    if not Game.timerrelaunch>0:
      return
    if self.iseliminated:
      return
    self.cango-=Game.deltatime*(self.cango>-1)
    if Game.timer<0:
      if self.isia :return
      if keydown(self.keyso[1]):
        self.chargingstartval+=Game.deltatime
      else:
        self.chargingstartval=0
      return
    startinfo(self)
    if Game.gamemode==2:
      speedgeror(self,Game.deltatime)
    else:
      if self.cango<=0 and not self.isia:
            speedgeror(self,Game.deltatime)
    predirval=0.01745329251994329*self.dir
    precosval=cos(predirval)
    presinval=sin(predirval)
    if self.isia:
      self.speed=randrange(50+10*Game.aipower,70+10*Game.aipower)
    self.x+=precosval*self.speed*Game.deltatime
    self.y+=presinval*self.speed*Game.deltatime
    setx=0
    sety=0
    for xte in (-1,0,1,2,3,4,5,6,7,8,9,10):
        setx+=precosval
        sety+=presinval
        if self.x+setx>320:
          self.x=320-setx
          self.speed=0
        if self.y+sety>220:
          self.y=220-sety
          self.speed=0
        if self.x+setx<0:
          self.x=-setx
          self.speed=0
        if self.y+sety<20:
            self.y=20-sety
            self.speed=0
    if self.speed>0 and not keydown(self.keyso[1]):
      self.speed-=Game.deltatime*30
    elif self.speed<0 and not keydown(self.keyso[0]):
      self.speed+=Game.deltatime*30
    if abs(self.speed)<0.1 and not (keydown(self.keyso[0]) or keydown(self.keyso[0])):
      self.speed=0
    if self.isia and distance(self.x,self.y,self.gox,self.goy)<4:
        self.gox=randint(10,310)
        self.goy=randint(30,210)
        self.dir=angle_to_point(self.x,self.y,self.gox,self.goy)
    if keydown(self.keyso[4]) and not self.isia  and self.cango<=0:
        self.coolres-=Game.deltatime
        bataillerespawn(self)
    else:
        self.coolres=3
def refreshpodium(Game):
  basepodium()
  if Game.nbjperteam==1:
    fillserps(["green","blue","yellow","pink"],Game.classement)
  else:
    color1=(255,0,0)
    color2=(0,255,255)
    if Game.classement[0]>Game.classement[1]:
      color1,color2=color2,color1
    fill_rect(120,120,4,40,color1)
    fill_rect(160,100,4,40,color2)
  if Game.gamemode==1:
    truc=[1,0,2,3]
    if Game.nbjperteam==1:
      for x in range(Game.nbofplayers+Game.nombredebots):
        draw_string((str(Game.sommecol[Game.classement[truc[x]]]/640)+"000000")[0:3]+" %",110+x*40,40+truc[x]*20,"black",(0,200,200))
    else:
      if Game.classement[0]<Game.classement[1]:
        draw_string((str(Game.classement[0]/640)+"000000")[0:3]+" %",110,60,"black",(0,200,200))
        draw_string((str(Game.classement[1]/640)+"000000")[0:3]+" %",150,40,"black",(0,200,200))
      else:
        draw_string((str(Game.classement[1]/640)+"000000")[0:3]+" %",110,60,"black",(0,200,200))
        draw_string((str(Game.classement[0]/640)+"000000")[0:3]+" %",150,40,"black",(0,200,200))
  draw_string("Shift pour aller au menu",20,20,"orange",(0,200,200))
def aideupdate(Game):
  if keydown(KEY_SHIFT):
    Game.refresh=True
    Game.menuin=0
def refreshmenu(Game):
  valc=18
  blueback=(40,60,250)
  fill_rect(0,0,320,320,blueback)
  draw_string("Snake Kart 8",50,0,(255,100,10),blueback)
  draw_string("Aide",50,valc,"orange" if Game.butselect==0 else "red",blueback)
  draw_string("Jouer",50,valc*2,"orange" if Game.butselect==1 else "red",blueback)
  draw_string("Mode de jeu :"+("guerre","snickball")[Game.gamemode-1],50,valc*3,"orange" if Game.butselect==2 else "red",blueback)
  draw_string("Bots QI : "+str(("nul","facile","normal","dur","extreme","impossible")[Game.aipower]),50,valc*4,"orange" if Game.butselect==3 else "red",blueback)
  draw_string("Nombres de joueurs : "+str(Game.nbofplayers),50,valc*5,"orange" if Game.butselect==4 else "red",blueback)
  draw_string("Temps limite : "+str(Game.tempslimite),50,valc*6,"orange" if Game.butselect==5 else "red",blueback)
  draw_string("Nombre de bots : "+str(Game.nombredebots),50,valc*7,"orange" if Game.butselect==6 else "red",blueback)
  draw_string("Joueurs par equipe : "+str(Game.nbjperteam),50,valc*8,"orange" if Game.butselect==7 else "red",blueback)
  if Game.nbjperteam==2:
    draw_string("Type d'equipe:"+str(("J1-J2:J3-J4","J1-J3:J2-J4","J1-J4:J2-J3")[Game.typofteam]),50,valc*9,"orange" if Game.butselect==8 else "red",blueback)
def menuupdate(Game):
  if monotonic()-Game.coolclick>0.2:
    if keydown(KEY_DOWN):
        if Game.nbjperteam==2:
          if Game.butselect==8:
            Game.butselect=0
          else:
            Game.butselect+=1
        else:
          if Game.butselect==7:
            Game.butselect=0
          else:
            Game.butselect+=1
        Game.refresh=True
        Game.coolclick=monotonic()
    if keydown(KEY_UP):
      Game.refresh=True
      Game.coolclick=monotonic()
      if Game.nbjperteam==2:
          if Game.butselect==0:
            Game.butselect=8
          else:
            Game.butselect-=1
      else:
          if Game.butselect==0:
            Game.butselect=7
          else:
            Game.butselect-=1
    if Game.butselect==0:
      if keydown(KEY_OK):
        Game.menuin=1#info
        Game.refresh=True
    if Game.butselect==1:
      if keydown(KEY_OK):
        Game.menuin=2#play
        Game.refresh=True
        initmap(Game)
    if Game.butselect==2:
        if keydown(KEY_RIGHT):
          if Game.gamemode!=2:
            Game.gamemode+=1
            Game.refresh=True
            Game.coolclick=monotonic()
        if keydown(KEY_LEFT):
          if Game.gamemode!=0:
            Game.gamemode-=1
            Game.refresh=True
            Game.coolclick=monotonic()
    if True:
      if Game.butselect==3:Game.aipower,Game.refresh,Game.coolclick=changeaipower(Game.aipower,Game.refresh,Game.coolclick)
      if Game.butselect==4:Game.nombredebots,Game.nbofplayers,Game.refresh,Game.coolclick=getnbofbotchnage(Game.nombredebots,Game.nbofplayers,Game.refresh,Game.coolclick)
      if Game.butselect==5:Game.tempslimite,Game.refresh,Game.coolclick=changetimeval(Game.tempslimite,Game.coolclick,Game.refresh)
      if Game.butselect==6:Game.nombredebots,Game.nbofplayers,Game.refresh,Game.coolclick=getnbofplayerchnage(Game.nombredebots,Game.nbofplayers,Game.refresh,Game.coolclick)
      if Game.butselect==7:
        if keydown(KEY_RIGHT) or keydown(KEY_LEFT):
            if Game.nbjperteam==1:
              Game.nbjperteam=2
              if (Game.nombredebots+Game.nbofplayers)==3:
                if Game.nombredebots==4:
                  Game.nbofplayers+=1
                else:
                  Game.nombredebots+=1
            else:
              Game.nbjperteam=1
            Game.refresh=True
            Game.coolclick=monotonic()
      if Game.butselect==8:
        if keydown(KEY_RIGHT):
            if Game.typofteam==2:
              Game.typofteam=0
            else:
              Game.typofteam+=1
            Game.refresh=True
            Game.coolclick=monotonic()
        if keydown(KEY_LEFT):
            if Game.typofteam==0:
              Game.typofteam=2
            else:
              Game.typofteam-=1
            Game.refresh=True
            Game.coolclick=monotonic()
    if Game.nbjperteam==2:     
      if (Game.nombredebots+Game.nbofplayers)==2: 
        Game.nbjperteam=1
      elif (Game.nombredebots+Game.nbofplayers)==3: 
        Game.nbjperteam=1
def gameloop(Game):
  while True:
    Game.deltainit=monotonic()
    if Game.menuin==0:
      if Game.refresh:
        Game.refresh=False
        refreshmenu(Game)
      menuupdate(Game)
    if Game.menuin==1:
      if Game.refresh:
        Game.refresh=False
        refreshaide(Game)
      aideupdate(Game)
    if Game.menuin==2:
      gameupdate(Game)
    if Game.menuin==3:
      if Game.refresh:
        refreshpodium(Game)
      podiumupdate(Game)
      Game.refresh=False
    Game.deltatime=monotonic()-Game.deltainit
    if Game.deltatime!=0:
      draw_string(str(1/Game.deltatime),240,20)
launcherwindow()
gameloop(gamegeror())

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.