copter.py

Created by aquaebm

Created on October 09, 2022

862 Bytes

Very simple horizontal-swingcopter-like game.

Use the VAR key to switch gravity in mid-air to avoid the obstacles and go as far as possible.

You lose when you touch an obstacle or when you go too far outside of the screen.


from util import *
@game_func
def run(g,key,pcol,col,bg):
  fill_screen(bg)
  vy=0
  score=0
  ypos=y=50
  f,e,z,c,t,s=fill_rect,enumerate,zip,get_pixel,int,sleep
  pressed=KeyPressHandler([key])
  spawn_obs=Timer(0)
  obs_x=[]
  obs_y=[]
  while col not in(c(73,y),c(73,y+12),c(86,y),c(86,y+12))and-30<y<240:
    if spawn_obs():
      obs_x.append(350)
      obs_y.append(randint(-10,190))
      spawn_obs.reset(uniform(.25,.45))
    if obs_x[0]<0:
      obs_x.pop(0)
      obs_y.pop(0)
      score+=1
      draw_string(str(score),280,0,col,bg)
    for i,(x,h)in e(z(obs_x,obs_y)):
      f(x-30,h,1,30,col)
      f(x,h,1,30,bg)
      obs_x[i]-=1
    if pressed[key]:g=-g
    vy+=g
    ypos+=vy
    f(74,y,12,12,bg)
    y=t(ypos)
    f(74,y,12,12,pcol)
    s(.002)
ARGS={"g":.023,"key":15,"pcol":(255,255,0),"col":CYAN,"bg":DARK_PURPLE}
run(**ARGS)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

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.