platformer.py

Created by chambounaudaubin

Created on January 01, 2025

9.73 KB


#script par Aubin Chambounaud
#440 lignes de code

from math import *
from kandinsky import fill_rect as f
from time import sleep as s
from ion import keydown as k,KEY_LEFT as kl, KEY_OK as ko, KEY_RIGHT as kr, KEY_UP as ku, KEY_DOWN as kd, KEY_EXE as ke
from kandinsky import *

play=1
def page():
  fill_rect(0,0,320,280,color(173,216,230))
  fill_rect(65,60,190,60,'white')
  fill_rect(0,212,320,5,'green')
  fill_rect(0,217,320,5,'brown')
  fill_rect(0,0,320,5,'green')
  fill_rect(0,5,320,5,'brown')
  draw_string("Jeu par Aubin",95,30,'black',color(173,216,230))
page()
selection=1
while play==1:
  if k(ku):
    selection=1
  if k(kd):
    selection=2
  if selection==1:
    draw_string("> comment jouer? <",70,70,'red')
    draw_string("      Jouer       ",70,90,'orange')
  else:
    draw_string("  comment jouer?  ",70,70,'orange')
    draw_string(">     Jouer      <",70,90,'red')
  if k(ko) and selection==1:
    draw_string("- fleches pour bouger",55,125,'black',color(173,216,230))
    draw_string("- OK pour sauter",55,145,'black',color(173,216,230))
    draw_string("- essaie de monter sur",55,165,'black',color(173,216,230))
    draw_string("  le nuage au niveau 4 ",55,185,'black',color(173,216,230))
  if k(ko) and selection==2:
    play=0
go=1

#definition des variables
x=0
y=100
xn=-30
yn=20
cloud_sens=1
fall=1
jump=-1
ground=1
background=1
xs=0
ys=0
jump_nb=0
note=0
time=0
death=0
fjc=0

#ciel
f(0,0,320,280,color(173,216,230))

#creation des piques
def spikes(xs,xy):
  f(xs,ys,10,1,'gray')
  f(xs,ys-1,10,1,'gray')
  f(xs+1,ys-2,8,1,'gray')
  f(xs+2,ys-3,6,1,'gray')
  f(xs+2,ys-4,6,1,'gray')
  f(xs+3,ys-5,4,1,'gray')
  f(xs+4,ys-6,2,1,'gray')
  f(xs+5,ys-7,1,1,'gray')

while go==1:
  #arriere plan
  if background==1:
    f(0,110,200,150,'green')
    f(100,210,250,50,'green')
    f(314,199,7,12,'orange')
    f(315,200,5,10,'yellow')
    f(50,70,10,40,'brown')
    f(30,50,40,20,'green')
    f(40,40,20,20,'green')
    f(40,80,10,10,'green')
  if background==2:
    f(0,150,40,80,'green')
    f(40,170,60,60,'green')
    f(100,150,120,80,'green')
    f(220,130,20,100,'green')
    f(240,150,100,80,'green')
    f(314,139,7,12,'orange')
    f(315,140,5,10,'yellow')
    xs=140
    ys=150
    spikes(xs,ys)
    xs=150
    spikes(xs,ys)
    xs=230
    ys=130
    spikes(xs,ys)
  if background==3:
    f(0,190,20,5,'green')
    f(60,170,20,5,'green')
    f(120,150,30,5,'green')
    f(185,170,10,5,'green')
    f(230,170,5,20,'green')
    f(280,170,5,20,'green')
    f(310,170,10,5,'green')
    f(0,195,20,5,'brown')
    f(60,175,20,5,'brown')
    f(120,155,30,5,'brown')
    f(185,175,10,5,'brown')
    f(230,175,5,20,'brown')
    f(280,175,5,20,'brown')
    f(310,175,10,5,'brown')
    f(314,159,7,12,'orange')
    f(315,160,5,10,'yellow')
  if background==4:
    f(0,180,20,5,'green')
    f(40,160,20,5,'green')
    f(80,140,20,5,'green')
    f(120,120,20,5,'green')
    f(120,90,20,5,'green')
    f(120,60,20,5,'green')
    f(120,20,20,5,'green')
    f(180,40,20,5,'green')
    f(220,40,20,5,'green')
    f(300,160,20,5,'green')
    f(0,185,20,5,'brown')
    f(40,165,20,5,'brown')
    f(80,145,20,5,'brown')
    f(120,125,20,5,'brown')
    f(120,95,20,5,'brown')
    f(120,65,20,5,'brown')
    f(120,25,20,5,'brown')
    f(180,45,20,5,'brown')
    f(220,45,20,5,'brown')
    f(300,165,20,5,'brown')
    f(260,80,60,5,'green')
    f(260,85,60,5,'brown')
    xs=260
    ys=80
    spikes(xs,ys)
    xs=270
    ys=80
    spikes(xs,ys)
    xs=280
    ys=80
    spikes(xs,ys)
    xs=290
    ys=80
    spikes(xs,ys)
    xs=300
    ys=80
    spikes(xs,ys)
    xs=310
    ys=80
    spikes(xs,ys)
    f(314,149,7,12,'orange')
    f(315,150,5,10,'yellow')
  #personnage
  f(x-1,y-1,12,12,color(173,216,230))
  f(x,y,10,10,'black')
  f(x+2,y+3,2,2,'white')
  f(x+6,y+3,2,2,'white')
  f(x+2,y+7,6,1,'white')
  #nuage
  if cloud_sens>0 and cloud_sens<=351:
    xn=xn+1
    cloud_sens=cloud_sens+1
  if cloud_sens>351:
    cloud_sens=-1
  if cloud_sens<0 and cloud_sens>=-351:
    cloud_sens=cloud_sens-1
    xn=xn-1
  if cloud_sens<-351:
    cloud_sens=1
  f(xn-1,yn-1,32,12,color(173,216,230))
  f(xn+9,yn-11,12,12,color(173,216,230))
  f(xn,yn,30,10,'white')
  f(xn+10,yn-10,10,10,'white')
  #saut
  if jump>=0:
    y=y-1
    jump=jump-1
  #contrainte du bord
  if x<0:
    x=x+1
  if x>310:
    x=x-1
  #contraintes du terrain 1
  if background==1:
    #resistance du sol et gravite
    if jump==-1:
      if 0<=x<200 and y<100:
        y=y+fall
      if x>=200 and y<200:
        y=y+fall
      if y==100 and x<200:
        ground=1
      elif y==200:
        ground=1
      else:
        ground=0
    #resistance du mur
    if x<=200 and y>100 and k(kl):
        x=x+1
    #niveau suivant
    if y>190 and x>315-10:
      f(0,0,320,280,color(173,216,230))
      background=2
      x=5
      y=140
  if background==2:
    if jump==-1:
      #resistance du sol et gravite
      if x<40 and y<140:
        y=y+fall
      if y==140 and x<40:
        ground=1
      if x>=40 and x<=90 and y<160:
        y=y+fall
      if x>=40 and x<90 and y==160:
        ground=1
      if x>40 and x<90 and y<160 :
        ground=0
      if x>=90 and x<210 and y<140:
        y=y+fall
      if y==140 and x<=40:
        ground=1
      if y==140 and x>90 and x<210:
        ground=1
      if x>=210 and x<240 and y<120:
        y=y+1
      if x>=210 and x<=240 and y==120:
        ground=1
      if x>=240 and y<140:
        y=y+1
      if x>240 and y==140:
        ground=1
    #resistance du mur
    if x<=40 and y<=160 and y>140 and k(kl):
      x=x+1
    if x>=90 and y<=160 and y>140 and k(kr):
      x=x-1
    if x>=210 and x<=220 and y<=140 and y>120:
      x=x-1
    if x<=240 and x>=220 and y<=140 and y>120 and k(kl):
      x=x+1
    #detection des piques
    if x>130 and x<150 and y<=140 and y>132:
      f(x-2,y-2,14,14,color(173,216,230))
      x=10
      y=120
      death=death+1
    if x>140 and x<160 and y<=140 and y>132:
      f(x-2,y-2,14,14,color(173,216,230))
      x=10
      y=120
      death=death+1
    if x>220 and x<240 and y<=120 and y>112:
      f(x-2,y-2,14,14,color(173,216,230))
      x=10
      y=120  
      death=death+1
    #niveau suivant
    if y>130 and x>305:
      f(0,0,320,280,color(173,216,230))
      background=3
      x=0
      y=180
  if background==3:
    #lave
    f(0,200,320,100,'red')
    if jump==-1:
      if x>=0 and x<=20 and y==180:
        ground=1
      elif x>=50 and x<=80 and y==160:
        ground=1
      elif x>=110 and x<=150 and y==140:
        ground=1
      elif x>=175 and x<=195 and y==160:
        ground=1
      elif x>=220 and x<=235 and y==160:
        ground=1
      elif x>=270 and x<=285 and y==160:
        ground=1
      elif x>=300 and x<=330 and y==160:
        ground=1
      else:
        ground=0
      if ground==0:
        y=y+fall
    #niveau suivant
    if x>300 and y==160:
      background=4
      x=0
      y=150
      f(0,0,320,280,color(173,216,230))
    #detection de la lave
    if y==190:
      f(x-2,y-2,14,14,color(173,216,230))
      x=0
      y=160
      death=death+1
  if background==4:
    #lave
    f(0,200,320,100,'red')
    if y<=100 and y>=85 and x>=110 and x<=140:
      jump=-1
    if y<=70 and y>=55 and x>=110 and x<=140:
      jump=-1
    if y==30 and x>=110 and x<=140:
      jump=-1
    if jump==-1:
      if x>=0 and x<=20 and y==170:
        ground=1
      elif x>=30 and x<=60 and y==150:
        ground=1
      elif x>=70 and x<=100 and y==130:
        ground=1
      elif x>=110 and x<=140 and y==110:
        ground=1
      elif x>=110 and x<=140 and y==80:
        ground=1
      elif x>=110 and x<=140 and y==50:
        ground=1
      elif x>=110 and x<=140 and y==10:
        ground=1
      elif x>=170 and x<=200 and y==30:
        ground=1
      elif x>=210 and x<=240 and y==30:
        ground=1
      elif x>=290 and x<=310 and y==150:
        ground=1
      elif x>=xn-10 and x<=xn+30 and y==yn-10:
        ground=1
      else:
        ground=0
      if ground==0:
        y=y+fall
    #rencontre avec nuage
      if x>xn-10 and x<xn+30 and y==yn-10:
        ground=1
        y=yn-10
        if cloud_sens>0:
          x=x+1
        else:
          x=x-1
    #colision avec piques et lave
    if x>=250 and x<=320 and y>=62 and y<=80:
      f(x-2,y-2,14,14,color(173,216,230))
      x=0
      y=150
      death=death+1
    if y>190:
      f(x-2,y-2,14,14,color(173,216,230))
      x=0
      y=150
      death=death+1
    #fin
    if x>=300 and y==150:
      go=0
  #definition des touches de controle
  #saut
  if k(ko) and ground==1 or k(ke) and ground==1:
    if fjc>10:
      jump=30
      jump_nb=jump_nb+1
      ground=0
  #avancer
  if k(kr):
    x=x+1
  #reculer
  if k(kl):
    x=x-1
  #pause
  s(0.01)
  time=time+1
  fjc=fjc+1
print(" ")
print("x=",x,",","y=",y)
print("temps=",time)
print("nb de saut=",jump_nb)
print("morts=",death)
if death==0:
  death=6.6
elif death==1:
  death=5.5
elif death==2:
  death=5
elif death==3:
  death=4
elif death<5:
  death=3
elif death<8:
  death=2
elif death<=10:
  death=1
elif death>10:
  death=0
if jump_nb<16:
  jump_nb=6.6
elif jump_nb<20:
  jump_nb=6
elif jump_nb<25:
  jump_nb=5.5
elif jump_nb<60:
  jump_nb=5
elif jump_nb<80:
  jump_nb=4
elif jump_nb<=120:
  jump_nb=2
elif jump_nb>120:
  jump_nb=0
if time<1600:
  time=6.6
elif time<1700:
  time=6
elif time<1900:
  time=5
elif time<2100:
  time=4
elif time<3000:
  time=3
elif time<4000:
  time=2
elif time<=5000:
  time=1
elif time>5000:
  time=0
note=round(death+jump_nb+time)
f(0,0,320,280,color(173,216,230))
draw_string("Bravo!",130,80,'black',color(173,216,230))
draw_string("Tu as reussi les 4 niveaux",50,100,'black',color(173,216,230))
draw_string("jeu par Aubin",100,120,'black',color(173,216,230))
draw_string("performance:"+str(note)+"/20",70,140,'black',color(173,216,230))
fill_rect(0,212,320,5,'green')
fill_rect(0,217,320,5,'brown')
fill_rect(0,0,320,5,'green')
fill_rect(0,5,320,5,'brown')

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.