Add files via upload
This commit is contained in:
parent
5ea263bfcb
commit
ce725f7531
BIN
crosshair.png
Normal file
BIN
crosshair.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 266 B |
7
default_env.tres
Normal file
7
default_env.tres
Normal file
@ -0,0 +1,7 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
60
game.gd
Normal file
60
game.gd
Normal file
@ -0,0 +1,60 @@
|
||||
extends Spatial
|
||||
|
||||
var noise = OpenSimplexNoise.new()
|
||||
var rnd = RandomNumberGenerator.new()
|
||||
var nodes = {}
|
||||
var player_pos = Vector3()
|
||||
var block_instance = load("res://block.tscn")
|
||||
|
||||
var player
|
||||
var time = 0
|
||||
var map
|
||||
var map_x = 1000
|
||||
var map_z = 1000
|
||||
var map_y = 10
|
||||
var rad = 10
|
||||
|
||||
func _ready():
|
||||
OS.window_position = Vector2(0,0)
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
player = load("res://player.tscn").instance()
|
||||
add_child(player)
|
||||
player.transform.origin.y = map_y+1
|
||||
|
||||
map = get_node("map")
|
||||
|
||||
noise.seed = rnd.randi()
|
||||
# noise.octaves = 1
|
||||
# noise.period = 40
|
||||
# noise.persistence = 2
|
||||
func _process(delta):
|
||||
player_pos = player.transform.origin
|
||||
time += delta
|
||||
if time > 0.01:
|
||||
time = 0
|
||||
for x in range(player_pos.x-rad,player_pos.x+rad):
|
||||
for y in range(player_pos.y-rad,player_pos.y+rad):
|
||||
for z in range(player_pos.z-rad,player_pos.z+rad):
|
||||
var a = noise.get_noise_3d(x,y,z) * 10
|
||||
if a >= 0.1 and a <= 3:
|
||||
var v = Vector3(x,y,z)
|
||||
if nodes.get(v) == null:
|
||||
if (x > -map_x and x < map_x) and (z > -map_z and z < map_z) and (y > 0 and y < map_y):
|
||||
add_node(v)
|
||||
var V = Vector3(x,0,z)
|
||||
if nodes.get(V) == null:
|
||||
add_node(V)
|
||||
|
||||
func add_node(pos):
|
||||
if nodes.get(pos) == null:
|
||||
#var b = block_instance.instance()
|
||||
#b.transform.origin = pos
|
||||
#add_child(b)
|
||||
nodes[pos] = true#b
|
||||
map.set_cell_item(pos.x,pos.y,pos.z,0)
|
||||
func remove_node(pos):
|
||||
map.set_cell_item(pos.x,pos.y,pos.z,-1)
|
||||
# if nodes.get(pos):
|
||||
# nodes[pos].queue_free()
|
||||
# map.set_cell_item(pos.x,pos.y,pos.z,-1)
|
||||
# nodes.erase(pos)
|
28
game.tscn
Normal file
28
game.tscn
Normal file
@ -0,0 +1,28 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://game.gd" type="Script" id=1]
|
||||
[ext_resource path="res://nodes.meshlib" type="MeshLibrary" id=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[sub_resource type="Environment" id=2]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
background_energy = 1.5
|
||||
fog_enabled = true
|
||||
|
||||
[node name="game" type="Spatial"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="map" type="GridMap" parent="."]
|
||||
mesh_library = ExtResource( 2 )
|
||||
cell_size = Vector3( 1, 1, 1 )
|
||||
data = {
|
||||
"cells": PoolIntArray( )
|
||||
}
|
||||
__meta__ = {
|
||||
"_editor_clip_": 0
|
||||
}
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource( 2 )
|
3
main.tscn
Normal file
3
main.tscn
Normal file
@ -0,0 +1,3 @@
|
||||
[gd_scene format=2]
|
||||
|
||||
[node name="main" type="Spatial"]
|
17
mesh_lib.tscn
Normal file
17
mesh_lib.tscn
Normal file
@ -0,0 +1,17 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://models/mesh.obj" type="ArrayMesh" id=2]
|
||||
|
||||
[sub_resource type="BoxShape" id=3]
|
||||
|
||||
[node name="Spatial" type="Spatial"]
|
||||
|
||||
[node name="grass" type="MeshInstance" parent="."]
|
||||
mesh = ExtResource( 2 )
|
||||
material/0 = null
|
||||
|
||||
[node name="StaticBody" type="StaticBody" parent="grass"]
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="grass/StaticBody"]
|
||||
transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0 )
|
||||
shape = SubResource( 3 )
|
BIN
models/Material.material
Normal file
BIN
models/Material.material
Normal file
Binary file not shown.
BIN
models/grass2.png
Normal file
BIN
models/grass2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
BIN
models/mesh.blend
Normal file
BIN
models/mesh.blend
Normal file
Binary file not shown.
13
models/mesh.mtl
Normal file
13
models/mesh.mtl
Normal file
@ -0,0 +1,13 @@
|
||||
# Blender MTL File: 'block.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd grass2.png
|
48
models/mesh.obj
Normal file
48
models/mesh.obj
Normal file
@ -0,0 +1,48 @@
|
||||
# Blender v2.81 (sub 16) OBJ File: 'block.blend'
|
||||
# www.blender.org
|
||||
mtllib mesh.mtl
|
||||
o Cube.001_Cube
|
||||
v -0.500000 -0.500000 0.500000
|
||||
v -0.500000 0.500000 0.500000
|
||||
v -0.500000 -0.500000 -0.500000
|
||||
v -0.500000 0.500000 -0.500000
|
||||
v 0.500000 -0.500000 0.500000
|
||||
v 0.500000 0.500000 0.500000
|
||||
v 0.500000 -0.500000 -0.500000
|
||||
v 0.500000 0.500000 -0.500000
|
||||
vt 1.000000 0.333333
|
||||
vt 1.000000 0.666667
|
||||
vt -0.000000 0.666667
|
||||
vt -0.000000 0.333333
|
||||
vt 1.000000 0.333333
|
||||
vt 1.000000 0.666667
|
||||
vt -0.000000 0.666667
|
||||
vt -0.000000 0.333333
|
||||
vt 1.000000 0.333333
|
||||
vt 1.000000 0.666667
|
||||
vt 0.000000 0.666667
|
||||
vt 0.000000 0.333333
|
||||
vt 1.000000 0.333333
|
||||
vt 1.000000 0.666667
|
||||
vt 0.000000 0.666667
|
||||
vt 0.000000 0.333333
|
||||
vt 0.000058 0.000058
|
||||
vt 0.999942 0.000058
|
||||
vt 0.999942 0.333353
|
||||
vt 0.000058 0.333353
|
||||
vt 1.000000 1.000000
|
||||
vt -0.000000 1.000000
|
||||
vn -1.0000 0.0000 0.0000
|
||||
vn 0.0000 0.0000 -1.0000
|
||||
vn 1.0000 0.0000 0.0000
|
||||
vn 0.0000 0.0000 1.0000
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
vn 0.0000 1.0000 0.0000
|
||||
usemtl Material
|
||||
s off
|
||||
f 1/1/1 2/2/1 4/3/1 3/4/1
|
||||
f 3/5/2 4/6/2 8/7/2 7/8/2
|
||||
f 7/9/3 8/10/3 6/11/3 5/12/3
|
||||
f 5/13/4 6/14/4 2/15/4 1/16/4
|
||||
f 3/17/5 7/18/5 5/19/5 1/20/5
|
||||
f 8/7/6 4/6/6 2/21/6 6/22/6
|
BIN
nodes.meshlib
Normal file
BIN
nodes.meshlib
Normal file
Binary file not shown.
75
player.gd
Normal file
75
player.gd
Normal file
@ -0,0 +1,75 @@
|
||||
extends KinematicBody
|
||||
|
||||
var direction = Vector3()
|
||||
var velocity = Vector3()
|
||||
|
||||
var gravity = -27
|
||||
var jump_height = 10
|
||||
var walk_speed = 10
|
||||
var fly = false
|
||||
|
||||
var view = {
|
||||
x=0,
|
||||
y=0,
|
||||
mouse_sensitivity = 0.3,
|
||||
camera = null,
|
||||
camera_angle = 0,
|
||||
camera_speed = 0.001,
|
||||
ray = null,
|
||||
}
|
||||
|
||||
func _ready():
|
||||
view.camera = $Camera
|
||||
view.ray = $Camera/RayCast
|
||||
|
||||
func _input(event):
|
||||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
pause_mode = true
|
||||
get_tree().quit()
|
||||
elif event is InputEventMouseMotion:
|
||||
var change = deg2rad(-event.relative.y * view.mouse_sensitivity)
|
||||
view.x += deg2rad(-event.relative.x * view.mouse_sensitivity)
|
||||
if abs(view.y + change + view.camera_angle) < PI:
|
||||
view.y += change
|
||||
view.camera_angle += change
|
||||
view.camera.transform.basis = Basis()
|
||||
view.camera.rotate_object_local(Vector3(0,1,0),view.x)
|
||||
view.camera.rotate_object_local(Vector3(1,0,0),view.y)
|
||||
elif event is InputEventMouseButton:
|
||||
if Input.is_action_just_pressed("left_click") and view.ray.is_colliding():
|
||||
var aim = $Camera.get_global_transform().basis
|
||||
var c = (view.ray.get_collision_point() + -aim.z).floor()
|
||||
Game.remove_node(c)
|
||||
|
||||
elif Input.is_action_just_pressed("right_click") and view.ray.is_colliding():
|
||||
var t = view.ray.get_collision_point().floor()
|
||||
Game.add_node(t)
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
direction = Vector3()
|
||||
var aim = $Camera.get_global_transform().basis
|
||||
if Input.is_key_pressed(KEY_W):
|
||||
direction -= aim.z
|
||||
if Input.is_key_pressed(KEY_S):
|
||||
direction += aim.z
|
||||
if Input.is_key_pressed(KEY_A):
|
||||
direction -= aim.x
|
||||
if Input.is_key_pressed(KEY_D):
|
||||
direction += aim.x
|
||||
if Input.is_action_just_pressed("fly_mode"):
|
||||
fly = fly == false
|
||||
direction = direction.normalized()
|
||||
|
||||
if fly:
|
||||
transform.origin += direction*0.1
|
||||
return
|
||||
|
||||
velocity.y += gravity * delta
|
||||
var tv = velocity
|
||||
tv = velocity.linear_interpolate(direction * walk_speed,6 * delta)
|
||||
velocity.x = tv.x
|
||||
velocity.z = tv.z
|
||||
velocity = move_and_slide(velocity,Vector3(0,1,0))
|
||||
if is_on_floor() and Input.is_key_pressed(KEY_SPACE):
|
||||
velocity.y = jump_height
|
36
player.tscn
Normal file
36
player.tscn
Normal file
@ -0,0 +1,36 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://crosshair.png" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="SphereShape" id=1]
|
||||
|
||||
[node name="player" type="KinematicBody"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Camera" type="Camera" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||
|
||||
[node name="RayCast" type="RayCast" parent="Camera"]
|
||||
enabled = true
|
||||
cast_to = Vector3( 0, 0, -5 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="."]
|
||||
transform = Transform( 0.25, 0, 0, 0, 1, 0, 0, 0, 0.25, 0, 0, 0 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_group_": true,
|
||||
"_edit_lock_": true,
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="CenterContainer"]
|
||||
margin_left = 496.0
|
||||
margin_top = 284.0
|
||||
margin_right = 528.0
|
||||
margin_bottom = 316.0
|
||||
texture = ExtResource( 2 )
|
46
project.godot
Normal file
46
project.godot
Normal file
@ -0,0 +1,46 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=4
|
||||
|
||||
_global_script_classes=[ ]
|
||||
_global_script_class_icons={
|
||||
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Voxel test"
|
||||
run/main_scene="res://main.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[autoload]
|
||||
|
||||
Game="*res://game.tscn"
|
||||
|
||||
[input]
|
||||
|
||||
fly_mode={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
right_click={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
left_click={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
environment/default_environment="res://default_env.tres"
|
Loading…
x
Reference in New Issue
Block a user