minecraftgut.py

Created by lex-kimmel

Created on December 11, 2023

3.93 KB


from kandinsky import *
from ion import *
from time import *
from random import *
from math import *
from ion import *

# Define colors
GRASS_COLOR = (178,215,76) 
DIRT_COLOR = (212, 115, 44)
SKY_COLOR = (93,142,221)  
PLAYER_HEAD_COLOR = (253,180,139)
PLAYER_BODY_COLOR = (33,39,95)
TREE_COLOR = (98,47,23)
orggrass=GRASS_COLOR
orgsky=SKY_COLOR
orgdirt=DIRT_COLOR
orgtree=TREE_COLOR

player_x=0
player_y=-2
camera_x=0
camera_y=6
target_FPS=16
real_fps=0
day=0.9
night=0
selector_x=0
selector_y=19
selector_moving=False


sec=monotonic()
active=1

def player_update():
  
  global player_x,player_y,selctor_moving
  terrain_height=round(formula(player_x/16)-1)
  player_height=round(player_y)
  if terrain_height>player_height:
    player_y+=1
    selctor_moving=True
  if terrain_height==player_height:
    if(keydown(KEY_UP)):
      player_y-=2
      selctor_moving=True
  if terrain_height<player_height:
    player_y-=1
    selctor_moving=True
  if keydown(KEY_LEFT):
    if formula((player_x/16)-1)>=player_y:
      player_x-=16
      selctor_moving=True
  if keydown(KEY_RIGHT):
    if formula((player_x/16)+1)>=player_y:
      player_x+=16
      selctor_moving=True
  draw_player()

def draw_player():
  fill_rect(round(-camera_x*16)+player_x+3,round(camera_y*16)-16+round(player_y*16)+3,9,9,PLAYER_HEAD_COLOR)
  set_pixel(round(-camera_x*16)+player_x+5,round(camera_y*16)-16+round(player_y*16)+5,(0,0,0))
  set_pixel(round(-camera_x*16)+player_x+9,round(camera_y*16)-16+round(player_y*16)+5,(0,0,0))
  fill_rect(round(-camera_x*16)+player_x+3,round(camera_y*16)-16+round(player_y*16)+13,9,16,PLAYER_BODY_COLOR)

def formula(x):
  val=-cos(x)+10*cos(0.1*(x+13))+20*cos(0.05*(x+29))+50*sin(0.013*(x+57))
  return val

def treeformula(x):
  val=20*sin(5*x) 
  return val

def tree(x,y):
  fill_rect(x*16+3,round(y*16)-32,10,32,TREE_COLOR)
  fill_rect(x*16-16,round(y*16)-64,48,48,GRASS_COLOR)
  


def selector(x,y):  
  global sec 
  global active
  if(active==1 or selctor_moving==True):
    fill_rect(x*16,y*16,2,16,(255,255,255))
    fill_rect(x*16,y*16,16,2,(255,255,255))
    fill_rect(x*16+16,y*16+16,-2,-16,(255,255,255))
    fill_rect(x*16+16,y*16+16,-16,-2,(255,255,255))
  
  if(monotonic()-sec>0.2):
    sec=monotonic()
    active*=-1
      
while True:
  selector_moving = False
  st=monotonic()
  day+=0.002
  if day>1:
    night=1
    GRASS_COLOR=orggrass
  if night>=1:
    day-=0.004
  if day <0.1:
    night=0
    day=0.1
  DIRT_COLOR=orgdirt
  GRASS_COLOR=orggrass
  SKY_COLOR=orgsky
  TREE_COLOR=orgtree
  GRASS_COLOR=(GRASS_COLOR[0]*day,GRASS_COLOR[1]*day,GRASS_COLOR[2]*day)
  DIRT_COLOR=(DIRT_COLOR[0]*day,DIRT_COLOR[1]*day,DIRT_COLOR[2]*day)
  SKY_COLOR=(SKY_COLOR[0]*day,SKY_COLOR[1]*day,SKY_COLOR[2]*day) 
  TREE_COLOR=(TREE_COLOR[0]*day,TREE_COLOR[1]*day,TREE_COLOR[2]*day)
  if player_x/16>camera_x+16:
    camera_x+=2
  if player_x/16<camera_x+4:
    camera_x-=2
  if (player_y+2)-((camera_y-5)*-1)>2:
    camera_y=5+(player_y+2)/-1
  elif (player_y+2)-((camera_y-5)*-1)<-2:
    camera_y=5+(player_y+2)/-1
  
  fill_rect(0, 0, 320, 240, SKY_COLOR)  # Clear the screen
  
  for x in range(20):
    y=round(formula(x+camera_x))+camera_y
    if treeformula(x+camera_x)>1:
      tree(x,y)
    
    fill_rect(x*16,round(y*16),16,3,GRASS_COLOR)
    fill_rect(x*16,round(y*16+3),16,round(14-y)*16,DIRT_COLOR)
  
  player_update()
  
  if(keydown(KEY_EIGHT)):
    selector_y-=1
    selctor_moving=True
  if(keydown(KEY_TWO)):
    selector_y+=1
    selctor_moving=True
  if(keydown(KEY_SIX)):
    selector_x+=1
    selctor_moving=True
  if(keydown(KEY_FOUR)):
    selector_x-=1
    selctor_moving=True
  
  selector(-camera_x+selector_x,round(camera_y)+selector_y)
  FPS=1/(monotonic()-st)
  draw_string("max: "+str(round(FPS))+" FPS",0,0)
  draw_string("current: "+str(round(real_fps))+" FPS",0,20)
   
  if monotonic()-st<1/target_FPS:
    if (1/target_FPS-(monotonic()-st)-0.005)>0:
        sleep((1/target_FPS-(monotonic()-st)-0.005))
  
  real_fps=1/(monotonic()-st)
  
  

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.