minecraft.py

Created by lex-kimmel

Created on October 14, 2023

1.34 KB

Minecraft game


from kandinsky import *
from ion import *
from time import sleep
from random import *
# Define colors for the grass block and details
GRASS_COLOR = (116,180,74)  # Green color
DIRT_COLOR = (124, 84, 60)   # Brown color
SKY_COLOR = (91,141,220)

# Create a function to draw a grass block
def draw_grass_block(x, y):
    # Draw the grass top
    for px in range(16):
        for py in range(3):
            set_pixel(x+px, y-py+2, (randint(-30,10)+GRASS_COLOR[0],randint(-30,10)+GRASS_COLOR[1],randint(-30,10)+GRASS_COLOR[2]))
    # Draw the grass bottom
    for px in range(16):
        for py in range(13):
            set_pixel(x+px, y-py+13+2, (randint(-20,20)+DIRT_COLOR[0],randint(-20,20)+DIRT_COLOR[1],randint(-10,10)+DIRT_COLOR[2]))
# Create a function to draw a dirt block
def draw_dirt_block(x, y):
    # Draw the dirt
    for px in range(16):
        for py in range(16):
            set_pixel(x+px, y-py+11+2, (randint(-20,20)+DIRT_COLOR[0],randint(-20,20)+DIRT_COLOR[1],randint(-10,10)+DIRT_COLOR[2]))

# Clear the screen


while True:
    # Draw a grass block at the current coordinates
    fill_rect(0, 0, 320, 240, SKY_COLOR)  # Clear the screen
    for x in range(20): 
        for y in range(6): 
            if y == 0:
                draw_grass_block(x*16, y*16+128)
            else:
                draw_dirt_block(x*16, y*16+128)
    

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.