pythasworld7.py

Created by wperez274

Created on February 06, 2022

6.37 KB


# Game By: Wilson
from math import *
from random import *
from kandinsky import *
from ion import *
from time import *
from kandinsky import fill_rect as F
from kandinsky import draw_string as STR
from random import randint as R
from ion import keydown as K

#for rgb tuple value
H=255

RED=(H,0,0)
BLACK=(0,0,0)
WHITE=(H,H,H)
CYAN=(0,H,H)
GREEN=(0,H,0)
BLUE=(0,0,H)

bg=BLACK
F(0,0,322,222,bg)
while not K(KEY_OK):
  F(0,10,322,3,BLUE)
  F(0,50,322,3,BLUE)
  STR("Pythagoras World",50,22,"white",bg)
  STR("Key [Backspace] = Pause/Unpause",5,110,"green",bg)
  STR("Use [ARROWS] to Avoid Rects",15,140,"cyan",bg)
  sleep(0.1)
  STR("( Press [OK] to START )",25,190,"white",bg)

sleep(0.2)
F(0,0,322,222,(0,0,0))
F(0,20,322,2,"gray")
F(0,200,322,2,"gray")

while not K(KEY_OK):
  STR("________TIPS:_______",40,50,"gray",(0,0,0))
  STR("Rects with values higher",10,100,"white",(0,0,0))
  STR("than [40] are hard to destroy.",10,130,"white",(0,0,0))
  STR("Avoid the Dark Matter!",20,160,"cyan",(0,0,0))

game=True
bg=(R(0,H),R(0,H),R(0,H))
psc=0
pe=35
px=20
py=100
pw=10
ph=5
pc=(R(200,H),R(200,H),R(200,H))

rx=R(300,500)
ry=R(20,200)
rw=R(20,60)
rh=R(20,60)
r_c=(R(0,H),R(0,H),R(0,H))
rmass=(rw*rh)/5

#rs can chase or change 
#shape dimension
r_t=0
r_g=False
r_chase=False
r_v=0

# dark matter!
darkmx=R(322,500)
darkmy=R(22,200)
darkmw=R(20,80)
darkmh=R(20,80)
darkm_c=(R(0,25),R(0,25),R(0,25))

# move r 
def move_Rect():
  global rx,ry,rw,rh,r_c
  rx-=1
  F(rx+rw,ry,1,rh,bg)
# move meteor 
def move_darkmatter():
  global darkmx,darkmy,darkmw,darkmh
  darkmx-=1
  F(darkmx+darkmw,darkmy,1,darkmh,bg)
#move player  
def move_Left():
  global px,py,pw,ph,pc
  px-=1
  F(px+pw,py,1,ph,bg)
def move_Right():
  global px,py,pw,ph,pc,bg
  px+=1
  F(px-1,py,1,ph,bg)
def move_Up():
  global px,py,pw,ph,pc,bg
  py-=1
  F(px,py+ph,pw,1,bg)
def move_Down():
  global px,py,pw,ph,pc,bg
  py+=1
  F(px,py-1,pw,1,bg)
# when keys pressed
def keyListen():
  if K(KEY_BACKSPACE):
    pause()
  if K(KEY_LEFT):
    move_Left()
  if K(KEY_RIGHT):
    move_Right()
  if K(KEY_UP):
    move_Up()
  if K(KEY_DOWN):
    move_Down()

# game is paused/unpaused
def pause():
  if K(KEY_BACKSPACE):
    STR("(PAUSED)",110,100,(R(0,H),R(0,H),R(0,H)),bg)
    while K(KEY_BACKSPACE):
      pass
    while not K(KEY_BACKSPACE):
      pass
    while K(KEY_BACKSPACE):
      STR("        ",110,100,bg,bg)
      pass
# draw the main things      
def drawGame():
  STR("Player[",5,0,"cyan",(0,0,0))
  F(73,4,round(pe/3),11,pc)
  STR("Enemy[",200,0,"green",(0,0,0))
  F(258,4,round(rmass*0.02),11,(H,0,0))
  F(0,0,4,222,RED)
  F(darkmx,darkmy,darkmw,darkmh,darkm_c)
  F(px,py,pw,ph,pc)
  F(rx,ry,rw,rh,r_c)

# Game over when pe is less
# than zero.
def gameEnd():
  global bg,psc
  for i in range(100):
    for j in range(100):
      i=R(0,321)
      j=R(0,222)
      F(i,j,R(2,5),R(2,5),choice([BLACK,"white","gray"]))
  STR("GAME OVER",100,90,(R(0,H),R(0,H),R(200,H)),(0,0,0))      
  STR("SCORE: "+str(psc),100,120,(R(200,H),R(200,H),R(200,H)),(0,0,0))      

def r_new():
  global rx,ry,rw,rw,r_c,rmass
  rx=R(250,322)
  ry=R(36,140)
  rw=R(20,100)
  rh=R(40,150)
  r_c=(R(0,H),R(0,H),R(0,H))
  rmass=(rw*rh)/6
       
F(0,22,322,222,bg)

def drawlava():
  for i in range(0,322):
    i+=1
    F(i,R(20,25),R(2,5),R(5,15),choice([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))]))
#ground  
  for i in range(0,322):
    i+=1
    lavay=R(205,220)
    F(i,lavay,R(2,5),30,choice([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))]))

drawlava()
while game:
# sometimes r will follow 
  r_chase=choice([1,0,1,0,0,0])
    
  drawGame()
  keyListen()
  move_Rect()
  move_darkmatter()
# when rangle reaches left wall
  if rx<0-rw-R(10,25):
    r_new()
    pe-=2
    F(73+int(pe/3),4,2,11,(0,0,0))
    F(px,py,pw,ph,(H,0,0))
    F(258,4,70,11,(0,0,0))

    for i in range(0,322):
      i+=1
      F(i,R(20,25),R(2,5),R(5,15),choice([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))]))
  
    for i in range(0,322):
      i+=1
      lavay=R(205,220)
      F(i,lavay,R(2,5),30,choice([(R(0,75),R(0,75),R(0,75)),(0,0,0),(R(0,55),R(0,55),R(0,55))]))

# if player gets hit, energy
  if px+pw >= rx and px <= rx+rw and py+ph >= ry and py <= ry+rh:
    F(px,py,pw,ph,RED)
    pe-=0.1
    F(73+int(pe/3),4,2,11,(0,0,0))
    px-=1
# dark matter is unbreakable
  if px+pw >= darkmx and px <= darkmx+darkmw and py+ph >= darkmy and py <= darkmy+darkmh:
    F(px,py,pw,ph,choice([BLACK,RED]))
    pe-=2
    F(73+int(pe/3),4,2,11,(0,0,0))
    sleep(0.01)
    
  if pe<1:
    game=False
  
  if r_chase:
    if int(ry+rh/2) < py:
      ry+=1
      F(rx,ry-1,rw,1,bg)
    if ry>py:
      ry-=1
      F(rx,ry+rh,rw,1,bg)
  
  if py+ph > 218:
    py=218-ph
    pe-=0.02
    F(px,py,pw,ph,RED)
    F(73+int(pe/3),4,2,11,(0,0,0))
    
  if py < 23:
    py=23
    pe-=0.02
    F(px,py,pw,ph,RED)
    F(73+int(pe/3),4,2,11,(0,0,0))
    
  # player touches lava on left
  if px < 3:
    px = 3
    F(px,py,pw,ph,RED)
    F(73+int(pe/3),4,2,11,(0,0,0))
    pe -= 0.2
    
  if px+pw>322:
    px=322-pw
    
  if K(KEY_OK):
    F(px+3,py,322,4,(R(0,H),R(0,H),R(0,H)))
    sleep(0.002)
    F(px+3,py,322,4,bg)
# player is low on energy
  if pe<=20:
    F(px+R(-3,3),py,R(2,4),R(2,4),"orange")
    F(px,py,pw,ph,choice([RED,BLACK,bg]))
    F(px,py-1,pw,1,bg)
    py+=choice([0,0,1,0])

  if darkmx<0-darkmw-R(10,20):
    darkmx=R(500,800)
    darkmy=R(22,200)
    darkmw=R(40,100)
    darkmh=R(50,120)
    darkm_c=(R(0,35),R(0,35),R(0,35))

# rs enemy shot
  if K(KEY_OK) and py >= ry and py+ph <= ry+rh and px+pw<=rx+rw:
    F(px,py,pw,ph,"green")
    pe+=0.005
    rmass-=6
    F(258+round(rmass*0.02),4,2,11,(0,0,0))
    psc+=1
    F(rx,ry,rw,rh,"cyan")
    F(rx,ry,rw,rh,bg)
   
    for i in range(R(5,20)):
      for j in range(R(5,20)):
        i=rx+R(0,rw)
        j=ry+R(0,rh)
        F(i,j,R(2,5),R(2,5),choice(["cyan",BLACK,bg,r_c,bg]))
# rmass reflects strengh of rangles

#player crashes into ceiling      if py<=36:
  if py<36:    
    py=R(35,36)
    pe-=0.5
    F(73+int(pe/3),4,2,11,(0,0,0))
    F(px,py,pw,ph,(H,0,0))
    drawlava()    
#player crashes into ground  
  if py>200:
    py=R(199,200)
    pe-=0.5
    F(73+int(pe/3),4,2,11,(0,0,0))
    F(px,py,pw,ph,(H,0,0))
    
    drawlava()


#rangle destroyed  
  if rmass<1:
    r_new()
    pe+=(rw*rh)*0.0005
    psc+=R(15,35)
    bg=(R(0,H),R(0,H),R(0,H))
    F(0,22,322,222,bg)
    F(0,0,322,20,(0,0,0))
    
    drawlava()
    
#game over  
gameEnd()

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.