etchasketch8.py

Created by wperez274

Created on July 11, 2023

9.32 KB

etchaskecth and secret game inside!


from math import *
from random import *
from random import randint as RINT
from kandinsky import *
from kandinsky import fill_rect as F
from ion import *
from time import *


EXIT=False
GAMEOVER=False

GAMEON=False


draw=True

pendown=True


colorRandomize=True

bg=(255,255,255)

rect_x=RINT(450,600)
rect_y=RINT(20,170)
rect_w=RINT(20,140)
rect_h=RINT(20,100)
rect_c=(255,0,0)

rect_e=rect_w*rect_h



line_width=RINT(2,8)




AMMO=20

score=0
energy=35



AMMO_x=RINT(600,1000)
AMMO_y=RINT(60,100)
AMMO_w=15
AMMO_h=15
AMMO_c=(0,255,0)


pos_x=150
pos_y=100

width=10

height=10

paint_color=(0,0,0)

sketch=False

eraser_t=0


F(0,0,322,222,bg)



def eraser():
  global width,height,bg,pos_x,pos_y
  
  
  F(pos_x,pos_y,width,height,bg)
  
def eraserAll():
  global bg
  bg=(255,255,255)
  paint_color=(0,0,0)
  colorRandomize=True
  
  F(0,0,322,222,bg)
  

def borderize():
  global pos_x,pos_y,size

  mycolor="cyan"
  
  F(pos_x,pos_y,2,height,mycolor)
  F(pos_x+width-2,pos_y,2,height,mycolor)
  F(pos_x,pos_y,width,2,mycolor)
  F(pos_x,pos_y+height-2,width,2,mycolor)
  

sleep(0.12)

while not EXIT:


  if keydown(KEY_TOOLBOX) and GAMEON==False:
    F(pos_x,pos_y,width,height,bg)
    
    F(pos_x,pos_y,3,height,(0,0,0))
    F(pos_x+width-3,pos_y,3,height,(0,0,0))
    F(pos_x,pos_y,width,3,(0,0,0))
    F(pos_x,pos_y+height-3,width,3,(0,0,0))

    
    
    pendown=False
    
  else:
    pendown=True

  
  if pendown:
    F(pos_x,pos_y,width,height,paint_color)
    
  else:
    F(pos_x,pos_y,width,height,bg)
    
    

  F(pos_x+1,pos_y,2,height,(0,0,0))
  F(pos_x+width-3,pos_y,2,height,(0,0,0))
  F(pos_x,pos_y+1,width,2,(0,0,0))
  F(pos_x,pos_y+height-3,width,2,(0,0,0))


  if colorRandomize:
    paint_color=(RINT(0,255),RINT(0,255),RINT(0,255))


  else:
    sketch=True

  if sketch:  
    F(pos_x,pos_y,width,height,paint_color)
    


  if keydown(KEY_LEFT) and GAMEON==False:
    pos_x-=3
    
    
    if keydown(KEY_POWER):
     
    
      sleep(0.03)
      pos_x-=width-1
    
    if keydown(KEY_EXE):
      sleep(0.15)
      borderize()
      pos_x-=width
    

  if keydown(KEY_RIGHT) and GAMEON==False:
    pos_x+=3
    if keydown(KEY_EXE):
      sleep(0.15)
      borderize()

      pos_x+=width


  if keydown(KEY_UP) and GAMEON==False:
    pos_y-=3
    
    
    if keydown(KEY_EXE):
      sleep(0.15)
      borderize()

      pos_y-=height
    

  if keydown(KEY_DOWN) and GAMEON==False:
    pos_y+=3

    if keydown(KEY_EXE):
      sleep(0.15)
      borderize()

      pos_y+=height


  if keydown(KEY_BACKSPACE) and GAMEON==False:
    eraser_t+=0.02
  
  if eraser_t>=1:
    eraser_t=0
    eraserAll()



    

  if keydown(KEY_TOOLBOX) and GAMEON==False:
    colorRandomize=False
    paint_color=bg
    
    eraser()


  if keydown(KEY_OK) and colorRandomize==False and GAMEON==False:
       
    sleep(0.2)
    colorRandomize=True
    sketch=False
    

  if keydown(KEY_OK) and colorRandomize and GAMEON==False:
       
    sleep(0.2)
    colorRandomize=False
    sketch=True
 

  if keydown(KEY_PLUS) and GAMEON==False:

    width-=1
    height-=1


  if keydown(KEY_MINUS) and GAMEON==False:
    width+=1
    height+=1

  if width<1:
    width=1
    
  if height<1:
    height=1

  if keydown(KEY_ANS) and GAMEON==False:
    sleep(0.2)
    bg=paint_color
    F(0,0,322,222,bg)
    colorRandomize=False
    paint_color=(0,0,0)

        
  if keydown(KEY_ZERO) and GAMEON==False:
    colorRandomize=False
    paint_color=(0,0,0)
    
  if keydown(KEY_DOT) and GAMEON==False:
    colorRandomize=False
    paint_color='white'

  if keydown(KEY_ONE) and GAMEON==False:
    colorRandomize=False
    paint_color=(255,0,0)

  if keydown(KEY_FOUR) and GAMEON==False:
    colorRandomize=False
    paint_color=(0,255,0)


  if keydown(KEY_SEVEN) and GAMEON==False:
    colorRandomize=False
    paint_color=(0,0,255)
    
#**********************    
#limit movement     
  if pos_x<=0:
    pos_x=1

  if pos_x+width>=318:
    pos_x=318-width

  if pos_y<=22:
    pos_y=22

  if pos_y+height>=218:
    pos_y=218-height





  if keydown(KEY_LEFTPARENTHESIS) and GAMEON==False:
    width-=2
  
  
  if keydown(KEY_RIGHTPARENTHESIS) and GAMEON==False:
    width+=2
    
  
  if keydown(KEY_MULTIPLICATION) and GAMEON==False:
    height-=2
    
  if keydown(KEY_DIVISION) and GAMEON==False:
    height+=2
    
  
  
  borderize()
  
  

  
  if width>=10 and height>=10 and GAMEON==False:
    F(0,0,322,22,(0,0,0))

   
    draw_string(","+str(bg),165,2,'green','black')
    
    if colorRandomize==False:
      draw_string(str(paint_color),2,2,'gray',"black")


  
  if GAMEON==False:
    draw_string("[π]=EXIT/PAUSE",180,205,(0,255,0),(0,0,0))
    draw_string("[Squared]=GAMEON",0,205,(0,255,255),(0,0,0))

  

  if keydown(KEY_PI):

    while not keydown(KEY_TANGENT) and not keydown(KEY_OK):
  
      draw_string("PRESS [OK] TO EXIT",50,100,(0,255,255),(0,0,0))
      draw_string("PRESS [tan] TO Resume",50,150,(0,255,0),(0,0,0))
    
    if keydown(KEY_OK):
      F(0,22,322,222,bg)  

      draw_string("GOOD BYE.",100,100)
      sleep(0.8)
      draw_string("Press [OK] to exit.",60,130)
      sleep(1.8)
      
      EXIT=True
      
      

      
      
    F(0,22,322,222,bg)

  
  

  if keydown(KEY_SQUARE):
    GAMEON=True
    F(0,0,322,222,(0,0,0))
    pos_x=20
    pos_y=100

    
    
  if keydown(KEY_SQRT):
    pos_x=20
    pos_y=100

    GAMEON=False
    
    
  if GAMEON:
    global mycolor
            
    mycolor=(0,255,255)
    colorRandomize=False
    paint_color=(0,0,0)
    
    width=30
    height=20
    
        
    if keydown(KEY_OK) and AMMO>0:
      F(pos_x+width,pos_y+int(height/2),322-pos_x,2,(255,0,0))
      F(pos_x+width,pos_y+int(height/2)-3,322-pos_x,1,(0,255,255))
      F(pos_x+width,pos_y+int(height/2)+3,322-pos_x,1,(0,255,255))
      AMMO-=1
      F(0,0,322,22,(0,0,0))
    

  
      if rect_y+rect_h>=pos_y+int(height/2) and rect_y<=pos_y+int(height/2)+3:
        
        if rect_x<=230:
        
          F(rect_x,rect_y,line_width,rect_h,(255,0,0))
          F(rect_x+rect_w-line_width,rect_y,line_width,rect_h,(255,0,0))
          F(rect_x,rect_y,rect_w,line_width,(255,0,0))
          F(rect_x,rect_y+rect_h-line_width,rect_w,line_width,(255,0,0))
        
          sleep(0.15)
          rect_x=RINT(300,500)
          rect_y=choice([RINT(-40,0),RINT(120,180)])
          rect_c=(RINT(0,255),RINT(0,255),RINT(0,255))
          rect_w=RINT(40,100)
          rect_w=RINT(40,200)
          
          


          line_width=RINT(2,6)
          energy+=1
              



    
    if AMMO<=0:
      AMMO=0    
    
    if rect_y<pos_y:
      rect_y+=choice([-1,0,2,4,5,6])
    if rect_y>pos_y:
      rect_y-=choice([-1,0,2,4,5,6])
 
 
#player hit, energy loss :"( 
 

    if pos_x+width>=rect_x and pos_x<=rect_x+rect_w and pos_y+height>=rect_y and pos_y<=rect_y+rect_h:
      F(0,0,322,22,(0,0,0))
      F(0,22,322,222,(255,0,0))
      energy-=0.75
      
    if energy<15:
      pos_y+=RINT(0,2)
      F(pos_x-RINT(1,5),pos_y+height+RINT(0,5),RINT(2,6),RINT(2,6),(255,0,0))
    
    
    if energy<=0:
      
      GAMEON=False
      GAMEOVER=True
      F(0,0,322,222,(0,0,255))

      
      
      
    if GAMEOVER:
      F(0,0,322,222,(0,0,0))
      draw_string("GAME OVER",100,100,(0,255,0),(0,0,0))
      draw_string("SCORE: "+str(score),100,140,(0,255,250),(0,0,0))
      
      sleep(2)
      width=15
      height=15
      pos_x=150
      pos_y=100
      
      
              
    
    if keydown(KEY_LEFT):
      pos_x-=16

    if keydown(KEY_RIGHT):
      pos_x+=16

    if keydown(KEY_UP):
      pos_y-=16

    if keydown(KEY_DOWN):
      pos_y+=16

      
    if pos_x<=1:
      
      pos_x=2

    if pos_x+width>=318:
      pos_x=318-width

    if pos_y<=23 and GAMEON:
      pos_y=23
      F(0,0,322,22,(0,0,0))


      energy-=0.05

    
    if pos_y+height>=220:
      pos_y=220-height
      F(0,0,322,22,(0,0,0))


      energy-=0.05
   

    F(AMMO_x,AMMO_y,AMMO_w,AMMO_h,AMMO_c)
    

    F(AMMO_x,AMMO_y,2,AMMO_h,(0,255,255))
    F(AMMO_x+AMMO_w-2,AMMO_y,2,AMMO_h,(0,255,255))
    F(AMMO_x,AMMO_y,AMMO_w,2,(0,255,255))
    F(AMMO_x,AMMO_y+AMMO_h-2,AMMO_w,2,(0,255,255))




    
    if AMMO_x+AMMO_w<0-RINT(-20,-5):
      AMMO_x=RINT(1000,1500)
      AMMO_y=RINT(20,170)
      
      
    if pos_x+width>=AMMO_x and pos_x<=AMMO_x+AMMO_w and pos_y+height>=AMMO_y and pos_y<=AMMO_y+AMMO_h:
      sleep(0.25)
      F(0,0,322,222,(0,255,0))
      AMMO+=5
      AMMO_x=RINT(1000,1500)
      AMMO_y=RINT(20,170)
      
      
      
      
  if GAMEON:
    F(pos_x+8,pos_y+3,12,7,(220,220,220))
 
    
    

    
    F(0,22,322,2,(255,0,0))
    F(0,219,322,2,(255,0,0))
    
    draw_string("ENERGY: ",2,2,(0,255,0),(0,50,0))    
    F(80,2,int(energy),16,(255,0,0))

    draw_string("AMMO: ",180,2,(0,255,0),(0,50,0))    
    F(240,2,int(AMMO*2),16,(0,255,255))




    
    F(0,20,322,222,(0,0,0))

    F(rect_x,rect_y,line_width,rect_h,rect_c)
    F(rect_x+rect_w-line_width,rect_y,line_width,rect_h,rect_c)
    F(rect_x,rect_y,rect_w,line_width,rect_c)
    F(rect_x,rect_y+rect_h-line_width,rect_w,line_width,rect_c)

    rect_x-=int(45/rect_w*height)
    

  if rect_x+rect_w<0-20:
    rect_x=RINT(280,500)
    rect_y=RINT(-70,180)
    rect_w=RINT(40,100)
    rect_h=RINT(40,200)
    score+=RINT(25,100)
    energy-=0.5
    rect_c=(RINT(0,255),RINT(0,255),RINT(0,255))
    line_width=RINT(2,10)  
      
    
            
print("\n\n\n\nBackground: ",bg)
sleep(0.4)
print("\nBrush: ",paint_color,"\n")

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.