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 extends KinematicBody
# member variables here, example: # member variables
# var a=2
# var b="textvar"
var g = -9.8 var g = -9.8
var vel = Vector3() var vel = Vector3()
const MAX_SPEED = 5 const MAX_SPEED = 5
@ -13,83 +10,78 @@ const ACCEL= 2
const DEACCEL= 4 const DEACCEL= 4
const MAX_SLOPE_ANGLE = 30 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")):
dir+=-cam_xform.basis[2] dir += -cam_xform.basis[2]
if (Input.is_action_pressed("move_backwards")): if (Input.is_action_pressed("move_backwards")):
dir+=cam_xform.basis[2] dir += cam_xform.basis[2]
if (Input.is_action_pressed("move_left")): if (Input.is_action_pressed("move_left")):
dir+=-cam_xform.basis[0] dir += -cam_xform.basis[0]
if (Input.is_action_pressed("move_right")): if (Input.is_action_pressed("move_right")):
dir+=cam_xform.basis[0] dir += cam_xform.basis[0]
dir.y=0 dir.y = 0
dir=dir.normalized() dir = dir.normalized()
vel.y+=delta*g vel.y += delta*g
var hvel = vel var hvel = vel
hvel.y=0 hvel.y = 0
var target = dir*MAX_SPEED var target = dir*MAX_SPEED
var accel var accel
if (dir.dot(hvel) >0): if (dir.dot(hvel) > 0):
accel=ACCEL accel = ACCEL
else: else:
accel=DEACCEL accel = DEACCEL
hvel = hvel.linear_interpolate(target,accel*delta) hvel = hvel.linear_interpolate(target, accel*delta)
vel.x = hvel.x
vel.z = hvel.z
vel.x=hvel.x;
vel.z=hvel.z
var motion = move(vel*delta) var motion = move(vel*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
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
attempts-=1 attempts -= 1
if (on_floor and floor_velocity!=Vector3()): if (on_floor and floor_velocity != Vector3()):
move(floor_velocity*delta) move(floor_velocity*delta)
if (on_floor and Input.is_action_pressed("jump")): if (on_floor and Input.is_action_pressed("jump")):
vel.y=JUMP_SPEED vel.y = JUMP_SPEED
var crid = get_node("../elevator1").get_rid() var crid = get_node("../elevator1").get_rid()
# print(crid," : ",PS.body_get_state(crid,PS.BODY_STATE_TRANSFORM))
func _ready(): func _ready():
# Initalization here # Initalization here
set_fixed_process(true) set_fixed_process(true)
pass
func _on_tcube_body_enter( body ): func _on_tcube_body_enter(body):
get_node("../ty").show() get_node("../ty").show()
pass # replace with function body

View File

@ -1,69 +1,57 @@
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
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)

Binary file not shown.

View File

@ -1,15 +1,12 @@
extends RigidBody extends RigidBody
# member variables here, example: # member variables
# var a=2
# var b="textvar"
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):
if (event.type==InputEvent.MOUSE_BUTTON and event.pressed): if (event.type==InputEvent.MOUSE_BUTTON and event.pressed):
if (not selected): if (not selected):
get_node("mesh").set_material_override(gray_mat) get_node("mesh").set_material_override(gray_mat)
@ -17,16 +14,11 @@ func _input_event(camera,event,pos,normal,shape):
get_node("mesh").set_material_override(null) get_node("mesh").set_material_override(null)
selected = not selected selected = not selected
func _mouse_enter(): func _mouse_enter():
get_node("mesh").set_scale( Vector3(1.1,1.1,1.1) ) get_node("mesh").set_scale(Vector3(1.1, 1.1, 1.1))
func _mouse_exit(): func _mouse_exit():
get_node("mesh").set_scale( Vector3(1,1,1) ) get_node("mesh").set_scale(Vector3(1, 1, 1))
func _ready():
# Initalization here
pass

View File

@ -1,61 +1,54 @@
extends Navigation extends Navigation
# member variables here, example: # member variables
# var a=2 const SPEED = 4.0
# var b="textvar"
const SPEED=4.0 var camrot = 0.0
var camrot=0.0 var begin = Vector3()
var end = Vector3()
var begin=Vector3()
var end=Vector3()
var m = FixedMaterial.new() var m = FixedMaterial.new()
var path=[] var path = []
var draw_path=false
func _process(delta): func _process(delta):
if (path.size() > 1):
if (path.size()>1):
var to_walk = delta*SPEED var to_walk = delta*SPEED
var to_watch = Vector3(0,1,0) var to_watch = Vector3(0, 1, 0)
while(to_walk>0 and path.size()>=2): while(to_walk > 0 and path.size() >= 2):
var pfrom = path[path.size()-1] var pfrom = path[path.size() - 1]
var pto = path[path.size()-2] var pto = path[path.size() - 2]
to_watch = (pto - pfrom).normalized() to_watch = (pto - pfrom).normalized()
var d = pfrom.distance_to(pto) var d = pfrom.distance_to(pto)
if (d<=to_walk): if (d <= to_walk):
path.remove(path.size()-1) path.remove(path.size() - 1)
to_walk-=d to_walk -= d
else: else:
path[path.size()-1] = pfrom.linear_interpolate(pto,to_walk/d) path[path.size() - 1] = pfrom.linear_interpolate(pto, to_walk/d)
to_walk=0 to_walk = 0
var atpos = path[path.size()-1] var atpos = path[path.size() - 1]
var atdir = to_watch var atdir = to_watch
atdir.y=0 atdir.y = 0
var t = Transform() var t = Transform()
t.origin=atpos t.origin = atpos
t=t.looking_at(atpos+atdir,Vector3(0,1,0)) t=t.looking_at(atpos + atdir, Vector3(0, 1, 0))
get_node("robot_base").set_transform(t) get_node("robot_base").set_transform(t)
if (path.size()<2): if (path.size() < 2):
path=[] path = []
set_process(false) set_process(false)
else: else:
set_process(false) set_process(false)
var draw_path=false
func _update_path(): func _update_path():
var p = get_simple_path(begin, end, true)
var p = get_simple_path(begin,end,true) path = Array(p) # Vector3array too complex to use, convert to regular array
path=Array(p) # Vector3array to complex to use, convert to regular array
path.invert() path.invert()
set_process(true) set_process(true)
@ -63,48 +56,41 @@ func _update_path():
var im = get_node("draw") var im = get_node("draw")
im.set_material_override(m) im.set_material_override(m)
im.clear() im.clear()
im.begin(Mesh.PRIMITIVE_POINTS,null) im.begin(Mesh.PRIMITIVE_POINTS, null)
im.add_vertex(begin) im.add_vertex(begin)
im.add_vertex(end) im.add_vertex(end)
im.end() im.end()
im.begin(Mesh.PRIMITIVE_LINE_STRIP,null) im.begin(Mesh.PRIMITIVE_LINE_STRIP, null)
for x in p: for x in p:
im.add_vertex(x) im.add_vertex(x)
im.end() im.end()
func _input(ev):
if (ev.type==InputEvent.MOUSE_BUTTON and ev.button_index==BUTTON_LEFT and ev.pressed): 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(ev.pos) var from = get_node("cambase/Camera").project_ray_origin(event.pos)
var to = from+get_node("cambase/Camera").project_ray_normal(ev.pos)*100 var to = from + get_node("cambase/Camera").project_ray_normal(event.pos)*100
var p = get_closest_point_to_segment(from,to) var p = get_closest_point_to_segment(from, to)
begin=get_closest_point(get_node("robot_base").get_translation()) begin = get_closest_point(get_node("robot_base").get_translation())
end=p end = p
_update_path() _update_path()
if (ev.type==InputEvent.MOUSE_MOTION): if (event.type == InputEvent.MOUSE_MOTION):
if (ev.button_mask&BUTTON_MASK_MIDDLE): if (event.button_mask&BUTTON_MASK_MIDDLE):
camrot += event.relative_x*0.005
camrot+=ev.relative_x*0.005 get_node("cambase").set_rotation(Vector3(0, camrot, 0))
get_node("cambase").set_rotation(Vector3(0,camrot,0))
print("camrot ", camrot) print("camrot ", camrot)
func _ready(): func _ready():
# Initalization here # Initalization here
set_process_input(true) set_process_input(true)
m.set_line_width(3) m.set_line_width(3)
m.set_point_size(3) m.set_point_size(3)
m.set_fixed_flag(FixedMaterial.FLAG_USE_POINT_SIZE,true) m.set_fixed_flag(FixedMaterial.FLAG_USE_POINT_SIZE, true)
m.set_flag(Material.FLAG_UNSHADED,true) m.set_flag(Material.FLAG_UNSHADED, true)
#begin = get_closest_point(get_node("start").get_translation()) #begin = get_closest_point(get_node("start").get_translation())
#end = get_closest_point(get_node("end").get_translation()) #end = get_closest_point(get_node("end").get_translation())
#call_deferred("_update_path") #call_deferred("_update_path")
pass

Binary file not shown.

View File

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

Binary file not shown.

View File

@ -1,23 +1,11 @@
extends Area extends Area
# member variables here, example: # member variables
# var a=2
# var b="textvar"
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
func _ready():
# Initalization here
pass

Binary file not shown.

View File

@ -1,14 +1,10 @@
extends RigidBody extends RigidBody
# member variables here, example: # member variables
# var a=2
# var b="textvar"
const STATE_WALKING = 0 const STATE_WALKING = 0
const STATE_DYING = 1 const STATE_DYING = 1
var prev_advance = false var prev_advance = false
var deaccel = 20.0 var deaccel = 20.0
var accel = 5 var accel = 5
@ -16,80 +12,67 @@ var max_speed = 2
var rot_dir = 4 var rot_dir = 4
var rot_speed = 1 var rot_speed = 1
var dying=false var dying = false
func _integrate_forces(state): func _integrate_forces(state):
var delta = state.get_step() var delta = state.get_step()
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):
state.set_linear_velocity(lv) state.set_linear_velocity(lv)
return return
for i in range(state.get_contact_count()): for i in range(state.get_contact_count()):
var cc = state.get_contact_collider_object(i) var cc = state.get_contact_collider_object(i)
var dp = state.get_contact_local_normal(i) var dp = state.get_contact_local_normal(i)
if (cc): if (cc):
if (cc extends preload("res://bullet.gd") and not cc.disabled): if (cc extends preload("res://bullet.gd") and not cc.disabled):
set_mode(MODE_RIGID) set_mode(MODE_RIGID)
dying=true dying = true
#lv=s.get_contact_local_normal(i)*400 #lv = s.get_contact_local_normal(i)*400
state.set_angular_velocity( -dp.cross(up).normalized() *33.0) state.set_angular_velocity(-dp.cross(up).normalized()*33.0)
get_node("AnimationPlayer").play("impact") get_node("AnimationPlayer").play("impact")
get_node("AnimationPlayer").queue("explode") get_node("AnimationPlayer").queue("explode")
set_friction(1) set_friction(1)
cc.disabled=true cc.disabled = true
get_node("sound").play("hit") get_node("sound").play("hit")
return return
var col_floor = get_node("Armature/ray_floor").is_colliding() var col_floor = get_node("Armature/ray_floor").is_colliding()
var col_wall = get_node("Armature/ray_wall").is_colliding() var col_wall = get_node("Armature/ray_wall").is_colliding()
var advance = not col_wall and col_floor var advance = not col_wall and col_floor
var dir = get_node("Armature").get_transform().basis[2].normalized() var dir = get_node("Armature").get_transform().basis[2].normalized()
var deaccel_dir = dir var deaccel_dir = dir
if (advance): if (advance):
if (dir.dot(lv) < max_speed): if (dir.dot(lv) < max_speed):
lv+=dir * accel * delta lv += dir*accel*delta
deaccel_dir = dir.cross(g).normalized() deaccel_dir = dir.cross(g).normalized()
else: else:
if (prev_advance): if (prev_advance):
rot_dir = 1 #randf() * 2.0 -1.0 rot_dir = 1 # randf()*2.0 - 1.0
dir = Matrix3(up,rot_dir * rot_speed * delta).xform(dir)
get_node("Armature").set_transform( Transform().looking_at(-dir,up) )
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) var dspeed = deaccel_dir.dot(lv)
dspeed -= deaccel * delta dspeed -= deaccel*delta
if (dspeed<0): if (dspeed < 0):
dspeed=0 dspeed = 0
lv = lv - deaccel_dir*deaccel_dir.dot(lv) + deaccel_dir*dspeed lv = lv - deaccel_dir*deaccel_dir.dot(lv) + deaccel_dir*dspeed
state.set_linear_velocity(lv) state.set_linear_velocity(lv)
prev_advance=advance prev_advance = advance
func _ready():
# Initalization here
pass
func _die(): func _die():
queue_free() queue_free()

Binary file not shown.

View File

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

View File

@ -1,12 +1,7 @@
extends RigidBody extends RigidBody
# member variables here, example: # member variables
# var a=2
# var b="textvar"
#var dir=Vector3()
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,21 +9,21 @@ const ANIM_AIR_DOWN = 2
const SHOOT_TIME = 1.5 const SHOOT_TIME = 1.5
const SHOOT_SCALE = 2 const SHOOT_SCALE = 2
const CHAR_SCALE = Vector3(0.3,0.3,0.3) 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_threshhold = 140
var max_speed=3.1 var max_speed = 3.1
var on_floor = false var on_floor = false
var prev_shoot = false var prev_shoot = false
@ -37,8 +32,8 @@ var last_floor_velocity = Vector3()
var shoot_blend = 0 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()
@ -47,47 +42,43 @@ 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)
ang = ang * s ang = ang*s
var turn = ang * p_adjust_rate * p_step var turn = ang*p_adjust_rate*p_step
var a var a
if (ang<turn): if (ang < turn):
a=ang a = ang
else: else:
a=turn a = turn
ang = (ang - a) * s 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):
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
if (state.get_contact_count() == 0): if (state.get_contact_count() == 0):
floor_velocity = last_floor_velocity floor_velocity = last_floor_velocity
else: else:
@ -98,104 +89,89 @@ func _integrate_forces( state ):
onfloor = true onfloor = true
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")):
dir+=-cam_xform.basis[2] dir += -cam_xform.basis[2]
if (Input.is_action_pressed("move_backwards")): if (Input.is_action_pressed("move_backwards")):
dir+=cam_xform.basis[2] dir += cam_xform.basis[2]
if (Input.is_action_pressed("move_left")): if (Input.is_action_pressed("move_left")):
dir+=-cam_xform.basis[0] dir += -cam_xform.basis[0]
if (Input.is_action_pressed("move_right")): if (Input.is_action_pressed("move_right")):
dir+=cam_xform.basis[0] dir += cam_xform.basis[0]
var jump_attempt = Input.is_action_pressed("jump") var jump_attempt = Input.is_action_pressed("jump")
var shoot_attempt = Input.is_action_pressed("shoot") var shoot_attempt = Input.is_action_pressed("shoot")
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_threshhold
if (dir.length()>0.1 and !sharp_turn) : if (dir.length() > 0.1 and !sharp_turn):
if (hspeed > 0.001) : if (hspeed > 0.001):
#linear_dir = linear_h_velocity/linear_vel #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))) #if (linear_vel > brake_velocity_limit and linear_dir.dot(ctarget_dir) < -cos(Math::deg2rad(brake_angular_limit)))
# brake=true # brake = true
#else #else
hdir = adjust_facing(hdir,target_dir,delta,1.0/hspeed*turn_speed,up) hdir = adjust_facing(hdir, target_dir, delta, 1.0/hspeed*turn_speed, up)
facing_dir = hdir facing_dir = hdir
else: else:
hdir = target_dir hdir = target_dir
if (hspeed<max_speed): if (hspeed < max_speed):
hspeed+=accel*delta hspeed += accel*delta
else: else:
hspeed-=deaccel*delta hspeed -= deaccel*delta
if (hspeed<0): if (hspeed < 0):
hspeed=0 hspeed = 0
hv = hdir*hspeed hv = hdir*hspeed
var mesh_xform = get_node("Armature").get_transform() var mesh_xform = get_node("Armature").get_transform()
var facing_mesh=-mesh_xform.basis[0].normalized() var facing_mesh = -mesh_xform.basis[0].normalized()
facing_mesh = (facing_mesh - up*facing_mesh.dot(up)).normalized() facing_mesh = (facing_mesh - up*facing_mesh.dot(up)).normalized()
facing_mesh = adjust_facing(facing_mesh,target_dir,delta,1.0/hspeed*turn_speed,up) facing_mesh = adjust_facing(facing_mesh, target_dir, delta, 1.0/hspeed*turn_speed, up)
var m3 = Matrix3(-facing_mesh,up,-facing_mesh.cross(up).normalized()).scaled( CHAR_SCALE ) var m3 = Matrix3(-facing_mesh, up, -facing_mesh.cross(up).normalized()).scaled(CHAR_SCALE)
get_node("Armature").set_transform(Transform(m3, mesh_xform.origin))
get_node("Armature").set_transform(Transform(m3,mesh_xform.origin))
if (not jumping and jump_attempt): if (not jumping and jump_attempt):
vv = 7.0 vv = 7.0
jumping = true jumping = true
get_node("sfx").play("jump") get_node("sfx").play("jump")
else: else:
if (vv > 0):
if (vv>0): anim = ANIM_AIR_UP
anim=ANIM_AIR_UP
else: else:
anim=ANIM_AIR_DOWN anim = ANIM_AIR_DOWN
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):
hspeed=0
hv = hdir*hspeed
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):
hspeed = 0
hv = hdir*hspeed
if (jumping and vv < 0): if (jumping and vv < 0):
jumping=false jumping = false
lv = hv+up*vv
lv = hv + up*vv
if (onfloor): if (onfloor):
movement_dir = lv movement_dir = lv
#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
@ -207,37 +183,30 @@ func _integrate_forces( state ):
state.set_linear_velocity(lv) state.set_linear_velocity(lv)
if (shoot_blend>0): if (shoot_blend > 0):
shoot_blend -= delta * SHOOT_SCALE shoot_blend -= delta*SHOOT_SCALE
if (shoot_blend<0): if (shoot_blend < 0):
shoot_blend=0 shoot_blend = 0
if (shoot_attempt and not prev_shoot): if (shoot_attempt and not prev_shoot):
shoot_blend = SHOOT_TIME shoot_blend = SHOOT_TIME
var bullet = preload("res://bullet.scn").instance() var bullet = preload("res://bullet.scn").instance()
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
if (onfloor): if (onfloor):
get_node("AnimationTreePlayer").blend2_node_set_amount("walk",hspeed / max_speed) get_node("AnimationTreePlayer").blend2_node_set_amount("walk", hspeed/max_speed)
get_node("AnimationTreePlayer").transition_node_set_current("state",anim)
get_node("AnimationTreePlayer").blend2_node_set_amount("gun",min(shoot_blend,1.0))
# state.set_angular_velocity(Vector3())
get_node("AnimationTreePlayer").transition_node_set_current("state", anim)
get_node("AnimationTreePlayer").blend2_node_set_amount("gun", min(shoot_blend, 1.0))
# state.set_angular_velocity(Vector3())
func _ready(): func _ready():
# Initalization here # Initalization here
get_node("AnimationTreePlayer").set_active(true) 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] [application]
name="SAT Collision Test" name="SAT Collision Test"
main_scene="res://sat_test.xml" main_scene="res://sat_test.scn"
icon="res://icon.png" 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,40 +1,30 @@
extends Control extends Control
# member variables here, example: # member variables
# var a=2 var town = null
# var b="textvar"
func _ready():
# Initalization here
pass
var town=null
func _back(): func _back():
town.queue_free() town.queue_free()
show() show()
func _load_scene(car): func _load_scene(car):
var tt = load(car).instance() var tt = load(car).instance()
tt.set_name("car") tt.set_name("car")
town = load("res://truck_scene.scn").instance() town = load("res://truck_scene.scn").instance()
town.get_node("instance_pos").add_child(tt) town.get_node("instance_pos").add_child(tt)
town.get_node("back").connect("pressed",self,"_back") town.get_node("back").connect("pressed", self, "_back")
get_parent().add_child(town) get_parent().add_child(town)
hide() hide()
func _on_van_1_pressed():
func _on_van_1_pressed():
_load_scene("res://car_base.scn") _load_scene("res://car_base.scn")
func _on_van_2_pressed(): func _on_van_2_pressed():
_load_scene("res://trailer_truck.scn") _load_scene("res://trailer_truck.scn")

Binary file not shown.

Binary file not shown.

View File

@ -1,69 +1,57 @@
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
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)

Binary file not shown.

Binary file not shown.

View File

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

View File

@ -2,23 +2,19 @@
extends ColorPickerButton extends ColorPickerButton
#virtual function
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()
#virtual function
func can_drop_data(pos, data):
return typeof(data)==TYPE_COLOR
#virtual function func can_drop_data(pos, data):
return typeof(data) == TYPE_COLOR
func drop_data(pos, data): func drop_data(pos, data):
set_color(data) set_color(data)

View File

@ -11,10 +11,12 @@
extends Control extends Control
# 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
func wait_for_input(action_bind): func wait_for_input(action_bind):
action = action_bind action = action_bind
# See note at the beginning of the script # 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.") get_node("contextual_help").set_text("Press a key to assign to the '" + action + "' action.")
set_process_input(true) set_process_input(true)
func _input(event): func _input(event):
# Handle the first pressed key # Handle the first pressed key
if (event.type == InputEvent.KEY): if (event.type == InputEvent.KEY):
@ -39,6 +42,7 @@ func _input(event):
# Add the new key binding # Add the new key binding
InputMap.action_add_event(action, event) InputMap.action_add_event(action, event)
func _ready(): func _ready():
# Initialise each button with the default key binding from InputMap # Initialise each button with the default key binding from InputMap
var input_event var input_event

Binary file not shown.

View File

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

View File

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

Binary file not shown.

View File

@ -1,31 +1,21 @@
extends Panel extends Panel
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initialization here
pass
func _goto_scene(): func _goto_scene():
var s = load("res://controls.scn") var s = load("res://controls.scn")
var si = s.instance() var si = s.instance()
get_parent().add_child(si) get_parent().add_child(si)
queue_free() queue_free()
pass
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()
#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. # The scene must be reloaded for changes to take effect.
func _on_english_pressed(): func _on_english_pressed():
TranslationServer.set_locale("en") TranslationServer.set_locale("en")

Binary file not shown.

View File

@ -1,35 +1,33 @@
extends Node extends Node
# member variables
var current_scene = null var current_scene = null
func goto_scene(path): func goto_scene(path):
# This function will usually be called from a signal callback, # This function will usually be called from a signal callback,
# or some other function from the running scene. # or some other function from the running scene.
# Deleting the current scene at this point might be # Deleting the current scene at this point might be
# a bad idea, because it may be inside of a callback or function of it. # a bad idea, because it may be inside of a callback or function of it.
# The worst case will be a crash or unexpected behavior. # The worst case will be a crash or unexpected behavior.
# The way around this is deferring the load to a later time, when # The way around this is deferring the load to a later time, when
# it is ensured that no code from the current scene is running: # it is ensured that no code from the current scene is running:
call_deferred("_deferred_goto_scene",path) call_deferred("_deferred_goto_scene",path)
func _deferred_goto_scene(path): func _deferred_goto_scene(path):
# Immediately free the current scene, # Immediately free the current scene,
# there is no risk here. # there is no risk here.
current_scene.free() current_scene.free()
# Load new scene # Load new scene
var s = ResourceLoader.load(path) var s = ResourceLoader.load(path)
# Instance the new scene # Instance the new scene
current_scene = s.instance() current_scene = s.instance()
# Add it to the active scene, as child of root # Add it to the active scene, as child of root
get_tree().get_root().add_child(current_scene) get_tree().get_root().add_child(current_scene)
@ -38,6 +36,6 @@ 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()
current_scene = root.get_child( root.get_child_count() -1 ) current_scene = root.get_child(root.get_child_count() - 1)

View File

@ -5,13 +5,12 @@ extends Panel
# var a=2 # var a=2
# var b="textvar" # var b="textvar"
func _ready(): func _ready():
# Initalization here # Initalization here
pass pass
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

Binary file not shown.

View File

@ -5,13 +5,12 @@ extends Panel
# var a=2 # var a=2
# var b="textvar" # var b="textvar"
func _ready(): func _ready():
# Initalization here # Initalization here
pass pass
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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,33 +8,36 @@ extends Node2D
# #
# Licensed under the MIT license # Licensed under the MIT license
# member variables
var joy_num var joy_num
var cur_joy var cur_joy
var axis_value var axis_value
var btn_state var btn_state
func _ready():
set_process_input(true)
func _input(ev): 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)):
get_node("btn"+str(btn)).add_color_override("font_color",Color(1,1,1,1)) get_node("btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1))
else: else:
get_node("btn"+str(btn)).add_color_override("font_color",Color(0.2,0.1,0.3,1)) 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(): func _on_unpause_pressed():
get_node("pause_popup").hide() get_node("pause_popup").hide()
get_tree().set_pause(false) get_tree().set_pause(false)

Binary file not shown.

View File

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

Binary file not shown.

View File

@ -5,13 +5,12 @@ extends Panel
# var a=2 # var a=2
# var b="textvar" # var b="textvar"
func _ready(): func _ready():
# Initalization here # Initalization here
pass pass
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

Binary file not shown.

View File

@ -5,13 +5,12 @@ extends Panel
# var a=2 # var a=2
# var b="textvar" # var b="textvar"
func _ready(): func _ready():
# Initalization here # Initalization here
pass pass
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

Binary file not shown.

View File

@ -1,31 +1,31 @@
extends Node2D extends Node2D
# member variables here, example: # member variables
# var a=2
# var b="textvar"
var thread = Thread.new() 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): 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")

Binary file not shown.

View File

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

View File

@ -1,10 +1,7 @@
extends Control extends Control
# member variables here, example: # member variables
# var a=2
# var b="textvar"
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"]
@ -14,6 +11,7 @@ var state = {
eases = Tween.EASE_IN, eases = Tween.EASE_IN,
} }
func _ready(): func _ready():
for index in range(trans.size()): for index in range(trans.size()):
var name = trans[index] var name = trans[index]
@ -39,9 +37,7 @@ func _ready():
get_node("modes/repeat").set_pressed(true) get_node("modes/repeat").set_pressed(true)
reset_tween() reset_tween()
# Initalization here
pass
func on_trans_changed(name, index): func on_trans_changed(name, index):
for index in range(trans.size()): for index in range(trans.size()):
@ -53,7 +49,8 @@ func on_trans_changed(name, index):
state.trans = index state.trans = index
reset_tween() reset_tween()
func on_eases_changed(name, index): func on_eases_changed(name, index):
for index in range(eases.size()): for index in range(eases.size()):
var pressed = eases[index] == name var pressed = eases[index] == name
@ -64,7 +61,8 @@ func on_eases_changed(name, index):
state.eases = index state.eases = index
reset_tween() reset_tween()
func on_modes_changed(name): func on_modes_changed(name):
var tween = get_node("tween") var tween = get_node("tween")
if name == "pause": if name == "pause":
@ -76,10 +74,12 @@ func on_modes_changed(name):
get_node("timeline").set_ignore_mouse(true) get_node("timeline").set_ignore_mouse(true)
else: else:
reset_tween() reset_tween()
func on_color_changed(color): func on_color_changed(color):
reset_tween() reset_tween()
func reset_tween(): func reset_tween():
var tween = get_node("tween") var tween = get_node("tween")
var pos = tween.tell() var pos = tween.tell()
@ -92,20 +92,20 @@ func reset_tween():
var size = get_node("tween/area").get_size() var size = get_node("tween/area").get_size()
if get_node("modes/move").is_pressed(): if get_node("modes/move").is_pressed():
tween.interpolate_method(sprite, "set_pos", Vector2(0,0), Vector2(size.width, size.height), 2, state.trans, state.eases) tween.interpolate_method(sprite, "set_pos", Vector2(0, 0), Vector2(size.width, size.height), 2, state.trans, state.eases)
tween.interpolate_property(sprite, "transform/pos", Vector2(size.width,size.height), Vector2(0, 0), 2, state.trans, state.eases, 2) tween.interpolate_property(sprite, "transform/pos", Vector2(size.width, size.height), Vector2(0, 0), 2, state.trans, state.eases, 2)
if get_node("modes/color").is_pressed(): if get_node("modes/color").is_pressed():
tween.interpolate_method(sprite, "set_modulate", get_node("color/color_from").get_color(), get_node("color/color_to").get_color(), 2, state.trans, state.eases) tween.interpolate_method(sprite, "set_modulate", get_node("color/color_from").get_color(), get_node("color/color_to").get_color(), 2, state.trans, state.eases)
tween.interpolate_property(sprite, "modulate", get_node("color/color_to").get_color(), get_node("color/color_from").get_color(), 2, state.trans, state.eases, 2) tween.interpolate_property(sprite, "modulate", get_node("color/color_to").get_color(), get_node("color/color_from").get_color(), 2, state.trans, state.eases, 2)
else: else:
sprite.set_modulate(Color(1, 1, 1, 1)) sprite.set_modulate(Color(1,1,1,1))
if get_node("modes/scale").is_pressed(): if get_node("modes/scale").is_pressed():
tween.interpolate_method(sprite, "set_scale", Vector2(0.5,0.5), Vector2(1.5, 1.5), 2, state.trans, state.eases) tween.interpolate_method(sprite, "set_scale", Vector2(0.5, 0.5), Vector2(1.5, 1.5), 2, state.trans, state.eases)
tween.interpolate_property(sprite, "transform/scale", Vector2(1.5,1.5), Vector2(0.5, 0.5), 2, state.trans, state.eases, 2) tween.interpolate_property(sprite, "transform/scale", Vector2(1.5, 1.5), Vector2(0.5, 0.5), 2, state.trans, state.eases, 2)
else: else:
sprite.set_scale(Vector2(1, 1)) sprite.set_scale(Vector2(1,1))
if get_node("modes/rotate").is_pressed(): if get_node("modes/rotate").is_pressed():
tween.interpolate_method(sprite, "_set_rotd", 0, 360, 2, state.trans, state.eases) tween.interpolate_method(sprite, "_set_rotd", 0, 360, 2, state.trans, state.eases)
@ -139,26 +139,27 @@ func reset_tween():
else: else:
tween.resume_all() tween.resume_all()
get_node("timeline").set_ignore_mouse(true) 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 timeline = get_node("timeline")
var tween = get_node("tween") var tween = get_node("tween")
var runtime = tween.get_runtime() var runtime = tween.get_runtime()
var ratio = 100 * (elapsed / runtime)
timeline.set_value(ratio)
var ratio = 100*(elapsed/runtime)
timeline.set_value(ratio)
func _on_timeline_value_changed( value ):
func _on_timeline_value_changed(value):
if !get_node("modes/pause").is_pressed(): if !get_node("modes/pause").is_pressed():
return return
var tween = get_node("tween") var tween = get_node("tween")
var runtime = tween.get_runtime() var runtime = tween.get_runtime()
tween.seek(runtime * value / 100) tween.seek(runtime*value/100)
func on_callback(arg): func on_callback(arg):
var label = get_node("tween/area/label") var label = get_node("tween/area/label")
label.add_text("on_callback -> " + arg + "\n") 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,72 +1,67 @@
extends Panel 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) # (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
var udp = PacketPeerUDP.new() var udp = PacketPeerUDP.new()
func _process(delta):
func _process(delta):
if (not udp.is_listening()): if (not udp.is_listening()):
return return
while(udp.get_available_packet_count()>0): while(udp.get_available_packet_count() > 0):
var packet = udp.get_var() var packet = udp.get_var()
if (typeof(packet)==TYPE_STRING): if (typeof(packet) == TYPE_STRING):
var host = udp.get_packet_ip() var host = udp.get_packet_ip()
var port = udp.get_packet_port() var port = udp.get_packet_port()
get_node("chat/text").add_text("("+host+":"+str(port)+":) "+packet) get_node("chat/text").add_text("(" + host + ":" + str(port) + ":) " + packet)
get_node("chat/text").newline() get_node("chat/text").newline()
func _ready(): func _ready():
# Initalization here # Initalization here
get_node("chat").add_style_override("panel",get_stylebox("bg","Tree")) get_node("chat").add_style_override("panel", get_stylebox("bg", "Tree"))
set_process(true) set_process(true)
func send_message(text): func send_message(text):
if (udp.is_listening()): if (udp.is_listening()):
udp.put_var(text) udp.put_var(text)
func _on_connect_toggled( pressed ):
func _on_connect_toggled(pressed):
if (pressed): if (pressed):
var err = udp.listen( get_node("listen_port").get_val() ) var err = udp.listen(get_node("listen_port").get_val())
if (err!=OK): 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) get_node("connect").set_pressed(false)
else: else:
get_node("status").set_text("Connected.") get_node("status").set_text("Connected.")
get_node("connect").set_text("Disconnect") get_node("connect").set_text("Disconnect")
err = udp.set_send_address(get_node("remote_host").get_text(),get_node("remote_port").get_val()) err = udp.set_send_address(get_node("remote_host").get_text(),get_node("remote_port").get_val())
if (err!=OK): 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) get_node("connect").set_pressed(false)
else: else:
send_message("* "+get_node("user_name").get_text()+" entered chat.") send_message("* " + get_node("user_name").get_text() + " entered chat.")
else: else:
udp.close() udp.close()
get_node("status").set_text("Disconnected.") get_node("status").set_text("Disconnected.")
get_node("connect").set_text("Connect") get_node("connect").set_text("Connect")
func _on_entry_line_text_entered(text):
_on_entry_button_pressed()
func _on_entry_line_text_entered( text ):
_on_entry_button_pressed();
func _on_entry_button_pressed(): func _on_entry_button_pressed():
var msg = get_node("entry_line").get_text() var msg = get_node("entry_line").get_text()
if (msg==""): if (msg == ""):
return return
send_message(get_node("user_name").get_text()+"> "+msg) send_message(get_node("user_name").get_text() + "> " + msg)
get_node("entry_line").set_text("") get_node("entry_line").set_text("")

Binary file not shown.

View File

@ -1,17 +1,18 @@
extends Control extends Control
# member variables
var mousepos var mousepos
func _fixed_process(delta):
func _fixed_process(delta):
var modetext = "Mode:\n" var modetext = "Mode:\n"
if(OS.is_window_fullscreen()): if(OS.is_window_fullscreen()):
modetext += "Fullscreen\n" modetext += "Fullscreen\n"
else: else:
modetext += "Windowed\n" modetext += "Windowed\n"
if(!OS.is_window_resizable()): if(!OS.is_window_resizable()):
modetext += "FixedSize\n" modetext += "FixedSize\n"
@ -29,119 +30,119 @@ func _fixed_process(delta):
get_node("Label_Mode").set_text(modetext) get_node("Label_Mode").set_text(modetext)
get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) get_node("Label_Position").set_text(str("Position:\n", OS.get_window_position()))
get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size()))
get_node("Label_MousePosition").set_text(str("Mouse Position:\n", mousepos ) ) get_node("Label_MousePosition").set_text(str("Mouse Position:\n", mousepos))
get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) ) get_node("Label_Screen_Count").set_text(str("Screen_Count:\n", OS.get_screen_count()))
get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_current_screen() ) ) get_node("Label_Screen_Current").set_text(str("Screen:\n", OS.get_current_screen()))
get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) get_node("Label_Screen0_Resolution").set_text(str("Screen0 Resolution:\n", OS.get_screen_size()))
get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position() ) ) get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n", OS.get_screen_position()))
if(OS.get_screen_count() > 1): if(OS.get_screen_count() > 1):
get_node("Button_Screen0").show() get_node("Button_Screen0").show()
get_node("Button_Screen1").show() get_node("Button_Screen1").show()
get_node("Label_Screen1_Resolution").show() get_node("Label_Screen1_Resolution").show()
get_node("Label_Screen1_Position").show() get_node("Label_Screen1_Position").show()
get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Resolution").set_text(str("Screen1 Resolution:\n", OS.get_screen_size(1)))
get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) ) get_node("Label_Screen1_Position").set_text(str("Screen1 Position:\n", OS.get_screen_position(1)))
else: else:
get_node("Button_Screen0").hide() get_node("Button_Screen0").hide()
get_node("Button_Screen1").hide() get_node("Button_Screen1").hide()
get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Resolution").hide()
get_node("Label_Screen1_Position").hide() get_node("Label_Screen1_Position").hide()
get_node("Button_Fullscreen").set_pressed( OS.is_window_fullscreen() ) get_node("Button_Fullscreen").set_pressed(OS.is_window_fullscreen())
get_node("Button_FixedSize").set_pressed( !OS.is_window_resizable() ) get_node("Button_FixedSize").set_pressed(!OS.is_window_resizable())
get_node("Button_Minimized").set_pressed( OS.is_window_minimized() ) get_node("Button_Minimized").set_pressed(OS.is_window_minimized())
get_node("Button_Maximized").set_pressed( OS.is_window_maximized() ) get_node("Button_Maximized").set_pressed(OS.is_window_maximized())
get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED ) get_node("Button_Mouse_Grab").set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED)
func check_wm_api(): func check_wm_api():
var s = "" var s = ""
if( !OS.has_method("get_screen_count") ): if(!OS.has_method("get_screen_count")):
s += " - get_screen_count()\n" s += " - get_screen_count()\n"
if( !OS.has_method("get_current_screen") ): if(!OS.has_method("get_current_screen")):
s += " - get_current_screen()\n" s += " - get_current_screen()\n"
if( !OS.has_method("set_current_screen") ): if(!OS.has_method("set_current_screen")):
s += " - set_current_screen()\n" s += " - set_current_screen()\n"
if( !OS.has_method("get_screen_position") ): if(!OS.has_method("get_screen_position")):
s += " - get_screen_position()\n" s += " - get_screen_position()\n"
if( !OS.has_method("get_screen_size") ): if(!OS.has_method("get_screen_size")):
s += " - get_screen_size()\n" s += " - get_screen_size()\n"
if( !OS.has_method("get_window_position") ): if(!OS.has_method("get_window_position")):
s += " - get_window_position()\n" s += " - get_window_position()\n"
if( !OS.has_method("set_window_position") ): if(!OS.has_method("set_window_position")):
s += " - set_window_position()\n" s += " - set_window_position()\n"
if( !OS.has_method("get_window_size") ): if(!OS.has_method("get_window_size")):
s += " - get_window_size()\n" s += " - get_window_size()\n"
if( !OS.has_method("set_window_size") ): if(!OS.has_method("set_window_size")):
s += " - set_window_size()\n" s += " - set_window_size()\n"
if( !OS.has_method("set_window_fullscreen") ): if(!OS.has_method("set_window_fullscreen")):
s += " - set_window_fullscreen()\n" s += " - set_window_fullscreen()\n"
if( !OS.has_method("is_window_fullscreen") ): if(!OS.has_method("is_window_fullscreen")):
s += " - is_window_fullscreen()\n" s += " - is_window_fullscreen()\n"
if( !OS.has_method("set_window_resizable") ): if(!OS.has_method("set_window_resizable")):
s += " - set_window_resizable()\n" s += " - set_window_resizable()\n"
if( !OS.has_method("is_window_resizable") ): if(!OS.has_method("is_window_resizable")):
s += " - is_window_resizable()\n" s += " - is_window_resizable()\n"
if( !OS.has_method("set_window_minimized") ): if(!OS.has_method("set_window_minimized")):
s += " - set_window_minimized()\n" s += " - set_window_minimized()\n"
if( !OS.has_method("is_window_minimized") ): if(!OS.has_method("is_window_minimized")):
s += " - is_window_minimized()\n" s += " - is_window_minimized()\n"
if( !OS.has_method("set_window_maximized") ): if(!OS.has_method("set_window_maximized")):
s += " - set_window_maximized()\n" s += " - set_window_maximized()\n"
if( !OS.has_method("is_window_maximized") ): if(!OS.has_method("is_window_maximized")):
s += " - is_window_maximized()\n" s += " - is_window_maximized()\n"
if( s.length() == 0 ): if(s.length() == 0):
return true return true
else: else:
var text = get_node("ImplementationDialog/Text").get_text() var text = get_node("ImplementationDialog/Text").get_text()
get_node("ImplementationDialog/Text").set_text( text + s ) get_node("ImplementationDialog/Text").set_text(text + s)
get_node("ImplementationDialog").show() get_node("ImplementationDialog").show()
return false return false
func _ready(): func _ready():
if( check_wm_api() ): if(check_wm_api()):
set_fixed_process(true) set_fixed_process(true)
set_process_input(true) set_process_input(true)
func _input(ev): func _input(event):
if (ev.type==InputEvent.MOUSE_MOTION): if (event.type == InputEvent.MOUSE_MOTION):
mousepos = ev.pos mousepos = event.pos
func _on_Button_MoveTo_pressed(): func _on_Button_MoveTo_pressed():
OS.set_window_position( Vector2(100,100) ) OS.set_window_position(Vector2(100, 100))
func _on_Button_Resize_pressed(): func _on_Button_Resize_pressed():
OS.set_window_size( Vector2(1024,768) ) OS.set_window_size(Vector2(1024, 768))
func _on_Button_Screen0_pressed(): func _on_Button_Screen0_pressed():

View File

@ -1,16 +1,17 @@
extends Spatial extends Spatial
# member variables
var r_pos = Vector2() var r_pos = Vector2()
var state var state
const STATE_MENU=0 const STATE_MENU = 0
const STATE_GRAB=1 const STATE_GRAB = 1
func direction(vector): func direction(vector):
var v = get_node("Camera").get_global_transform().basis * vector var v = get_node("Camera").get_global_transform().basis*vector
v = v.normalized() v = v.normalized()
return v return v
@ -22,7 +23,6 @@ func impulse(event, action):
func _fixed_process(delta): func _fixed_process(delta):
if(state != STATE_GRAB): if(state != STATE_GRAB):
return return
@ -34,31 +34,31 @@ func _fixed_process(delta):
var org = get_translation() var org = get_translation()
if (Input.is_action_pressed("move_forward")): if (Input.is_action_pressed("move_forward")):
dir += direction(Vector3(0,0,-1)) dir += direction(Vector3(0, 0, -1))
if (Input.is_action_pressed("move_backwards")): if (Input.is_action_pressed("move_backwards")):
dir += direction(Vector3(0,0,1)) dir += direction(Vector3(0, 0, 1))
if (Input.is_action_pressed("move_left")): if (Input.is_action_pressed("move_left")):
dir += direction(Vector3(-1,0,0)) dir += direction(Vector3(-1, 0, 0))
if (Input.is_action_pressed("move_right")): if (Input.is_action_pressed("move_right")):
dir += direction(Vector3(1,0,0)) dir += direction(Vector3(1, 0, 0))
dir = dir.normalized() dir = dir.normalized()
move(dir * 10 * delta) move(dir*10*delta)
var d = delta * 0.1 var d = delta*0.1
var yaw = get_transform().rotated(Vector3(0,1,0), d * r_pos.x) var yaw = get_transform().rotated(Vector3(0, 1, 0), d*r_pos.x)
set_transform(yaw) set_transform(yaw)
var cam = get_node("Camera") var cam = get_node("Camera")
var pitch = cam.get_transform().rotated(Vector3(1,0,0), d * r_pos.y) var pitch = cam.get_transform().rotated(Vector3(1, 0, 0), d*r_pos.y)
cam.set_transform(pitch) cam.set_transform(pitch)
r_pos.x = 0.0 r_pos.x = 0.0
r_pos.y = 0.0 r_pos.y = 0.0
func _input( event ): func _input(event):
if(event.type == InputEvent.MOUSE_MOTION): if(event.type == InputEvent.MOUSE_MOTION):
r_pos = event.relative_pos r_pos = event.relative_pos
@ -76,4 +76,3 @@ func _ready():
set_process_input(true) set_process_input(true)
state = STATE_MENU state = STATE_MENU

View File

@ -1,73 +1,67 @@
extends Node2D extends Node2D
# member variables here, example: # member variables
# var a=2
# var b="textvar"
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 positio 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")):
left_pos.y+=-PAD_SPEED*delta left_pos.y += -PAD_SPEED*delta
if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")): if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")):
left_pos.y+=PAD_SPEED*delta left_pos.y += PAD_SPEED*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")):
right_pos.y+=-PAD_SPEED*delta right_pos.y += -PAD_SPEED*delta
if (right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")): if (right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")):
right_pos.y+=PAD_SPEED*delta right_pos.y += PAD_SPEED*delta
get_node("right").set_pos(right_pos)
get_node("right").set_pos(right_pos)
func _ready(): 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() pad_size = get_node("left").get_texture().get_size()
set_process(true) 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 extends Spatial
# member variables here, example:
# var a=2
# var b="textvar"
func _ready(): func _ready():
# Initalization here # Initalization here
var tex = get_node("Viewport").get_render_target_texture() var tex = get_node("Viewport").get_render_target_texture()
get_node("Quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE,tex) 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,45 +1,38 @@
extends Spatial extends Spatial
# member variables here, example: # member variables
# var a=2 var prev_pos = null
# var b="textvar"
var prev_pos=null
func _input( ev ): func _input(event):
#all other (non-mouse) events # all other (non-mouse) events
if (not ev.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(ev) get_node("viewport").input(event)
#mouse events for area # mouse events for area
func _on_area_input_event( camera, ev, 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
ev.pos=pos event.global_pos = pos
ev.global_pos=pos if (prev_pos == null):
if (prev_pos==null): prev_pos = pos
prev_pos=pos if (event.type == InputEvent.MOUSE_MOTION):
if (ev.type==InputEvent.MOUSE_MOTION): event.relative_pos = pos - prev_pos
ev.relative_pos=pos-prev_pos prev_pos = pos
prev_pos=pos # sned the event to the viewport
get_node("viewport").input(event)
get_node("viewport").input(ev)
func _ready(): func _ready():
# Initalization here # Initalization here
get_node("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture() ) get_node("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture())
set_process_input(true) set_process_input(true)
pass

Binary file not shown.

View File

@ -1,27 +1,16 @@
extends Control extends Control
# member variables here, example:
# var a=2
# var b="textvar"
func _ready():
# Initialization here
pass
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 aptured # 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)
pass # replace with function body