def __init__(self, resolution=4, radius=.5, height=1, add_bottom=True, mode='triangle', **kwargs): v = Vec3(radius, 0, 0) origin = Vec3(0, 0, 0) degrees_to_rotate = 360 / resolution verts = [] for i in range(resolution): verts.append(Vec3(v[0], 0, v[1])) v = rotate_point_2d(v, origin, -degrees_to_rotate) verts.append(Vec3(v[0], 0, v[1])) verts.append(Vec3(0, height, 0)) if add_bottom: for i in range(resolution): verts.append(Vec3(v[0], 0, v[1])) verts.append(Vec3(0, 0, 0)) v = rotate_point_2d(v, origin, -degrees_to_rotate) verts.append(Vec3(v[0], 0, v[1])) super().__init__(vertices=verts, uvs=[e.xy for e in verts], mode=mode, **kwargs)
def __init__(self, world: BulletWorld, entity: Entity, radius=1, height=2, name='Player', **opts) -> None: super().__init__(BulletCapsuleShape(radius / 2, height / 2, 1), radius / 2, name) self.np = application.base.render.attachNewNode(self) if entity.parent: self.np.reparent_to(entity.parent) rotation = Vec3(0, 0, 0) if None in rotation: hpr = entity.getHpr() for x in range(len(hpr)): rotation[x] = hpr[x] self.np.setHpr(rotation) self.np.setPos(entity.x, entity.y, entity.z) entity.reparent_to(self.np) world.attachCharacter(self) self.__fall_speed = None self.__jump_speed = None self.__max_jump_height = None for x in opts: setattr(self, x, opts[x])
def __init__(self, world: BulletWorld, entity: Entity, mass=0, rotation=[None, None, None]) -> None: super().__init__(world, entity, BulletPlaneShape(Vec3(0, 1, 0), 0), 'plane', rotation, mass)
def on_mouse_exit(self): if not self.disabled and self.model: self.model.setColorScale(self.color) if not mouse.left and self.highlight_scale != 1: self.model.setScale(Vec3(1, 1, 1)) if hasattr(self, 'tooltip'): self.tooltip.enabled = False
def input(self, key): if self.disabled or not self.model: return if key == 'left mouse down': if self.hovered: self.model.setColorScale(self.pressed_color) self.model.setScale( Vec3(self.pressed_scale, self.pressed_scale, 1)) if key == 'left mouse up': if self.hovered: self.model.setColorScale(self.highlight_color) self.model.setScale( Vec3(self.highlight_scale, self.highlight_scale, 1)) else: self.model.setColorScale(self.color) self.model.setScale(Vec3(1, 1, 1))
def __init__( self, world:BulletWorld, entity:Entity, rotation=[None, None, None], scale=[None, None, None] ) -> None: if None in scale: for x in range(len(entity.scale)): scale[x] = entity.scale[x]/2 super().__init__(world, entity, BulletBoxShape(Vec3(*scale)), 'box', rotation)
def move(self, direction): self.direction = direction if self.is_head: self.follower.rotation = ( (self.direction[1] * (self.direction[1] + 1) - self.direction[0]) * 90, 90, 90) # is reached boundaries if direction[0] == -1 and self.position[0] <= 0: self.position = Vec3(MAP_SIZE_X - 1, self.position[1], self.position[2]) elif direction[1] == -1 and self.position[1] <= 0: self.position = Vec3(self.position[0], MAP_SIZE_Y - 1, self.position[2]) elif direction[0] == 1 and self.position[0] >= MAP_SIZE_X - 1: self.position = Vec3(0, self.position[1], self.position[2]) elif direction[1] == 1 and self.position[1] >= MAP_SIZE_Y - 1: self.position = Vec3(self.position[0], 0, self.position[2]) else: self.position = self.position + direction
def on_mouse_enter(self): if not self.disabled and self.model: self.model.setColorScale(self.highlight_color) if self.highlight_scale != 1: self.model.setScale( Vec3(self.highlight_scale, self.highlight_scale, 1)) if hasattr(self, 'tooltip'): self.tooltip.scale = (0, 0, 0) self.tooltip.enabled = True if not hasattr(self.tooltip, 'original_scale'): self.tooltip.original_scale = 1 self.tooltip.animate_scale(self.tooltip.original_scale)
def __init__(self, world:BulletWorld, entity:Entity, shape, name, rotation): super().__init__(name) self.addShape(shape) self.np = application.base.render.attachNewNode(self) world.attachGhost(self) if entity.parent: self.np.reparent_to(entity.parent) if None in rotation: hpr = entity.getHpr() for x in range(len(hpr)): rotation[x] = hpr[x] self.np.setHpr(Vec3(*rotation)) self.np.setPos(entity.x, entity.y, entity.z) entity.reparent_to(self.np)
def __init__(self, **kwargs): super().__init__(**kwargs) self.phoneme_store = None self.voxels = [] self.correct = False self.started = False self.update_counter = None self.score = 0 self.difficulty = 3 # lower difficulty is harder self.help_text = Text( '', parent=camera.ui, x=-.6, y=.35, enabled=False ) self.score_text = Text( '', parent=camera.ui, x=.5, y=.35, enabled=False ) self.player = None self.ground = Entity(model='plane', scale=(100, 1, 100), y=-1, color=color.yellow.tint(-.2), texture='white_cube', texture_scale=(100, 100), collider='box', enabled=False) self.sky = Entity(model='sphere', texture='sky2.jpg', scale=10000, double_sided=True, color=color.white, enabled=False) self.rotated_y = 30 self.next_block = Entity(parent=camera.ui, rotation=Vec3(10, 30, 30), model='cube', scale=.1, x=.7, y=.2, texture='index') self.give_up_button = Button(parent=scene, text='give up', double_sided=True, x=-1, z=ARENA_DEPTH, y=3, on_click=self.give_up, enabled=False, scale_x=2) self.reset_text = Text( 'Press ESC to change words and/or start again.', parent=scene, x=0, z=ARENA_DEPTH, y=2, double_sided=True, enabled=False, scale=15 )
def __init__(self, title='', content=[], **kwargs): super().__init__(origin=(-0,.5), scale=(.5, Text.size*2), color=color.black) self.content = content self.text = title self.popup = False self._prev_input_field = None self._original_scale = self.scale for key, value in kwargs.items(): setattr(self, key ,value) if self.text_entity: self.text_entity.world_scale_y = 1 self.panel = Entity(parent=self, model='quad', origin=(0,.5), z=.1, color=self.color.tint(.1), collider='box') if self.popup: self.lock = Vec3(1,1,1) self.bg = Button(parent=self, z=1, scale=(999, 999), color=color.black66, highlight_color=color.black66, pressed_color=color.black66) self.bg.on_click = self.close self.layout()
def create_clouds(self): self.sky.enable() for i in range(20): cloud = Entity(parent=scene, model='cube', texture='index', scale_x=random.randint(2, ARENA_DEPTH), scale_y=random.randint(1, 6), scale_z=random.randint(2, ARENA_DEPTH), color=color.white, position=Vec3(random.randint(-50, ARENA_DEPTH+50), random.randint(10, 50), random.randint(-50, ARENA_DEPTH+50))) self.voxels.append(cloud)
uniform vec4 p3d_ColorScale; in vec2 texcoords; out vec4 fragColor; void main() { vec4 color = texture(p3d_Texture0, texcoords) * p3d_ColorScale; fragColor = color.rgba; } ''', default_input={ 'texture_scale' : Vec2(1,1), 'texture_offset' : Vec2(0.0, 0.0), 'position_offsets' : [Vec3(i,0,0) for i in range(256)], 'rotation_offsets' : [Vec4(0) for i in range(256)], 'scale_multipliers' : [Vec3(1) for i in range(256)], } ) if __name__ == '__main__': from ursina import Ursina, Entity, EditorCamera, Vec3, color, application, time, Cone import random app = Ursina(vsync=False) instances = [] Entity(model='plane', texture='grass', scale=128) application.asset_folder = application.asset_folder.parent.parent
def spin_block(self): self.rotated_y -= 1 self.next_block.rotation = Vec3(10, self.rotated_y, 30)
def random_position(self): self.position = Vec3(randrange(MAP_SIZE_X), randrange(MAP_SIZE_Y), 0)
def update(self): self.position = Vec3(mouse.x, mouse.y, -100)
import random import threading import time from ursina import held_keys, Vec3, Wait, destroy, color from .CONFIGS import SNAKE_COLOR, SNAKE_DT, KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_PAUSE, SNAKE_TAIL_COLOR, \ SNAKE_POS0, EYE_COLOR from .block import Block KEYS = [KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN] DIRECTIONS = { KEY_LEFT: Vec3(-1, 0, 0), KEY_RIGHT: Vec3(1, 0, 0), KEY_DOWN: Vec3(0, -1, 0), KEY_UP: Vec3(0, 1, 0) } class Snake(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.new(SNAKE_POS0) self.daemon = True # close thread correctly!!! def new(self, position): self.turns = {} self.rnd_direction() self.head = Block(is_head=True,
def rnd_direction(self): if random.choice([0, 1]) == 0: self.direction = Vec3(0, random.choice([-1, 1]), 0) else: self.direction = Vec3(random.choice([-1, 1]), 0, 0)
def LoadSystem(): Sun = Object(mass=1.989e30, radius=695508e3, lineColor=color.white, model="Assets/Sphere.obj", texture="Assets/Sun-map") Sun._position = [[0.0, 0.0, 0.0]] Sun.scale = 1 Sun.static = True Mercury = Object(mass=330e21, radius=2439.4e3, lineColor=color.light_gray, model="Assets/Sphere.obj", texture="Assets/Mercury-map") Mercury.position = Vec3(20, 0, 0) Mercury.scale = Mercury.radius / Sun.radius * 100 Mercury._maxPoint = 80 Venus = Object(mass=4.867e24, radius=6052e3, lineColor=color.lime, model="Assets/Sphere.obj", texture="Assets/Venus-map") Venus.position = Vec3(30, 0, 0) Venus.scale = Venus.radius / Sun.radius * 100 Venus._maxPoint = 215 Earth = Object(mass=5.972e24, radius=6371e3, lineColor=color.blue, model="Assets/Sphere.obj", texture="Assets/Earth-map") Earth.position = Vec3(40, 0, 0) Earth.scale = Earth.radius / Sun.radius * 100 Earth._maxPoint = 366 Mars = Object(mass=641.71e21, radius=3389e3, lineColor=color.orange, model="Assets/Sphere.obj", texture="Assets/Mars-map") Mars.position = Vec3(50, 0, 0) Mars.scale = Mars.radius / Sun.radius * 100 Mars._maxPoint = 666 # the devil ? Jupiter = Object(mass=1.898e27, radius=69911e3, lineColor=color.yellow, model="Assets/Sphere.obj", texture="Assets/Jupiter-map") Jupiter.position = Vec3(60, 0, 0) Jupiter.scale = Jupiter.radius / Sun.radius * 100 Jupiter._maxPoint = 6000 Saturn = Object(mass=5.683e26, radius=58232e3, lineColor=color.yellow, model="Assets/Sphere.obj", texture="Assets/Saturn-map") Saturn.position = Vec3(70, 0, 0) Saturn.scale = Saturn.radius / Sun.radius * 100 Saturn._maxPoint = 6666 Uranus = Object(mass=8.681e25, radius=25362e3, lineColor=color.azure, model="Assets/Sphere.obj", texture="Assets/Uranus-map") Uranus.position = Vec3(80, 0, 0) Uranus.scale = Uranus.radius / Sun.radius * 100 Uranus._maxPoint = 66666 Neptune = Object(mass=1.024e26, radius=24622e3, lineColor=color.magenta, model="Assets/Sphere.obj", texture="Assets/Neptune-map") Neptune.position = Vec3(90, 0, 0) Neptune.scale = Neptune.radius / Sun.radius * 100 Neptune._maxPoint = 666666 # Km/s to m/s Mercury._position = [[ -1.004302793346122E+07 * 1000, -6.782848247285485E+07 * 1000, -4.760889633162629E+06 * 1000 ]] Mercury._velocity = [[ 3.847265155592926E+01 * 1000, -4.158689546981208E+00 * 1000, -3.869763647804497E+00 * 1000 ]] Venus._position = [[ 1.076209595805564E+08 * 1000, 8.974122818036491E+06 * 1000, -6.131976661929069E+06 * 1000 ]] Venus._velocity = [[ -2.693485084259549E+00 * 1000, 3.476650462014290E+01 * 1000, 6.320912271467272E-01 * 1000 ]] Earth._position = [[ -2.545323708273825E+07 * 1000, 1.460913442868109E+08 * 1000, -2.726527903765440E+03 * 1000 ]] Earth._velocity = [[ -2.986338200235307E+01 * 1000, -5.165822246700293E+00 * 1000, 1.135526860257752E-03 * 1000 ]] Mars._position = [[ -1.980535522170065E+08 * 1000, -1.313944334060654E+08 * 1000, 2.072245594990239E+06 * 1000 ]] Mars._velocity = [[ 1.439273929359666E+01 * 1000, -1.805004074289640E+01 * 1000, -7.312485979614864E-01 * 1000 ]] Jupiter._position = [[ 7.814210740177372E+07 * 1000, -7.769489405106664E+08 * 1000, 1.474081608655989E+06 * 1000 ]] Jupiter._velocity = [[ 1.283931035365873E+01 * 1000, 1.930357075733133E+00 * 1000, -2.952599466798547E-01 * 1000 ]] Saturn._position = [[ 5.674914809473343E+08 * 1000, -1.388366463018738E+09 * 1000, 1.549265783457875E+06 * 1000 ]] Saturn._velocity = [[ 8.406493531200095E+00 * 1000, 3.627774839464044E+00 * 1000, -3.983651341797232E-01 * 1000 ]] Uranus._position = [[ 2.426731532276310E+09 * 1000, 1.703392504032894E+09 * 1000, -2.511215084173620E+07 * 1000 ]] Uranus._velocity = [[ -3.962351584219718E+00 * 1000, 5.256523421272158E+00 * 1000, 7.095167477538000E-02 * 1000 ]] Neptune._position = [[ 4.374094274093674E+09 * 1000, -9.514049067425712E+08 * 1000, -8.121317847458720E+07 * 1000 ]] Neptune._velocity = [[ 1.118822506695780E+00 * 1000, 5.342644352002246E+00 * 1000, -1.362606261073369E-01 * 1000 ]] return [Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Sun]