from math import * from random import * from kandinsky import * from ion import * from time import * def draw_string_letters(text,x,y,c1=(0,0,0),c2=(255,255,255),dec=0): for l in text: draw_string(l,x+dec,y,c1,c2) dec+=10 sleep(0.05) def carotte(x,y): fill_rect(x-8,y,16,4,(0,200,0)) fill_rect(x-2,y-4,4,4,(0,200,0)) fill_rect(x-6,y+4,12,8,(255,150,0)) fill_rect(x-4,y+12,8,6,(255,150,0)) fill_rect(x-2,y+18,4,2,(255,150,0)) def carotte_or(x,y): fill_rect(x-8,y,16,4,(0,200,0)) fill_rect(x-2,y-4,4,4,(0,200,0)) fill_rect(x-6,y+4,12,8,(255,220,0)) fill_rect(x-4,y+12,8,6,(255,220,0)) fill_rect(x-2,y+18,4,2,(255,220,0)) def carotte_pourrie(x,y): fill_rect(x-8,y,16,4,(80,100,0)) fill_rect(x-2,y-4,4,4,(80,100,0)) fill_rect(x-6,y+4,12,8,(20,10,40)) fill_rect(x-4,y+12,8,6,(20,10,40)) fill_rect(x-2,y+18,4,2,(20,10,40)) def lapin1(x,y): fill_rect(x-12,y,8,20,(240,200,150)) fill_rect(x+4,y,8,20,(240,200,150)) fill_rect(x-10,y+2,4,18,(250,150,150)) fill_rect(x+6,y+2,4,18,(250,150,150)) fill_rect(x-16,y+20,32,28,(240,200,150)) fill_rect(x-12,y+24,8,8,(240,)*3) fill_rect(x+4,y+24,8,8,(240,)*3) fill_rect(x-10,y+26,4,4,(30,)*3) fill_rect(x+6,y+26,4,4,(30,)*3) fill_rect(x-14,y+34,28,12,(250,150,150)) fill_rect(x-5,y+34,4,4,(240,)*3) fill_rect(x+1,y+34,4,4,(240,)*3) def lapin1_2(x,y): fill_rect(x-24,y,16,20,(240,200,150)) fill_rect(x+8,y,16,20,(240,200,150)) fill_rect(x-20,y+2,8,18,(250,150,150)) fill_rect(x+12,y+2,8,18,(250,150,150)) fill_rect(x-32,y+20,64,28,(240,200,150)) fill_rect(x-24,y+24,16,8,(240,)*3) fill_rect(x+8,y+24,16,8,(240,)*3) fill_rect(x-20,y+26,8,4,(30,)*3) fill_rect(x+12,y+26,8,4,(30,)*3) fill_rect(x-28,y+34,56,12,(250,150,150)) fill_rect(x-10,y+34,8,4,(240,)*3) fill_rect(x+2,y+34,8,4,(240,)*3) def lapin2(x,y): fill_rect(x-12,y,8,20,(240,200,150)) fill_rect(x+4,y,8,20,(240,200,150)) fill_rect(x-10,y+2,4,18,(250,150,150)) fill_rect(x+6,y+2,4,18,(250,150,150)) fill_rect(x-16,y+20,32,28,(240,200,150)) fill_rect(x-12,y+24,8,8,(240,)*3) fill_rect(x+4,y+24,8,8,(240,)*3) fill_rect(x-11,y+25,6,6,(30,)*3) fill_rect(x+5,y+25,6,6,(30,)*3) fill_rect(x-7,y+38,14,2,(250,150,150)) fill_rect(x-5,y+38,4,4,(240,)*3) fill_rect(x+1,y+38,4,4,(240,)*3) def lapin2_2(x,y): fill_rect(x-24,y,16,20,(240,200,150)) fill_rect(x+8,y,16,20,(240,200,150)) fill_rect(x-20,y+2,8,18,(250,150,150)) fill_rect(x+12,y+2,8,18,(250,150,150)) fill_rect(x-32,y+20,64,28,(240,200,150)) fill_rect(x-24,y+24,16,8,(240,)*3) fill_rect(x+8,y+24,16,8,(240,)*3) fill_rect(x-22,y+25,12,6,(30,)*3) fill_rect(x+10,y+25,12,6,(30,)*3) fill_rect(x-14,y+38,28,2,(250,150,150)) fill_rect(x-10,y+38,8,4,(240,)*3) fill_rect(x+2,y+38,8,4,(240,)*3) def lapin3(x,y): fill_rect(x-12,y+10,8,10,(240,200,150)) fill_rect(x+4,y+10,8,10,(240,200,150)) fill_rect(x-10,y+12,4,8,(250,150,150)) fill_rect(x+6,y+12,4,8,(250,150,150)) fill_rect(x-16,y+20,32,28,(240,200,150)) fill_rect(x-12,y+24,8,4,(240,)*3) fill_rect(x+4,y+24,8,4,(240,)*3) fill_rect(x-10,y+25,4,2,(30,)*3) fill_rect(x+6,y+25,4,2,(30,)*3) fill_rect(x-14,y+29,28,18,(250,150,150)) fill_rect(x-5,y+29,4,4,(240,)*3) fill_rect(x+1,y+29,4,4,(240,)*3) def lapin3_2(x,y): fill_rect(x-24,y+10,16,10,(240,200,150)) fill_rect(x+8,y+10,16,10,(240,200,150)) fill_rect(x-20,y+12,8,8,(250,150,150)) fill_rect(x+12,y+12,8,8,(250,150,150)) fill_rect(x-32,y+20,64,28,(240,200,150)) fill_rect(x-24,y+24,16,4,(240,)*3) fill_rect(x+8,y+24,16,4,(240,)*3) fill_rect(x-20,y+25,8,2,(30,)*3) fill_rect(x+12,y+25,8,2,(30,)*3) fill_rect(x-28,y+29,56,18,(250,150,150)) fill_rect(x-10,y+29,8,4,(240,)*3) fill_rect(x+2,y+29,8,4,(240,)*3) def lapin4(x,y): fill_rect(x-11,y,8,6,(240,200,150)) fill_rect(x+5,y,8,6,(240,200,150)) fill_rect(x-9,y+2,4,4,(250,150,150)) fill_rect(x+7,y+2,4,4,(250,150,150)) fill_rect(x-12,y+6,8,7,(240,200,150)) fill_rect(x+4,y+6,8,7,(240,200,150)) fill_rect(x-10,y+6,4,7,(250,150,150)) fill_rect(x+6,y+6,4,7,(250,150,150)) fill_rect(x-11,y+13,8,7,(240,200,150)) fill_rect(x+5,y+13,8,7,(240,200,150)) fill_rect(x-9,y+13,4,7,(250,150,150)) fill_rect(x+7,y+13,4,7,(250,150,150)) fill_rect(x-16,y+20,32,28,(240,200,150)) fill_rect(x-9,y+25,2,6,(30,)*3) fill_rect(x+7,y+25,2,6,(30,)*3) fill_rect(x-11,y+27,6,2,(30,)*3) fill_rect(x+5,y+27,6,2,(30,)*3) fill_rect(x-14,y+37,4,4,(250,150,150)) fill_rect(x-10,y+38,4,4,(250,150,150)) fill_rect(x-6,y+37,4,4,(250,150,150)) fill_rect(x-2,y+38,4,4,(250,150,150)) fill_rect(x+2,y+37,4,4,(250,150,150)) fill_rect(x+6,y+38,4,4,(250,150,150)) fill_rect(x+10,y+37,4,4,(250,150,150)) def lapin4_2(x,y): fill_rect(x-22,y,16,6,(240,200,150)) fill_rect(x+10,y,16,6,(240,200,150)) fill_rect(x-18,y+2,8,4,(250,150,150)) fill_rect(x+14,y+2,8,4,(250,150,150)) fill_rect(x-24,y+6,16,7,(240,200,150)) fill_rect(x+8,y+6,16,7,(240,200,150)) fill_rect(x-20,y+6,8,7,(250,150,150)) fill_rect(x+12,y+6,8,7,(250,150,150)) fill_rect(x-22,y+13,16,7,(240,200,150)) fill_rect(x+10,y+13,16,7,(240,200,150)) fill_rect(x-18,y+13,8,7,(250,150,150)) fill_rect(x+14,y+13,8,7,(250,150,150)) fill_rect(x-32,y+20,64,28,(240,200,150)) fill_rect(x-18,y+25,4,6,(30,)*3) fill_rect(x+14,y+25,4,6,(30,)*3) fill_rect(x-22,y+27,12,2,(30,)*3) fill_rect(x+10,y+27,12,2,(30,)*3) fill_rect(x-28,y+37,8,4,(250,150,150)) fill_rect(x-20,y+38,8,4,(250,150,150)) fill_rect(x-12,y+37,8,4,(250,150,150)) fill_rect(x-4,y+38,8,4,(250,150,150)) fill_rect(x+4,y+37,8,4,(250,150,150)) fill_rect(x+12,y+38,8,4,(250,150,150)) fill_rect(x+20,y+37,8,4,(250,150,150)) def lapin(n,x,y,bigger=False): if not bigger: if n==1:lapin1(x,y) elif n==2:lapin2(x,y) elif n==3:lapin3(x,y) elif n==4:lapin4(x,y) elif bigger: if n==1:lapin1_2(x,y) elif n==2:lapin2_2(x,y) elif n==3:lapin3_2(x,y) elif n==4:lapin4_2(x,y) class CAROTTES: def __init__(self): self.x=randint(2,30)*10 self.y=14 self.vy=0 self.t=randint(0,3)%3 def draw(self,x): if self.t==0 and 13<self.y<134:carotte(self.x,self.y) elif self.t==1 and 13<self.y<134:carotte_or(self.x,self.y) elif self.t==2 and 13<self.y<134:carotte_pourrie(self.x,self.y) else:self.__init__() def move(self): self.y+=int(self.vy) self.vy=self.vy*0.99+0.5 def poslapin(self,x,bigger=False): if x-15<self.x<x+15 and not bigger:return 3 elif bigger and x-30<self.x<x+30:return 3 else:return 1 def back_ground(c1,c2,hungry=False,bg=0): fill_rect(10,10,300,140,(100-trunc(bg/2),200-bg,250-bg)) fill_rect(0,162,320,60,(235,130,0)) carotte(10,168);draw_string("x"+str(c1),18,168,(255,170,0),(235,130,0)) carotte_or(10,198);draw_string("x"+str(c2),18,198,(255,170,0),(235,130,0)) draw_string("SCORE",260,168,(255,170,0),(235,130,0));draw_string(" "+str(c1+(c2*2)),260,188,(255,170,0),(235,130,0)) if hungry:draw_string("HUNGRY!",125,178,(255,170,0),(235,130,0)) def start(): print(">>> RabbitGame\n>>> -Record small:615 by my father\n>>> -Record bigger:393 by me\n>>> scrit by Merle") fill_rect(0,0,320,222,(205,100,0));fill_rect(8,8,304,144,(0,0,0));fill_rect(0,160,320,2,(0,0,0)) back_ground(0,0,False) draw_string("Yum it's raining.",85,20,(0,0,0),(100,200,250)) draw_string("Chargement ...",95,55,(0,0,0),(100,200,250)) draw_string("12/11/2023 Create by Merle",10,130,(0,0,0),(100,200,250)) strLoad="loading game" for i in range(0,10):carotte_pourrie(60+(i*20),80) for i in range(0,10): carotte(60+(i*20),80) for j in range(0,10): draw_string("Chargement "+str((i*10)+j)+"%",95,55,(0,0,0),(100,200,250)) draw_string(strLoad[((i*10)+j)%len(strLoad)],100+((((i*10)+j)%len(strLoad))*10),105,(0,0,0),(100,200,250)) draw_string(" ",100+(((((i*10)+j)+6)%len(strLoad))*10),105,(0,0,0),(100,200,250)) sleep(1/(27-((i*10)+j)%27)) def notice(): fill_rect(0,0,320,222,(205,100,0));fill_rect(8,8,304,144,(0,0,0));fill_rect(0,160,320,2,(0,0,0)) back_ground(0,0,False) lapin(1,26,102) fill_rect(28,38,204,74,(0,0,0));fill_rect(30,40,200,70,(255,255,255)) fill_rect(48,110,8,10,(0,0,0)) fill_rect(50,110,6,10,(255,255,255)) fill_rect(54,116,2,4,(0,0,0)) fill_rect(56,110,2,6,(0,0,0)) fill_rect(46,120,8,2,(0,0,0)) fill_rect(48,120,4,2,(255,255,255)) fill_rect(46,122,6,2,(0,0,0)) draw_string_letters(" Hello,",35,45) draw_string_letters("I'm a Rabbit.",35,65) draw_string_letters(" [Ok]",35,85) while not keydown(KEY_OK):pass fill_rect(28,38,204,74,(0,0,0));fill_rect(30,40,200,70,(255,255,255)) fill_rect(48,110,8,10,(0,0,0)) fill_rect(50,110,6,10,(255,255,255)) fill_rect(54,116,2,4,(0,0,0)) draw_string_letters("Move whith arrows,",35,45) draw_string_letters("and eat carots.",35,65) draw_string_letters(" [Ok]",35,85) while not keydown(KEY_OK):pass fill_rect(28,38,204,74,(0,0,0));fill_rect(30,40,200,70,(255,255,255)) fill_rect(48,110,8,10,(0,0,0)) fill_rect(50,110,6,10,(255,255,255)) fill_rect(54,116,2,4,(0,0,0)) carotte(40,45) draw_string_letters(":1 point",50,45) carotte_or(40,65) draw_string_letters(":2 points",50,65) draw_string_letters(" [Ok]",35,85) while not keydown(KEY_OK):pass fill_rect(28,38,204,74,(0,0,0));fill_rect(30,40,200,70,(255,255,255)) fill_rect(48,110,8,10,(0,0,0)) fill_rect(50,110,6,10,(255,255,255)) fill_rect(54,116,2,4,(0,0,0)) draw_string_letters("Don't eat black",35,45) draw_string_letters("carots!",35,65) draw_string_letters("Pause:[Ok] [Ok]",35,85) while not keydown(KEY_OK):pass while keydown(KEY_OK):pass def shop(Ca,Ca_or,bigger,bg,Buy): global carotte,carotte_or fill_rect(0,0,320,222,(205,100,0));fill_rect(8,8,304,144,(0,0,0));fill_rect(0,160,320,2,(0,0,0)) t,L=monotonic(),0 while not keydown(KEY_DOWN): back_ground(Ca,Ca_or,False) draw_string("SHOP",140,20,(0,0,0),(100,200,250)) draw_string("[OK] to buy",90,40,(0,0,0),(100,200,250)) draw_string("[DOWN] to back",90,60,(0,0,0),(100,200,250)) draw_string("< >",110,95,(0,0,0),(100,200,250)) if keydown(KEY_OK)and L==0 and not Buy and Ca_or>=50:Ca_or-=50;bigger=True;Buy=True elif keydown(KEY_RIGHT)or keydown(KEY_LEFT):L=(L+1)%2 if L==0: if 1<monotonic()-t<2 and not Buy:draw_string("Big Rabbit",110,130,(0,0,0),(100,200,250)) elif monotonic()-t>2 and not Buy:t=monotonic() elif not Buy:draw_string("Cost:50",110,130,(0,0,0),(100,200,250));carotte_or(195,130) elif Buy:draw_string("Big Rabbit",110,130,(0,0,0),(100,200,250)) elif L==1:draw_string("Small Rabbit",100,130,(0,0,0),(100,200,255)) if L==0:lapin(1,160,80,True) elif L==1:lapin(1,160,80,False) if Buy and L==0:bigger=True elif L==1:bigger=False sleep(0.1) return Ca,Ca_or,bigger,bg,Buy def game(M,Ca=0,Ca_or=0,bigger=False,bg=0,Buy=False): try: fill_rect(0,0,320,222,(205,100,0));fill_rect(8,8,304,144,(0,0,0));fill_rect(0,160,320,2,(0,0,0)) Carottes=[CAROTTES()] Mode=[["Easy","Normal","Hard","Speed","Glissades Easy","Glissades Normal","Glissades Hard","Glissades Speed",],[[5,0.4],[10,0.5],[15,0.6],[25,0.5],[5,0.8],[10,0.85],[15,0.9],[25,0.85]]] t=monotonic() while not keydown(KEY_OK): if monotonic()-t>5:Carottes+=[CAROTTES()];t=monotonic() back_ground(Ca,Ca_or,False) draw_string("MENU",140,20,(0,0,0),(100,200,250)) draw_string("[OK] to play",90,40,(0,0,0),(100,200,250)) draw_string("[UP] to shop",90,60,(0,0,0),(100,200,250)) draw_string("Modes:"+Mode[0][M%len(Mode[0])],90,80,(0,0,0),(100,200,250)) draw_string("[EXE] Tutorial",90,100,(0,0,0),(100,200,250)) for carotte in Carottes:carotte.draw(0);carotte.move() if keydown(KEY_EXE):notice() elif keydown(KEY_UP):Ca,Ca_or,bigger,bg,Buy=shop(Ca,Ca_or,bigger,bg,Buy) elif keydown(KEY_LEFT):M-=1 elif keydown(KEY_RIGHT):M+=1 sleep(1/Mode[1][M%len(Mode[0])][0]) while keydown(KEY_OK):pass d=Mode[1][M%len(Mode[0])] fill_rect(0,0,320,222,(205,100,0));fill_rect(8,8,304,144,(0,0,0));fill_rect(0,160,320,2,(0,0,0)) carottes,carottes_or,Carottes=0,0,[CAROTTES()] x,vx,pos,miam,hungry,Hungry=160,0,1,False,monotonic(),False fps,t,redraw,game_over,spawn,glissade=d[0],monotonic(),True,False,1,d[1] while not game_over: if monotonic()-t>spawn: t,spawn,fps=monotonic(),spawn+5,fps+1 Carottes+=[CAROTTES()] if spawn>56: if bg==0:b=5 elif bg==200:b=-5 bg+=b elif spawn>36: if bg==0:b=0 elif bg==200:b=-5 bg+=b elif spawn>16: if bg==0:b=5 elif bg==200:b=0 bg+=b else:bg=0 if monotonic()-hungry>7:Hungry=True if monotonic()-hungry>10:Hungry=True;game_over=True if keydown(KEY_EXE):game_over=True if keydown(KEY_OK): while keydown(KEY_OK):pass while not keydown(KEY_OK):draw_string("PAUSE",135,70,(0,0,0),(100,200,250)) while keydown(KEY_OK):pass hungry,t=monotonic(),monotonic() if keydown(KEY_LEFT):vx=-10;redraw=True elif keydown(KEY_RIGHT):vx=10;redraw=True x+=int(vx) vx=vx*glissade if abs(vx)<1:vx=0 else:redraw=True for carotte in Carottes: carotte.move() if carotte.poslapin(x,bigger)==3: miam=True if carotte.y>126: if carotte.t==2:game_over=True elif carotte.t==0:carottes+=1 elif carotte.t==1:carottes_or+=1 Hungry,hungry=False,monotonic() carotte.__init__() if miam:pos,miam=3,False elif pos==1:pos=2 else:pos=1 if not bigger: if x<26:x=26;vx=0 elif x>294:x=294;vx=0 if bigger: if x<42:x=42;vx=0 elif x>278:x=278;vx=0 back_ground(carottes,carottes_or,Hungry,bg) lapin(pos,x,102,bigger) for carotte in Carottes:carotte.draw(x) sleep(1/fps) Ca+=carottes Ca_or+=carottes_or while not keydown(KEY_EXE): back_ground(carottes,carottes_or,Hungry) draw_string("GAME OVER",115,30,(0,0,0),(100,200,250)) draw_string("[BACK] to retry",85,50,(0,0,0),(100,200,250)) draw_string("[EXE] to quit",95,70,(0,0,0),(100,200,250)) lapin(4,x,102,bigger) for carotte in Carottes:carotte.draw(x);carotte.move() sleep(1/fps) except KeyboardInterrupt:game(M,Ca,Ca_or,bigger,bg,Buy) start() game(1)