egor8.py
Created by
wperez274
Created on
March 26, 2023
6.67 KB
from math import *
from random import *
from random import randint as R
from kandinsky import *
from ion import *
from time import *
red = ( 255 , 0 , 0 )
green = ( 0 , 255 , 0 )
dark_green = ( 0 , 105 , 0 )
blue = ( 0 , 0 , 255 )
cyan = ( 0 , 255 , 255 )
yellow = ( 255 , 255 , 0 )
black = ( 0 , 0 , 0 )
white = ( 255 , 255 , 255 )
gray = ( 220 , 220 , 220 )
GAME = True
MAPX = 0
MAPY = 0
gx = 0
gy = 200
gw = 322
gh = R ( 2 , 4 )
grassc = choice ([
' green ' , ' brown ' ,
' pink ' , dark_green ,
white
])
cloudx = R ( - 850 , - 550 )
cloudy = R ( 10 , 40 )
cloudw = R ( 30 , 50 )
cloudh = R ( 10 , 25 )
cloudc = white
e2x = R ( 350 , 550 )
e2h = R ( 10 , 22 )
e2y = gy - e2h
e2w = R ( 10 , 30 )
e2c = red
edir = " down "
def move_e ():
global ex , ey , ew , eh , edir , gx , gy
if edir == " left " :
ex -= R ( 0 , 1 )
if edir == " right " :
ex += R ( 0 , 1 )
if edir == " up " :
ey -= R ( 0 , 1 )
if edir == " down " :
ey += R ( 0 , 1 )
if ey <= 100 :
ey = 100
edir = " down "
if ey + eh >= gy - 3 :
ey = gy - 3 - eh
edir = " up "
platforms1_x = MAPX + R ( 2000 , 3000 )
platforms1_h = R ( 50 , 150 )
platforms1_y = gy - platforms1_h
platforms1_w = R ( 385 , 700 )
platforms1_c = ( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 ))
platforms2_x = MAPX + R ( 5000 , 8000 )
platforms2_h = R ( 75 , 120 )
platforms2_y = gy - platforms1_h
platforms2_w = R ( 885 , 2400 )
platforms2_c = ( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 ))
goalx = MAPX + 2500
foodx = MAPX + R ( 320 , 520 )
foody = MAPY + R ( - 200 , - 100 )
foodw = foodh = 10
foodc = white
score = 0
energy = 35
ph = 25
px = 25
py = gy - ph - 1
pw = 12
peyes = ( 0 , 0 , 0 )
pc = cyan
pspeed = 4
jumpE = 1
ex = R ( 350 , 600 )
ey = R ( 0 , 50 )
ew = 200
eh = 10
ec = ( 100 , 25 , 45 )
ebc = ( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 ))
rope_locations = [
MAPX + 15250 ,
MAPX + 32250
]
rope1_x = MAPX + 1280
rope1_w = 5
rope1_h = gy
rope1_c = ( 220 , 220 , 220 )
rope2_x = MAPX + 2000
rope2_w = 5
rope2_h = gy
rope2_c = ( 0 , 255 , 255 )
bg = ( 0 , 0 , 0 )
def draw_ground ():
fill_rect ( gx , gy , gw , 40 , dark_green )
fill_rect ( gx , gy , gw , gh , grassc )
fill_rect ( 0 , 0 , 322 , 222 - ( 222 - gy ), black )
draw_ground ()
for i in range ( 0 , 322 , R ( 5 , 10 )):
i += R ( 1 , 3 )
fill_rect ( i , R ( gy + 3 , 220 ), R ( 2 , 5 ), R ( 2 , 5 ), choice ([( 0 , 100 , 0 ),( 0 , 255 , 0 ), black ]))
while GAME :
draw_string ( " E: " , 2 , 2 , green , black )
fill_rect ( 30 , 3 , int ( energy ), 15 ,( 255 , 0 , 0 ))
fill_rect ( ex , ey , ew , eh , ec )
fill_rect ( ex , ey , 2 , eh , ebc )
fill_rect ( ex + ew - 2 , ey , 2 , eh , ebc )
fill_rect ( ex , ey , ew , 2 , ebc )
fill_rect ( ex , ey + eh - 2 , ew , 2 , ebc )
fill_rect ( ex + ew + 1 , ey , 2 , eh , bg )
fill_rect ( ex , ey - 2 , ew , 2 , bg )
fill_rect ( ex , ey + eh + 1 , ew , 2 , bg )
if keydown ( KEY_LEFT ):
px -= pspeed
fill_rect ( 0 , 0 , 322 , 222 - ( 222 - gy ), bg )
if keydown ( KEY_TOOLBOX ):
px -= pspeed
fill_rect ( 0 , 0 , 322 , 222 - ( 222 - gy ), black )
if keydown ( KEY_RIGHT ):
px += pspeed
fill_rect ( 0 , 0 , 322 , 222 - ( 222 - gy ), bg )
#**********************
if px >= 201 :
px = 200
MAPX -= pspeed
fill_rect ( 0 , 0 , 322 , 222 - ( 222 - gy ), black )
if px <= 100 :
px = 101
MAPX += pspeed
fill_rect ( 0 , 0 , 322 , 222 - ( 222 - gy ), black )
#**********************
if keydown ( KEY_TOOLBOX ):
px += pspeed * 3
if keydown ( KEY_BACKSPACE ) and jumpE > 0 :
fill_rect ( px , py , pw , ph , bg )
py = gy - ph * 4
# jumpE=1
if keydown ( KEY_TOOLBOX ):
py -= pspeed * 2
move_e ()
py += 1
if jumpE >= 2 and jumpE <= 3 :
py -= 1
if py + ph >= gy :
py = gy - ph
if energy <= 0 :
GAME = False
if px + pw >= ex and px <= ex + ew and py + ph >= ey and py <= ey + eh :
fill_rect ( 0 , 0 , 322 , 222 - ( 222 - gy ), red )
energy -= 0.2
if px + pw >= e2x and px <= e2x + e2w and py + ph >= e2y and py <= e2y + e2h :
sleep ( 0.015 )
fill_rect ( 0 , 0 , 322 , 222 - ( 222 - gy ), red )
energy -= 0.5
ex -= 2
if ex + ew <= 0 - R ( 10 , 30 ):
ex = R ( 500 , 1000 )
ey = R ( 0 , 100 )
ew = R ( 50 , 120 )
eh = R ( 7 , 20 )
ec = ( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 ))
ebc = ( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 ))
fill_rect ( px , py , pw , ph , pc )
if jumpE < 2 :
fill_rect ( px , py , 1 , ph , blue )
fill_rect ( px + pw - 1 , py , 1 , ph , blue )
fill_rect ( px , py , pw , 1 , blue )
fill_rect ( px , py + ph - 1 , pw , 1 , blue )
if jumpE >= 2 :
fill_rect ( px , py , 2 , ph ,( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 )))
fill_rect ( px + pw - 2 , py , 2 , ph ,( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 )))
fill_rect ( px , py , pw , 2 ,( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 )))
fill_rect ( px , py + ph - 2 , pw , 2 ,( R ( 0 , 255 ), R ( 0 , 255 ), R ( 0 , 255 )))
fill_rect ( px + 3 , py + 4 , 2 , 4 , peyes )
fill_rect ( px + 8 , py + 4 , 2 , 4 , peyes )
fill_rect ( px , py - 2 , pw , 2 , bg )
if keydown ( KEY_DOWN ):
fill_rect ( px , py - 12 , pw , 12 , bg )
ph = 13
py = gy - 1 - ph
jumpE = 1
else :
ph = 25
if keydown ( KEY_BACKSPACE ):
jumpE -= 0.1
if jumpE <= 0 :
py += 1
if jumpE >= 3 :
jumpE = 1
if py + ph == gy - 1 and not keydown ( KEY_DOWN ):
jumpE = 1
cloudx += 1
e2x -= 2
if cloudx > R ( 500 , 1000 ):
cloudx = R ( - 800 , - 500 )
cloudy = R ( 50 , 160 )
cloudw = R ( 25 , 60 )
cloudh = R ( 7 , 18 )
if e2x + e2w <= 0 - R ( 10 , 20 ):
e2x = R ( 800 , 1600 )
e2h = R ( 10 , 22 )
e2y = R ( py + 2 - e2h , gy - e2h - 1 )
e2w = R ( 10 , 20 )
e2c = ( R ( 0 , 55 ), R ( 0 , 55 ), R ( 0 , 55 ))
fill_rect ( cloudx , cloudy , cloudw , cloudh , cloudc )
fill_rect ( cloudx - 2 , cloudy , 2 , cloudh , bg )
fill_rect ( cloudx , cloudy , 2 , cloudh , gray )
fill_rect ( cloudx + cloudw - 2 , cloudy , 2 , cloudh , gray )
fill_rect ( cloudx , cloudy , cloudw , 2 , gray )
fill_rect ( cloudx , cloudy + cloudh - 2 , cloudw , 2 , gray )
fill_rect ( e2x , e2y , e2w , e2h , e2c )
fill_rect ( e2x + e2w + 1 , e2y , 2 , e2h , bg )
fill_rect ( e2x , e2y , 1 , e2h , white )
fill_rect ( e2x + e2w - 1 , e2y , 1 , e2h , white )
fill_rect ( e2x , e2y , e2w , 1 , white )
fill_rect ( e2x , e2y + e2h - 1 , e2w , 1 , white )
fill_rect ( MAPX + 1600 , 0 , 580 , 120 - ( 222 - gy ), white )
fill_rect ( MAPX + 3600 , 0 , 780 , 80 - ( 222 - gy ), " orange " )
fill_rect ( MAPX + 5600 , 0 , 1780 , 60 - ( 222 - gy ), blue )
fill_rect ( MAPX + 7500 , 0 , 1580 , 120 - ( 222 - gy ), ' purple ' )
fill_rect ( MAPX + 9000 , 0 , 1280 , 80 - ( 222 - gy ), ' gray ' )
fill_rect ( MAPX + 12600 , 0 , 1180 , 60 - ( 222 - gy ), ' red ' )
fill_rect ( MAPX + 5900 , gy - 60 , 780 , 59 , yellow )
foody += 1
fill_rect ( MAPX + foodx , MAPY + foody , foodw , foodh , foodc )
fill_rect ( MAPX + foodx , MAPY + foody - 1 , foodw , 1 , bg )
if foody + foodh >= gy - 1 :
foody = gy - foodh - 1
if px + pw >= MAPX + foodx and px <= MAPX + foodx + foodw and py + ph >= MAPY + foody and py <= MAPY + foody + foodh :
sleep ( 0.15 )
fill_rect ( MAPX + foodx , MAPY + foody , foodw , foodh , bg )
foodx += px + R ( 1000 , 2500 )
foody = R ( - 900 , - 300 )
energy += 3
foodc = ( R ( 100 , 255 ), R ( 100 , 255 ), R ( 100 , 255 ))
fill_rect ( e2x + int ( e2w / 6 ), e2y + int ( e2h / 4 ), int ( e2w / 4 ), int ( e2h / 4 ), choice ([ red , white , black , green ]))
fill_rect ( MAPX + rope_locations [ 0 ], 0 , rope1_w , rope1_h , rope1_c )
if keydown ( KEY_UP ):
if px + pw >= MAPX + rope1_x + 2 and px <= MAPX + rope1_x + rope1_w - 2 :
py -= 3
fill_rect ( px , py + ph + 1 , pw , 2 , bg )
if px + pw >= cloudx and px <= cloudx + cloudw and py + ph >= cloudy and py + ph <= cloudy + 2 :
py = cloudy - ph
px = cloudx + 20
px += 1
jumpE = 1
if py <= 0 :
py = 0
fill_rect ( MAPX + platforms1_x , platforms1_y , platforms1_w , platforms1_h , platforms1_c )
fill_rect ( 0 , 0 , 322 , 222 , black )
draw_string ( " GAME OVER " , 100 , 100 ,( R ( 100 , 255 ), R ( 100 , 255 ), R ( 100 , 255 )),( 0 , 0 , 0 ))