level_sprite_maker_32.py

Created by wperez274

Created on April 05, 2023

12 KB

””” Basic Guide: ====================================

Key [ Backspace ] = Set shape or object. Key [ VAR ] = Undo Last object. Key [ COSINE ] = Test Game Level. Key [ EXE ] = EXIT & Print Data of All Set Objects and Background as well.. ================================ FAST MODE:

Hold [ SHIFT ] to SHAPE Change fast.

SHAPE Change ***********

    ( - Decrease Width ) [ ( ], [ ) ] ( Increase Width+ )
    ( - Decrease Height ) [ * ], [ / ] ( Increase Height + ) 


Hold [ Sqrt ] to go fast with Movement ( LEFT RIGHT UP DOWN ) ************************* **Colors:

[ OK ] + Random Color of Current unset object. [ 0 ] (ZERO) = RANDOMIZE All Colored Objects and Background. [ 1 ] = Change All Set Objects Color to Black.
[ 7 ] = Red [ 8 ] = Green [ . ] = Change Current Unset Object to Color Black & Background to White. [ x10^ ] = Opposite of [ . ]

(Every Key has a different function)


guide = """
Basic Guide:
====================================

  Keys:
------------------------------------------   

Key [ Backspace ] = Set shape or object.
Key [ VAR ] = Undo Last object.
Key [ COSINE ] = Test Game Level.
Key [ EXE ] = EXIT & Print Data of All Set Objects 
and Background as well..
================================
FAST MODE:

Hold [ SHIFT ] to SHAPE Change fast.
-----------------------------------------------------
 SHAPE Change ***********************

        ( - Decrease Width ) [ ( ], [ ) ] ( Increase Width+ )
        ( - Decrease Height ) [ * ], [ / ] ( Increase Height + ) 

*********************************************************    
    
Hold [ Sq^ ] to go fast with Movement ( LEFT RIGHT UP DOWN ).

**Colors:

[ OK ] + Random Color of Current unset object.
[ 0 ] (ZERO) = RANDOMIZE All Colored Objects and Background.
[ 1 ] = Change All Set Objects Color to Black.   
[ 7 ] = Red
[ 8 ] = Green
[ . ] = Change Current Unset Object to Color Black & Background to White.
[ x10^ ] = Opposite of [ . ]  
 


Every Key has a different fucntion.

##################################


"""





#LEVEL & SPRITE CREATOR
#BY: WILSON
from math import *
from random import *
from random import randint as RAND 
from kandinsky import *
from kandinsky import fill_rect as F

from ion import keydown as KEYP

from kandinsky import draw_string as STR 
from ion import *
from time import *

M=255


MAPX=0
MAPY=0

sketch_mode=False

TEST_ON=False


bg=(M,)*3

pixels_captured=0

SW=322
SH=222

faston=True

BLACK=(0,)*3
WHITE=(M,)*3
GRAY=(180,)*3

RED=(M,0,0)
GREEN=(0,M,0)
BLUE=(0,0,M)

CYAN=(0,M,M)
YELLOW=(M,M,100)
MAGENTA=(M,0,M)



GRAY=(155,)*3
RED=(155,0,0)
GREEN=(0,155,0)
BLUE=(0,0,155)



penup=False
pendown=True




px=40
py=100



pc=(0,0,255)


pw=50
ph=10

ALLSCREENPIXELS=[]


###########################
#
# TO EDIT A LEVEL,
#
# PASTE DATA BELOW HERE!!
#
############################
#    level to edit

edited_bg= (242, 187, 75) 
edited_level= [
[MAPX+28, MAPY+105, 294, 117, (49, 14, 65)],
[MAPX+199, MAPY+52, 123, 7, (82, 92, 26)], [82, 79, 79, 7, (62, 208, 36)],
[MAPX+145, MAPY+148, 22, 42, (0, M, M)], [224, 148, 24, 42, (46, 230, 247)],
[MAPX+75, MAPY+144, 27, 43, (224, 90, 148)], [207, 59, 115, 44, (35, 6, 95)],
[MAPX+1, MAPY+46, 50, 20, (0, 0, 0)], [97, 40, 50, 20, (0, 0, 0,)]

]


edited_level_on=False




n=[px,py,pw,ph,pc]



edited_n=[]

grillon=False



TESTMODE=False

def TEST():
  
  global ALLSCREENPIXELS,refresh_level,bg,px,py,pw,ph,pc

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

  GAME_OVER=False
  float_energy=30
  score=0
  life=3
  x=100
  y=30
  w=RAND(13,16)
  h=RAND(12,24)
  c=(RAND(0,255),RAND(0,255),RAND(0,255))
  




  for i in ALLSCREENPIXELS:
    F(*i)

  while not GAME_OVER and not keydown(KEY_OK):
    
    

    draw_string("E:[",2,1)
    fill_rect(30,4,int(float_energy),13,(0,255,255))

    
    
    fill_rect(x,y,w,h,c)
    fill_rect(x+3,y+3,4,3,BLACK)
    fill_rect(x+9,y+3,4,3,BLACK)

    if keydown(KEY_LEFT):
      x-=1
      fill_rect(x+w+1,y,1,h,bg)



    if keydown(KEY_RIGHT):
      x+=1
      fill_rect(x-1,y,1,h,bg)

    if x<0:
      x=321
    if x>322:
      x=0
      
    if keydown(KEY_UP) and float_energy>0 or keydown(KEY_BACKSPACE) and float_energy>0:
      y-=2
      fill_rect(230,4,int(float_energy),13,bg)
      float_energy-=0.4
      fill_rect(x,y+h+1,w,1,bg)



    for i in ALLSCREENPIXELS:
      if x+w>i[0] and x<i[0]+i[2] and y+h>i[1] and y+h<i[1]+2 and i[-1]==(255,0,0):
        sleep(0.2)
        life-=1
        x=100
        y=30
        float_energy=40
        
        

    for i in ALLSCREENPIXELS:
      if x+w>i[0] and x<i[0]+i[2] and y+h>i[1] and y+h<i[1]+2:
        float_energy=0
        y-=1
        
        float_energy=40
        
                
    for i in ALLSCREENPIXELS:
      if x+w>i[0] and x<i[0]+i[2] and y+h>i[1] and y+h<i[1]+i[3]:
        for i in ALLSCREENPIXELS:
          F(*i)
        
        

    if life<1:
      sleep(0.4)
      fill_rect(0,0,322,222,(0,0,0))
      sleep(1)
      draw_string("GAME OVER",100,80,(255,0,0),(0,0,0))
      sleep(1)
      draw_string("Score:"+str(score),100,130,WHITE,(0,0,0))
      sleep(1.5)
      draw_string("PRESS [OK]",120,180,BLACK,GREEN)
      GAME_OVER=True
      
      px=100
      py=100
      pw=20
      ph=6
      refresh_level()
      TEST_ON=False
      
      
      
      
      


      

    if get_pixel(x,y+h) != (0,0,0) and get_pixel(x+w,y+h) != (0,0,0) or get_pixel(x,y+h) != (255,)*3 and get_pixel(x+w,y+h) != (255,)*3:
      sleep(0.001)  
      y+=1
      fill_rect(x-1,y-1,w+2,1,bg)



    if get_pixel(x,y+h) == (0,0,0) and get_pixel(x+w,y+h) == (0,0,0):
      float_energy=30

    if y+h>222:
      float_energy=30
      y=222-h
  


def draw_grill():
  global pw,ph,SW,SH
  size = pw


  for i in range(320//size):
    fill_rect(size*i,0,1,size*(220//size),BLACK)
    if size*i <= 220:
      fill_rect(0,size*i,320,1,BLACK)


def print_data():
  global pw,ph,pixels_captured


  STR("W:"+str(pw)+",H:"+str(ph),40,1,BLACK,bg)

  STR("[P]:"+str(len(ALLSCREENPIXELS)),140,1,CYAN,BLACK)
  F(60,20,SW,2,BLACK)


#********************
#///important!/////
#dont remove
#///////////////////


def draw_edited_level():
  global edited_level,edited_bg,SW,SH
  


  for i in edited_level:
    fill_rect(*i)





def refresh_level():
  global ALLSCREENPIXELS,bg,SW,SH,TEST
  
  if TEST_ON==False:
    F(0,0,SW,SH,bg)

  
  for i in ALLSCREENPIXELS:
    fill_rect(*i)
  




 
sleep(0.5)

cursx=150
cursy=0

#main function




EXIT=False



while not KEYP(KEY_EXE) and not EXIT:
 

  if KEYP(KEY_LOG):
    print_data()

 

  F(px,py,pw,ph,pc)


#**************************
#  navigate
#**************************

  if KEYP(KEY_LEFT):
    px-=3
    
  if KEYP(KEY_RIGHT):

    px+=3

  if KEYP(KEY_UP):

    py-=3

  if KEYP(KEY_DOWN):
    
    py+=3
  

#**************************



  if KEYP(KEY_BACKSPACE):
    sleep(0.2)
    ALLSCREENPIXELS.append(n)
    STR("[P]:"+str(len(ALLSCREENPIXELS)),1,1,CYAN,BLACK)
          
#****[ pen : up,down,erase
    



#dont remove this
  n=[px,py,pw,ph,pc]

# colors
  if KEYP(KEY_EE):
    sleep(0.2)
    pc=WHITE
    bg=BLACK
    refresh_level()  
    

  
#***********************
#***********************

  if KEYP(KEY_ONE):
    sleep(0.2)
    for i in ALLSCREENPIXELS:
      i[-1]=(0,0,0)
      
    refresh_level()






  if KEYP(KEY_TWO):
    sleep(0.2)

    pc=(RAND(0,M),M,RAND(0,M))
    F(px,py,pw,ph,pc)




  if KEYP(KEY_THREE):
    sleep(0.2)

    pc=(RAND(0,M),RAND(0,M),M)
    F(px,py,pw,ph,pc)


  if KEYP(KEY_FOUR):
    sleep(0.2)
    pc=(0,0,255)
    F(px,py,pw,ph,pc)
    

  if KEYP(KEY_SIX):
    sleep(0.2)
    pc=(255,255,0)
    F(px,py,pw,ph,pc)



  if KEYP(KEY_SEVEN):
    sleep(0.2)
    pc=(255,0,0)
    
    
    

    
  if KEYP(KEY_EIGHT):
    sleep(0.2)

    pc=(0,255,0)
    F(px,py,pw,ph,pc)

#/////////////////////////
#grill on
  if KEYP(KEY_NINE):
    sleep(0.2)

    draw_grill()
    
    sketch_mode=True
    
    

    
  if keydown(KEY_PI):
    sketch_mode=False
    bg=WHITE
    pc=BLACK
    
    refresh_level()
    
    


  if KEYP(KEY_ANS):
    sleep(0.2)
    cursx=20
    cursy=120
    
    F(0,0,SW,SH,BLACK)
    

    while not KEYP(KEY_OK):



      STR("Press [OK] ",20,0)


      if len(ALLSCREENPIXELS)>=0:
        STR(str(ALLSCREENPIXELS),cursx,cursy,GREEN,BLACK)

      if KEYP(KEY_LEFT):
        F(200,1,122,20,WHITE)

        if len(ALLSCREENPIXELS)<10:
          cursx-=2
        if len(ALLSCREENPIXELS)>=10:
          cursx-=5

      if KEYP(KEY_RIGHT):
        F(200,1,122,20,WHITE)

        if len(ALLSCREENPIXELS)<10:
          cursx+=2
        if len(ALLSCREENPIXELS)>=10:
          cursx+=5



        
      if cursx>310:
        cursx=310
        
      if cursx<-len(ALLSCREENPIXELS)*322:
        cursx=-len(ALLSCREENPIXELS)*322


        
        
      STR("X,Y: "+str(cursx)+","+str(cursy),200,1,CYAN,BLACK)
          
    refresh_level()      
    F(px,py,pw,ph,pc)




  if KEYP(KEY_LEFTPARENTHESIS):    
    pw-=2
    F(px,py,pw,ph,pc)
    
    if keydown(KEY_SHIFT):
      pw-=6
      if sketch_mode==False:
        refresh_level()
      
        
  
  if KEYP(KEY_RIGHTPARENTHESIS):
    pw+=2
    F(px,py,pw,ph,pc)
    if keydown(KEY_SHIFT):
      pw+=6
      if sketch_mode==False:
        refresh_level()



  if KEYP(KEY_MULTIPLICATION):
    ph-=2
    F(px,py,pw,ph,pc)
    if keydown(KEY_SHIFT):
      ph-=6
      if sketch_mode==False:
        refresh_level()

    

  if KEYP(KEY_DIVISION):
    ph+=2

    if keydown(KEY_SHIFT):
      ph+=6
      if sketch_mode==False:
        refresh_level()




  if KEYP(KEY_PLUS):
    pw-=2
    ph-=2
    F(px,py,pw,ph,pc)

    if keydown(KEY_SHIFT):
      pw-=6
      ph-=6
      
      
      if sketch_mode==False:
        refresh_level()



  if KEYP(KEY_MINUS):
    F(px,py,pw,ph,pc)
    pw+=2
    ph+=2
    
    if keydown(KEY_SHIFT):
      pw+=6
      ph+=6
      if sketch_mode==False:
        refresh_level()
    




  if pw<2:
    pw=2
    

  if ph<2:
    ph=2
    

  


  if KEYP(KEY_OK):
    sleep(0.2)
    pc=choice([
    "red",GREEN,BLUE,
    YELLOW,CYAN,GRAY,
    BLACK,WHITE
    ])


  if pixels_captured<0:
    pixels_captured=0
  

  if KEYP(KEY_OK):

    pc=(RAND(0,M),RAND(0,M),RAND(0,M))

    refresh_level()
    
  if KEYP(KEY_DOT):
    bg=WHITE
    pc=BLACK
    refresh_level()
    
    

  if KEYP(KEY_LEFT) or KEYP(KEY_RIGHT) or KEYP(KEY_UP) or KEYP(KEY_DOWN):
    if grillon==False:    
      refresh_level()


    
  if KEYP(KEY_ZERO):
    sleep(0.2)
    if len(ALLSCREENPIXELS)>0:
      for i in ALLSCREENPIXELS:
        i[-1]=(RAND(0,M),RAND(0,M),RAND(0,M))
      
            
      
    
    bg=(RAND(0,M),RAND(0,M),RAND(0,M))
    pc=(RAND(0,M),RAND(0,M),RAND(0,M))
    refresh_level()


    


  if KEYP(KEY_NINE):
    sleep(0.2)
    draw_grill()
    grillon=True
 
      
      
    
  if KEYP(KEY_EXP):
    sleep(0.2)
    edited_level_on=True
    draw_edited_level()


  if KEYP(KEY_SINE):
      sleep(0.2)
      STR("EDIT MODE",190,1,WHITE,WHITE)
      edited_level_on=False
      refresh_level()
      




  if edited_level_on:
      STR("EDIT MODE",190,1,BLACK,CYAN)
      draw_edited_level()

    


  if py<0:
    py=0



  if py>300:
    py=190


  





  if px<0:
    px=0
    
  if px+pw>322:
    px=322-pw
  if py<0:
    py=0
  if py+ph>222:
    py=222-ph

  
    
  if KEYP(KEY_LEFT):
    F(200,2,70,18,WHITE)
    if keydown(KEY_SQUARE):
      px-=8
      if sketch_mode==False:
        refresh_level()


    
    
    
  if KEYP(KEY_RIGHT):
    F(200,2,70,18,WHITE)
    if keydown(KEY_SQUARE):
      px+=8
      if sketch_mode==False:
        refresh_level()



  if KEYP(KEY_UP):
    F(200,2,70,18,WHITE)
    if keydown(KEY_SQUARE):
      py-=8
      if sketch_mode==False:
        refresh_level()



  if KEYP(KEY_DOWN):
    F(200,2,70,18,WHITE)
    if keydown(KEY_SQUARE):
      py+=8
      if sketch_mode==False:
        refresh_level()


#important
# pop last piece

  if KEYP(KEY_VAR):
    if len(ALLSCREENPIXELS)>0:
      sleep(0.2)
      del ALLSCREENPIXELS[-1]
      refresh_level()
    
    





  if KEYP(KEY_LOG):
    TESTMODE==True
    
    
  if TESTMODE:
    TEST()
    
    
  if KEYP(KEY_TANGENT) or KEYP(KEY_BACKSPACE):

    STR("[P]:"+str(len(ALLSCREENPIXELS)),1,1,CYAN,BLACK)




  if KEYP(KEY_LEFTPARENTHESIS):
    F(px+pw-1,py,1,ph,CYAN)
    F(px+pw+1,py,2,ph,bg)

  if KEYP(KEY_MULTIPLICATION):
    F(px,py+ph-1,pw,1,CYAN)
    F(px,py+ph+1,pw,2,bg)

  if KEYP(KEY_PLUS):
    F(px,py+ph-1,pw,1,CYAN)
    F(px,py+ph+1,pw,2,bg)

    F(px+pw-1,py,1,ph,CYAN)
    F(px+pw+1,py,2,ph,bg)



  if KEYP(KEY_POWER):
    sleep(0.2)
    px=150
    py=100
    pw=3
    ph=3
    bg=BLACK
    pc=WHITE
    
    
    

  if KEYP(KEY_VAR):
    if len(ALLSCREENPIXELS)==0:
      pw=10
      ph=10
      refresh_level()
      sleep(0.1)


      


  if KEYP(KEY_TOOLBOX):
    sleep(0.2)
    pw+=pw
    ph+=ph

    
    

  if pw>SW:
    pw=SW
    

  if ph>SH:
    ph=SH



  getkey=KEYP

    
    
  if getkey(KEY_COSINE):
    sleep(0.2)    
    TEST()
#    bg=WHITE



    
        
#///END//////  

STR("press [OK]",100,100)  
  

sleep(1)




print("\n") 
name=input("name: ") 



if len(name)<1: 
  name="ALLSCREENPIXELS"
    
  

  
print("bg = ",bg) 


print(name,"=",ALLSCREENPIXELS)

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.