Simple Platform Game Example.
Will improve daily.
[Backspace] = float
from math import * from random import * from random import randint as RAND from kandinsky import * from kandinsky import fill_rect as F from ion import * from time import * RED=(255,0,0) WHITE=(255,)*3 BLACK=(0,)*3 GREEN=(0,255,0) CYAN=(0,255,255) BLUE=(0,0,255) GAME_OVER=False float_energy=30 times_almost_fell=0 traveled=0 score=0 life=3 x=115 y=30 w=14 h=22 c=(RAND(100,255),RAND(100,255),RAND(100,255)) base=[0,randint(60,120),50,5,(0,0,0)] #************************** bg=WHITE MAPX=0 MAPY=0 MAPW=5000 MAPH=222 MAPBOX_X1=[MAPX,MAPY,5,MAPH,(0,0,0)] MAPBOX_X2=[MAPX+MAPW-5,MAPY,5,MAPH,(0,0,0)] MAPBOX_Y1=[MAPX,MAPY,MAPW,5,(0,0,0)] MAPBOX_Y2=[MAPX,MAPY+MAPH-5,MAPW,5,(0,0,0)] rope_x=MAPX+RAND(200,500) rope_h=RAND(50,120) rope_y=MAPY+MAPH-rope_h-5 rope_w=RAND(500,1200) rope_c=(RAND(0,255),RAND(0,255),RAND(0,255)) rope=[rope_x,rope_y,rope_w,rope_h,rope_c] r1_x=MAPX+RAND(1000,1200) r1_h=RAND(50,120) r1_y=MAPY+MAPH-r1_h-5 r1_w=RAND(180,420) r1_c=(RAND(0,255),RAND(0,255),RAND(0,255)) r2_x=MAPX+RAND(1500,1800) r2_h=RAND(80,150) r2_y=MAPY+MAPH-r2_h-5 r2_w=RAND(450,800) r2_c=(RAND(0,255),RAND(0,255),RAND(0,255)) r3_x=MAPX+RAND(2500,3000) r3_h=RAND(80,160) r3_y=MAPY+MAPH-r3_h-5 r3_w=RAND(500,1200) r3_c=(RAND(0,255),RAND(0,255),RAND(0,255)) wall_list_x=[ [r1_x,r1_y,r1_w,r1_h,r1_c], [r2_x,r2_y,r2_w,r2_h,r2_c], [r2_x,r2_y,r2_w,r2_h,r2_c] ] F(0,0,322,222,bg) while not GAME_OVER: MAPBOX_X1=[MAPX,MAPY,5,MAPH,(0,0,0)] MAPBOX_X2=[MAPX+MAPW-5,MAPY,5,MAPH,(0,0,0)] MAPBOX_Y1=[MAPX,MAPY,MAPW,5,(0,0,0)] MAPBOX_Y2=[MAPX,MAPY+MAPH-5,MAPW,5,(0,0,0)] F(*MAPBOX_X1) F(*MAPBOX_X2) F(*MAPBOX_Y1) F(*MAPBOX_Y2) F(x,y,w,h,c) F(x+3,y+3,4,5,BLACK) F(x+9,y+3,4,5,BLACK) if keydown(KEY_LEFT): x-=2 F(x+w+1,y,2,h,WHITE) if keydown(KEY_RIGHT): x+=2 F(x-2,y,2,h,WHITE) if keydown(KEY_BACKSPACE) and float_energy>0: y-=2 F(230,4,int(float_energy),13,bg) float_energy-=0.4 F(x,y+h+1,w,1,WHITE) if get_pixel(x,y+h+2) == (255,0,0) and get_pixel(x+w,y+h-1) == (255,0,0): sleep(0.25) F(x,y,w,h,(255,)*3) x=15 y=30 life-=1 if life<1: sleep(0.4) F(0,0,322,222,(0,0,0)) sleep(1) draw_string("GAME OVER",100,80,(255,0,0),(0,0,0)) sleep(1) draw_string("Score:"+str(score),100,130,WHITE,(0,0,0)) sleep(1.5) draw_string("PRESS [OK]",120,180,BLACK,GREEN) GAME_OVER=True if get_pixel(x,y+h) != (0,0,0) and get_pixel(x+w,y+h) != BLACK: sleep(0.001) y+=1 F(x-1,y-1,w+2,1,(255,)*3) if get_pixel(x,y+h) != WHITE and get_pixel(x+w,y+h) != WHITE: float_energy=30 if y<0: y=0 if x+w<-1: x=322 if x>322: x=-1-w if not GAME_OVER: draw_string("E:[",5,5) F(35,8,int(float_energy),13,(0,255,0)) if x>222: x=222 MAPX-=2 if x<50: x=50 MAPX+=2 wall_list_x[0]=[MAPX+r1_x,MAPY+r1_y,r1_w,r1_h,r1_c] wall_list_x[1]=[MAPX+r2_x,MAPY+r2_y,r2_w,r2_h,r2_c] wall_list_x[2]=[MAPX+r3_x,MAPY+r3_y,r3_w,r3_h,r3_c] F(*wall_list_x[0]) F(*wall_list_x[1]) F(*wall_list_x[2]) F(wall_list_x[0][0]+wall_list_x[0][2]+1,wall_list_x[0][1],3,wall_list_x[0][3],bg) F(wall_list_x[0][0],wall_list_x[0][1],wall_list_x[0][2],3,BLACK) F(wall_list_x[1][0]+wall_list_x[1][2]+1,wall_list_x[1][1],3,wall_list_x[1][3],bg) F(wall_list_x[1][0],wall_list_x[1][1],wall_list_x[1][2],3,BLACK) F(wall_list_x[2][0]+wall_list_x[2][2]+1,wall_list_x[2][1],3,wall_list_x[2][3],bg) F(wall_list_x[2][0],wall_list_x[2][1],wall_list_x[2][2],3,BLACK) MAPX-=1 print("") print("traveled:",traveled) sleep(0.2) print("times_almost_fell:",times_almost_fell)