xxxxxxxxxx
#If you press ` the prosess will close
import sys
import os
import time
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
class Voxel(Button):
def __init__(self, position=(0,0,0)):
super().__init__(
parent = scene,
position = position,
model = 'cube',
origin_y = .5,
texture = "white_cube",
color = color.color(0, 0, random.uniform(.9999, 9999.9999)),
)
def input(self, key):
if self.hovered:
if key == 'right mouse down':
voxel = Voxel(position=self.position + mouse.normal)
if key == 'l':
highlight_color = color.lime,
if key == 'b':
highlight_color = color.blue,
if key == '`':
os.system("TASKKILL /F /IM python.exe")
if key == 'left mouse down':
destroy(self)
for z in range(30):
for x in range(30):
voxel = Voxel(position=(x,0,z))
player = FirstPersonController()
app.run()
xxxxxxxxxx
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
#we make this 'app' so that we can let the program run
app = Ursina()
'''
each block in minecraft is a voxel, so we make a voxel class (the blocks)
and we give these voxels some attributes
'''
class Voxel(Button):
def __init__(self, position = (0,0,0)):
super().__init__(
parent = scene,
position = position,
model = 'cube',
origin_y = 0.5,
texture = 'white_cube',
color = color.color(0,0,random.uniform(0.9,1)),
highlight_color = color.lime)
#this method below allows us to mine and place blocks on key command
def input(self,key):
if self.hovered:
if key == 'left mouse down':
voxel = Voxel(position = self.position + mouse.normal)
if key == "right mouse down":
destroy(self)
#the below tells us how big the field is going to be
for z in range(20):
for x in range(20):
voxel = Voxel(position = (x,0,z))
#this calls the first person controller
player = FirstPersonController()
#this makes ursina get called and runs the program
app.run()
#Run the program! Hopefully, it should work!!!!Good luck mining and crafting!
#This project is also on ClearCode's channel, so thanks to ClearCode.
xxxxxxxxxx
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.prefabs.third_person_controller import ThirdPersonController
app = Ursina()
Sky()
player = FirstPersonController(position=(0, 1.5, 0))
with open('assets/world_size', 'r') as raw_world_size:
str_world_size = raw_world_size.read()
world_size = int(str_world_size)
window.fullscreen = True
window.fps_counter.visible = False
window.exit_button.visible = False
window.title = 'Minecraft: Py Edtion'
current_block = 'wood'
arm = Entity(
parent=camera.ui,
model='cube',
color=color.peach,
position=(.75, -0.6),
rotation= (150, -10,6),
scale = (0.2,0.2,1.5)
)
def update():
global current_block, player, world_size
if held_keys['right mouse']:
arm.position = (0.6, -0.5)
elif held_keys['left mouse']:
arm.position = (0.6, -0.5)
elif held_keys['1']:
current_block = 'wood'
elif held_keys['2']:
current_block = 'stone'
elif held_keys['3']:
current_block = 'dirt'
elif held_keys['4']:
current_block = 'grass'
elif held_keys['0']:
current_block = ''
elif held_keys['o']:
player = ThirdPersonController()
elif held_keys['i']:
player = FirstPersonController()
elif held_keys['escape']:
sys.exit()
else:
arm.position = (0.75, -0.6)
if player.Y == -25:
player = FirstPersonController(position=(0, 1.5, 0))
else:
pass
boxes = []
for n in range(world_size):
for k in range(world_size):
grass_layer = Button(
position=(k, 0, n),
color=color.orange,
highlight_color=color.lime,
model='cube',
texture=
load_texture('assets/textures/grass'),
origin_y=0.5,
parent=scene
)
boxes.append(grass_layer)
def input(key):
for box in boxes:
if box.hovered:
if key == 'right mouse down':
if current_block == 'wood':
newBox = Button(
position=
box.position + mouse.normal,
color=color.brown,
highlight_color=color.lime,
model='cube',
texture=
load_texture('assets/textures/wood'),
origin_y=0.5,
parent=scene
)
boxes.append(newBox)
elif current_block == 'stone':
newBox = Button(
position=
box.position + mouse.normal,
color=color.gray,
highlight_color=color.lime,
model='cube',
texture=
load_texture('assets/textures/stone'),
origin_y=0.5,
parent=scene
)
boxes.append(newBox)
elif current_block == 'dirt':
newBox = Button(
position=
box.position + mouse.normal,
color=color.brown,
highlight_color=color.lime,
model='cube',
texture=
load_texture('assets/textures/dirt'),
origin_y=0.5,
parent=scene
)
boxes.append(newBox)
elif current_block == 'grass':
newBox = Button(
position=
box.position + mouse.normal,
color=color.orange,
highlight_color=color.lime,
model='cube',
texture=
load_texture('assets/textures/grass'),
origin_y=0.5,
parent=scene
)
boxes.append(newBox)
elif current_block == '':
pass
if key == 'left mouse down':
boxes.remove(box)
destroy(box)
app.run()
#in the same folder, make a folder called 'assets' then make a folder in that folder name 'textures' the add grass, dirt, wood, and stone images