Use upper-cased first letter at the start of comment sentences

This commit is contained in:
Rémi Verschelde 2015-11-21 13:31:25 +01:00
parent 8639cecf4c
commit 8c4f19e79d
30 changed files with 150 additions and 164 deletions

View File

@ -1,7 +1,7 @@
extends KinematicBody extends KinematicBody
# member variables # Member variables
var g = -9.8 var g = -9.8
var vel = Vector3() var vel = Vector3()
const MAX_SPEED = 5 const MAX_SPEED = 5
@ -12,7 +12,7 @@ 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 dir = Vector3() # Where does the player intend to walk to
var cam_xform = get_node("target/camera").get_global_transform() var cam_xform = get_node("target/camera").get_global_transform()
if (Input.is_action_pressed("move_forward")): if (Input.is_action_pressed("move_forward")):
@ -49,13 +49,13 @@ func _fixed_process(delta):
var on_floor = false var on_floor = false
var original_vel = vel var original_vel = vel
var floor_velocity = Vector3() var floor_velocity = Vector3()
var attempts=4 var attempts = 4
while(is_colliding() and attempts): while(is_colliding() and attempts):
var n = get_collision_normal() var n = get_collision_normal()
if (rad2deg(acos(n.dot(Vector3(0, 1, 0)))) < MAX_SLOPE_ANGLE): if (rad2deg(acos(n.dot(Vector3(0, 1, 0)))) < MAX_SLOPE_ANGLE):
# if angle to the "up" vectors is < angle tolerance # If angle to the "up" vectors is < angle tolerance,
# char is on floor # char is on floor
floor_velocity = get_collider_velocity() floor_velocity = get_collider_velocity()
on_floor = true on_floor = true
@ -63,7 +63,7 @@ func _fixed_process(delta):
motion = n.slide(motion) motion = n.slide(motion)
vel = n.slide(vel) vel = n.slide(vel)
if (original_vel.dot(vel) > 0): if (original_vel.dot(vel) > 0):
# do not allow to slide towads the opposite direction we were coming from # Do not allow to slide towads the opposite direction we were coming from
motion=move(motion) motion=move(motion)
if (motion.length() < 0.001): if (motion.length() < 0.001):
break break

View File

@ -1,7 +1,7 @@
extends Camera extends Camera
# member variables # Member variables
var collision_exception = [] var collision_exception = []
export var min_distance = 0.5 export var min_distance = 0.5
export var max_distance = 4.0 export var max_distance = 4.0
@ -19,15 +19,15 @@ func _fixed_process(dt):
var delta = pos - target var delta = pos - target
# regular delta follow # Regular delta follow
# check ranges # Check ranges
if (delta.length() < min_distance): if (delta.length() < min_distance):
delta = delta.normalized()*min_distance delta = delta.normalized()*min_distance
elif (delta.length() > max_distance): elif (delta.length() > max_distance):
delta = delta.normalized()*max_distance delta = delta.normalized()*max_distance
# check upper and lower height # Check upper and lower height
if (delta.y > max_height): if (delta.y > max_height):
delta.y = max_height delta.y = max_height
if (delta.y < min_height): if (delta.y < min_height):
@ -37,14 +37,14 @@ func _fixed_process(dt):
look_at_from_pos(pos, target, up) look_at_from_pos(pos, target, up)
# turn a little up or down # Turn a little up or down
var t = get_transform() var t = get_transform()
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
set_transform(t) set_transform(t)
func _ready(): func _ready():
# find collision exceptions for ray # Find collision exceptions for ray
var node = self var node = self
while(node): while(node):
if (node extends RigidBody): if (node extends RigidBody):
@ -53,5 +53,5 @@ func _ready():
else: else:
node = node.get_parent() node = node.get_parent()
set_fixed_process(true) set_fixed_process(true)
# this detaches the camera transform from the parent spatial node # This detaches the camera transform from the parent spatial node
set_as_toplevel(true) set_as_toplevel(true)

View File

@ -1,9 +1,9 @@
extends RigidBody extends RigidBody
# member variables # Member variables
var gray_mat = FixedMaterial.new() var gray_mat = FixedMaterial.new()
var selected=false var selected = false
func _input_event(camera, event, pos, normal, shape): func _input_event(camera, event, pos, normal, shape):

View File

@ -1,7 +1,7 @@
extends Navigation extends Navigation
# member variables # Member variables
const SPEED = 4.0 const SPEED = 4.0
var camrot = 0.0 var camrot = 0.0
@ -11,7 +11,7 @@ var end = Vector3()
var m = FixedMaterial.new() var m = FixedMaterial.new()
var path = [] var path = []
var draw_path=false var draw_path = false
func _process(delta): func _process(delta):

View File

@ -1,5 +1,5 @@
extends RigidBody extends RigidBody
# member variables # Member variables
var disabled=false var disabled = false

View File

@ -1,11 +1,11 @@
extends Area extends Area
# member variables # Member variables
var taken = false var taken = false
func _on_coin_body_enter(body): func _on_coin_body_enter(body):
if (not taken and body extends preload("res://player.gd")): if (not taken and body extends preload("res://player.gd")):
get_node("anim").play("take") get_node("anim").play("take")
taken=true taken = true

View File

@ -1,7 +1,7 @@
extends RigidBody extends RigidBody
# member variables # Member variables
const STATE_WALKING = 0 const STATE_WALKING = 0
const STATE_DYING = 1 const STATE_DYING = 1
@ -20,7 +20,7 @@ func _integrate_forces(state):
var lv = state.get_linear_velocity() var lv = state.get_linear_velocity()
var g = state.get_total_gravity() var g = state.get_total_gravity()
lv += g*delta # apply gravity lv += g*delta # Apply gravity
var up = -g.normalized() var up = -g.normalized()
if (dying): if (dying):

View File

@ -1,95 +1,80 @@
extends Camera extends Camera
# member variables here, example: # Member variables
# var a=2 var collision_exception = []
# var b="textvar" export var min_distance = 0.5
export var max_distance = 4.0
var collision_exception=[] export var angle_v_adjust = 0.0
export var min_distance=0.5 export var autoturn_ray_aperture = 25
export var max_distance=4.0 export var autoturn_speed = 50
export var angle_v_adjust=0.0
export var autoturn_ray_aperture=25
export var autoturn_speed=50
var max_height = 2.0 var max_height = 2.0
var min_height = 0 var min_height = 0
func _fixed_process(dt): func _fixed_process(dt):
var target = get_parent().get_global_transform().origin var target = get_parent().get_global_transform().origin
var pos = get_global_transform().origin var pos = get_global_transform().origin
var up = Vector3(0,1,0) var up = Vector3(0, 1, 0)
var delta = pos - target var delta = pos - target
#regular delta follow # Regular delta follow
#check ranges
# Check ranges
if (delta.length() < min_distance): if (delta.length() < min_distance):
delta = delta.normalized() * min_distance delta = delta.normalized()*min_distance
elif (delta.length() > max_distance): elif (delta.length() > max_distance):
delta = delta.normalized() * max_distance delta = delta.normalized()*max_distance
#check upper and lower height # Check upper and lower height
if ( delta.y > max_height): if (delta.y > max_height):
delta.y = max_height delta.y = max_height
if ( delta.y < min_height): if (delta.y < min_height):
delta.y = min_height delta.y = min_height
#check autoturn # Check autoturn
var ds = PhysicsServer.space_get_direct_state(get_world().get_space())
var ds = PhysicsServer.space_get_direct_state( get_world().get_space() ) var col_left = ds.intersect_ray(target, target + Matrix3(up, deg2rad(autoturn_ray_aperture)).xform(delta), collision_exception)
var col = ds.intersect_ray(target, target + delta, collision_exception)
var col_right = ds.intersect_ray(target, target + Matrix3(up, deg2rad(-autoturn_ray_aperture)).xform(delta), collision_exception)
var col_left = ds.intersect_ray(target,target+Matrix3(up,deg2rad(autoturn_ray_aperture)).xform(delta),collision_exception)
var col = ds.intersect_ray(target,target+delta,collision_exception)
var col_right = ds.intersect_ray(target,target+Matrix3(up,deg2rad(-autoturn_ray_aperture)).xform(delta),collision_exception)
if (!col.empty()): if (!col.empty()):
#if main ray was occluded, get camera closer, this is the worst case scenario # If main ray was occluded, get camera closer, this is the worst case scenario
delta = col.position - target delta = col.position - target
elif (!col_left.empty() and col_right.empty()): elif (!col_left.empty() and col_right.empty()):
#if only left ray is occluded, turn the camera around to the right # If only left ray is occluded, turn the camera around to the right
delta = Matrix3(up,deg2rad(-dt*autoturn_speed)).xform(delta) delta = Matrix3(up, deg2rad(-dt*autoturn_speed)).xform(delta)
elif (col_left.empty() and !col_right.empty()): elif (col_left.empty() and !col_right.empty()):
#if only right ray is occluded, turn the camera around to the left # If only right ray is occluded, turn the camera around to the left
delta = Matrix3(up,deg2rad(dt*autoturn_speed)).xform(delta) delta = Matrix3(up, deg2rad(dt*autoturn_speed)).xform(delta)
else: else:
#do nothing otherwise, left and right are occluded but center is not, so do not autoturn # Do nothing otherwise, left and right are occluded but center is not, so do not autoturn
pass pass
#apply lookat # Apply lookat
if (delta==Vector3()): if (delta == Vector3()):
delta = (pos - target).normalized() * 0.0001 delta = (pos - target).normalized()*0.0001
pos = target + delta pos = target + delta
look_at_from_pos(pos,target,up) look_at_from_pos(pos, target, up)
#turn a little up or down # Turn a little up or down
var t = get_transform() var t = get_transform()
t.basis = Matrix3(t.basis[0],deg2rad(angle_v_adjust)) * t.basis t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
set_transform(t) set_transform(t)
func _ready(): func _ready():
# Find collision exceptions for ray
#find collision exceptions for ray
var node = self var node = self
while(node): while(node):
if (node extends RigidBody): if (node extends RigidBody):
collision_exception.append(node.get_rid()) collision_exception.append(node.get_rid())
break break
else: else:
node=node.get_parent() node = node.get_parent()
# Initalization here
set_fixed_process(true) set_fixed_process(true)
#this detaches the camera transform from the parent spatial node # This detaches the camera transform from the parent spatial node
set_as_toplevel(true) set_as_toplevel(true)

View File

@ -1,7 +1,7 @@
extends RigidBody extends RigidBody
# member variables # Member variables
const ANIM_FLOOR = 0 const ANIM_FLOOR = 0
const ANIM_AIR_UP = 1 const ANIM_AIR_UP = 1
const ANIM_AIR_DOWN = 2 const ANIM_AIR_DOWN = 2
@ -14,14 +14,14 @@ const CHAR_SCALE = Vector3(0.3, 0.3, 0.3)
var facing_dir = Vector3(1, 0, 0) var facing_dir = Vector3(1, 0, 0)
var movement_dir = Vector3() var movement_dir = Vector3()
var jumping=false var jumping = false
var turn_speed = 40 var turn_speed = 40
var keep_jump_inertia = true var keep_jump_inertia = true
var air_idle_deaccel = false var air_idle_deaccel = false
var accel = 19.0 var accel = 19.0
var deaccel = 14.0 var deaccel = 14.0
var sharp_turn_threshhold = 140 var sharp_turn_threshold = 140
var max_speed = 3.1 var max_speed = 3.1
var on_floor = false var on_floor = false
@ -34,7 +34,7 @@ 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 n = p_target # Normal
var t = n.cross(current_gn).normalized() var t = n.cross(current_gn).normalized()
var x = n.dot(p_facing) var x = n.dot(p_facing)
@ -42,7 +42,7 @@ func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
var ang = atan2(y,x) var ang = atan2(y,x)
if (abs(ang) < 0.001): # too small if (abs(ang) < 0.001): # Too small
return p_facing return p_facing
var s = sign(ang) var s = sign(ang)
@ -59,22 +59,22 @@ func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
func _integrate_forces(state): func _integrate_forces(state):
var lv = state.get_linear_velocity() # linear velocity var lv = state.get_linear_velocity() # Linear velocity
var g = state.get_total_gravity() var g = state.get_total_gravity()
var delta = state.get_step() var delta = state.get_step()
# var d = 1.0 - delta*state.get_total_density() # var d = 1.0 - delta*state.get_total_density()
# if (d < 0): # if (d < 0):
# d = 0 # d = 0
lv += g*delta # apply gravity lv += g*delta # Apply gravity
var anim = ANIM_FLOOR var anim = ANIM_FLOOR
var up = -g.normalized() # (up is against gravity) var up = -g.normalized() # (up is against gravity)
var vv = up.dot(lv) # vertical velocity 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 hdir = hv.normalized() # Horizontal direction
var hspeed = hv.length() # horizontal speed var hspeed = hv.length() # Horizontal speed
var floor_velocity var floor_velocity
var onfloor = false var onfloor = false
@ -90,7 +90,7 @@ func _integrate_forces(state):
floor_velocity = state.get_contact_collider_velocity_at_pos(i) floor_velocity = state.get_contact_collider_velocity_at_pos(i)
break break
var dir = Vector3() # where does the player intend to walk to var dir = Vector3() # Where does the player intend to walk to
var cam_xform = get_node("target/camera").get_global_transform() var cam_xform = get_node("target/camera").get_global_transform()
if (Input.is_action_pressed("move_forward")): if (Input.is_action_pressed("move_forward")):
@ -108,7 +108,7 @@ func _integrate_forces(state):
var target_dir = (dir - up*dir.dot(up)).normalized() var target_dir = (dir - up*dir.dot(up)).normalized()
if (onfloor): if (onfloor):
var sharp_turn = hspeed > 0.1 and rad2deg(acos(target_dir.dot(hdir))) > sharp_turn_threshhold var sharp_turn = hspeed > 0.1 and rad2deg(acos(target_dir.dot(hdir))) > sharp_turn_threshold
if (dir.length() > 0.1 and !sharp_turn): if (dir.length() > 0.1 and !sharp_turn):
if (hspeed > 0.001): if (hspeed > 0.001):
@ -171,7 +171,7 @@ func _integrate_forces(state):
#lv += floor_velocity #lv += floor_velocity
last_floor_velocity = floor_velocity last_floor_velocity = floor_velocity
else: else:
if (on_floor) : if (on_floor):
#if (keep_jump_inertia): #if (keep_jump_inertia):
# lv += last_floor_velocity # lv += last_floor_velocity
pass pass
@ -194,7 +194,7 @@ func _integrate_forces(state):
bullet.set_transform(get_node("Armature/bullet").get_global_transform().orthonormalized()) bullet.set_transform(get_node("Armature/bullet").get_global_transform().orthonormalized())
get_parent().add_child(bullet) get_parent().add_child(bullet)
bullet.set_linear_velocity(get_node("Armature/bullet").get_global_transform().basis[2].normalized()*20) bullet.set_linear_velocity(get_node("Armature/bullet").get_global_transform().basis[2].normalized()*20)
PS.body_add_collision_exception(bullet.get_rid(), get_rid()) # add it to bullet PS.body_add_collision_exception(bullet.get_rid(), get_rid()) # Add it to bullet
get_node("sfx").play("shoot") get_node("sfx").play("shoot")
prev_shoot = shoot_attempt prev_shoot = shoot_attempt

View File

@ -1,7 +1,7 @@
extends Control extends Control
# member variables # Member variables
var town = null var town = null

View File

@ -1,7 +1,7 @@
extends Camera extends Camera
# member variables # Member variables
var collision_exception = [] var collision_exception = []
export var min_distance = 0.5 export var min_distance = 0.5
export var max_distance = 4.0 export var max_distance = 4.0
@ -19,15 +19,15 @@ func _fixed_process(dt):
var delta = pos - target var delta = pos - target
# regular delta follow # Regular delta follow
# check ranges # Check ranges
if (delta.length() < min_distance): if (delta.length() < min_distance):
delta = delta.normalized()*min_distance delta = delta.normalized()*min_distance
elif (delta.length() > max_distance): elif (delta.length() > max_distance):
delta = delta.normalized()*max_distance delta = delta.normalized()*max_distance
# check upper and lower height # Check upper and lower height
if ( delta.y > max_height): if ( delta.y > max_height):
delta.y = max_height delta.y = max_height
if ( delta.y < min_height): if ( delta.y < min_height):
@ -37,14 +37,14 @@ func _fixed_process(dt):
look_at_from_pos(pos, target, up) look_at_from_pos(pos, target, up)
# turn a little up or down # Turn a little up or down
var t = get_transform() var t = get_transform()
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
set_transform(t) set_transform(t)
func _ready(): func _ready():
# find collision exceptions for ray # Find collision exceptions for ray
var node = self var node = self
while(node): while(node):
if (node extends RigidBody): if (node extends RigidBody):
@ -53,5 +53,5 @@ func _ready():
else: else:
node = node.get_parent() node = node.get_parent()
set_fixed_process(true) set_fixed_process(true)
# this detaches the camera transform from the parent spatial node # This detaches the camera transform from the parent spatial node
set_as_toplevel(true) set_as_toplevel(true)

View File

@ -1,7 +1,7 @@
extends VehicleBody extends VehicleBody
# member variables # Member variables
const STEER_SPEED = 1 const STEER_SPEED = 1
const STEER_LIMIT = 0.4 const STEER_LIMIT = 0.4

View File

@ -3,12 +3,12 @@ extends ColorPickerButton
func get_drag_data(pos): func get_drag_data(pos):
# use another colorpicker as drag preview # Use another colorpicker as drag preview
var cpb = ColorPickerButton.new() var cpb = ColorPickerButton.new()
cpb.set_color(get_color()) cpb.set_color(get_color())
cpb.set_size(Vector2(50, 50)) cpb.set_size(Vector2(50, 50))
set_drag_preview(cpb) set_drag_preview(cpb)
# return color as drag data # Return color as drag data
return get_color() return get_color()

View File

@ -1,3 +1,6 @@
extends Control
# Note for the reader: # Note for the reader:
# #
# This demo conveniently uses the same names for actions and for the container nodes # This demo conveniently uses the same names for actions and for the container nodes
@ -9,9 +12,7 @@
# action and the node, e.g.: # action and the node, e.g.:
# button.connect("pressed", self, "wait_for_input", [ button, action ]) # button.connect("pressed", self, "wait_for_input", [ button, action ])
extends Control # Member variables
# member variables
var player_actions = [ "move_up", "move_down", "move_left", "move_right", "jump" ] var player_actions = [ "move_up", "move_down", "move_left", "move_right", "jump" ]
var action # To register the action the UI is currently handling var action # To register the action the UI is currently handling
var button # Button node corresponding to the above action var button # Button node corresponding to the above action

View File

@ -10,7 +10,7 @@ func _goto_scene():
func _on_system_pressed(): func _on_system_pressed():
# will autodetect based on system, then fall back # Will autodetect based on system, then fall back
# to english if not found # to english if not found
_goto_scene() _goto_scene()

View File

@ -1,6 +1,6 @@
extends Node extends Node
# member variables # Member variables
var current_scene = null var current_scene = null
@ -34,7 +34,7 @@ func _deferred_goto_scene(path):
func _ready(): func _ready():
# Get the current scene, the first time. # Get the current scene, the first time.
# it is always the last child of root, # It is always the last child of root,
# after the autoloaded nodes. # after the autoloaded nodes.
var root = get_tree().get_root() var root = get_tree().get_root()

View File

@ -1,7 +1,7 @@
extends Panel extends Panel
# member variables here, example: # Member variables here, example:
# var a=2 # var a=2
# var b="textvar" # var b="textvar"
@ -13,4 +13,4 @@ func _ready():
func _on_goto_scene_pressed(): func _on_goto_scene_pressed():
get_node("/root/global").goto_scene("res://scene_b.scn") get_node("/root/global").goto_scene("res://scene_b.scn")
pass # replace with function body pass # Replace with function body

View File

@ -1,7 +1,7 @@
extends Panel extends Panel
# member variables here, example: # Member variables here, example:
# var a=2 # var a=2
# var b="textvar" # var b="textvar"
@ -13,4 +13,4 @@ func _ready():
func _on_goto_scene_pressed(): func _on_goto_scene_pressed():
get_node("/root/global").goto_scene("res://scene_a.scn") get_node("/root/global").goto_scene("res://scene_a.scn")
pass # replace with function body pass # Replace with function body

View File

@ -8,7 +8,7 @@ extends Node2D
# #
# Licensed under the MIT license # Licensed under the MIT license
# member variables # Member variables
var joy_num var joy_num
var cur_joy var cur_joy
var axis_value var axis_value
@ -16,21 +16,21 @@ var btn_state
func _input(event): func _input(event):
# get the joystick device number from the spinbox # Get the joystick device number from the spinbox
joy_num = get_node("joy_num").get_value() joy_num = get_node("joy_num").get_value()
# display the name of the joystick if we haven't already # Display the name of the joystick if we haven't already
if joy_num != cur_joy: if joy_num != cur_joy:
cur_joy = joy_num cur_joy = joy_num
get_node("joy_name").set_text(Input.get_joy_name(joy_num)) get_node("joy_name").set_text(Input.get_joy_name(joy_num))
# loop through the axes and show their current values # Loop through the axes and show their current values
for axis in range(0, 8): for axis in range(0, 8):
axis_value = Input.get_joy_axis(joy_num, axis) axis_value = Input.get_joy_axis(joy_num, axis)
get_node("axis_prog" + str(axis)).set_value(100*axis_value) get_node("axis_prog" + str(axis)).set_value(100*axis_value)
get_node("axis_val" + str(axis)).set_text(str(axis_value)) get_node("axis_val" + str(axis)).set_text(str(axis_value))
# loop through the buttons and highlight the ones that are pressed # Loop through the buttons and highlight the ones that are pressed
for btn in range(0, 17): for btn in range(0, 17):
btn_state = 1 btn_state = 1
if (Input.is_joy_button_pressed(joy_num, btn)): if (Input.is_joy_button_pressed(joy_num, btn)):

View File

@ -1,7 +1,7 @@
extends VBoxContainer extends VBoxContainer
# member variables # Member variables
var regex = RegEx.new() var regex = RegEx.new()

View File

@ -1,7 +1,7 @@
extends Panel extends Panel
# member variables here, example: # Member variables here, example:
# var a=2 # var a=2
# var b="textvar" # var b="textvar"
@ -13,4 +13,4 @@ func _ready():
func _on_goto_scene_pressed(): func _on_goto_scene_pressed():
get_tree().change_scene("res://scene_b.scn") get_tree().change_scene("res://scene_b.scn")
pass # replace with function body pass # Replace with function body

View File

@ -1,7 +1,7 @@
extends Panel extends Panel
# member variables here, example: # Member variables here, example:
# var a=2 # var a=2
# var b="textvar" # var b="textvar"
@ -13,4 +13,4 @@ func _ready():
func _on_goto_scene_pressed(): func _on_goto_scene_pressed():
get_tree().change_scene("res://scene_a.scn") get_tree().change_scene("res://scene_a.scn")
pass # replace with function body pass # Replace with function body

View File

@ -1,31 +1,31 @@
extends Node2D extends Node2D
# member variables # Member variables
var thread = Thread.new() var thread = Thread.new()
# this function runs in a thread! # This function runs in a thread!
# threads always take one userdata argument # Threads always take one userdata argument
func _bg_load(path): func _bg_load(path):
print("THREAD FUNC!") print("THREAD FUNC!")
# load the resource # Load the resource
var tex = ResourceLoader.load(path) var tex = ResourceLoader.load(path)
# call _bg_load_done on main thread # Call _bg_load_done on main thread
call_deferred("_bg_load_done") call_deferred("_bg_load_done")
return tex # return it return tex # return it
func _bg_load_done(): func _bg_load_done():
# wait for the thread to complete, get the returned value # Wait for the thread to complete, get the returned value
var tex = thread.wait_to_finish() var tex = thread.wait_to_finish()
# set to the sprite # Set to the sprite
get_node("sprite").set_texture(tex) get_node("sprite").set_texture(tex)
func _on_load_pressed(): func _on_load_pressed():
if (thread.is_active()): if (thread.is_active()):
# already working # Already working
return return
print("START THREAD!") print("START THREAD!")
thread.start(self, "_bg_load", "res://mona.png") thread.start(self, "_bg_load", "res://mona.png")

View File

@ -1,7 +1,7 @@
extends Control extends Control
# member variables # Member variables
var trans = ["linear", "sine", "quint", "quart", "quad", "expo", "elastic", "cubic", "circ", "bounce", "back"] var trans = ["linear", "sine", "quint", "quart", "quad", "expo", "elastic", "cubic", "circ", "bounce", "back"]
var eases = ["in", "out", "in_out", "out_in"] var eases = ["in", "out", "in_out", "out_in"]
var modes = ["move", "color", "scale", "rotate", "callback", "follow", "repeat", "pause"] var modes = ["move", "color", "scale", "rotate", "callback", "follow", "repeat", "pause"]

View File

@ -5,7 +5,7 @@ extends Panel
# (UDP can lose packets and you won't normally find out, so don't do a chat this way) # (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. # This is just a demo that shows how to use the UDP class.
# member variables # Member variables
var udp = PacketPeerUDP.new() var udp = PacketPeerUDP.new()

View File

@ -1,7 +1,7 @@
extends Control extends Control
# member variables # Member variables
var mousepos var mousepos

View File

@ -1,7 +1,7 @@
extends Spatial extends Spatial
# member variables # Member variables
var r_pos = Vector2() var r_pos = Vector2()
var state var state

View File

@ -1,45 +1,45 @@
extends Node2D extends Node2D
# member variables # Member variables
const INITIAL_BALL_SPEED = 80 const INITIAL_BALL_SPEED = 80
var ball_speed = INITIAL_BALL_SPEED var ball_speed = INITIAL_BALL_SPEED
var screen_size = Vector2(640,400) var screen_size = Vector2(640, 400)
# default ball direction # Default ball direction
var direction = Vector2(-1,0) var direction = Vector2(-1, 0)
var pad_size = Vector2(8,32) var pad_size = Vector2(8, 32)
const PAD_SPEED = 150 const PAD_SPEED = 150
func _process(delta): func _process(delta):
# get ball position and pad rectangles # Get ball position and pad rectangles
var ball_pos = get_node("ball").get_pos() var ball_pos = get_node("ball").get_pos()
var left_rect = Rect2(get_node("left").get_pos() - pad_size*0.5, pad_size) 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) var right_rect = Rect2(get_node("right").get_pos() - pad_size*0.5, pad_size)
# integrate new ball postion # Integrate new ball postion
ball_pos += direction*ball_speed*delta ball_pos += direction*ball_speed*delta
# flip when touching roof or floor # Flip when touching roof or floor
if ((ball_pos.y < 0 and direction.y < 0) or (ball_pos.y > screen_size.y and direction.y > 0)): if ((ball_pos.y < 0 and direction.y < 0) or (ball_pos.y > screen_size.y and direction.y > 0)):
direction.y = -direction.y direction.y = -direction.y
# flip, change direction and increase speed when touching pads # Flip, change direction and increase speed when touching pads
if ((left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)): if ((left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)):
direction.x = -direction.x direction.x = -direction.x
ball_speed *= 1.1 ball_speed *= 1.1
direction.y = randf()*2.0 - 1 direction.y = randf()*2.0 - 1
direction = direction.normalized() direction = direction.normalized()
# check gameover # Check gameover
if (ball_pos.x < 0 or ball_pos.x > screen_size.x): if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
ball_pos = screen_size*0.5 ball_pos = screen_size*0.5
ball_speed = INITIAL_BALL_SPEED ball_speed = INITIAL_BALL_SPEED
direction = Vector2(-1,0) direction = Vector2(-1, 0)
get_node("ball").set_pos(ball_pos) get_node("ball").set_pos(ball_pos)
# move left pad # Move left pad
var left_pos = get_node("left").get_pos() var left_pos = get_node("left").get_pos()
if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")): if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
@ -49,7 +49,7 @@ func _process(delta):
get_node("left").set_pos(left_pos) get_node("left").set_pos(left_pos)
# move right pad # Move right pad
var right_pos = get_node("right").get_pos() var right_pos = get_node("right").get_pos()
if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")): if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
@ -62,6 +62,6 @@ func _process(delta):
func _ready(): func _ready():
# Initalization here # Initalization here
screen_size = get_viewport_rect().size # get actual size screen_size = get_viewport_rect().size # Get actual size
pad_size = get_node("left").get_texture().get_size() pad_size = get_node("left").get_texture().get_size()
set_process(true) set_process(true)

View File

@ -1,26 +1,26 @@
extends Spatial extends Spatial
# member variables # Member variables
var prev_pos = null var prev_pos = null
func _input(event): func _input(event):
# all other (non-mouse) events # All other (non-mouse) events
if (not event.type in [InputEvent.MOUSE_BUTTON, InputEvent.MOUSE_MOTION, InputEvent.SCREEN_DRAG, InputEvent.SCREEN_TOUCH]): if (not event.type in [InputEvent.MOUSE_BUTTON, InputEvent.MOUSE_MOTION, InputEvent.SCREEN_DRAG, InputEvent.SCREEN_TOUCH]):
get_node("viewport").input(event) get_node("viewport").input(event)
# mouse events for area # Mouse events for Area
func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx): func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
# use click pos (click in 3d space, convert to area space) # Use click pos (click in 3d space, convert to area space)
var pos = get_node("area").get_global_transform().affine_inverse()*click_pos var pos = get_node("area").get_global_transform().affine_inverse()*click_pos
# convert to 2D # Convert to 2D
pos = Vector2(pos.x, pos.y) pos = Vector2(pos.x, pos.y)
# convert to viewport coordinate system # Convert to viewport coordinate system
pos.x = (pos.x + 1.5)*100 pos.x = (pos.x + 1.5)*100
pos.y = (-pos.y + 0.75)*100 pos.y = (-pos.y + 0.75)*100
# set to event # Set to event
event.pos = pos event.pos = pos
event.global_pos = pos event.global_pos = pos
if (prev_pos == null): if (prev_pos == null):
@ -28,7 +28,7 @@ func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
if (event.type == InputEvent.MOUSE_MOTION): if (event.type == InputEvent.MOUSE_MOTION):
event.relative_pos = pos - prev_pos event.relative_pos = pos - prev_pos
prev_pos = pos prev_pos = pos
# sned the event to the viewport # Send the event to the viewport
get_node("viewport").input(event) get_node("viewport").input(event)

View File

@ -4,13 +4,13 @@ extends Control
func _on_button_pressed(): func _on_button_pressed():
get_viewport().queue_screen_capture() get_viewport().queue_screen_capture()
# let two frames pass to make sure the screen was captured # Let two frames pass to make sure the screen was captured
yield(get_tree(),"idle_frame") yield(get_tree(), "idle_frame")
yield(get_tree(),"idle_frame") yield(get_tree(), "idle_frame")
# retrieve the captured image # Retrieve the captured image
var img = get_viewport().get_screen_capture() var img = get_viewport().get_screen_capture()
# create a texture for it # Create a texture for it
var tex = ImageTexture.new() var tex = ImageTexture.new()
tex.create_from_image(img) tex.create_from_image(img)
# set it to the capture node # Set it to the capture node
get_node("capture").set_texture(tex) get_node("capture").set_texture(tex)