jeu_de_platforme.py
Created by
charlie18-coquel
Created on
November 07, 2021
6.25 KB
from kandinsky import *
from time import *
from random import *
from ion import *
loop = 0
levell = 15
limitup = 31
limitdown = 191
game = 0
jumpcount = 0
yplat = []
xplat = []
lplat = []
count = 0
lava = 0
def background ():
fill_rect ( 0 , 0 , 320 , 222 , ' black ' )
def randomlevel ( x , y , l ):
for i in range ( levell ):
l . insert ( i , randint ( 10 , 80 ))
if i == 0 :
y . insert ( i , randint ( limitup , limitdown ))
x . insert ( i , 100 )
else :
x . insert ( i , x [ i - 1 ] + randint ( 125 , 150 ))
updown = randint ( 1 , 2 )
randomh = randint ( 1 , 40 )
if updown == 1 :
if y [ i - 1 ] - randomh < limitup :
y . insert ( i , limitup )
else :
y . insert ( i , y [ i - 1 ] - randomh )
elif updown == 2 :
y . insert ( i , randint ( y [ i - 1 ], limitdown ))
def plateforms ():
for i in range ( levell ):
if i == levell - 1 :
fill_rect ( xplat [ i ], yplat [ i ], lplat [ i ], 5 , ' green ' )
else :
fill_rect ( xplat [ i ], yplat [ i ], lplat [ i ], 5 , ' white ' )
def platformsresetright ():
for i in range ( levell ):
fill_rect ( xplat [ i ] + lplat [ i ], yplat [ i ], 1 , 10 , ' black ' )
def platformsresetleft ():
for i in range ( levell ):
fill_rect ( xplat [ i ] - 1 , yplat [ i ], 1 , 10 , ' black ' )
def hero_static ():
fill_rect ( xp + 3 , yp + 1 , 3 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 2 , 5 , 1 , ' white ' )
fill_rect ( xp + 1 , yp + 3 , 2 , 1 , ' white ' )
fill_rect ( xp + 6 , yp + 3 , 2 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 4 , 1 , 2 , ' white ' )
fill_rect ( xp + 6 , yp + 4 , 1 , 2 , ' white ' )
fill_rect ( xp + 3 , yp + 6 , 3 , 1 , ' white ' )
fill_rect ( xp + 4 , yp + 7 , 1 , 1 , ' white ' )
fill_rect ( xp + 1 , yp + 8 , 7 , 1 , ' white ' )
fill_rect ( xp , yp + 9 , 9 , 1 , ' white ' )
fill_rect ( xp , yp + 10 , 9 , 1 , ' white ' )
fill_rect ( xp , yp + 11 , 9 , 1 , ' white ' )
fill_rect ( xp , yp + 12 , 9 , 1 , ' white ' )
fill_rect ( xp , yp + 13 , 9 , 1 , ' white ' )
fill_rect ( xp , yp + 14 , 1 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 14 , 5 , 1 , ' white ' )
fill_rect ( xp + 8 , yp + 14 , 1 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 15 , 2 , 1 , ' white ' )
fill_rect ( xp + 5 , yp + 15 , 2 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 16 , 2 , 1 , ' white ' )
fill_rect ( xp + 5 , yp + 16 , 2 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 17 , 2 , 1 , ' white ' )
fill_rect ( xp + 5 , yp + 17 , 2 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 18 , 2 , 1 , ' white ' )
fill_rect ( xp + 5 , yp + 18 , 2 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 19 , 2 , 1 , ' white ' )
fill_rect ( xp + 5 , yp + 19 , 2 , 1 , ' white ' )
def hero_move ():
fill_rect ( xp + 3 , yp + 1 , 3 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 2 , 5 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 3 , 1 , 1 , ' white ' )
fill_rect ( xp + 6 , yp + 3 , 1 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 4 , 1 , 2 , ' white ' )
fill_rect ( xp + 8 , yp + 4 , 1 , 3 , ' white ' )
fill_rect ( xp + 6 , yp + 4 , 1 , 2 , ' white ' )
fill_rect ( xp + 3 , yp + 6 , 3 , 1 , ' white ' )
fill_rect ( xp + 4 , yp + 7 , 1 , 1 , ' white ' )
fill_rect ( xp + 7 , yp + 7 , 2 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 8 , 6 , 1 , ' white ' )
fill_rect ( xp + 1 , yp + 9 , 6 , 1 , ' white ' )
fill_rect ( xp , yp + 10 , 7 , 1 , ' white ' )
fill_rect ( xp , yp + 11 , 1 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 11 , 5 , 1 , ' white ' )
fill_rect ( xp , yp + 12 , 1 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 12 , 5 , 1 , ' white ' )
fill_rect ( xp , yp + 13 , 1 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 13 , 5 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 14 , 6 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 15 , 2 , 1 , ' white ' )
fill_rect ( xp + 6 , yp + 15 , 3 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 16 , 2 , 1 , ' white ' )
fill_rect ( xp + 7 , yp + 16 , 2 , 1 , ' white ' )
fill_rect ( xp + 1 , yp + 17 , 3 , 1 , ' white ' )
fill_rect ( xp + 7 , yp + 17 , 2 , 1 , ' white ' )
fill_rect ( xp , yp + 18 , 3 , 1 , ' white ' )
fill_rect ( xp + 7 , yp + 18 , 2 , 1 , ' white ' )
fill_rect ( xp , yp + 19 , 2 , 1 , ' white ' )
def hero_jump ():
fill_rect ( xp + 3 , yp + 1 , 3 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 2 , 5 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 3 , 1 , 1 , ' white ' )
fill_rect ( xp + 6 , yp + 3 , 1 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 4 , 1 , 2 , ' white ' )
fill_rect ( xp + 8 , yp + 4 , 1 , 3 , ' white ' )
fill_rect ( xp + 6 , yp + 4 , 1 , 2 , ' white ' )
fill_rect ( xp + 3 , yp + 6 , 3 , 1 , ' white ' )
fill_rect ( xp , yp + 4 , 1 , 3 , ' white ' )
fill_rect ( xp , yp + 7 , 2 , 1 , ' white ' )
fill_rect ( xp + 4 , yp + 7 , 1 , 1 , ' white ' )
fill_rect ( xp + 7 , yp + 7 , 2 , 1 , ' white ' )
fill_rect ( xp + 1 , yp + 8 , 7 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 9 , 5 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 10 , 5 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 11 , 5 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 12 , 5 , 1 , ' white ' )
fill_rect ( xp + 2 , yp + 13 , 5 , 1 , ' white ' )
fill_rect ( xp + 1 , yp + 14 , 7 , 1 , ' white ' )
fill_rect ( xp + 1 , yp + 15 , 3 , 1 , ' white ' )
fill_rect ( xp + 6 , yp + 15 , 3 , 1 , ' white ' )
fill_rect ( xp , yp + 16 , 2 , 1 , ' white ' )
fill_rect ( xp + 7 , yp + 16 , 2 , 1 , ' white ' )
fill_rect ( xp , yp + 17 , 2 , 1 , ' white ' )
fill_rect ( xp + 7 , yp + 17 , 2 , 1 , ' white ' )
fill_rect ( xp , yp + 18 , 2 , 1 , ' white ' )
fill_rect ( xp + 7 , yp + 18 , 2 , 1 , ' white ' )
def victory ():
for i in range ( 222 ):
fill_rect ( 0 , i , 320 , 1 , ' green ' )
sleep ( 0.01 )
draw_string ( " YOU WIN " , 160 , 111 )
sleep ( 5 )
def death ():
for i in range ( 222 ):
fill_rect ( 0 , i , 320 , 1 , ' gray ' )
sleep ( 0.01 )
fill_rect ( 130 , 61 , 60 , 50 , ' white ' )
sleep ( 0.3 )
fill_rect ( 140 , 111 , 40 , 30 , ' white ' )
sleep ( 0.3 )
fill_rect ( 140 , 71 , 10 , 30 , ' gray ' )
sleep ( 0.3 )
fill_rect ( 170 , 71 , 10 , 30 , ' gray ' )
sleep ( 0.3 )
fill_rect ( 145 , 112 , 5 , 28 , ' gray ' )
sleep ( 0.3 )
fill_rect ( 153 , 112 , 5 , 28 , ' gray ' )
sleep ( 0.3 )
fill_rect ( 162 , 112 , 5 , 28 , ' gray ' )
sleep ( 0.3 )
fill_rect ( 170 , 112 , 5 , 28 , ' gray ' )
sleep ( 5 )
def hero ():
if h == 1 :
heroreset ()
hero_static ()
if h == 2 :
heroreset ()
hero_move ()
if h == 3 :
heroreset ()
hero_jump ()
def heroreset ():
fill_rect ( xp , yp , 10 , 20 , ' black ' )
def lava1 ():
lw = 1
lwc = 0
fill_rect ( 0 , 212 , 320 , 10 , ' gray ' )
for i in range ( 0 , 320 , 2 ):
if lw == 1 :
lwc = 1
elif lw == 10 :
lwc = - 1
lw = lw + lwc
fill_rect ( i , 212 , 2 , - lw , ' gray ' )
while loop == 0 :
randomlevel ( xplat , yplat , lplat )
xp = xplat [ 0 ]
yp = yplat [ 0 ] - 20
h = 1
background ()
plateforms ()
hero ()
lava1 ()
while game == 0 :
h = 1
if keydown ( KEY_RIGHT ):
platformsresetright ()
xplat = [ x - 1 for x in xplat ]
plateforms ()
h = 2
if keydown ( KEY_LEFT ):
platformsresetleft ()
xplat = [ x + 1 for x in xplat ]
plateforms ()
h = 2
gravityleft = get_pixel ( xp , yp + 20 )
gravityright = get_pixel ( xp + 10 , yp + 20 )
nofall = color ( ' white ' )
lavacolor1 = color ( ' gray ' )
if keydown ( KEY_UP ):
if jumpcount == 0 and gravityleft == nofall or gravityright == nofall :
jumpcount = 75
if jumpcount == 0 and gravityleft != nofall and gravityright != nofall :
heroreset ()
yp = yp + 1
if jumpcount > 0 :
heroreset ()
yp = yp - 1
jumpcount = jumpcount - 1
h = 3
if gravityleft == lavacolor1 :
heroreset ()
death ()
break
if gravityleft == color ( ' green ' ):
victory ()
break
count = count + 1
hero ()