importkandinskyimportionimportmathimporttimeimportrandomplayerX=145playerSize=30playerVelocity=0crateSize=playerSizecrateX=random.randint(0,320-playerSize)crateY=0crateVelocity=0crateDistance=math.fabs(playerX-crateX)running=Truescore=""score30=""playerSpeed=5start=time.monotonic()whilerunning:# Update player position
crateY+=crateVelocityplayerX+=playerVelocity# Manages player input
ifion.keydown(ion.KEY_LEFT):playerVelocity=-playerSpeedifion.keydown(ion.KEY_RIGHT):playerVelocity=playerSpeed# Calculates the distance of the player from the crate
crateDistance=math.fabs(playerX-crateX)# Creates map wrap
ifplayerX>320:playerX=-playerSizeifplayerX<-playerSize:playerX=320# Caps the speed of the crate
ifcrateVelocity<5:crateVelocity+=1# Resets crate position when it touches the ground and increments the score
ifcrateY>=222-crateSize:crateY=0crateX=random.randint(0,320-playerSize)score+="*"iflen(score)>=30:score30+="*"score=""kandinsky.fill_rect(0,0,320,20,"white")# Game Over system
ifcrateY>=222-crateSize-playerSizeandcrateDistance<=playerSize:running=False# Renders the objects
kandinsky.fill_rect(playerX,222-playerSize,playerSize,playerSize,kandinsky.color(0,0,0))kandinsky.fill_rect(crateX,crateY,crateSize,crateSize,kandinsky.color(255,0,0))kandinsky.draw_string(score,0,0)kandinsky.draw_string(score30,0,20)time.sleep(1/60)kandinsky.fill_rect(playerX,222-playerSize,playerSize,playerSize,kandinsky.color(255,255,255))kandinsky.fill_rect(crateX,crateY,crateSize,crateSize,kandinsky.color(255,255,255))# Ends the game
kandinsky.draw_string("Game Over",0,0)time.sleep(1)print("Score:",len(score)+30*len(score30))print ("Time:",round(time.monotonic()-start,1),"seconds")print("Game by Henri Caboche")
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
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.