예제 #1
0
perlin = generateBlockPositions(16, 32, 16)

# for z in range(8):
#     for x in range(8):
#         for y in range(1):
#             block = Block(position=(x,y,z), texture=grass_texture)

block_list = []
terrain = Entity()

for a in perlin:
    block = Block(position=(a[0], a[1], a[2]), parent=terrain)
    block_list.append(block)

terrain.combine()
player = FirstPersonController(gravity=0)
player.add_script(NoclipMode())


def update():
    player.y += held_keys['q'] * 1
    player.y -= held_keys['e'] * 1

    # cast = boxcast(player.world_position, thickness=(10,10), debug=True)
    # print(cast.entities)
    # for block in block_list:
    #    if block not in cast.entities:
    #        block.visible = False
    #    elif block in cast.entities:
    #        block.visible = True
예제 #2
0
app = Ursina()

random.seed(0)
Entity.default_shader = lit_with_shadows_shader

ground = Entity(model='plane',
                collider='box',
                scale=64,
                texture='grass',
                texture_scale=(4, 4))

editor_camera = EditorCamera(enabled=False, ignore_paused=True)
player = FirstPersonController(model='cube',
                               z=-10,
                               color=color.orange,
                               origin_y=-.5,
                               speed=8)
player.collider = BoxCollider(player, Vec3(0, 1, 0), Vec3(1, 2, 1))

gun = Entity(model='cube',
             parent=camera,
             position=(.5, -.25, .25),
             scale=(.3, .2, 1),
             origin_z=-.5,
             color=color.red,
             on_cooldown=False)
gun.muzzle_flash = Entity(parent=gun,
                          z=1,
                          world_scale=.5,
                          model='quad',
예제 #3
0
    # If block is destroyed, active hand animation is played
    if held_keys['left mouse']:
        hand.active()
    else:
        hand.passive()
    # If keys "1", "2", "3" or "4" are pressed, change between grass, stone, brick and dirt blocks
    if held_keys['1']: block_pick = 1  # Grass block
    if held_keys['2']: block_pick = 2  # Stone block
    if held_keys['3']: block_pick = 3  # Brick block
    if held_keys['4']: block_pick = 4  # Dirt block


# 5. 1st person view
from ursina.prefabs.first_person_controller import FirstPersonController
camera.fov = 85
player = FirstPersonController()  # Maps the player to the 1st person view

player_speed = player.x = 1


# 14. Sprinting
class Sprint(Entity):
    global player_speed
    if held_keys['ctrl', 'w'] or held_keys['w', 'ctrl']:
        player_speed = player_speed * 2


# 15. Inventory
class Lower_Inventory(Entity):
    def __init__(self, **kwargs):
        super().__init__(parent=camera.ui,
예제 #4
0

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(.9, 1.0)),
            highlight_color=color.lime,
        )

    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)


for z in range(30):
    for x in range(30):
        voxel = Voxel(position=(x, 0, z))

player = FirstPersonController(jump_duration=0.3, jump_height=1.2, speed=10)

app.run()
from ursina.prefabs.first_person_controller import FirstPersonController

# Create app
app = Ursina()

# Terrain
t = Entity(model=Terrain("heightmap-2692", skip=8),
           scale=(1024, 75, 1024),
           texture="colormap-2692")

t.collider = t.model

water = Entity(model=Plane(subdivisions=(6, 6)),
               collider="plane",
               color=rgb(184, 221, 247),
               scale=(1024, 1, 1024))
water.position = (0, 31, 0)

# Misc
player = FirstPersonController()
player.position = (0, 75, 0)

scene.fog_color = color.gray
scene.fog_density = .005
Sky()

# Run app
app.run()

# https://stackoverflow.com/questions/59867493/how-to-make-perlin-noise-color-gradient-generation-in-python-similar-to-the-nois
예제 #6
0
               scale=(1, 5, 10),
               x=2,
               y=.01,
               rotation_y=45,
               collider='box',
               texture='white_cube')
    e.texture_scale = (e.scale_z, e.scale_y)
    e = Entity(model='cube',
               scale=(1, 5, 10),
               x=-2,
               y=.01,
               collider='box',
               texture='white_cube')
    e.texture_scale = (e.scale_z, e.scale_y)

    player = FirstPersonController(model='cube', y=1, origin_y=-.5)
    player.gun = None

    gun = Button(parent=scene,
                 model='cube',
                 color=color.blue,
                 origin_y=-.5,
                 position=(3, 0, 3),
                 collider='box')
    gun.on_click = Sequence(Func(setattr, gun, 'parent', camera),
                            Func(setattr, player, 'gun', gun))

    gun_2 = duplicate(gun, z=7, x=8)
    slope = Entity(model='cube',
                   collider='box',
                   position=(0, 0, 8),
예제 #7
0
    #for z in range(0, height):
    #    for x in range(0, width):
    #        voxel = Voxel(position=(x,0,z))

    for y in range(size_wall):
        for i in range(0, height):
            for j in range(0, width):
                if y == 0:
                    voxel = Voxel(position=(i, y, j))
                elif (maze[i][j] == 'u'):
                    pass
                elif (maze[i][j] == 'c'):
                    pass
                else:
                    voxel = Voxel(position=(i, y, j))
    """
    for z in range(size_room):
        for x in range(size_room):
            for y in range(size_wall):
                if x ==0 or z==0 or x == size_room-1 or z==size_room-1: 
                    voxel = Voxel(position=(x,y,z))
                else:
                    voxel = Voxel(position=(x,0,z))
    """


CreateRoom()
player = FirstPersonController(position=(5, 0, 5))
#sky = Sky()
#hand = Hand()
app.run()
예제 #8
0
    def add(self):
        platform = Platform(self.x, self.y, self.z)

        # Changes the platforms location
        self.x = random.randint(-10 - self.x_delta, 10 + self.x_delta)
        self.y -= 10
        self.z += 50 + self.z_delta

        self.platforms.append(platform)
        # How much extra challenge is added, [0, 0, ..., 0, 1]
        # There is a low change the delta increases
        self.x_delta += random.choice([*[0] * 9, 1])
        self.z_delta += random.choice([*[0] * 9, 1])


if __name__ == "__main__":
    sky = urs.Sky()
    urs.scene.fog_density = 0.01

    platforms = Platforms()
    # Creates all the platforms
    [platforms.add() for _ in range(100)]
    # Colors the last one red
    platforms.platforms[-1].color = urs.color.hex("#cb2a2a")

    player = FirstPersonController()
    player.speed = 40

    app.run()
예제 #9
0
### This is a 3D platformer which randomly generates the number of platforms that you put in. ###

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
import random as rng

app=Ursina()

a=0

def plat(d,o):
    global a
    a+=d
    Entity(model='cube',color=color.cyan,position=(o,-50,a),collider='box',scale=(5,100,10),texture='vertical_gradient')

def randplat():
    plat(rng.randint(17,20),rng.randint(-5,5))

plat(0,0)

Entity(model='cube',color=color.black,position=(0,-50,0),collider='box',scale=(10000,1,10000),texture='circle')

numplat=input('# of platforms\n')

for i in range(1,int(numplat)):
    randplat()

player=FirstPersonController(speed=20)

app.run()
예제 #10
0
level.bow.parent = camera
level.bow.position = (.5, 0, 1)
level.bow.enabled = False
level.bow.shader = colored_lights_shader

level.gate.collider = 'box'
level.gate_001.collider = 'box'
level.gate_pattern.world_parent = level.gate
level.gate_pattern_001.world_parent = level.gate_001

level.eye_trigger.collider = 'box'
level.goat.collider = 'mesh'

from ursina.prefabs.first_person_controller import FirstPersonController
player = FirstPersonController(position=level.start_point.position, speed=10)
level.start_point.enabled = False

for e in level.children:
    if not 'terrain' in e.name:
        e.shader = colored_lights_shader

    if 'box_collider' in e.name:
        e.visible = False
        e.collider = 'box'

    if 'pebble' in e.name:
        e.position = raycast(e.position, Vec3(0, -1, 0)).world_point

    elif 'rock' in e.name:
        e.collider = 'box'
from ursina import *


app = Ursina()

e = Entity(model=Terrain('loddefjord_height_map', skip=8), texture='loddefjord_color', scale=100, scale_y=50)
Sky(rotation_y=125)

scene.fog_color = color.gray
scene.fog_density = .01

from ursina.prefabs.first_person_controller import FirstPersonController
fpc = FirstPersonController(speed=10)

window.exit_button.visible = False
window.fps_counter.enabled = False
mouse.visible = False



# from ursina .shaders import camera_vertical_blur_shader
# camera.shader = camera_vertical_blur_shader
# camera.set_shader_input('blur_size', .0)
#
# camera.blur_amount = 0
# def update():
#     camera.set_shader_input("blur_size", camera.blur_amount)
#
# t = Text('It was like a dream', enabled=False, scale=3, origin=(0,0), color=color.dark_text)
#
# def input(key):
예제 #12
0
            model = 'sphere',
            texture = sky_texture,
            scale = 230,
            double_sided = True)

class Hand(Entity):
    def __init__(self):
        super().__init__(
            parent = camera.ui,
            model = 'assets/arm',
            texture = arm_texture,
            scale = 0.2,
            rotation = Vec3(150,-10,0),
            position = Vec2(0.4,-0.7))

    def active(self):
        self.position = Vec2(0.3,-0.6)

    def passive(self):
        self.position = Vec2(0.4,-0.7)

for z in range(80):
    for x in range(80):
        voxel = Voxel(position = (x, 0, z))

player = FirstPersonController(jump_height = 0.07, jump_duration = 0.2, color = color.white33)
sky = Sky()
hand = Hand()

app.run()
예제 #13
0
level.bow.position = (.5,0,1)
level.bow.enabled = False
level.bow.shader = colored_lights_shader

level.gate.collider = 'box'
level.gate_001.collider = 'box'
level.gate_pattern.world_parent = level.gate
level.gate_pattern_001.world_parent = level.gate_001

level.eye_trigger.collider = 'box'
level.goat.collider = 'mesh'



from ursina.prefabs.first_person_controller import FirstPersonController
player = FirstPersonController(position=level.start_point.position, speed=10)
level.start_point.enabled = False


for e in level.children:
    if not 'terrain' in e.name:
        e.shader = colored_lights_shader

    if 'box_collider' in e.name:
        e.visible = False
        e.collider = 'box'

    if 'pebble' in e.name:
        e.position = raycast(e.position, Vec3(0,-1,0)).world_point

    elif 'rock' in e.name:
        window.fullscreen_size = resolution
        window.windowed_size = resolution
        if len(argv) > 2:
            window.fullscreen = int(argv[2])

    except exception as e:
        print(
            f'correct usage is ``logic.py height fullscreen`` height should be in pixels, 1 for fullscreen, 0 for windowed')


window.vsync = True

scene.fog_color = COLOR_RUST
scene.fog_density = (10, 60)

player = FirstPersonController(gravity=0)
camera.position = Vec3(0, 1, -20)
camera.rotation = Vec3(15, 0, 0)
player.cursor.enabled = False

walls = make_walls(450)
floor = make_floor(9, 60)


lower_floor = Entity(model='cube', color=COLOR_RUST,  position=(0, -2, 0),
                     scale=(10000, 1, 10000),
                     rotation=(0, 0, 0)
                     )

siren_light = Lighting(player, player.position + Vec3(1, 7, 0), color.black, rotation=player.down)
CheckPoint.init_light(Entity('cube', color=color.rgba(255,5,5,128), scale=(25,25,25)))
예제 #15
0
from ursina import *

app = Ursina()

# Make a simple game so we have something to test with
from ursina.prefabs.first_person_controller import FirstPersonController
player = FirstPersonController(gravity=0, model='cube', color=color.azure)
camera.z = -10
ground = Entity(model='plane', texture='grass', scale=10)

# Create an Entity for handling pausing an unpausing.
# Make sure to set ignore_paused to True so the pause handler itself can still receive input while the game is paused.
pause_handler = Entity(ignore_paused=True)
pause_text = Text(
    'PAUSED', origin=(0, 0), scale=2, enabled=False
)  # Make a Text saying "PAUSED" just to make it clear when it's paused.


def pause_handler_input(key):
    if key == 'escape':
        application.paused = not application.paused  # Pause/unpause the game.
        pause_text.enabled = application.paused  # Also toggle "PAUSED" graphic.


pause_handler.input = pause_handler_input  # Assign the input function to the pause handler.

app.run()
예제 #16
0
    radius = 2.6
    jupiter.x = np.cos(t + angle*4) * radius*2
    jupiter.z = np.sin(t + angle*4) * radius*2
    radius = 3
    saturn.x = np.cos(t + angle*5) * radius*2
    saturn.z = np.sin(t + angle*5) * radius*2
    radius = 3.4
    uranus.x = np.cos(t + angle*6) * radius*2
    uranus.z = np.sin(t + angle*6) * radius*2
    radius = 3.8
    neptune.x = np.cos(t + angle*7) * radius*2
    neptune.z = np.sin(t + angle*7) * radius*2
    print(held_keys)
    if held_keys['up arrow']:
        player.y += 0.05
    if held_keys['down arrow']:
        player.y -= 0.05
app = Ursina()
sun = Entity(model='sphere', color = color.yellow, scale=2)
mercury = Entity(model='sphere', color = color.gray, scale=0.2)
venus = Entity(model='sphere', color = color.orange, scale=0.3)
earth = Entity(model='sphere', color = color.blue, scale=0.4)
mars = Entity(model='sphere', color = color.red, scale=0.25)
jupiter = Entity(model='sphere', color = color.white, scale=0.9)
saturn = Entity(model='sphere', color = color.light_gray, scale=0.8)
uranus = Entity(model='sphere', color = color.blue, scale=0.7)
neptune = Entity(model='sphere', color = color.black, scale=0.7)
t = -np.pi
player = FirstPersonController()
player.gravity = 0
app.run()
        self.air_time = 0
        self.grounded = True


if __name__ == '__main__':
    from ursina.prefabs.first_person_controller import FirstPersonController
    # window.vsync = False
    app = Ursina()
    Sky(color=color.gray)
    ground = Entity(model='plane', scale=(100,1,100), color=color.yellow.tint(-.2), texture='white_cube', texture_scale=(100,100), collider='box')
    e = Entity(model='cube', scale=(1,5,10), x=2, y=.01, rotation_y=45, collider='box', texture='white_cube')
    e.texture_scale = (e.scale_z, e.scale_y)
    e = Entity(model='cube', scale=(1,5,10), x=-2, y=.01, collider='box', texture='white_cube')
    e.texture_scale = (e.scale_z, e.scale_y)

    player = FirstPersonController(y=1)
    # camera.z = -10
    player.gun = None

    gun = Button(parent=scene, model='cube', color=color.blue, origin_y=-.5, position=(3,0,3), collider='box')
    gun.on_click = Sequence(Func(setattr, gun, 'parent', camera), Func(setattr, player, 'gun', gun))

    gun_2 = duplicate(gun, z=7, x=8)
    slope = Entity(model='cube', collider='box', position=(0,0,8), scale=6, rotation=(45,0,0), texture='brick', texture_scale=(8,8))
    slope = Entity(model='cube', collider='box', position=(5,0,10), scale=6, rotation=(80,0,0), texture='brick', texture_scale=(8,8))
    # hill = Entity(model='sphere', position=(20,-10,10), scale=(25,25,25), collider='sphere', color=color.green)
    hill = Entity(model='sphere', position=(20,-0,10), scale=(25,25,25), collider='mesh', color=color.green)
    from ursina.shaders import basic_lighting_shader
    for e in scene.entities:
        e.shader = basic_lighting_shader
예제 #18
0
	# 		  model=model,
	# 		  texture=textureGrass,
	# 		  nameBlock='grass')
	# if y == size_y - 1:
	# 	[Block(model='cube', position=(x, i, y + 1), colorB=color.rgba(0, 0, 0, 0)) for i in range(heightOfTransparentBlocks)]
	# elif y == 0:
	# 	[Block(model='cube', position=(x, i, y - 1), colorB=color.rgba(0, 0, 0, 0)) for i in range(heightOfTransparentBlocks)]
	# if x == size_x - 1:
	# 	[Block(model='cube', position=(x + 1, i, y), colorB=color.rgba(0, 0, 0, 0)) for i in range(heightOfTransparentBlocks)]
	# elif x == 0:
	# 	[Block(model='cube', position=(x - 1, i, y), colorB=color.rgba(0, 0, 0, 0)) for i in range(heightOfTransparentBlocks)]

	inv = Inventory()
	inv.fillInv(order_blocks, textureListInv)

	player = FirstPersonController()
	cursorTexture = load_texture('data/texture/cursor.png')
	destroy(player.cursor)
	player.cursor = Entity(parent=camera.ui, model='quad', scale=.03, texture=cursorTexture,
						   position_z=-0.01)
	player.position = (5, 0, 5)
	player.mouse_sensitivity = Vec2(50, 50)
	player.jump_duration = 0.25
	player.jump_height = 1.5

	file = listMap[0]  # стандартная карта
	loadMapFromFile(file)

	hand = Hand()
	sky = Sky()
	fileName = 'data/map/' + genWorldName()
예제 #19
0
    e.model.colorize()

    from ursina.prefabs.first_person_controller import FirstPersonController

    ground = Entity(model='plane',
                    scale=32,
                    texture='white_cube',
                    texture_scale=(32, 32),
                    collider='box')
    box = Entity(model='cube',
                 collider='box',
                 texture='white_cube',
                 scale=(10, 2, 2),
                 position=(2, 1, 5),
                 color=color.light_gray)
    player = FirstPersonController(y=1, enabled=True)

    ec = EditorCamera(rotation_smoothing=3)
    ec.enabled = False
    rotation_info = Text(position=window.top_left)

    def update():
        rotation_info.text = str(int(ec.rotation_y)) + '\n' + str(
            int(ec.rotation_x))

    def input(key):
        if key == 'tab':  # press tab to toggle edit/play mode
            ec.enabled = not ec.enabled
            player.enabled = not player.enabled

    app.run()
예제 #20
0
def 第1人稱視角():
    if not common.is_engine_created:
        Engine3D()

    common.stage.editor_camera.enabled = False
    common.player = FirstPersonController()
예제 #21
0
    return ls


postavlenye_bloku = []

asas = 5
aaa = '12121'
obg = []
ls = do_ls()
for i in range(len(ls)):
    for j in range(len(ls[i])):
        random.shuffle(ls[i][j])
punch_sound = Audio('assets/stone3', loop=False, autoplay=False)
Light(tupe='ambient', color=(0.5, 0.5, 0.5, 1))
Light(tupe='directional', color=(0.5, 0.5, 0.5, 1), direction=(1, 1, 1))
player = FirstPersonController(y=20)
b = 1
cnt = 0
sky_texture = load_texture('assets/skybox.png')
arm_texture = load_texture('assets/arm_texture.png')
window.fps_counter.enabled = False
window.exit_button.visible = False
# window.fullscreen = True


def update():
    global b, cnt, asas
    for q in obg:
        q.rotation_y += 16
    if held_keys['left mouse'] or held_keys['right mouse']:
        hand.active()
예제 #22
0
    global Monsters, run_monster
    new = Animation(
        'assets//tentakelding',
        collider='box',
        position=(-11, 2, 20),
        scale=(1.3, 0.8),
    )
    Monsters.append(new)
    if run_monster:
        invoke(new_monster, delay=random.uniform(1, 3))


app = Ursina()
Sky()

player = FirstPersonController(y=2, origin_y=-.5)
ground = Entity(model='plane',
                scale=(100, 1, 100),
                color=color.lime,
                texture="white_cube",
                texture_scale=(100, 100),
                collider='box')

wall_1 = Entity(model="cube",
                collider="box",
                position=(-8, 0, 20),
                scale=(.5, 8, 30),
                rotation=(0, 0, 0),
                texture="brick",
                texture_scale=(5, 5),
                color=color.rgb(255, 128, 0))