drone16x.py

Created by wperez274

Created on February 01, 2023

7.51 KB

game potential. Stars, blocks, random char letters.


from kandinsky import *
from ion import *
from time import *
from random import *
from kandinsky import fill_rect as FILL
from kandinsky import draw_string as STR
from ion import keydown as KEY
from random import randint as RAND

time=0
bg=(0,20,100)
FILL(0,0,322,222,bg)
  
def menu():
  global time,bg
  FILL(0,20,322,3,"cyan")
  STR("DRONE 16",110,70)
  FILL(0,20,322,3,"cyan")
  
  while not KEY(KEY_OK) and not KEY(KEY_EXE):
    time+=1    
    STR("key [Backspace] = Pause/Resume",10,200,"yellow",bg)
    
    if time>0 and time<500:
      STR("PRESS [OK] key to start",40,160,(0,255,255),(0,20,100))
      
    if time>500 and time<800:
        STR("                         ",40,160,(0,20,100),(0,20,100))
      
    if time>800:
      time=0
  
     
  if KEY(KEY_OK):
    menu=0

menu()

paused=False

score=0
clock=0
star_size=1
star_colors=["white","yellow",
"orange","red","blue"]

C=(RAND(0,255),RAND(0,255),RAND(0,255))
R=(RAND(0,255),RAND(0,255),RAND(0,255))
c=RAND(0,322)
d=RAND(0,222)

R=RAND(0,70)
G=RAND(0,70)
B=RAND(0,70)

rr=40
gg=25
bb=100

r=RAND(0,80)
g=RAND(10,50)
b=RAND(15,25)

r2=RAND(5,55)
g2=RAND(5,55)
b2=RAND(5,55)

energy=50
energy_x=RAND(5,250)
energy_y=RAND(10,200)
energy_width=9
energy_height=15
energy_timer=0

RC=(RAND(0,230),RAND(0,230),RAND(0,230))
move=True
game_end=False

p_timer=0
p_LEFT=1
p_RIGHT=2
p_UP=3
p_DOWN=4

p_x=10
p_y=100

sleep_slow=1/10**4
p_speed_fast=1/10**9
p_pace=1
p_speed_range=2
p_width=10
p_height=4
p_color="white"
SCREEN_width=321
SCREEN_height=222

rect_width=RAND(15,40)
rect_height=RAND(170,210)
rect_x=RAND(270,365)
rect_y=RAND(10,200)
rect_color=(r,g,b)

rect_width2=RAND(15,40)
rect_height2=RAND(170,210)
rect_x2=RAND(270,400)
rect_y2=RAND(10,200)
rect_color2=(r,g,b)

rect_LEFT=False
rect_RIGHT=False
rect_UP=False
rect_DOWN=False
rect_UP=False
timer_rect=0

background_timer=0
background_color=(RAND(0,255),RAND(0,255),RAND(0,255))
FILL(0,0,322,222,background_color)

bit_color=(RAND(100,255),RAND(100,255),RAND(100,255))   
ascii=RAND(33,126)
bit=chr(int(ascii))

while not game_end and not paused:
  
  clock+=1
  background_timer+=0.01
  draw_string(str(bit),energy_x,energy_y,bit_color,"black")
  FILL(0,20,322,2,"red")
  FILL(0,210,322,2,"red")
  
  
  if clock>0 and clock<30:
    c=RAND(0,322)
    d=RAND(0,90)
    C=star_colors[RAND(0,4)]
  
  FILL(c,d,star_size,star_size,C)
  STR("SCORE:"+str(score),200,2,"cyan",background_color)

  STR("Energy:"+str(int(energy)),2,2,"white",background_color)


  rect_x-=1
  rect_x2-=1
  energy_timer+=1

  
  if rect_x < -rect_width-1:
    rect_x=RAND(170,350)
    rect_y=RAND(-50,200)
    rect_width=RAND(20,70)
    rect_height=RAND(80,150)
    r=RAND(5,255)
    g=RAND(5,255)
    b=RAND(5,255)
    rect_color=(r,g,b)
    clock=0
    c=RAND(0,322)
    d=RAND(0,90)
    C=star_colors[RAND(0,4)]
    FILL(c,d,star_size,star_size,C)
 
    
  if rect_x2 < -rect_width2-1:
    rect_x2=RAND(150,350)
    rect_y2=RAND(0,200)
    rect_width2=RAND(20,80)
    rect_height2=RAND(80,200)
    r2=RAND(5,55)
    g2=RAND(5,55)
    b2=RAND(5,55)
    rect_color2=(r2,g2,b2)
    
  FILL(rect_x,rect_y,rect_width,rect_height,rect_color)
  FILL(rect_x+rect_width+1,rect_y,1,rect_height,background_color)
  
  FILL(rect_x2,rect_y2,rect_width2,rect_height2,rect_color2)
  FILL(rect_x2+rect_width2+1,rect_y2,1,rect_height2,background_color)

  FILL(p_x,p_y,p_width,p_height,p_color)
  FILL(p_x,p_y,p_width,p_height,p_color)
# player losses energy
# red glow indicates energy loss         
  if p_x+10 > rect_x and p_x<=rect_x+rect_width and p_y+4 >= rect_y and p_y <= rect_y+rect_height or p_x+10 > rect_x2 and p_x<=rect_x2+rect_width2 and p_y+4 >= rect_y2 and p_y <= rect_y2+rect_height2:
    energy-=0.5
    FILL(p_x,p_y,p_width,p_height,"red")

  
  if energy<1:
    game_end=True
  if p_x+10>321:
    p_x=321-10
    move=False
  else:
    move=True
# player gains energy  
  if p_x+p_width >= energy_x and p_y+p_height >= energy_y and p_y <= energy_y+energy_height or p_x <= rect_x+rect_width and p_y+p_height >= rect_y and p_y <= energy_y+energy_height:
    energy+=1
    STR(".",energy_x,energy_y,background_color,background_color)      
    energy_x=RAND(-10,400)
    energy_y=RAND(-10,300)
    energy_timer=0
    score+=25
    bit_color=(RAND(0,255),RAND(0,255),RAND(0,255))   
    ascii=RAND(33,126)
    bit=chr(int(ascii))
    FILL(p_x,p_y,p_width,p_height,"green")
    
   
  if energy_timer>RAND(400,600):
    STR(" ",energy_x,energy_y,background_color,background_color)      
    energy_x=RAND(-10,400)
    energy_y=RAND(-10,300)
    energy_timer=0
    bit_color=(RAND(100,255),RAND(100,255),RAND(100,255))   
    ascii=RAND(33,126)
    bit=chr(int(ascii))

  if p_x<(SCREEN_width-SCREEN_width):
    move=False
    p_x=SCREEN_width-SCREEN_width
  else:
    move=True
#top laser
# player loses energy
  if p_y<22:
    move=False
    p_y=22
    energy-=0.2
    FILL(p_x,p_y,p_width,p_height,"red")

  else:
    move=True
# bottom laser
# player loses energy
  if p_y+p_height>211:
    move=False
    p_y=211-p_height
    energy-=0.2
    FILL(p_x,p_y,p_width,p_height,"red")


  else:
    move=True
  if move:
    if KEY(KEY_RIGHT):
      move=True
      energy-=0.002
      sleep(sleep_slow)
      p_x+=p_pace
      FILL(p_x-1,p_y,1,4,background_color)
      
      if KEY(KEY_OK):
        move=True
        for i in range(p_speed_range):
          p_x+=1
          FILL(p_x-1,p_y,1,10,background_color)
    if KEY(KEY_LEFT):
      move=True
      energy-=0.002
      sleep(sleep_slow)
      p_x-=p_pace
      FILL(p_x+10,p_y,1,10,background_color)
      
      if KEY(KEY_OK):
        move=True
        energy-=0.005
        for i in range(p_speed_range):
          p_x-=1
          FILL(p_x+10,p_y,1,10,background_color)
    if KEY(KEY_UP):
      move=True
      energy-=0.002
      sleep(sleep_slow)
      p_y-=1
      FILL(p_x,p_y+4,10,1,background_color)
      
      if KEY(KEY_OK):
        move=True
        energy-=0.05
        for i in range(p_speed_range):
          p_y-=1
          FILL(p_x,p_y+4,10,1,background_color)
      
    if KEY(KEY_DOWN):
      move=True
      energy-=0.002
      sleep(sleep_slow)
      p_y+=1
      FILL(p_x,p_y-1,10,1,background_color)
      if KEY(KEY_OK):
        move=True
        energy-=0.001
        for i in range(p_speed_range):
          p_y+=1
          FILL(p_x,p_y-1,10,1,background_color)
      
    if KEY(KEY_BACKSPACE):
      STR("(PAUSED)",100,10,"white",background_color)
      STR("OK Key = Fast Speed",70,50,"white",background_color)
      while KEY(KEY_BACKSPACE):
        pass
      while not KEY(KEY_BACKSPACE):
        pass
      while KEY(KEY_BACKSPACE):
        STR("        ",100,10,background_color,background_color)
        STR("                    ",70,50,background_color,background_color)
        pass 
    if KEY(KEY_SHIFT):
      STR("(PAUSED)",100,10,"white",background_color)
      STR("OK Key = Fast Speed",70,50,"white",background_color)
      while KEY(KEY_SHIFT):
        pass
      while not KEY(KEY_SHIFT):
        pass
      while KEY(KEY_SHIFT):
        STR("        ",100,10,background_color,background_color)
        STR("                    ",70,50,background_color,background_color)
        pass 
  if background_timer>RAND(10,20):
    background_timer=0
    background_color=(RAND(0,250),RAND(0,250),RAND(0,250))
    FILL(0,0,322,222,background_color)
        

for i in range(100):
    for j in range(100):
      i=RAND(0,321)
      j=RAND(0,222)
      FILL(i,j,RAND(3,9),RAND(3,9),(choice([100,200,255]),0,RAND(0,50)))
  
STR("GAME OVER",100,70,(255,)*3,(0,)*3)      
STR("Score: "+str(score),100,120,(0,255,0),(0,)*3)
FILL(0,0,322,40,(269,)*3)
FILL(0,182,322,40,(269,)*3)

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.