1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Improve code formatting and update to 2.0

The scripts were streamlined using more or less the following conventions:
 - space after a comma in lists of arguments
 - space around weak operators (+, -), no space around strong operators (*, /)
 - space after a comment start (#)
 - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
 - function blocks separate by two newlines

The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
This commit is contained in:
Rémi Verschelde
2015-12-09 08:38:23 +01:00
parent efbb834936
commit 8639cecf4c
95 changed files with 505 additions and 5637 deletions

View File

@@ -1,10 +1,7 @@
extends KinematicBody
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var g = -9.8
var vel = Vector3()
const MAX_SPEED = 5
@@ -13,8 +10,8 @@ const ACCEL= 2
const DEACCEL= 4
const MAX_SLOPE_ANGLE = 30
func _fixed_process(delta):
func _fixed_process(delta):
var dir = Vector3() #where does the player intend to walk to
var cam_xform = get_node("target/camera").get_global_transform()
@@ -44,17 +41,14 @@ func _fixed_process(delta):
hvel = hvel.linear_interpolate(target, accel*delta)
vel.x=hvel.x;
vel.x = hvel.x
vel.z = hvel.z
var motion = move(vel*delta)
var on_floor = false
var original_vel = vel
var floor_velocity = Vector3()
var attempts=4
while(is_colliding() and attempts):
@@ -82,14 +76,12 @@ func _fixed_process(delta):
vel.y = JUMP_SPEED
var crid = get_node("../elevator1").get_rid()
# print(crid," : ",PS.body_get_state(crid,PS.BODY_STATE_TRANSFORM))
func _ready():
# Initalization here
set_fixed_process(true)
pass
func _on_tcube_body_enter(body):
get_node("../ty").show()
pass # replace with function body

View File

@@ -1,10 +1,7 @@
extends Camera
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var collision_exception = []
export var min_distance = 0.5
export var max_distance = 4.0
@@ -14,6 +11,7 @@ export var autoturn_speed=50
var max_height = 2.0
var min_height = 0
func _fixed_process(dt):
var target = get_parent().get_global_transform().origin
var pos = get_global_transform().origin
@@ -24,7 +22,6 @@ func _fixed_process(dt):
# regular delta follow
# check ranges
if (delta.length() < min_distance):
delta = delta.normalized()*min_distance
elif (delta.length() > max_distance):
@@ -46,9 +43,7 @@ func _fixed_process(dt):
set_transform(t)
func _ready():
# find collision exceptions for ray
var node = self
while(node):
@@ -57,13 +52,6 @@ func _ready():
break
else:
node = node.get_parent()
# Initalization here
set_fixed_process(true)
# this detaches the camera transform from the parent spatial node
set_as_toplevel(true)

Binary file not shown.

View File

@@ -1,14 +1,11 @@
extends RigidBody
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var gray_mat = FixedMaterial.new()
var selected=false
func _input_event(camera, event, pos, normal, shape):
if (event.type==InputEvent.MOUSE_BUTTON and event.pressed):
if (not selected):
@@ -22,11 +19,6 @@ func _input_event(camera,event,pos,normal,shape):
func _mouse_enter():
get_node("mesh").set_scale(Vector3(1.1, 1.1, 1.1))
func _mouse_exit():
get_node("mesh").set_scale(Vector3(1, 1, 1))
func _ready():
# Initalization here
pass

View File

@@ -1,10 +1,7 @@
extends Navigation
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
const SPEED = 4.0
var camrot = 0.0
@@ -14,12 +11,11 @@ var end=Vector3()
var m = FixedMaterial.new()
var path = []
var draw_path=false
func _process(delta):
if (path.size() > 1):
var to_walk = delta*SPEED
var to_watch = Vector3(0, 1, 0)
while(to_walk > 0 and path.size() >= 2):
@@ -46,16 +42,13 @@ func _process(delta):
if (path.size() < 2):
path = []
set_process(false)
else:
set_process(false)
var draw_path=false
func _update_path():
var p = get_simple_path(begin, end, true)
path=Array(p) # Vector3array to complex to use, convert to regular array
path = Array(p) # Vector3array too complex to use, convert to regular array
path.invert()
set_process(true)
@@ -72,12 +65,11 @@ func _update_path():
im.add_vertex(x)
im.end()
func _input(ev):
if (ev.type==InputEvent.MOUSE_BUTTON and ev.button_index==BUTTON_LEFT and ev.pressed):
var from = get_node("cambase/Camera").project_ray_origin(ev.pos)
var to = from+get_node("cambase/Camera").project_ray_normal(ev.pos)*100
func _input(event):
if (event.type == InputEvent.MOUSE_BUTTON and event.button_index == BUTTON_LEFT and event.pressed):
var from = get_node("cambase/Camera").project_ray_origin(event.pos)
var to = from + get_node("cambase/Camera").project_ray_normal(event.pos)*100
var p = get_closest_point_to_segment(from, to)
begin = get_closest_point(get_node("robot_base").get_translation())
@@ -85,15 +77,13 @@ func _input(ev):
_update_path()
if (ev.type==InputEvent.MOUSE_MOTION):
if (ev.button_mask&BUTTON_MASK_MIDDLE):
camrot+=ev.relative_x*0.005
if (event.type == InputEvent.MOUSE_MOTION):
if (event.button_mask&BUTTON_MASK_MIDDLE):
camrot += event.relative_x*0.005
get_node("cambase").set_rotation(Vector3(0, camrot, 0))
print("camrot ", camrot)
func _ready():
# Initalization here
set_process_input(true)
@@ -104,7 +94,3 @@ func _ready():
#begin = get_closest_point(get_node("start").get_translation())
#end = get_closest_point(get_node("end").get_translation())
#call_deferred("_update_path")
pass

Binary file not shown.

View File

@@ -1,14 +1,5 @@
extends RigidBody
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var disabled=false
func _ready():
# Initalization here
pass

Binary file not shown.

View File

@@ -1,11 +1,7 @@
extends Area
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var taken = false
@@ -13,11 +9,3 @@ func _on_coin_body_enter( body ):
if (not taken and body extends preload("res://player.gd")):
get_node("anim").play("take")
taken=true
func _ready():
# Initalization here
pass

Binary file not shown.

View File

@@ -1,14 +1,10 @@
extends RigidBody
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
const STATE_WALKING = 0
const STATE_DYING = 1
var prev_advance = false
var deaccel = 20.0
var accel = 5
@@ -18,10 +14,8 @@ var rot_speed = 1
var dying = false
func _integrate_forces(state):
var delta = state.get_step()
var lv = state.get_linear_velocity()
var g = state.get_total_gravity()
@@ -50,18 +44,12 @@ func _integrate_forces(state):
get_node("sound").play("hit")
return
var col_floor = get_node("Armature/ray_floor").is_colliding()
var col_wall = get_node("Armature/ray_wall").is_colliding()
var advance = not col_wall and col_floor
var dir = get_node("Armature").get_transform().basis[2].normalized()
var deaccel_dir = dir
if (advance):
@@ -75,7 +63,6 @@ func _integrate_forces(state):
dir = Matrix3(up, rot_dir*rot_speed*delta).xform(dir)
get_node("Armature").set_transform(Transform().looking_at(-dir, up))
var dspeed = deaccel_dir.dot(lv)
dspeed -= deaccel*delta
if (dspeed < 0):
@@ -83,13 +70,9 @@ func _integrate_forces(state):
lv = lv - deaccel_dir*deaccel_dir.dot(lv) + deaccel_dir*dspeed
state.set_linear_velocity(lv)
prev_advance = advance
func _ready():
# Initalization here
pass
func _die():
queue_free()

Binary file not shown.

View File

@@ -1,7 +1,7 @@
[application]
name="Platformer 3D"
main_scene="res://stage.xml"
main_scene="res://stage.scn"
icon="res://icon.png"
[display]

View File

@@ -1,12 +1,7 @@
extends RigidBody
# member variables here, example:
# var a=2
# var b="textvar"
#var dir=Vector3()
# member variables
const ANIM_FLOOR = 0
const ANIM_AIR_UP = 1
const ANIM_AIR_DOWN = 2
@@ -37,8 +32,8 @@ var last_floor_velocity = Vector3()
var shoot_blend = 0
func adjust_facing(p_facing, p_target,p_step, p_adjust_rate,current_gn):
func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
var n = p_target # normal
var t = n.cross(current_gn).normalized()
@@ -60,12 +55,10 @@ func adjust_facing(p_facing, p_target,p_step, p_adjust_rate,current_gn):
a = turn
ang = (ang - a)*s
return ((n * cos(ang)) + (t * sin(ang))) * p_facing.length()
return (n*cos(ang) + t*sin(ang))*p_facing.length()
func _integrate_forces(state):
var lv = state.get_linear_velocity() # linear velocity
var g = state.get_total_gravity()
var delta = state.get_step()
@@ -78,9 +71,7 @@ func _integrate_forces( state ):
var up = -g.normalized() # (up is against gravity)
var vv = up.dot(lv) # vertical velocity
var hv = lv - (up*vv) # horizontal velocity
var hv = lv - up*vv # horizontal velocity
var hdir = hv.normalized() # horizontal direction
var hspeed = hv.length() # horizontal speed
@@ -99,7 +90,6 @@ func _integrate_forces( state ):
floor_velocity = state.get_contact_collider_velocity_at_pos(i)
break
var dir = Vector3() # where does the player intend to walk to
var cam_xform = get_node("target/camera").get_global_transform()
@@ -118,12 +108,10 @@ func _integrate_forces( state ):
var target_dir = (dir - up*dir.dot(up)).normalized()
if (onfloor):
var sharp_turn = hspeed > 0.1 and rad2deg(acos(target_dir.dot(hdir))) > sharp_turn_threshhold
if (dir.length() > 0.1 and !sharp_turn):
if (hspeed > 0.001):
#linear_dir = linear_h_velocity/linear_vel
#if (linear_vel > brake_velocity_limit and linear_dir.dot(ctarget_dir) < -cos(Math::deg2rad(brake_angular_limit)))
# brake = true
@@ -131,12 +119,10 @@ func _integrate_forces( state ):
hdir = adjust_facing(hdir, target_dir, delta, 1.0/hspeed*turn_speed, up)
facing_dir = hdir
else:
hdir = target_dir
if (hspeed < max_speed):
hspeed += accel*delta
else:
hspeed -= deaccel*delta
if (hspeed < 0):
@@ -157,7 +143,6 @@ func _integrate_forces( state ):
jumping = true
get_node("sfx").play("jump")
else:
if (vv > 0):
anim = ANIM_AIR_UP
else:
@@ -165,13 +150,10 @@ func _integrate_forces( state ):
var hs
if (dir.length() > 0.1):
hv += target_dir*(accel*0.2)*delta
if (hv.length() > max_speed):
hv = hv.normalized()*max_speed
else:
if (air_idle_deaccel):
hspeed = hspeed - (deaccel*0.2)*delta
if (hspeed < 0):
@@ -179,23 +161,17 @@ func _integrate_forces( state ):
hv = hdir*hspeed
if (jumping and vv < 0):
jumping = false
lv = hv + up*vv
if (onfloor):
movement_dir = lv
#lv += floor_velocity
last_floor_velocity = floor_velocity
else:
if (on_floor) :
#if (keep_jump_inertia):
# lv += last_floor_velocity
pass
@@ -231,13 +207,6 @@ func _integrate_forces( state ):
# state.set_angular_velocity(Vector3())
func _ready():
# Initalization here
get_node("AnimationTreePlayer").set_active(true)
pass

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,5 @@
[application]
name="SAT Collision Test"
main_scene="res://sat_test.xml"
main_scene="res://sat_test.scn"
icon="res://icon.png"

Binary file not shown.

View File

@@ -1,179 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resource_file type="PackedScene" subresource_count="5" version="0.99" version_name="Godot Engine v0.99.3735-pre-beta">
<ext_resource path="res://box.*" type="PackedScene"></ext_resource>
<ext_resource path="res://sphere.*" type="PackedScene"></ext_resource>
<ext_resource path="res://capsule.*" type="PackedScene"></ext_resource>
<ext_resource path="res://convex.*" type="PackedScene"></ext_resource>
<main_resource>
<dictionary name="_bundled" shared="false">
<string> "names" </string>
<string_array len="30">
<string> "Node" </string>
<string> "__meta__" </string>
<string> "sphere" </string>
<string> "Spatial" </string>
<string> "transform/local" </string>
<string> "box" </string>
<string> "convex" </string>
<string> "Camera" </string>
<string> "projection" </string>
<string> "fov" </string>
<string> "near" </string>
<string> "far" </string>
<string> "vaspect" </string>
<string> "current" </string>
<string> "visible_layers" </string>
<string> "environment" </string>
<string> "OmniLight" </string>
<string> "layers" </string>
<string> "params/energy" </string>
<string> "colors/ambient" </string>
<string> "colors/diffuse" </string>
<string> "colors/specular" </string>
<string> "shadow/shadow" </string>
<string> "shadow/darkening" </string>
<string> "shadow/z_offset" </string>
<string> "shadow/z_slope_scale" </string>
<string> "projector" </string>
<string> "operator" </string>
<string> "params/radius" </string>
<string> "params/attenuation" </string>
</string_array>
<string> "version" </string>
<int> 1 </int>
<string> "conn_count" </string>
<int> 0 </int>
<string> "node_count" </string>
<int> 7 </int>
<string> "variants" </string>
<array len="26" shared="false">
<dictionary shared="false">
<string> "__editor_plugin_states__" </string>
<dictionary shared="false">
<string> "2D" </string>
<dictionary shared="false">
<string> "zoom" </string>
<real> 1 </real>
<string> "ofs" </string>
<vector2> 1, 1 </vector2>
</dictionary>
<string> "3D" </string>
<dictionary shared="false">
<string> "zfar" </string>
<real> 500 </real>
<string> "fov" </string>
<real> 400 </real>
<string> "viewports" </string>
<array len="4" shared="false">
<dictionary shared="false">
<string> "distance" </string>
<real> 34.508423 </real>
<string> "x_rot" </string>
<real> 0.7 </real>
<string> "y_rot" </string>
<real> 1.262503 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 13.3659, 3.22136, 2.27417 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
</array>
<string> "viewport_mode" </string>
<int> 1 </int>
<string> "default_light" </string>
<bool> False </bool>
<string> "show_grid" </string>
<bool> True </bool>
<string> "show_origin" </string>
<bool> True </bool>
<string> "znear" </string>
<real> 0.1 </real>
</dictionary>
</dictionary>
<string> "__editor_run_settings__" </string>
<dictionary shared="false">
<string> "custom_args" </string>
<string> "-l $scene" </string>
<string> "run_mode" </string>
<int> 0 </int>
</dictionary>
<string> "__editor_plugin_screen__" </string>
<string> "3D" </string>
</dictionary>
<resource resource_type="PackedScene" path="res://sphere.*"> </resource>
<transform> 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -2.93877 </transform>
<resource resource_type="PackedScene" path="res://box.*"> </resource>
<transform> 1, 0, 0, 0, 1, 0, 0, 0, 1, 13.5356, 0, -3.40082 </transform>
<resource resource_type="PackedScene" path="res://convex.*"> </resource>
<transform> 1, 0, 0, 0, 1, 0, 0, 0, 1, 22.8626, 0, -2.50073 </transform>
<resource resource_type="PackedScene" path="res://capsule.*"> </resource>
<transform> 1, 0, 0, 0, 1, 0, 0, 0, 1, 28.4061, 0, -2.76809 </transform>
<transform> 1, 0, 0, 0, 0.819152, 0.573576, 0, -0.573576, 0.819152, 14.482, 11.1225, 20.5858 </transform>
<int> 0 </int>
<real> 60 </real>
<real> 0.1 </real>
<real> 100 </real>
<bool> False </bool>
<int> -1 </int>
<resource name=""></resource> <transform> 1, 0, 0, 0, 1, 0, 0, 0, 1, 66.4797, 0, 10.4696 </transform>
<int> 1 </int>
<real> 1.5 </real>
<color> 0.355828, 0.346354, 0.329995, 1 </color>
<color> 1, 1, 1, 1 </color>
<real> 0 </real>
<real> 0.05 </real>
<real> 500 </real>
<real> 0.535887 </real>
</array>
<string> "nodes" </string>
<int_array len="105"> -1, -1, 0, 0, -1, 1, 1, 0, 0, 0, 0, 3, 2, 1, 1, 4, 2, 0, 0, 0, 3, 5, 3, 1, 4, 4, 0, 0, 0, 3, 6, 5, 1, 4, 6, 0, 0, 0, 3, 3, 7, 1, 4, 8, 0, 0, 0, 7, 7, -1, 9, 4, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 14, 14, 15, 15, 16, 0, 0, 0, 16, 16, -1, 14, 4, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 14, 23, 22, 24, 23, 25, 22, 26, 16, 27, 10, 28, 24, 29, 25, 0 </int_array>
<string> "conns" </string>
<int_array len="0"> </int_array>
</dictionary>
</main_resource>
</resource_file>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,25 +1,16 @@
extends Control
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initalization here
pass
# member variables
var town = null
func _back():
town.queue_free()
show()
func _load_scene(car):
var tt = load(car).instance()
tt.set_name("car")
town = load("res://truck_scene.scn").instance()
@@ -28,13 +19,12 @@ func _load_scene(car):
get_parent().add_child(town)
hide()
func _on_van_1_pressed():
func _on_van_1_pressed():
_load_scene("res://car_base.scn")
func _on_van_2_pressed():
_load_scene("res://trailer_truck.scn")

Binary file not shown.

Binary file not shown.

View File

@@ -1,10 +1,7 @@
extends Camera
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var collision_exception = []
export var min_distance = 0.5
export var max_distance = 4.0
@@ -14,6 +11,7 @@ export var autoturn_speed=50
var max_height = 2.0
var min_height = 0
func _fixed_process(dt):
var target = get_parent().get_global_transform().origin
var pos = get_global_transform().origin
@@ -24,7 +22,6 @@ func _fixed_process(dt):
# regular delta follow
# check ranges
if (delta.length() < min_distance):
delta = delta.normalized()*min_distance
elif (delta.length() > max_distance):
@@ -46,9 +43,7 @@ func _fixed_process(dt):
set_transform(t)
func _ready():
# find collision exceptions for ray
var node = self
while(node):
@@ -57,13 +52,6 @@ func _ready():
break
else:
node = node.get_parent()
# Initalization here
set_fixed_process(true)
# this detaches the camera transform from the parent spatial node
set_as_toplevel(true)

Binary file not shown.

Binary file not shown.

View File

@@ -1,23 +1,17 @@
extends VehicleBody
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
const STEER_SPEED = 1
const STEER_LIMIT = 0.4
var steer_angle = 0
var steer_target = 0
export var engine_force = 40
func _fixed_process(delta):
if (Input.is_action_pressed("ui_left")):
steer_target = -STEER_LIMIT
elif (Input.is_action_pressed("ui_right")):
@@ -35,7 +29,6 @@ func _fixed_process(delta):
else:
set_brake(0.0)
if (steer_target < steer_angle):
steer_angle -= STEER_SPEED*delta
if (steer_target > steer_angle):
@@ -46,9 +39,8 @@ func _fixed_process(delta):
steer_angle = steer_target
set_steering(steer_angle)
func _ready():
# Initalization here
set_fixed_process(true)
pass

View File

@@ -2,9 +2,7 @@
extends ColorPickerButton
#virtual function
func get_drag_data(pos):
# use another colorpicker as drag preview
var cpb = ColorPickerButton.new()
cpb.set_color(get_color())
@@ -13,12 +11,10 @@ func get_drag_data(pos):
# return color as drag data
return get_color()
#virtual function
func can_drop_data(pos, data):
return typeof(data) == TYPE_COLOR
#virtual function
func drop_data(pos, data):
set_color(data)

View File

@@ -11,10 +11,12 @@
extends Control
# member variables
var player_actions = [ "move_up", "move_down", "move_left", "move_right", "jump" ]
var action # To register the action the UI is currently handling
var button # Button node corresponding to the above action
func wait_for_input(action_bind):
action = action_bind
# See note at the beginning of the script
@@ -22,6 +24,7 @@ func wait_for_input(action_bind):
get_node("contextual_help").set_text("Press a key to assign to the '" + action + "' action.")
set_process_input(true)
func _input(event):
# Handle the first pressed key
if (event.type == InputEvent.KEY):
@@ -39,6 +42,7 @@ func _input(event):
# Add the new key binding
InputMap.action_add_event(action, event)
func _ready():
# Initialise each button with the default key binding from InputMap
var input_event

Binary file not shown.

View File

@@ -1,17 +1,6 @@
extends Panel
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initialization here
pass
func _on_RichTextLabel_meta_clicked(meta):
OS.shell_open(meta)
pass # replace with function body

View File

@@ -1,20 +1,9 @@
extends Panel
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initialization here
pass
func _on_back_pressed():
var s = load("res://main.scn")
var si = s.instance()
get_parent().add_child(si)
queue_free()
pass # replace with function body

Binary file not shown.

View File

@@ -1,22 +1,12 @@
extends Panel
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initialization here
pass
func _goto_scene():
var s = load("res://controls.scn")
var si = s.instance()
get_parent().add_child(si)
queue_free()
pass
func _on_system_pressed():
@@ -24,7 +14,7 @@ func _on_system_pressed():
# to english if not found
_goto_scene()
#NOTE: Changling locale will not change the text in the controls,
# NOTE: Changing locale will not change the text in the controls,
# The scene must be reloaded for changes to take effect.
func _on_english_pressed():

Binary file not shown.

View File

@@ -1,11 +1,10 @@
extends Node
# member variables
var current_scene = null
func goto_scene(path):
# This function will usually be called from a signal callback,
# or some other function from the running scene.
# Deleting the current scene at this point might be
@@ -19,7 +18,6 @@ func goto_scene(path):
func _deferred_goto_scene(path):
# Immediately free the current scene,
# there is no risk here.
current_scene.free()

View File

@@ -5,13 +5,12 @@ extends Panel
# var a=2
# var b="textvar"
func _ready():
# Initalization here
pass
func _on_goto_scene_pressed():
get_node("/root/global").goto_scene("res://scene_b.scn")
pass # replace with function body

Binary file not shown.

View File

@@ -5,13 +5,12 @@ extends Panel
# var a=2
# var b="textvar"
func _ready():
# Initalization here
pass
func _on_goto_scene_pressed():
get_node("/root/global").goto_scene("res://scene_a.scn")
pass # replace with function body

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -8,15 +8,14 @@ extends Node2D
#
# Licensed under the MIT license
# member variables
var joy_num
var cur_joy
var axis_value
var btn_state
func _ready():
set_process_input(true)
func _input(ev):
func _input(event):
# get the joystick device number from the spinbox
joy_num = get_node("joy_num").get_value()
@@ -38,3 +37,7 @@ func _input(ev):
get_node("btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1))
else:
get_node("btn" + str(btn)).add_color_override("font_color", Color(0.2, 0.1, 0.3, 1))
func _ready():
set_process_input(true)

Binary file not shown.

View File

@@ -11,5 +11,3 @@ func _on_pause_pressed():
func _on_unpause_pressed():
get_node("pause_popup").hide()
get_tree().set_pause(false)

Binary file not shown.

View File

@@ -1,11 +1,15 @@
extends VBoxContainer
# member variables
var regex = RegEx.new()
func update_expression(text):
regex.compile(text)
update_text()
func update_text():
var text = get_node("Text").get_text()
var list = get_node("List")
@@ -18,7 +22,7 @@ func update_text():
label.set_text(res)
list.add_child(label)
func _ready():
get_node("Text").set_text("They asked me \"What's going on \\\"in the manor\\\"?\"")
update_expression(get_node("Expression").get_text())

Binary file not shown.

View File

@@ -5,13 +5,12 @@ extends Panel
# var a=2
# var b="textvar"
func _ready():
# Initalization here
pass
func _on_goto_scene_pressed():
get_tree().change_scene("res://scene_b.scn")
pass # replace with function body

Binary file not shown.

View File

@@ -5,13 +5,12 @@ extends Panel
# var a=2
# var b="textvar"
func _ready():
# Initalization here
pass
func _on_goto_scene_pressed():
get_tree().change_scene("res://scene_a.scn")
pass # replace with function body

Binary file not shown.

View File

@@ -1,12 +1,10 @@
extends Node2D
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var thread = Thread.new()
# this function runs in a thread!
# threads always take one userdata argument
func _bg_load(path):
@@ -17,12 +15,14 @@ func _bg_load(path):
call_deferred("_bg_load_done")
return tex # return it
func _bg_load_done():
# wait for the thread to complete, get the returned value
var tex = thread.wait_to_finish()
# set to the sprite
get_node("sprite").set_texture(tex)
func _on_load_pressed():
if (thread.is_active()):
# already working

Binary file not shown.

View File

@@ -1,7 +1,7 @@
[application]
name="Tween Demo"
main_scene="res://main.xml"
main_scene="res://main.scn"
icon="res://icon.png"
target_fps=60

View File

@@ -1,10 +1,7 @@
extends Control
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var trans = ["linear", "sine", "quint", "quart", "quad", "expo", "elastic", "cubic", "circ", "bounce", "back"]
var eases = ["in", "out", "in_out", "out_in"]
var modes = ["move", "color", "scale", "rotate", "callback", "follow", "repeat", "pause"]
@@ -14,6 +11,7 @@ var state = {
eases = Tween.EASE_IN,
}
func _ready():
for index in range(trans.size()):
var name = trans[index]
@@ -40,8 +38,6 @@ func _ready():
reset_tween()
# Initalization here
pass
func on_trans_changed(name, index):
for index in range(trans.size()):
@@ -54,6 +50,7 @@ func on_trans_changed(name, index):
state.trans = index
reset_tween()
func on_eases_changed(name, index):
for index in range(eases.size()):
var pressed = eases[index] == name
@@ -65,6 +62,7 @@ func on_eases_changed(name, index):
state.eases = index
reset_tween()
func on_modes_changed(name):
var tween = get_node("tween")
if name == "pause":
@@ -77,9 +75,11 @@ func on_modes_changed(name):
else:
reset_tween()
func on_color_changed(color):
reset_tween()
func reset_tween():
var tween = get_node("tween")
var pos = tween.tell()
@@ -140,8 +140,8 @@ func reset_tween():
tween.resume_all()
get_node("timeline").set_ignore_mouse(true)
func _on_tween_step( object, key, elapsed, value ):
func _on_tween_step(object, key, elapsed, value):
var timeline = get_node("timeline")
var tween = get_node("tween")
@@ -159,6 +159,7 @@ func _on_timeline_value_changed( value ):
var runtime = tween.get_runtime()
tween.seek(runtime*value/100)
func on_callback(arg):
var label = get_node("tween/area/label")
label.add_text("on_callback -> " + arg + "\n")

BIN
demos/misc/tween/main.scn Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -1,14 +1,15 @@
extends Panel
# Really simple UDP chat client, not intended as a chat example!!
# Really simple UDP chat client, not intended as a comprehensive chat implementation.
# (UDP can lose packets and you won't normally find out, so don't do a chat this way)
# This is just a demo that shows how to use the UDP class.
# member variables
var udp = PacketPeerUDP.new()
func _process(delta):
func _process(delta):
if (not udp.is_listening()):
return
@@ -21,47 +22,41 @@ func _process(delta):
get_node("chat/text").newline()
func _ready():
# Initalization here
get_node("chat").add_style_override("panel", get_stylebox("bg", "Tree"))
set_process(true)
func send_message(text):
if (udp.is_listening()):
udp.put_var(text)
func _on_connect_toggled(pressed):
if (pressed):
var err = udp.listen(get_node("listen_port").get_val())
if (err != OK):
get_node("status").set_text("Error:\nCan't Listen.")
get_node("status").set_text("Error:\nCan't listen.")
get_node("connect").set_pressed(false)
else:
get_node("status").set_text("Connected.")
get_node("connect").set_text("Disconnect")
err = udp.set_send_address(get_node("remote_host").get_text(),get_node("remote_port").get_val())
if (err != OK):
get_node("status").set_text("Error:\nCan't Resolve.")
get_node("status").set_text("Error:\nCan't resolve.")
get_node("connect").set_pressed(false)
else:
send_message("* " + get_node("user_name").get_text() + " entered chat.")
else:
udp.close()
get_node("status").set_text("Disconnected.")
get_node("connect").set_text("Connect")
func _on_entry_line_text_entered(text):
_on_entry_button_pressed();
_on_entry_button_pressed()
func _on_entry_button_pressed():
var msg = get_node("entry_line").get_text()

Binary file not shown.

View File

@@ -1,10 +1,11 @@
extends Control
# member variables
var mousepos
func _fixed_process(delta):
func _fixed_process(delta):
var modetext = "Mode:\n"
if(OS.is_window_fullscreen()):
@@ -131,9 +132,9 @@ func _ready():
set_process_input(true)
func _input(ev):
if (ev.type==InputEvent.MOUSE_MOTION):
mousepos = ev.pos
func _input(event):
if (event.type == InputEvent.MOUSE_MOTION):
mousepos = event.pos
func _on_Button_MoveTo_pressed():

View File

@@ -1,16 +1,17 @@
extends Spatial
# member variables
var r_pos = Vector2()
var state
const STATE_MENU = 0
const STATE_GRAB = 1
func direction(vector):
var v = get_node("Camera").get_global_transform().basis*vector
v = v.normalized()
return v
@@ -22,7 +23,6 @@ func impulse(event, action):
func _fixed_process(delta):
if(state != STATE_GRAB):
return
@@ -76,4 +76,3 @@ func _ready():
set_process_input(true)
state = STATE_MENU

View File

@@ -1,9 +1,7 @@
extends Node2D
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
const INITIAL_BALL_SPEED = 80
var ball_speed = INITIAL_BALL_SPEED
var screen_size = Vector2(640,400)
@@ -14,9 +12,7 @@ const PAD_SPEED = 150
func _process(delta):
# get ball positio and pad rectangles
# get ball position and pad rectangles
var ball_pos = get_node("ball").get_pos()
var left_rect = Rect2(get_node("left").get_pos() - pad_size*0.5, pad_size)
var right_rect = Rect2(get_node("right").get_pos() - pad_size*0.5, pad_size)
@@ -41,7 +37,6 @@ func _process(delta):
ball_speed = INITIAL_BALL_SPEED
direction = Vector2(-1,0)
get_node("ball").set_pos(ball_pos)
# move left pad
@@ -65,9 +60,8 @@ func _process(delta):
get_node("right").set_pos(right_pos)
func _ready():
# Initalization here
screen_size = get_viewport_rect().size # get actual size
pad_size = get_node("left").get_texture().get_size()
set_process(true)

Binary file not shown.

View File

@@ -1,183 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resource_file type="PackedScene" subresource_count="6" version="0.99" version_name="Godot Engine v0.99.3735-pre-beta">
<ext_resource path="res://pong.*" type="GDScript"></ext_resource>
<ext_resource path="res://separator.*" type="ImageTexture"></ext_resource>
<ext_resource path="res://left_pallete.*" type="ImageTexture"></ext_resource>
<ext_resource path="res://right_pallete.*" type="ImageTexture"></ext_resource>
<ext_resource path="res://ball.*" type="ImageTexture"></ext_resource>
<main_resource>
<dictionary name="_bundled" shared="false">
<string> "names" </string>
<string_array len="27">
<string> "game" </string>
<string> "Node2D" </string>
<string> "visibility/visible" </string>
<string> "visibility/opacity" </string>
<string> "visibility/self_opacity" </string>
<string> "visibility/on_top" </string>
<string> "transform/pos" </string>
<string> "transform/rot" </string>
<string> "transform/scale" </string>
<string> "script/script" </string>
<string> "__meta__" </string>
<string> "left" </string>
<string> "Sprite" </string>
<string> "texture" </string>
<string> "centered" </string>
<string> "offset" </string>
<string> "flip_h" </string>
<string> "flip_v" </string>
<string> "vframes" </string>
<string> "hframes" </string>
<string> "frame" </string>
<string> "modulate" </string>
<string> "region" </string>
<string> "region_rect" </string>
<string> "right" </string>
<string> "separator" </string>
<string> "ball" </string>
</string_array>
<string> "version" </string>
<int> 1 </int>
<string> "conn_count" </string>
<int> 0 </int>
<string> "node_count" </string>
<int> 5 </int>
<string> "variants" </string>
<array len="20" shared="false">
<bool> True </bool>
<real> 1 </real>
<vector2> 0, 0 </vector2>
<real> 0 </real>
<vector2> 1, 1 </vector2>
<resource resource_type="GDScript" path="res://pong.*"> </resource>
<dictionary shared="false">
<string> "__editor_plugin_states__" </string>
<dictionary shared="false">
<string> "Script" </string>
<dictionary shared="false">
<string> "current" </string>
<int> 0 </int>
<string> "sources" </string>
<array len="1" shared="false">
<string> "res://pong.gd" </string>
</array>
</dictionary>
<string> "2D" </string>
<dictionary shared="false">
<string> "pixel_snap" </string>
<bool> True </bool>
<string> "zoom" </string>
<real> 1.108033 </real>
<string> "ofs" </string>
<vector2> -54.59, -36.0052 </vector2>
</dictionary>
<string> "3D" </string>
<dictionary shared="false">
<string> "zfar" </string>
<real> 500 </real>
<string> "fov" </string>
<real> 45 </real>
<string> "viewports" </string>
<array len="4" shared="false">
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
</array>
<string> "viewport_mode" </string>
<int> 1 </int>
<string> "default_light" </string>
<bool> True </bool>
<string> "show_grid" </string>
<bool> True </bool>
<string> "show_origin" </string>
<bool> True </bool>
<string> "znear" </string>
<real> 0.1 </real>
</dictionary>
</dictionary>
<string> "__editor_run_settings__" </string>
<dictionary shared="false">
<string> "custom_args" </string>
<string> "-l $scene" </string>
<string> "run_mode" </string>
<int> 0 </int>
</dictionary>
<string> "__editor_plugin_screen__" </string>
<string> "Script" </string>
</dictionary>
<vector2> 67.6875, 183.208 </vector2>
<resource resource_type="ImageTexture" path="res://left_pallete.*"> </resource>
<bool> False </bool>
<int> 1 </int>
<int> 0 </int>
<color> 1, 1, 1, 1 </color>
<rect2> 0, 0, 0, 0 </rect2>
<vector2> 577, 187 </vector2>
<resource resource_type="ImageTexture" path="res://right_pallete.*"> </resource>
<vector2> 320, 200 </vector2>
<resource resource_type="ImageTexture" path="res://separator.*"> </resource>
<vector2> 320.283, 188 </vector2>
<resource resource_type="ImageTexture" path="res://ball.*"> </resource>
</array>
<string> "nodes" </string>
<int_array len="197"> -1, -1, 1, 0, -1, 9, 2, 0, 3, 1, 4, 1, 5, 0, 6, 2, 7, 3, 8, 4, 9, 5, 10, 6, 0, 0, 0, 12, 11, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 7, 7, 3, 8, 4, 13, 8, 14, 0, 15, 2, 16, 9, 17, 9, 18, 10, 19, 10, 20, 11, 21, 12, 22, 9, 23, 13, 0, 0, 0, 12, 24, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 14, 7, 3, 8, 4, 13, 15, 14, 0, 15, 2, 16, 9, 17, 9, 18, 10, 19, 10, 20, 11, 21, 12, 22, 9, 23, 13, 0, 0, 0, 12, 25, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 16, 7, 3, 8, 4, 13, 17, 14, 0, 15, 2, 16, 9, 17, 9, 18, 10, 19, 10, 20, 11, 21, 12, 22, 9, 23, 13, 0, 0, 0, 12, 26, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 18, 7, 3, 8, 4, 13, 19, 14, 0, 15, 2, 16, 9, 17, 9, 18, 10, 19, 10, 20, 11, 21, 12, 22, 9, 23, 13, 0 </int_array>
<string> "conns" </string>
<int_array len="0"> </int_array>
</dictionary>
</main_resource>
</resource_file>

View File

@@ -1,14 +1,8 @@
extends Spatial
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initalization here
var tex = get_node("Viewport").get_render_target_texture()
get_node("Quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, tex)
pass

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@@ -1,23 +1,19 @@
extends Spatial
# member variables here, example:
# var a=2
# var b="textvar"
# member variables
var prev_pos = null
func _input( ev ):
func _input(event):
# all other (non-mouse) events
if (not ev.type in [InputEvent.MOUSE_BUTTON,InputEvent.MOUSE_MOTION,InputEvent.SCREEN_DRAG,InputEvent.SCREEN_TOUCH]):
get_node("viewport").input(ev)
if (not event.type in [InputEvent.MOUSE_BUTTON, InputEvent.MOUSE_MOTION, InputEvent.SCREEN_DRAG, InputEvent.SCREEN_TOUCH]):
get_node("viewport").input(event)
# mouse events for area
func _on_area_input_event( camera, ev, click_pos, click_normal, shape_idx ):
#use click pos (click in 3d space, convert to area space
func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
# use click pos (click in 3d space, convert to area space)
var pos = get_node("area").get_global_transform().affine_inverse()*click_pos
# convert to 2D
pos = Vector2(pos.x, pos.y)
@@ -25,21 +21,18 @@ func _on_area_input_event( camera, ev, click_pos, click_normal, shape_idx ):
pos.x = (pos.x + 1.5)*100
pos.y = (-pos.y + 0.75)*100
# set to event
ev.pos=pos
ev.global_pos=pos
event.pos = pos
event.global_pos = pos
if (prev_pos == null):
prev_pos = pos
if (ev.type==InputEvent.MOUSE_MOTION):
ev.relative_pos=pos-prev_pos
if (event.type == InputEvent.MOUSE_MOTION):
event.relative_pos = pos - prev_pos
prev_pos = pos
get_node("viewport").input(ev)
# sned the event to the viewport
get_node("viewport").input(event)
func _ready():
# Initalization here
get_node("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture())
set_process_input(true)
pass

Binary file not shown.

View File

@@ -1,20 +1,10 @@
extends Control
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initialization here
pass
func _on_button_pressed():
get_viewport().queue_screen_capture()
#let two frames pass to make sure the screen was aptured
# let two frames pass to make sure the screen was captured
yield(get_tree(),"idle_frame")
yield(get_tree(),"idle_frame")
# retrieve the captured image
@@ -24,4 +14,3 @@ func _on_button_pressed():
tex.create_from_image(img)
# set it to the capture node
get_node("capture").set_texture(tex)
pass # replace with function body