Use upper-cased first letter at the start of comment sentences
This commit is contained in:
parent
8639cecf4c
commit
8c4f19e79d
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends KinematicBody
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var g = -9.8
|
||||
var vel = Vector3()
|
||||
const MAX_SPEED = 5
|
||||
|
@ -12,7 +12,7 @@ const MAX_SLOPE_ANGLE = 30
|
|||
|
||||
|
||||
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()
|
||||
|
||||
if (Input.is_action_pressed("move_forward")):
|
||||
|
@ -55,7 +55,7 @@ func _fixed_process(delta):
|
|||
var n = get_collision_normal()
|
||||
|
||||
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
|
||||
floor_velocity = get_collider_velocity()
|
||||
on_floor = true
|
||||
|
@ -63,7 +63,7 @@ func _fixed_process(delta):
|
|||
motion = n.slide(motion)
|
||||
vel = n.slide(vel)
|
||||
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)
|
||||
if (motion.length() < 0.001):
|
||||
break
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Camera
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var collision_exception = []
|
||||
export var min_distance = 0.5
|
||||
export var max_distance = 4.0
|
||||
|
@ -19,15 +19,15 @@ func _fixed_process(dt):
|
|||
|
||||
var delta = pos - target
|
||||
|
||||
# regular delta follow
|
||||
# Regular delta follow
|
||||
|
||||
# check ranges
|
||||
# Check ranges
|
||||
if (delta.length() < min_distance):
|
||||
delta = delta.normalized()*min_distance
|
||||
elif (delta.length() > max_distance):
|
||||
delta = delta.normalized()*max_distance
|
||||
|
||||
# check upper and lower height
|
||||
# Check upper and lower height
|
||||
if (delta.y > max_height):
|
||||
delta.y = max_height
|
||||
if (delta.y < min_height):
|
||||
|
@ -37,14 +37,14 @@ func _fixed_process(dt):
|
|||
|
||||
look_at_from_pos(pos, target, up)
|
||||
|
||||
# turn a little up or down
|
||||
# Turn a little up or down
|
||||
var t = get_transform()
|
||||
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
||||
set_transform(t)
|
||||
|
||||
|
||||
func _ready():
|
||||
# find collision exceptions for ray
|
||||
# Find collision exceptions for ray
|
||||
var node = self
|
||||
while(node):
|
||||
if (node extends RigidBody):
|
||||
|
@ -53,5 +53,5 @@ func _ready():
|
|||
else:
|
||||
node = node.get_parent()
|
||||
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)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends RigidBody
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var gray_mat = FixedMaterial.new()
|
||||
var selected = false
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Navigation
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
const SPEED = 4.0
|
||||
|
||||
var camrot = 0.0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
extends RigidBody
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var disabled = false
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Area
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var taken = false
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends RigidBody
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
const STATE_WALKING = 0
|
||||
const STATE_DYING = 1
|
||||
|
||||
|
@ -20,7 +20,7 @@ func _integrate_forces(state):
|
|||
var lv = state.get_linear_velocity()
|
||||
var g = state.get_total_gravity()
|
||||
|
||||
lv += g*delta # apply gravity
|
||||
lv += g*delta # Apply gravity
|
||||
var up = -g.normalized()
|
||||
|
||||
if (dying):
|
||||
|
|
|
@ -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
|
||||
|
@ -21,44 +18,41 @@ func _fixed_process(dt):
|
|||
|
||||
var delta = pos - target
|
||||
|
||||
#regular delta follow
|
||||
|
||||
#check ranges
|
||||
# Regular delta follow
|
||||
|
||||
# Check ranges
|
||||
if (delta.length() < min_distance):
|
||||
delta = delta.normalized()*min_distance
|
||||
elif (delta.length() > max_distance):
|
||||
delta = delta.normalized()*max_distance
|
||||
|
||||
#check upper and lower height
|
||||
# Check upper and lower height
|
||||
if (delta.y > max_height):
|
||||
delta.y = max_height
|
||||
if (delta.y < min_height):
|
||||
delta.y = min_height
|
||||
|
||||
#check autoturn
|
||||
|
||||
# Check autoturn
|
||||
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)
|
||||
|
||||
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
|
||||
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)
|
||||
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)
|
||||
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
|
||||
|
||||
#apply lookat
|
||||
# Apply lookat
|
||||
if (delta == Vector3()):
|
||||
delta = (pos - target).normalized()*0.0001
|
||||
|
||||
|
@ -66,16 +60,14 @@ func _fixed_process(dt):
|
|||
|
||||
look_at_from_pos(pos, target, up)
|
||||
|
||||
#turn a little up or down
|
||||
# Turn a little up or down
|
||||
var t = get_transform()
|
||||
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
||||
set_transform(t)
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
|
||||
#find collision exceptions for ray
|
||||
# Find collision exceptions for ray
|
||||
var node = self
|
||||
while(node):
|
||||
if (node extends RigidBody):
|
||||
|
@ -83,13 +75,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
|
||||
# This detaches the camera transform from the parent spatial node
|
||||
set_as_toplevel(true)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends RigidBody
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
const ANIM_FLOOR = 0
|
||||
const ANIM_AIR_UP = 1
|
||||
const ANIM_AIR_DOWN = 2
|
||||
|
@ -21,7 +21,7 @@ var keep_jump_inertia = true
|
|||
var air_idle_deaccel = false
|
||||
var accel = 19.0
|
||||
var deaccel = 14.0
|
||||
var sharp_turn_threshhold = 140
|
||||
var sharp_turn_threshold = 140
|
||||
|
||||
var max_speed = 3.1
|
||||
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):
|
||||
var n = p_target # normal
|
||||
var n = p_target # Normal
|
||||
var t = n.cross(current_gn).normalized()
|
||||
|
||||
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)
|
||||
|
||||
if (abs(ang) < 0.001): # too small
|
||||
if (abs(ang) < 0.001): # Too small
|
||||
return p_facing
|
||||
|
||||
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):
|
||||
var lv = state.get_linear_velocity() # linear velocity
|
||||
var lv = state.get_linear_velocity() # Linear velocity
|
||||
var g = state.get_total_gravity()
|
||||
var delta = state.get_step()
|
||||
# var d = 1.0 - delta*state.get_total_density()
|
||||
# if (d < 0):
|
||||
# d = 0
|
||||
lv += g*delta # apply gravity
|
||||
lv += g*delta # Apply gravity
|
||||
|
||||
var anim = ANIM_FLOOR
|
||||
|
||||
var up = -g.normalized() # (up is against gravity)
|
||||
var vv = up.dot(lv) # vertical velocity
|
||||
var hv = lv - up*vv # horizontal velocity
|
||||
var vv = up.dot(lv) # Vertical velocity
|
||||
var hv = lv - up*vv # Horizontal velocity
|
||||
|
||||
var hdir = hv.normalized() # horizontal direction
|
||||
var hspeed = hv.length() # horizontal speed
|
||||
var hdir = hv.normalized() # Horizontal direction
|
||||
var hspeed = hv.length() # Horizontal speed
|
||||
|
||||
var floor_velocity
|
||||
var onfloor = false
|
||||
|
@ -90,7 +90,7 @@ 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 dir = Vector3() # Where does the player intend to walk to
|
||||
var cam_xform = get_node("target/camera").get_global_transform()
|
||||
|
||||
if (Input.is_action_pressed("move_forward")):
|
||||
|
@ -108,7 +108,7 @@ 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
|
||||
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 (hspeed > 0.001):
|
||||
|
@ -194,7 +194,7 @@ func _integrate_forces(state):
|
|||
bullet.set_transform(get_node("Armature/bullet").get_global_transform().orthonormalized())
|
||||
get_parent().add_child(bullet)
|
||||
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")
|
||||
|
||||
prev_shoot = shoot_attempt
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Control
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var town = null
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Camera
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var collision_exception = []
|
||||
export var min_distance = 0.5
|
||||
export var max_distance = 4.0
|
||||
|
@ -19,15 +19,15 @@ func _fixed_process(dt):
|
|||
|
||||
var delta = pos - target
|
||||
|
||||
# regular delta follow
|
||||
# Regular delta follow
|
||||
|
||||
# check ranges
|
||||
# Check ranges
|
||||
if (delta.length() < min_distance):
|
||||
delta = delta.normalized()*min_distance
|
||||
elif (delta.length() > max_distance):
|
||||
delta = delta.normalized()*max_distance
|
||||
|
||||
# check upper and lower height
|
||||
# Check upper and lower height
|
||||
if ( delta.y > max_height):
|
||||
delta.y = max_height
|
||||
if ( delta.y < min_height):
|
||||
|
@ -37,14 +37,14 @@ func _fixed_process(dt):
|
|||
|
||||
look_at_from_pos(pos, target, up)
|
||||
|
||||
# turn a little up or down
|
||||
# Turn a little up or down
|
||||
var t = get_transform()
|
||||
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
||||
set_transform(t)
|
||||
|
||||
|
||||
func _ready():
|
||||
# find collision exceptions for ray
|
||||
# Find collision exceptions for ray
|
||||
var node = self
|
||||
while(node):
|
||||
if (node extends RigidBody):
|
||||
|
@ -53,5 +53,5 @@ func _ready():
|
|||
else:
|
||||
node = node.get_parent()
|
||||
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)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends VehicleBody
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
const STEER_SPEED = 1
|
||||
const STEER_LIMIT = 0.4
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@ extends ColorPickerButton
|
|||
|
||||
|
||||
func get_drag_data(pos):
|
||||
# use another colorpicker as drag preview
|
||||
# Use another colorpicker as drag preview
|
||||
var cpb = ColorPickerButton.new()
|
||||
cpb.set_color(get_color())
|
||||
cpb.set_size(Vector2(50, 50))
|
||||
set_drag_preview(cpb)
|
||||
# return color as drag data
|
||||
# Return color as drag data
|
||||
return get_color()
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
|
||||
extends Control
|
||||
|
||||
# Note for the reader:
|
||||
#
|
||||
# This demo conveniently uses the same names for actions and for the container nodes
|
||||
|
@ -9,9 +12,7 @@
|
|||
# action and the node, e.g.:
|
||||
# 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 action # To register the action the UI is currently handling
|
||||
var button # Button node corresponding to the above action
|
||||
|
|
|
@ -10,7 +10,7 @@ func _goto_scene():
|
|||
|
||||
|
||||
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
|
||||
_goto_scene()
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
extends Node
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var current_scene = null
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ func _deferred_goto_scene(path):
|
|||
|
||||
func _ready():
|
||||
# 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.
|
||||
|
||||
var root = get_tree().get_root()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Panel
|
||||
|
||||
# member variables here, example:
|
||||
# Member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
|
@ -13,4 +13,4 @@ func _ready():
|
|||
|
||||
func _on_goto_scene_pressed():
|
||||
get_node("/root/global").goto_scene("res://scene_b.scn")
|
||||
pass # replace with function body
|
||||
pass # Replace with function body
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Panel
|
||||
|
||||
# member variables here, example:
|
||||
# Member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
|
@ -13,4 +13,4 @@ func _ready():
|
|||
|
||||
func _on_goto_scene_pressed():
|
||||
get_node("/root/global").goto_scene("res://scene_a.scn")
|
||||
pass # replace with function body
|
||||
pass # Replace with function body
|
||||
|
|
|
@ -8,7 +8,7 @@ extends Node2D
|
|||
#
|
||||
# Licensed under the MIT license
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var joy_num
|
||||
var cur_joy
|
||||
var axis_value
|
||||
|
@ -16,21 +16,21 @@ var btn_state
|
|||
|
||||
|
||||
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()
|
||||
|
||||
# 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:
|
||||
cur_joy = 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):
|
||||
axis_value = Input.get_joy_axis(joy_num, axis)
|
||||
get_node("axis_prog" + str(axis)).set_value(100*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):
|
||||
btn_state = 1
|
||||
if (Input.is_joy_button_pressed(joy_num, btn)):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends VBoxContainer
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var regex = RegEx.new()
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Panel
|
||||
|
||||
# member variables here, example:
|
||||
# Member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
|
@ -13,4 +13,4 @@ func _ready():
|
|||
|
||||
func _on_goto_scene_pressed():
|
||||
get_tree().change_scene("res://scene_b.scn")
|
||||
pass # replace with function body
|
||||
pass # Replace with function body
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Panel
|
||||
|
||||
# member variables here, example:
|
||||
# Member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
|
@ -13,4 +13,4 @@ func _ready():
|
|||
|
||||
func _on_goto_scene_pressed():
|
||||
get_tree().change_scene("res://scene_a.scn")
|
||||
pass # replace with function body
|
||||
pass # Replace with function body
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
|
||||
extends Node2D
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var thread = Thread.new()
|
||||
|
||||
|
||||
# this function runs in a thread!
|
||||
# threads always take one userdata argument
|
||||
# This function runs in a thread!
|
||||
# Threads always take one userdata argument
|
||||
func _bg_load(path):
|
||||
print("THREAD FUNC!")
|
||||
# load the resource
|
||||
# Load the resource
|
||||
var tex = ResourceLoader.load(path)
|
||||
# call _bg_load_done on main thread
|
||||
# Call _bg_load_done on main thread
|
||||
call_deferred("_bg_load_done")
|
||||
return tex # return it
|
||||
|
||||
|
||||
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()
|
||||
# set to the sprite
|
||||
# Set to the sprite
|
||||
get_node("sprite").set_texture(tex)
|
||||
|
||||
|
||||
func _on_load_pressed():
|
||||
if (thread.is_active()):
|
||||
# already working
|
||||
# Already working
|
||||
return
|
||||
print("START THREAD!")
|
||||
thread.start(self, "_bg_load", "res://mona.png")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Control
|
||||
|
||||
# member variables
|
||||
# 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"]
|
||||
|
|
|
@ -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)
|
||||
# This is just a demo that shows how to use the UDP class.
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var udp = PacketPeerUDP.new()
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Control
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var mousepos
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
extends Spatial
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var r_pos = Vector2()
|
||||
var state
|
||||
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
|
||||
extends Node2D
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
const INITIAL_BALL_SPEED = 80
|
||||
var ball_speed = INITIAL_BALL_SPEED
|
||||
var screen_size = Vector2(640, 400)
|
||||
# default ball direction
|
||||
# Default ball direction
|
||||
var direction = Vector2(-1, 0)
|
||||
var pad_size = Vector2(8, 32)
|
||||
const PAD_SPEED = 150
|
||||
|
||||
|
||||
func _process(delta):
|
||||
# get ball position 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)
|
||||
|
||||
# integrate new ball postion
|
||||
# Integrate new ball postion
|
||||
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)):
|
||||
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)):
|
||||
direction.x = -direction.x
|
||||
ball_speed *= 1.1
|
||||
direction.y = randf()*2.0 - 1
|
||||
direction = direction.normalized()
|
||||
|
||||
# check gameover
|
||||
# Check gameover
|
||||
if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
|
||||
ball_pos = screen_size*0.5
|
||||
ball_speed = INITIAL_BALL_SPEED
|
||||
|
@ -39,7 +39,7 @@ func _process(delta):
|
|||
|
||||
get_node("ball").set_pos(ball_pos)
|
||||
|
||||
# move left pad
|
||||
# Move left pad
|
||||
var left_pos = get_node("left").get_pos()
|
||||
|
||||
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)
|
||||
|
||||
# move right pad
|
||||
# Move right pad
|
||||
var right_pos = get_node("right").get_pos()
|
||||
|
||||
if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
|
||||
|
@ -62,6 +62,6 @@ func _process(delta):
|
|||
|
||||
func _ready():
|
||||
# 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()
|
||||
set_process(true)
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
|
||||
extends Spatial
|
||||
|
||||
# member variables
|
||||
# Member variables
|
||||
var prev_pos = null
|
||||
|
||||
|
||||
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]):
|
||||
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):
|
||||
# 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
|
||||
# convert to 2D
|
||||
# Convert to 2D
|
||||
pos = Vector2(pos.x, pos.y)
|
||||
# convert to viewport coordinate system
|
||||
# Convert to viewport coordinate system
|
||||
pos.x = (pos.x + 1.5)*100
|
||||
pos.y = (-pos.y + 0.75)*100
|
||||
# set to event
|
||||
# Set to event
|
||||
event.pos = pos
|
||||
event.global_pos = pos
|
||||
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):
|
||||
event.relative_pos = pos - prev_pos
|
||||
prev_pos = pos
|
||||
# sned the event to the viewport
|
||||
# Send the event to the viewport
|
||||
get_node("viewport").input(event)
|
||||
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ extends Control
|
|||
|
||||
func _on_button_pressed():
|
||||
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")
|
||||
# retrieve the captured image
|
||||
# Retrieve the captured image
|
||||
var img = get_viewport().get_screen_capture()
|
||||
# create a texture for it
|
||||
# Create a texture for it
|
||||
var tex = ImageTexture.new()
|
||||
tex.create_from_image(img)
|
||||
# set it to the capture node
|
||||
# Set it to the capture node
|
||||
get_node("capture").set_texture(tex)
|
||||
|
|
Loading…
Reference in New Issue