wilsons_world.py

Created by wperez274

Created on June 19, 2023

2.98 KB


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 *
from time import *


RED=(255,0,0)
WHITE=(255,)*3
BLACK=(0,)*3
GREEN=(0,255,0)
CYAN=(0,255,255)



GAME_OVER=False


float_energy=30
times_almost_fell=0
traveled=0
score=0
life=3
x=15
y=30
w=RAND(13,16)
h=RAND(12,20)
c=(RAND(0,255),RAND(0,255),RAND(0,255))

base=[0,randint(60,120),50,5,(0,0,0)]




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



bg=WHITE


MAPX=0
MAPY=0
MAPW=5000
MAPH=200


MAPBOX_X1=[MAPX,MAPY,5,MAPH,(0,0,0)]
MAPBOX_X2=[MAPX+MAPW-5,MAPY,5,MAPH,(0,0,0)]
MAPBOX_Y1=[MAPX,MAPY,MAPW,5,(0,0,0)]
MAPBOX_Y2=[MAPX,MAPY+MAPH-5,MAPW,5,(0,0,0)]



r1_x=MAPX+RAND(200,500)
r1_h=RAND(50,120)
r1_y=MAPY+MAPH-r1_h-5
r1_w=RAND(500,1200)
r1_c=(RAND(0,255),RAND(0,255),RAND(0,255))


wall_1=[r1_x,r1_y,r1_w,r1_h,r1_c]


while not GAME_OVER:

  
  MAPBOX_X1=[MAPX,MAPY,5,MAPH,(0,0,0)]
  MAPBOX_X2=[MAPX+MAPW-5,MAPY,5,MAPH,(0,0,0)]
  MAPBOX_Y1=[MAPX,MAPY,MAPW,5,(0,0,0)]
  MAPBOX_Y2=[MAPX,MAPY+MAPH-5,MAPW,5,(0,0,0)]



  fill_rect(*MAPBOX_X1)
  fill_rect(*MAPBOX_X2)
  fill_rect(*MAPBOX_Y1)
  fill_rect(*MAPBOX_Y2)


  



  fill_rect(*wall_1)



  if keydown(KEY_LEFT):
#    fill_rect(0,0,322,222,(255,)*3)
    MAPX+=3
    F(wall_1[0]-3,wall_1[1],3,wall_1[3],bg)
    




#  if keydown(KEY_RIGHT):
#    fill_rect(0,0,322,222,(255,)*3)
#    MAPX-=3
#    F(wall_1[0]+wall_1[2]+1,wall_1[1],3,wall_1[3],bg)
#    F(MAPX+2,MAPY,3,222,bg)    

#  if keydown(KEY_UP):
#    fill_rect(0,0,322,222,(255,)*3)
#    MAPY+=3


  if keydown(KEY_DOWN):
    fill_rect(0,0,322,222,(255,)*3)
    MAPY-=3



  
  wall_1=[MAPX+r1_x,MAPY+r1_y,r1_w,r1_h,r1_c]




#  sleep(0.01)

#  MAPX-=1
  

  if MAPX>0:
    MAPX=0

  if MAPY<0:
    MAPY=0

  if MAPY>0:
    MAPY=0
  
  
  fill_rect(*base)
  fill_rect(100,120,60,5,BLACK)

  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,WHITE)

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


  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,WHITE)
    float_energy-=0.4
    fill_rect(x,y+h+1,w,1,(255,)*3)


  if get_pixel(x,y+h+2) == (255,0,0) and get_pixel(x+w,y+h-1) == (255,0,0):
    sleep(0.25)
    fill_rect(x,y,w,h,(255,)*3)
    x=15
    y=30
    life-=1


  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          



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

  


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



  if y<0:
    y=0
    
  if x+w<-1:
    x=322
  if x>322:
    x=-1-w

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.