level_game_maker.py

Created by wperez274

Created on September 09, 2023

7.4 KB

Awesome Level and Game Maker


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

guide="""
keys:

Arrows      = Move Shape
[OK]        = Set or Store Shape
[Backspace] = Delete Last Piece
[()],[)]    = -(Width), +(Width) 
[x] ,[/]    = -(Height), +(Height)
[Toolbox]   = Change Color of piece
[6]         = Change Color of piece
[7]         = Red 
[8]         = Green
[9]         = Blue
[0]         = GUIDE Menu
[Comma]     = Change Color of Background
 


Shift + Arrows = Move Fast
[ln]           = Load Data to Add to


"""

guide_x=0
guide_y=0

while not keydown(KEY_LEFT) and keydown(KEY_RIGHT):# and guide_y > -200:
  draw_string(str(guide),guide_x,guide_y)
  sleep(0.1)
  guide_y-=1
  
  if guide_y < -200:
    guide_y=200
    fill_rect(0,0,322,222,(255,)*3)
    draw_string("Press [Left] or [right] Arrow",40,100,(0,0,0),(0,255,255))

SW=322
SH=222

my_shapes=[]

x=100
y=100
w=60
h=15
c=(0,0,0)

bg=(255,)*3
x_y=0
my_pix=[]
my_pix_copy=[]


def draw_guide():
  global guide,guide_x, guide_y
  
  draw_string(str(guide),guide_x,guide_y)
  sleep(0.1)
  guide_y-=1
  
  if guide_y < -200:
    guide_y=200
    fill_rect(0,0,322,222,(255,)*3)
    draw_string("Press [Left] or [right] Arrow",40,100,(0,0,0),(0,255,255))
  
def clear_screen():
  F(0,0,322,222,bg)

def redraw():
  for i in my_shapes:
    F(*i)
    
  for i in my_pix_copy:
    F(*i)

def data_print():
  draw_string("Shapes:"+str(len(my_shapes)),140,1,(0,0,0),(0,255,255))
  draw_string("Pixel x_y:"+str(x_y),1,1)
  sleep(0.5)
  F(0,0,322,20,bg)

def show_grill():
  global SW,SH,gray,red,green,black
  global white,cyan,grill_gap,grill_line_c,bg

  SW=322
  SH=222
  gray=(200,)*3
  red=(255,0,0)
  green=(0,255,0)
  black=(0,0,0)
  white=(255,)*3
  cyan=(0,255,255)  
  grill_gap=20

#verticle lines, top to bottom
  for i in range(0,SW,grill_gap):
    F(i,0,1,SH,grill_line_c)
#horizontal lines, left to right
  for j in range(0,SH,grill_gap):
    F(0,j,SW,1,grill_line_c)


sprite_set=[]
sprite_on=0
grill_line_c=(0,255,255)
grill_on=0

def load_shapes():
  bg= (135, 255, 250)
  my_saved_shapes= [[0, 164, 60, 15, (0, 0, 0)], [82, 98, 60, 15, (0, 0, 0)], [229, 105, 39, 117, (0, 0, 0)], [219, 97, 57, 9, (24, 134, 226)], [-29, 213, 351, 9, 'red']]
  for i in my_saved_shapes:
    F(*i)

sketchmode=False
mybgcolors=[]
clear_screen()
edit_mode_on=0

# Main Loop
while not keydown(KEY_EXE):
  
  F(x,y,w,h,c)
  
  if keydown(KEY_LEFT):
    x-=2
    if sketchmode==0:
      F(x+w+1,y-1,2,h+2,bg)
    redraw()

    if keydown(KEY_SQUARE):
      x-=6
      if sketchmode==0:
        F(x+w+1,y-1,6,h+8,bg)

  if keydown(KEY_RIGHT):
    x+=2
    if sketchmode==0:
      F(x-2,y-1,2,h+2,bg)
    redraw()
    if keydown(KEY_SQUARE):
      x+=6
      if sketchmode==0:
        F(x-6,y-1,6,h+8,bg)


  if keydown(KEY_UP):
    y-=2
    if sketchmode==0:
      F(x-1,y+h+1,w+2,2,bg)
    redraw()
    if keydown(KEY_SQUARE):
      y-=6
      if sketchmode==0:
        F(x-1,y+h+1,w+2,6,bg)    
    
  if keydown(KEY_DOWN):
    y+=2
    if sketchmode==0:
      F(x-1,y-2,w+2,2,bg)
    redraw()
    if keydown(KEY_SQUARE):
      y+=6
      if sketchmode==0:
        F(x-1,y-6,w+2,6,bg)

    
  if keydown(KEY_OK):
    sleep(0.2)
    my_shapes.append([x,y,w,h,c])
    draw_string("Shapes:"+str(len(my_shapes)),1,1,(0,0,0),(0,255,255))
    draw_string("Shape captured!",140,1)
    sleep(0.5)
    F(0,0,322,20,bg)

  if keydown(KEY_VAR):
    sleep(0.2)
    print([x,y])
    x_y+=1
    my_pix.append([x,y])
    my_pix_copy.append([x,y,w,h,(0,0,200)])
    draw_string("Pixel:"+str(x_y),1,1)
    draw_string("Pixel[x,y] Captured!",110,1,(0,0,140))
    sleep(0.6)
    F(0,0,322,20,bg)

  if keydown(KEY_BACKSPACE):
    sleep(0.2)
    if len(my_shapes)>0:
      del my_shapes[-1]
      clear_screen()
      redraw()
      
    if my_shapes==[]:
      sleep(0.2)
      if len(my_pix_copy)>0:
        del my_pix_copy[-1]
        clear_screen()
        redraw()
            
  if keydown(KEY_POWER):
    sleep(0.2)
    if len(my_pix_copy)>0:
      del my_pix_copy[-1]
      redraw()
        
    
  if keydown(KEY_SHIFT):
    if keydown(KEY_BACKSPACE):
      sleep(0.2)
      clear_screen()
      my_shapes=[]
      my_pix=[]



  if keydown(KEY_LEFTPARENTHESIS):
    sleep(0.01)
    w-=1
    F(x+w+1,y,1,h,bg)
    if keydown(KEY_SHIFT):
      w-=5
      F(x+w+1,y,5,h,bg)

      
  if keydown(KEY_RIGHTPARENTHESIS):
    sleep(0.01)
    w+=1
    if keydown(KEY_SHIFT):
      w+=5
      


  if keydown(KEY_MULTIPLICATION):
    sleep(0.01)
    h-=1
    F(x,y+h+1,w+1,1,bg)
    if keydown(KEY_SHIFT):
      h-=5
      F(x,y+h+1,w+1,5,bg)


  if keydown(KEY_DIVISION):
    sleep(0.01)
    h+=1
    if keydown(KEY_SHIFT):
      h+=5


  if keydown(KEY_IMAGINARY):
    sleep(0.2)
    bg=(R(0,255),R(0,255),R(0,255))
    fill_rect(0,0,322,222,bg)

  if w<2:
    w=2
  if h<2:
    h=2
  if x<0:
    x=0
  if x+w>322:
    x=322-w
  if y<0:
    y=0
    
  if y+h>222:
    y=222-h
    
    
  if keydown(KEY_COMMA):
    sleep(0.2)
    bg=(R(0,255),R(0,255),R(0,255))
    clear_screen()
    redraw()
    

  if keydown(KEY_PI):
    sleep(0.2)
    w=3
    h=3
    grill_line_c=choice([
    'green','blue','black',
    'white','gray',(0,225,255)
    ])

    grill_on+=1

  if grill_on:
    show_grill()

    

  if grill_on>1:
    grill_on=0
    clear_screen()


  if keydown(KEY_SQRT):
    sleep(0.2)
    w=3
    h=3
    sketchmode+=1

  if sketchmode:
    draw_string("[sketch on]",200,1,(0,)*3,(0,255,255))

    
  if sketchmode>1:
    sketchmode=0
    draw_string("[sketch on]",200,1,bg,bg)
        

  if keydown(KEY_FOUR):
    sleep(0.2)
    c='yellow'
    
  if keydown(KEY_FIVE):
    sleep(0.2)
    c=(0,0,0)
    
  if keydown(KEY_SIX):
    sleep(0.2)
    c=(255,)*3
    


  if keydown(KEY_SEVEN):
    sleep(0.2)
    c='red'

  if keydown(KEY_EIGHT):
    sleep(0.2)
    c='green'
  if keydown(KEY_NINE):
    sleep(0.2)
    c='blue'

  if keydown(KEY_TOOLBOX):
    sleep(0.2)
    c=(R(0,255),R(0,255),R(0,255))
    
    
    
    
  if keydown(KEY_TANGENT):
    sleep(0.2)
    mybgcolors.append(bg)
    draw_string("bg captured!",100,1)
    sleep(0.5)
    draw_string("bg captured!",100,1,bg,bg)


  if keydown(KEY_BACKSPACE):
    if w>12:
      if len(my_shapes)<1:
        sleep(0.2)
        w=12
        h=12
        clear_screen()
    
    if w==322 and h==222:
      x=80
      y=80
      w=100
      h=100
      bg=c
      c=(R(0,255),R(0,255),R(0,255))
      

  if bg==c:
    c=(R(0,255),R(0,255),R(0,255))


  if keydown(KEY_COSINE):
    sleep(0.2)
    data_print()


    


  if keydown(KEY_LN):
      sleep(0.2)
      edit_mode_on+=1


  if edit_mode_on>1:
    fill_rect(0,0,322,222,bg)
    edit_mode_on=0
    


  if edit_mode_on==1:
    draw_string("edit_mode_on",5,1,(0,255,255),(0,0,0))
    load_shapes()
    if  keydown(KEY_LEFT) or keydown(KEY_RIGHT) or keydown(KEY_UP) or keydown(KEY_DOWN):
      load_shapes()

    
    

  if keydown(KEY_ZERO):
    sleep(0.2)
    while not keydown(KEY_LEFT) and not keydown(KEY_RIGHT):
      draw_guide()
    F(0,0,322,222,bg)
    


    




mybgcolors=list(set(mybgcolors))  





draw_string("PRESS OK",100,150,(0,)*3,(0,255,255))

print("")
print("-------------------------")
print("mybgcolors=",mybgcolors)
print("-------------------------")
print("bg=",bg)  
print("-------------------------")
print("w,h,c=[",w,",",h,",",c,"]")
print("-------------------------")
print("my_pix=",my_pix)
print("-------------------------")
print("my_shapes=",my_shapes)

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.