highway_game.py

Created by marius-layan

Created on February 05, 2024

6.66 KB

Voici mon jeu nommé highway, le but est simple:

on incarne une petite voiture rouge qui doit éviter les autres voitures qui arrives en face, sinon c’est Game Over. (un code de triche à était intégré, a vous de chercher dans le script c’est quoi) Le jeu est fonctionnel mais il manque un système de vitesse progressive.

BON JEU !


from math import *
from random import *
from ion import *
from kandinsky import *
from time import *
while True:
  yy,ab,ac,ad,a,b,c,d,e,f,g,l,u,r,k,w,p,q,z,v,x=1,30,-40,220,230,0,0,0,0,50,50,0,0,0,0,0,0,0,0,2,0
  liste,bb,dd,cc,carL,grass,road,strip,h,j,i=[145,82,207],(70,90,255),2,0,[(230,20,20),(10,10,230),(240,240,240),(20,190,20),(255,150,50)],(50,200,50),(100,100,100),(230,230,230),(230,20,20),(a-230,0,150),(20,20,20)
  fill_rect(0,0,320,222,grass);fill_rect(60,0,200,222,road);fill_rect(60,0,8,222,strip);fill_rect(252,0,8,222,strip);fill_rect(124,0,5,30,strip);fill_rect(188,0,5,30,strip);fill_rect(124,45,5,30,strip);fill_rect(188,45,5,30,strip);fill_rect(124,90,5,30,strip);fill_rect(188,90,5,30,strip);fill_rect(124,135,5,30,strip);fill_rect(188,135,5,30,strip);fill_rect(a-145,220,20,-40,h);fill_rect(a-138,180,6,-5,h);fill_rect(a-144,175,18,-3,h);fill_rect(a-140,210,10,-10,j);fill_rect(a-126,220,4,-10,i);fill_rect(a-148,220,4,-10,i);fill_rect(a-148,195,3,-10,i);fill_rect(a-125,195,3,-10,i)
  car,car2=choice(carL),choice(carL)
  while 1==yy:
    c+=1
    if e!=f and e!=f+0.5:e+=dd
    if keydown(KEY_RIGHT) and a!=360 and e==g:
      a+=13
      if a>216:fill_rect(a-145,ad,20,-40,h);fill_rect(a-138,180,6,-5,h);fill_rect(a-145,175,20,-3,h);fill_rect(a-140,210,10,-10,j);fill_rect(a-126,220,4,-10,i);fill_rect(a-148,220,4,-10,i);fill_rect(a-148,195,3,-10,i);fill_rect(a-125,195,3,-10,i);fill_rect(a-165,ad-10,20,-15,road);fill_rect(a-165,185,20,-5,road);fill_rect(a-165,220,17,-48,road);fill_rect(a-150,183,5,-11,road);fill_rect(40,160,20,62,grass)
      else:fill_rect(a-145,ad,20,-40,h);fill_rect(a-138,180,6,-5,h);fill_rect(a-145,175,20,-3,h);fill_rect(a-140,210,10,-10,j);fill_rect(a-126,220,4,-10,i);fill_rect(a-148,220,4,-10,i);fill_rect(a-148,195,3,-10,i);fill_rect(a-125,195,3,-10,i);fill_rect(a-165,ad-10,20,-15,grass);fill_rect(a-165,185,20,-5,grass);fill_rect(a-165,220,17,-48,grass);fill_rect(a-150,183,5,-11,grass)
      if a<240:fill_rect(60,230,8,-60,strip)
      l+=1;e=0
    if keydown(KEY_LEFT) and a!=230 and e==g and a!=152:
      a-=13
      if a>229:fill_rect(a-145,ad,20,-40,h);fill_rect(a-138,180,6,-5,h);fill_rect(a-145,175,20,-3,h);fill_rect(a-140,210,10,-10,j);fill_rect(a-126,220,4,-10,i);fill_rect(a-148,220,4,-10,i);fill_rect(a-148,195,3,-10,i);fill_rect(a-125,195,3,-10,i);fill_rect(a-125,ad-10,20,-15,road);fill_rect(a-125,185,20,-5,road);fill_rect(a-122,220,17,-48,road);fill_rect(a-125,183,5,-11,road)
      else:fill_rect(a-145,ad,20,-40,h);fill_rect(a-138,180,6,-5,h);fill_rect(a-145,175,20,-3,h);fill_rect(a-140,210,10,-10,j);fill_rect(a-126,220,4,-10,i);fill_rect(a-148,220,4,-10,i);fill_rect(a-148,195,3,-10,i);fill_rect(a-125,195,3,-10,i);fill_rect(a-125,ad-10,20,-15,grass);fill_rect(a-125,185,20,-5,grass);fill_rect(a-122,220,17,-48,grass);fill_rect(a-125,183,5,-11,grass);fill_rect(60,170,40,52,road)
      if a<240:fill_rect(60,230,8,-60,strip)
      l+=1;e=0
    if keydown(KEY_ONE) and keydown(KEY_TWO) and keydown(KEY_THREE) and e==g and a>229:
      draw_string("code",a-155,ad-50);draw_string("de",a-145,ad-34);draw_string("triche",a-165,ad-18);fill_rect(a-150,ad-32,5,10,road);fill_rect(a-125,ad-32,5,10,road)
      sleep(0.5)
      draw_string("code",a-155,ad-50,'green','red');draw_string("de",a-145,ad-34,'green','red');draw_string("triche",a-165,ad-18,'green','red')
      sleep(0.03)
      draw_string("code",a-155,ad-50,'white','black');draw_string("de",a-145,ad-34,'white','black');draw_string("triche",a-165,ad-18,'white','black')
      sleep(0.03)
      draw_string("code",a-155,ad-50,'blue','yellow');draw_string("de",a-145,ad-34,'blue','yellow');draw_string("triche",a-165,ad-18,'blue','yellow')
      sleep(0.03)
      fill_rect(a-165,ad+10,60,-60,road)
      if a==230:fill_rect(a-165,ad+10,3,-60,strip)
      if a==360:fill_rect(252,0,8,222,strip)
      a,e=165,0;fill_rect(a-145,ad,20,-40,h);fill_rect(a-138,180,6,-5,h);fill_rect(a-145,175,20,-3,h);fill_rect(a-140,210,10,-10,j);fill_rect(a-126,220,4,-10,i);fill_rect(a-148,220,4,-10,i);fill_rect(a-148,195,3,-10,i);fill_rect(a-125,195,3,-10,i);l+=1
    if c==v:
      draw_string("score: ",260,0,'white','green');draw_string(str(x),260,18,'white','green');x+=1
      if p==0:p=choice(liste);p+=1
      fill_rect(p,b,ab,ac,car);fill_rect(p+22,b,8,-5,'yellow');fill_rect(p,b,8,-5,'yellow');fill_rect(p,b-51,31,1,road);fill_rect(p,b-10,-3,-13,'black');fill_rect(p,b-13,-3,-2,road);fill_rect(p,b-35,-3,-13,'black');fill_rect(p,b-48,-3,-2,road);fill_rect(p,b-10,-3,-13,'black');fill_rect(p,b-23,-3,-2,road);fill_rect(p+33,b-35,-3,-13,'black');fill_rect(p+33,b-48,-3,-2,road);fill_rect(p+33,b-10,-3,-13,'black');fill_rect(p+33,b-23,-3,-2,road);fill_rect(p+2,b-10,25,-10,bb);b+=1;k,c=1,0;u+=1;w+=1
    if u==280:car,b,u,p=choice(carL),0,0,choice(liste)
    if w==420:car2,w,r,q=choice(carL),140,0,choice(liste)
    if w>140 and k==1:
      if q==0:q=choice(liste);q+=1
      fill_rect(q,r,ab,ac,car2);fill_rect(q+22,r,8,-5,'yellow');fill_rect(q,r,8,-5,'yellow');fill_rect(q,r-51,31,1,road);fill_rect(q,r-10,-3,-13,'black');fill_rect(q,r-13,-3,-2,road);fill_rect(q,r-35,-3,-13,'black');fill_rect(q,r-48,-3,-2,road);fill_rect(q,r-10,-3,-13,'black');fill_rect(q,r-23,-3,-2,road);fill_rect(q+33,r-35,-3,-13,'black');fill_rect(q+33,r-48,-3,-2,road);fill_rect(q+33,r-10,-3,-13,'black');fill_rect(q+33,r-23,-3,-2,road);fill_rect(q+2,r-10,25,-10,bb);r+=1;k=0
    if b<ad<b-ac and p<a-145<p+ab+3:yy=0
    elif q<a-145<q+ab+3 and r<ad<r-ac:yy=0
    elif b<ad<b-ac and p-3<a-145+20<p+ab:yy=0
    elif q-3<a-145+20<q+ab and r<ad<r-ac:yy=0
    elif b<ad+40<b-ac and p<a-145<p+ab+3:yy=0
    elif q<a-145<q+ab+3 and r<ad+40<r-ac:yy=0
    elif b<ad+40<b-ac and p-3<a-145+20<p+ab:yy=0
    elif q-3<a-145+20<q+ab and r<ad+40<r-ac:yy=0
  if yy==0:
    h,j=(160,20,20),(0,0,60);fill_rect(a-145,ad,20,-40,h);fill_rect(a-138,180,6,-5,h);fill_rect(a-145,175,20,-3,h);fill_rect(a-140,210,10,-10,j);fill_rect(a-126,220,4,-10,i);fill_rect(a-148,220,4,-10,i);fill_rect(a-148,195,3,-10,i);fill_rect(a-125,195,3,-10,i)
    sleep(0.4)
    fill_rect(260,0,60,50,grass);fill_rect(68,0,55,222,road);fill_rect(129,0,58,222,road);fill_rect(193,0,55,222,road);fill_rect(68,170,180,222,road)
    sleep(0.1)
    draw_string("GAME OVER",113,90,'black','red')
    sleep(0.2)
    sc,triche=111,0
    if x<1000:sc-=0
    elif 999<x<10000:sc-=5
    elif 9999<x<100000:sc-=10
    elif 99999<x<1000000:sc-=15
    elif 999999<x<10000000:sc-=20
    else:triche=1
    if triche==0:draw_string("Score: ",sc,120,'black',grass);draw_string(str(x),sc+63,120,'black',grass)
    elif triche==1:draw_string("Tu as trafique ton Score ?",sc-80,120,'black',grass)
    while True:
      draw_string("PLAY",139,20,'red',road);draw_string("[OK]",139,50,'green',road)
      if keydown(KEY_OK) or keydown(KEY_EXE):
        break