night_game.py

Created by wperez274

Created on December 31, 2021

3.74 KB

Potential Game. I will work on this and try to make a game. So this is just a template.


from kandinsky import *

from kandinsky import fill_rect as F
from kandinsky import draw_string as STR
from random import randint as R

from math import *
from ion import *
from ion import keydown as KEY
from time import *
from random import *

def spawn_rects():
  F(0,0,322,222,bg)
  F(map_x,200,R(60,110),100,R1)  
  F(map_x+100,R(140,210),R(60,100),100,R2)  
  F(R(200,250),R(-10,20),R(20,60),R(50,200),R2)    
  F(R(200,250),R(-10,20),R(20,60),R(50,200),R3)
  F(R(200,250),R(-10,20),R(50,90),R(40,80),R3)
map_x=0
map_y=0
map_w=3220
map_h=222


clock=0
star_size=1



star_colors=["white",
"yellow",
"orange",
"red",
"blue"
]
C=star_colors[R(0,4)]


R1=(R(0,25),R(0,25),R(0,25))
R2=(R(5,50),R(5,50),R(5,50))
R3=(R(0,10),R(0,10),R(0,10))


c=R(0,322)
d=R(0,222)

# heart is 7 * 7 sprite.
heart_t=0

game=True

px=10
py=100
pc=(245,245,245)
pw=10
ph=10
ps=10

bg=(0,0,150)

ts = 2

tc="black"
fc="red"
x=0
y=0

  
  
rect=[(x,y+ts,ts,ts*3,tc),
  (x+ts*1,y+ts*1,ts,ts*3,fc),
  (x+ts*2,y+ts*2,ts,ts*3,fc),
  (x+ts*3,y+ts*3,ts,ts*3,fc),
  (x+ts*4,y+ts*2,ts,ts*3,fc),
  (x+ts*4,y+ts*2,ts,ts*3,fc),
  (x+ts*5,y+ts*1,ts,ts*3,fc),
  (x+ts*6,y+ts*1,ts,ts*3,tc),
  (x+ts*1,y,ts,ts,tc),
  (x+ts*2,y+ts*1,ts,ts,tc),
  (x+ts*3,y+ts*2,ts,ts,tc),
  (x+ts*4,y+ts*1,ts,ts,tc),
  (x+ts*5,y,ts,ts,tc),
  (x+ts*1,y+ts*4,ts,ts,tc),
  (x+ts*2,y+ts*5,ts,ts,tc),
  (x+ts*3,y+ts*6,ts,ts,tc),
  (x+ts*4,y+ts*5,ts,ts,tc),
  (x+ts*5,y+ts*4,ts,ts,tc)
]

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

F(map_x,200,R(60,110),100,R1)  
F(map_x+100,R(140,210),R(60,100),100,R2)  
F(map_x+R(200,250),R(150,200),R(20,60),200,R2)  
F(map_x+R(250,300),R(170,210),R(40,70),200,R3)  

F(R(50,100),R(-50,-10),R(60,100),R(25,150),R2)  
F(R(200,250),R(-10,20),R(20,60),R(50,200),R2)  
F(R(250,300),R(-60,0),R(60,100),100,R2)  
F(R(200,250),R(-80,20),R(20,60),200,R2)  
F(R(0,50),R(-50,40),R(50,80),R(50,100),R2)

while game:
 
  for i in rect:
    F(*i)
    
  F(px,py,ps,ps,pc)
  
  if KEY(KEY_LEFT):
    px-=1
    F(px+ps,py,1,ps,bg)
    if px<0:
      px=322
      F(0,0,322,222,bg)
      F(map_x,200,R(60,110),100,R1)  
      F(map_x+100,R(140,210),R(60,100),100,R2)  
      F(map_x+R(200,250),R(150,200),R(100,200),R(150,200),bg)
      F(R(50,100),R(-50,-10),R(60,100),R(25,150),R2)  
      F(R(200,250),R(-10,20),R(20,60),R(50,200),R2)    
      F(R(200,250),R(-10,20),R(20,60),R(50,200),R3)
      F(R(200,250),R(-10,20),R(20,60),R(40,80),R1)

  if KEY(KEY_RIGHT):
    px+=1
    F(px-1,py,1,ps,bg)
    if px>322:
      px=0
      F(0,0,322,222,bg)
      F(map_x,200,R(60,110),100,R1)  
      F(map_x+100,R(140,210),R(60,100),100,R2)  
      F(map_x+R(200,250),R(150,200),R(20,60),200,R2)  
      F(R(200,250),R(-10,20),R(20,60),R(50,200),R2)    
      F(R(200,250),R(-10,20),R(20,60),R(50,200),R3)
      F(R(200,250),R(-10,20),R(50,80),R(50,200),R1)
  
  if KEY(KEY_UP):
    py-=1
    F(px,py+ps,ps,1,bg)
    if py<0:
      py=222
      F(0,0,322,222,bg)
      F(map_x,200,R(60,110),100,R1)  
      F(map_x+100,R(140,210),R(60,100),100,R2)  
      F(map_x+R(200,250),R(150,200),R(20,60),200,R2)  
      F(R(200,250),R(-10,20),R(20,60),R(50,200),R2)    
      F(R(200,250),R(-10,20),R(20,60),R(50,200),R3)
      F(R(200,250),R(-10,20),R(50,80),R(50,200),R1)

    
  if KEY(KEY_DOWN):
    py+=1
    F(px,py-1,ps,1,bg)
    if py>222:
      py=0
      F(0,0,322,222,bg)
      F(map_x,200,R(60,110),100,R1)  
      F(map_x+100,R(140,210),R(60,100),100,R2)  
      F(map_x+R(200,250),R(150,200),R(20,60),200,R2)  
      F(R(200,250),R(-10,20),R(20,60),R(50,200),R2)    
      F(R(200,250),R(-10,20),R(20,60),R(50,200),R3)
      F(R(200,250),R(-10,20),R(50,80),R(50,200),R1)

    
    
    
    
  clock+=1
  if clock>0 and clock<30:
    c=R(0,322)
    d=R(0,90)
    C=star_colors[R(0,4)]
  
  F(c,d,star_size,star_size,C)
    

  
  
  if get_pixel(px+ps,py)=="black":
    game=0

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.