mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2025-12-16 05:20:06 +01:00
[2.1] Simplify list of branches in the README (#1255)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# Top-most EditorConfig file.
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file.
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
19
.github/workflows/static_checks.yml
vendored
Normal file
19
.github/workflows/static_checks.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
name: Static Checks
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
format:
|
||||
name: File formatting (file_format.sh)
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -qq dos2unix recode
|
||||
|
||||
- name: File formatting checks (file_format.sh)
|
||||
run: |
|
||||
bash ./file_format.sh
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -18,4 +18,5 @@ mono_crash.*.json
|
||||
|
||||
# System/tool-specific ignores
|
||||
.directory
|
||||
.DS_Store
|
||||
*~
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends TileMap
|
||||
|
||||
# Member variables
|
||||
@@ -30,7 +29,7 @@ var l = range(2, 5)
|
||||
# Process that runs in realtime
|
||||
func _fixed_process(delta):
|
||||
position = get_node("../troll").get_pos()
|
||||
|
||||
|
||||
# Calculate the corresponding tile
|
||||
# from the players position
|
||||
x = int(position.x/get_cell_size().x)
|
||||
@@ -38,11 +37,11 @@ func _fixed_process(delta):
|
||||
# causes problems because of rounding problems
|
||||
if position.x < 0:
|
||||
x -= 1 # Correct negative values
|
||||
|
||||
|
||||
y = int(position.y/get_cell_size().y)
|
||||
if (position.y < 0):
|
||||
y -= 1
|
||||
|
||||
|
||||
# Check if the player moved one tile further
|
||||
if ((x_old != x) or (y_old != y)):
|
||||
# Create the transparent part (visited area)
|
||||
@@ -55,7 +54,7 @@ func _fixed_process(delta):
|
||||
set_cell(m, n, 1, 0, 0)
|
||||
end -= 1
|
||||
start += 1
|
||||
|
||||
|
||||
# Create the actual and active visible part
|
||||
var end = l.size() - 1
|
||||
var start = 0
|
||||
@@ -65,7 +64,7 @@ func _fixed_process(delta):
|
||||
set_cell(m, n, -1)
|
||||
end -= 1
|
||||
start += 1
|
||||
|
||||
|
||||
x_old = x
|
||||
y_old = y
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
@@ -13,7 +12,7 @@ const MOTION_SPEED = 160 # Pixels/second
|
||||
|
||||
func _fixed_process(delta):
|
||||
var motion = Vector2()
|
||||
|
||||
|
||||
if (Input.is_action_pressed("move_up")):
|
||||
motion += Vector2(0, -1)
|
||||
if (Input.is_action_pressed("move_bottom")):
|
||||
@@ -22,10 +21,10 @@ func _fixed_process(delta):
|
||||
motion += Vector2(-1, 0)
|
||||
if (Input.is_action_pressed("move_right")):
|
||||
motion += Vector2(1, 0)
|
||||
|
||||
|
||||
motion = motion.normalized()*MOTION_SPEED*delta
|
||||
motion = move(motion)
|
||||
|
||||
|
||||
# Make character slide nicely through the world
|
||||
var slide_attempts = 4
|
||||
while(is_colliding() and slide_attempts > 0):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
# the kinematic controller works.
|
||||
# move() will allow to move the node, and will
|
||||
# always move it to a non-colliding spot,
|
||||
# always move it to a non-colliding spot,
|
||||
# as long as it starts from a non-colliding spot too.
|
||||
|
||||
# Member variables
|
||||
@@ -13,7 +12,7 @@ const MOTION_SPEED = 160 # Pixels/second
|
||||
|
||||
func _fixed_process(delta):
|
||||
var motion = Vector2()
|
||||
|
||||
|
||||
if (Input.is_action_pressed("move_up")):
|
||||
motion += Vector2(0, -1)
|
||||
if (Input.is_action_pressed("move_bottom")):
|
||||
@@ -22,10 +21,10 @@ func _fixed_process(delta):
|
||||
motion += Vector2(-1, 0)
|
||||
if (Input.is_action_pressed("move_right")):
|
||||
motion += Vector2(1, 0)
|
||||
|
||||
|
||||
motion = motion.normalized()*MOTION_SPEED*delta
|
||||
motion = move(motion)
|
||||
|
||||
|
||||
# Make character slide nicely through the world
|
||||
var slide_attempts = 4
|
||||
while(is_colliding() and slide_attempts > 0):
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
# the kinematic controller works.
|
||||
# move() will allow to move the node, and will
|
||||
# always move it to a non-colliding spot,
|
||||
# always move it to a non-colliding spot,
|
||||
# as long as it starts from a non-colliding spot too.
|
||||
|
||||
# Member variables
|
||||
@@ -13,7 +12,7 @@ const MOTION_SPEED = 160 # Pixels/seconds
|
||||
|
||||
func _fixed_process(delta):
|
||||
var motion = Vector2()
|
||||
|
||||
|
||||
if (Input.is_action_pressed("move_up")):
|
||||
motion += Vector2(0, -1)
|
||||
if (Input.is_action_pressed("move_bottom")):
|
||||
@@ -22,10 +21,10 @@ func _fixed_process(delta):
|
||||
motion += Vector2(-1, 0)
|
||||
if (Input.is_action_pressed("move_right")):
|
||||
motion += Vector2(1, 0)
|
||||
|
||||
|
||||
motion = motion.normalized()*MOTION_SPEED*delta
|
||||
motion = move(motion)
|
||||
|
||||
|
||||
# Make character slide nicely through the world
|
||||
var slide_attempts = 4
|
||||
while(is_colliding() and slide_attempts > 0):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# Member variables
|
||||
@@ -37,14 +36,14 @@ func _fixed_process(delta):
|
||||
dir += Vector2(-1, 0)
|
||||
if (Input.is_action_pressed("right")):
|
||||
dir += Vector2(1, 0)
|
||||
|
||||
|
||||
if (dir != Vector2()):
|
||||
dir = dir.normalized()
|
||||
speed = speed.linear_interpolate(dir*MAX_SPEED, delta*ACCEL)
|
||||
var motion = speed*delta
|
||||
motion.y *= VSCALE
|
||||
motion = move(motion)
|
||||
|
||||
|
||||
if (is_colliding()):
|
||||
var n = get_collision_normal()
|
||||
motion = n.slide(motion)
|
||||
@@ -52,13 +51,13 @@ func _fixed_process(delta):
|
||||
|
||||
var next_anim = ""
|
||||
var next_mirror = false
|
||||
|
||||
|
||||
if (dir == Vector2() and speed.length() < IDLE_SPEED):
|
||||
next_anim = "idle"
|
||||
next_mirror = false
|
||||
elif (speed.length() > IDLE_SPEED*0.1):
|
||||
var angle = atan2(abs(speed.x), speed.y)
|
||||
|
||||
|
||||
next_mirror = speed.x > 0
|
||||
if (angle < PI/8):
|
||||
next_anim = "bottom"
|
||||
@@ -72,7 +71,7 @@ func _fixed_process(delta):
|
||||
else:
|
||||
next_anim = "top"
|
||||
next_mirror = false
|
||||
|
||||
|
||||
if (next_anim != current_anim or next_mirror != current_mirror):
|
||||
get_node("frames").set_flip_h(next_mirror)
|
||||
get_node("anim").play(next_anim)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
@@ -32,13 +31,13 @@ var prev_jump_pressed = false
|
||||
func _fixed_process(delta):
|
||||
# Create forces
|
||||
var force = Vector2(0, GRAVITY)
|
||||
|
||||
|
||||
var walk_left = Input.is_action_pressed("move_left")
|
||||
var walk_right = Input.is_action_pressed("move_right")
|
||||
var jump = Input.is_action_pressed("jump")
|
||||
|
||||
|
||||
var stop = true
|
||||
|
||||
|
||||
if (walk_left):
|
||||
if (velocity.x <= WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED):
|
||||
force.x -= WALK_FORCE
|
||||
@@ -47,50 +46,50 @@ func _fixed_process(delta):
|
||||
if (velocity.x >= -WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED):
|
||||
force.x += WALK_FORCE
|
||||
stop = false
|
||||
|
||||
|
||||
if (stop):
|
||||
var vsign = sign(velocity.x)
|
||||
var vlen = abs(velocity.x)
|
||||
|
||||
|
||||
vlen -= STOP_FORCE*delta
|
||||
if (vlen < 0):
|
||||
vlen = 0
|
||||
|
||||
|
||||
velocity.x = vlen*vsign
|
||||
|
||||
|
||||
# Integrate forces to velocity
|
||||
velocity += force*delta
|
||||
|
||||
|
||||
# Integrate velocity into motion and move
|
||||
var motion = velocity*delta
|
||||
|
||||
|
||||
# Move and consume motion
|
||||
motion = move(motion)
|
||||
|
||||
|
||||
var floor_velocity = Vector2()
|
||||
|
||||
|
||||
if (is_colliding()):
|
||||
# You can check which tile was collision against with this
|
||||
# print(get_collider_metadata())
|
||||
|
||||
|
||||
# Ran against something, is it the floor? Get normal
|
||||
var n = get_collision_normal()
|
||||
|
||||
|
||||
if (rad2deg(acos(n.dot(Vector2(0, -1)))) < FLOOR_ANGLE_TOLERANCE):
|
||||
# If angle to the "up" vectors is < angle tolerance
|
||||
# char is on floor
|
||||
on_air_time = 0
|
||||
floor_velocity = get_collider_velocity()
|
||||
|
||||
|
||||
if (on_air_time == 0 and force.x == 0 and get_travel().length() < SLIDE_STOP_MIN_TRAVEL and abs(velocity.x) < SLIDE_STOP_VELOCITY and get_collider_velocity() == Vector2()):
|
||||
# Since this formula will always slide the character around,
|
||||
# a special case must be considered to to stop it from moving
|
||||
# Since this formula will always slide the character around,
|
||||
# a special case must be considered to to stop it from moving
|
||||
# if standing on an inclined floor. Conditions are:
|
||||
# 1) Standing on floor (on_air_time == 0)
|
||||
# 2) Did not move more than one pixel (get_travel().length() < SLIDE_STOP_MIN_TRAVEL)
|
||||
# 3) Not moving horizontally (abs(velocity.x) < SLIDE_STOP_VELOCITY)
|
||||
# 4) Collider is not moving
|
||||
|
||||
|
||||
revert_motion()
|
||||
velocity.y = 0.0
|
||||
else:
|
||||
@@ -100,21 +99,21 @@ func _fixed_process(delta):
|
||||
velocity = n.slide(velocity)
|
||||
# Then move again
|
||||
move(motion)
|
||||
|
||||
|
||||
if (floor_velocity != Vector2()):
|
||||
# If floor moves, move with floor
|
||||
move(floor_velocity*delta)
|
||||
|
||||
|
||||
if (jumping and velocity.y > 0):
|
||||
# If falling, no longer jumping
|
||||
jumping = false
|
||||
|
||||
|
||||
if (on_air_time < JUMP_MAX_AIRBORNE_TIME and jump and not prev_jump_pressed and not jumping):
|
||||
# Jump must also be allowed to happen if the character left the floor a little bit ago.
|
||||
# Makes controls more snappy.
|
||||
velocity.y = -JUMP_SPEED
|
||||
jumping = true
|
||||
|
||||
|
||||
on_air_time += delta
|
||||
prev_jump_pressed = jump
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
# the kinematic controller works.
|
||||
# move() will allow to move the node, and will
|
||||
# always move it to a non-colliding spot,
|
||||
# always move it to a non-colliding spot,
|
||||
# as long as it starts from a non-colliding spot too.
|
||||
|
||||
# Member variables
|
||||
@@ -13,7 +12,7 @@ const MOTION_SPEED = 160 # Pixels/second
|
||||
|
||||
func _fixed_process(delta):
|
||||
var motion = Vector2()
|
||||
|
||||
|
||||
if (Input.is_action_pressed("move_up")):
|
||||
motion += Vector2(0, -1)
|
||||
if (Input.is_action_pressed("move_bottom")):
|
||||
@@ -22,7 +21,7 @@ func _fixed_process(delta):
|
||||
motion += Vector2(-1, 0)
|
||||
if (Input.is_action_pressed("move_right")):
|
||||
motion += Vector2(1, 0)
|
||||
|
||||
|
||||
motion = motion.normalized()*MOTION_SPEED*delta
|
||||
move(motion)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Sprite
|
||||
|
||||
# Member variables
|
||||
@@ -14,18 +13,18 @@ export(int, "Direct", "Constant", "Smooth") var mode = MODE_DIRECT
|
||||
|
||||
func _process(delta):
|
||||
var mpos = get_viewport().get_mouse_pos()
|
||||
|
||||
|
||||
if (mode == MODE_DIRECT):
|
||||
look_at(mpos)
|
||||
elif (mode == MODE_CONSTANT):
|
||||
var ang = get_angle_to(mpos)
|
||||
var s = sign(ang)
|
||||
ang = abs(ang)
|
||||
|
||||
|
||||
rotate(min(ang, ROTATION_SPEED*delta)*s)
|
||||
elif (mode == MODE_SMOOTH):
|
||||
var ang = get_angle_to(mpos)
|
||||
|
||||
|
||||
rotate(ang*delta*SMOOTH_SPEED)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Sprite
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Navigation2D
|
||||
|
||||
# Member variables
|
||||
@@ -22,10 +21,10 @@ func _process(delta):
|
||||
else:
|
||||
path[path.size() - 1] = pfrom.linear_interpolate(pto, to_walk/d)
|
||||
to_walk = 0
|
||||
|
||||
|
||||
var atpos = path[path.size() - 1]
|
||||
get_node("agent").set_pos(atpos)
|
||||
|
||||
|
||||
if (path.size() < 2):
|
||||
path = []
|
||||
set_process(false)
|
||||
@@ -37,7 +36,7 @@ func _update_path():
|
||||
var p = get_simple_path(begin, end, true)
|
||||
path = Array(p) # Vector2array too complex to use, convert to regular array
|
||||
path.invert()
|
||||
|
||||
|
||||
set_process(true)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Member variables
|
||||
@@ -36,13 +35,13 @@ func _integrate_forces(s):
|
||||
new_anim = "explode"
|
||||
elif (state == STATE_WALKING):
|
||||
new_anim = "walk"
|
||||
|
||||
|
||||
var wall_side = 0.0
|
||||
|
||||
|
||||
for i in range(s.get_contact_count()):
|
||||
var cc = s.get_contact_collider_object(i)
|
||||
var dp = s.get_contact_local_normal(i)
|
||||
|
||||
|
||||
if (cc):
|
||||
if (cc extends bullet_class and not cc.disabled):
|
||||
set_mode(MODE_RIGID)
|
||||
@@ -53,12 +52,12 @@ func _integrate_forces(s):
|
||||
cc.disable()
|
||||
get_node("sound").play("hit")
|
||||
break
|
||||
|
||||
|
||||
if (dp.x > 0.9):
|
||||
wall_side = 1.0
|
||||
elif (dp.x < -0.9):
|
||||
wall_side = -1.0
|
||||
|
||||
|
||||
if (wall_side != 0 and wall_side != direction):
|
||||
direction = -direction
|
||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
||||
@@ -68,13 +67,13 @@ func _integrate_forces(s):
|
||||
elif (direction > 0 and not rc_right.is_colliding() and rc_left.is_colliding()):
|
||||
direction = -direction
|
||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
||||
|
||||
|
||||
lv.x = direction*WALK_SPEED
|
||||
|
||||
|
||||
if(anim != new_anim):
|
||||
anim = new_anim
|
||||
get_node("anim").play(anim)
|
||||
|
||||
|
||||
s.set_linear_velocity(lv)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
@@ -12,7 +11,7 @@ func _fixed_process(delta):
|
||||
accum = fmod(accum, PI*2.0)
|
||||
var d = sin(accum)
|
||||
var xf = Matrix32()
|
||||
xf[2]= motion*d
|
||||
xf[2]= motion*d
|
||||
get_node("platform").set_transform(xf)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Character Demo, written by Juan Linietsky.
|
||||
@@ -14,12 +13,12 @@ extends RigidBody2D
|
||||
# -Interaction with other physics-based objects is free
|
||||
# -Only have to deal with the object linear velocity, not position
|
||||
# -All collision/area framework available
|
||||
#
|
||||
#
|
||||
# But also has the following disadvantages:
|
||||
#
|
||||
#
|
||||
# -Objects may bounce a little bit sometimes
|
||||
# -Going up ramps sends the chracter flying up, small hack is needed.
|
||||
# -A ray collider is needed to avoid sliding down on ramps and
|
||||
# -A ray collider is needed to avoid sliding down on ramps and
|
||||
# undesiderd bumps, small steps and rare numerical precision errors.
|
||||
# (another alternative may be to turn on friction when the character is not moving).
|
||||
# -Friction cant be used, so floor velocity must be considered
|
||||
@@ -56,38 +55,38 @@ var enemy
|
||||
func _integrate_forces(s):
|
||||
var lv = s.get_linear_velocity()
|
||||
var step = s.get_step()
|
||||
|
||||
|
||||
var new_anim = anim
|
||||
var new_siding_left = siding_left
|
||||
|
||||
|
||||
# Get the controls
|
||||
var move_left = Input.is_action_pressed("move_left")
|
||||
var move_right = Input.is_action_pressed("move_right")
|
||||
var jump = Input.is_action_pressed("jump")
|
||||
var shoot = Input.is_action_pressed("shoot")
|
||||
var spawn = Input.is_action_pressed("spawn")
|
||||
|
||||
|
||||
if spawn:
|
||||
var e = enemy.instance()
|
||||
var p = get_pos()
|
||||
p.y = p.y - 100
|
||||
e.set_pos(p)
|
||||
get_parent().add_child(e)
|
||||
|
||||
|
||||
# Deapply prev floor velocity
|
||||
lv.x -= floor_h_velocity
|
||||
floor_h_velocity = 0.0
|
||||
|
||||
|
||||
# Find the floor (a contact with upwards facing collision normal)
|
||||
var found_floor = false
|
||||
var floor_index = -1
|
||||
|
||||
|
||||
for x in range(s.get_contact_count()):
|
||||
var ci = s.get_contact_local_normal(x)
|
||||
if (ci.dot(Vector2(0, -1)) > 0.6):
|
||||
found_floor = true
|
||||
floor_index = x
|
||||
|
||||
|
||||
# A good idea when impementing characters of all kinds,
|
||||
# compensates for physics imprecission, as well as human reaction delay.
|
||||
if (shoot and not shooting):
|
||||
@@ -99,22 +98,22 @@ func _integrate_forces(s):
|
||||
else:
|
||||
ss = 1.0
|
||||
var pos = get_pos() + get_node("bullet_shoot").get_pos()*Vector2(ss, 1.0)
|
||||
|
||||
|
||||
bi.set_pos(pos)
|
||||
get_parent().add_child(bi)
|
||||
|
||||
|
||||
bi.set_linear_velocity(Vector2(800.0*ss, -80))
|
||||
get_node("sprite/smoke").set_emitting(true)
|
||||
get_node("sound").play("shoot")
|
||||
PS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide
|
||||
else:
|
||||
shoot_time += step
|
||||
|
||||
|
||||
if (found_floor):
|
||||
airborne_time = 0.0
|
||||
else:
|
||||
airborne_time += step # Time it spent in the air
|
||||
|
||||
|
||||
var on_floor = airborne_time < MAX_FLOOR_AIRBORNE_TIME
|
||||
|
||||
# Process jump
|
||||
@@ -132,10 +131,10 @@ func _integrate_forces(s):
|
||||
jumping = false
|
||||
elif (not jump):
|
||||
stopping_jump = true
|
||||
|
||||
|
||||
if (stopping_jump):
|
||||
lv.y += STOP_JUMP_FORCE*step
|
||||
|
||||
|
||||
if (on_floor):
|
||||
# Process logic when character is on floor
|
||||
if (move_left and not move_right):
|
||||
@@ -150,14 +149,14 @@ func _integrate_forces(s):
|
||||
if (xv < 0):
|
||||
xv = 0
|
||||
lv.x = sign(lv.x)*xv
|
||||
|
||||
|
||||
# Check jump
|
||||
if (not jumping and jump):
|
||||
lv.y = -JUMP_VELOCITY
|
||||
jumping = true
|
||||
stopping_jump = false
|
||||
get_node("sound").play("jump")
|
||||
|
||||
|
||||
# Check siding
|
||||
if (lv.x < 0 and move_left):
|
||||
new_siding_left = true
|
||||
@@ -189,7 +188,7 @@ func _integrate_forces(s):
|
||||
if (xv < 0):
|
||||
xv = 0
|
||||
lv.x = sign(lv.x)*xv
|
||||
|
||||
|
||||
if (lv.y < 0):
|
||||
if (shoot_time < MAX_SHOOT_POSE_TIME):
|
||||
new_anim = "jumping_weapon"
|
||||
@@ -200,28 +199,28 @@ func _integrate_forces(s):
|
||||
new_anim = "falling_weapon"
|
||||
else:
|
||||
new_anim = "falling"
|
||||
|
||||
|
||||
# Update siding
|
||||
if (new_siding_left != siding_left):
|
||||
if (new_siding_left):
|
||||
get_node("sprite").set_scale(Vector2(-1, 1))
|
||||
else:
|
||||
get_node("sprite").set_scale(Vector2(1, 1))
|
||||
|
||||
|
||||
siding_left = new_siding_left
|
||||
|
||||
|
||||
# Change animation
|
||||
if (new_anim != anim):
|
||||
anim = new_anim
|
||||
get_node("anim").play(anim)
|
||||
|
||||
|
||||
shooting = shoot
|
||||
|
||||
|
||||
# Apply floor velocity
|
||||
if (found_floor):
|
||||
floor_h_velocity = s.get_contact_collider_velocity_at_pos(floor_index).x
|
||||
lv.x += floor_h_velocity
|
||||
|
||||
|
||||
# Finally, apply gravity and set back the linear velocity
|
||||
lv += s.get_total_gravity()*step
|
||||
s.set_linear_velocity(lv)
|
||||
@@ -229,7 +228,7 @@ func _integrate_forces(s):
|
||||
|
||||
func _ready():
|
||||
enemy = ResourceLoader.load("res://enemy.tscn")
|
||||
|
||||
|
||||
# if !Globals.has_singleton("Facebook"):
|
||||
# return
|
||||
# var Facebook = Globals.get_singleton("Facebook")
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
func _on_bullet_body_enter( body ):
|
||||
if (body.has_method("hit_by_bullet")):
|
||||
body.call("hit_by_bullet")
|
||||
|
||||
|
||||
func _on_Timer_timeout():
|
||||
get_node("anim").play("shutdown")
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
|
||||
var taken=false
|
||||
|
||||
func _on_coin_body_enter( body ):
|
||||
|
||||
|
||||
if (not taken and body extends preload("res://player.gd")):
|
||||
get_node("anim").play("taken")
|
||||
taken=true
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
|
||||
@@ -22,35 +21,35 @@ onready var detect_wall_right = get_node("detect_wall_right")
|
||||
onready var sprite = get_node("sprite")
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
|
||||
var new_anim="idle"
|
||||
|
||||
|
||||
if (state==STATE_WALKING):
|
||||
|
||||
|
||||
linear_velocity+= GRAVITY_VEC*delta
|
||||
linear_velocity.x = direction * WALK_SPEED
|
||||
linear_velocity = move_and_slide( linear_velocity, FLOOR_NORMAL )
|
||||
|
||||
|
||||
if (not detect_floor_left.is_colliding() or detect_wall_left.is_colliding()):
|
||||
direction=1.0
|
||||
|
||||
|
||||
if (not detect_floor_right.is_colliding() or detect_wall_right.is_colliding()):
|
||||
direction=-1.0
|
||||
|
||||
|
||||
sprite.set_scale( Vector2(direction,1.0) )
|
||||
|
||||
|
||||
new_anim="walk"
|
||||
else:
|
||||
new_anim="explode"
|
||||
|
||||
|
||||
if (anim!=new_anim):
|
||||
anim=new_anim
|
||||
get_node("anim").play(anim)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func hit_by_bullet():
|
||||
state=STATE_KILLED
|
||||
state=STATE_KILLED
|
||||
|
||||
func _ready():
|
||||
set_fixed_process(true)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
@@ -12,7 +11,7 @@ func _fixed_process(delta):
|
||||
accum = fmod(accum, PI*2.0)
|
||||
var d = sin(accum)
|
||||
var xf = Matrix32()
|
||||
xf[2]= motion*d
|
||||
xf[2]= motion*d
|
||||
get_node("platform").set_transform(xf)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
const GRAVITY_VEC = Vector2(0,900)
|
||||
@@ -12,7 +11,7 @@ const BULLET_VELOCITY = 1000
|
||||
const SHOOT_TIME_SHOW_WEAPON = 0.2
|
||||
|
||||
var linear_vel = Vector2()
|
||||
var onair_time = 0 #
|
||||
var onair_time = 0 #
|
||||
var on_floor = false
|
||||
var shoot_time=99999 #time since last shot
|
||||
var shooting = false
|
||||
@@ -23,69 +22,69 @@ var anim=""
|
||||
onready var sprite = get_node("sprite")
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
|
||||
#increment counters
|
||||
|
||||
|
||||
onair_time+=delta
|
||||
shoot_time+=delta
|
||||
|
||||
|
||||
|
||||
|
||||
### MOVEMENT ###
|
||||
|
||||
|
||||
# Apply Gravity
|
||||
linear_vel += delta * GRAVITY_VEC
|
||||
# Move and Slide
|
||||
linear_vel = move_and_slide( linear_vel, FLOOR_NORMAL, SLOPE_SLIDE_STOP )
|
||||
# Detect Floor
|
||||
if (is_move_and_slide_on_floor()):
|
||||
onair_time=0
|
||||
|
||||
onair_time=0
|
||||
|
||||
on_floor = onair_time < MIN_ONAIR_TIME
|
||||
|
||||
|
||||
### CONTROL ###
|
||||
|
||||
|
||||
# Horizontal Movement
|
||||
var target_speed = 0
|
||||
if (Input.is_action_pressed("move_left")):
|
||||
target_speed += -1
|
||||
if (Input.is_action_pressed("move_right")):
|
||||
target_speed += 1
|
||||
|
||||
|
||||
target_speed *= WALK_SPEED
|
||||
linear_vel.x = lerp( linear_vel.x, target_speed, 0.1 )
|
||||
|
||||
|
||||
# Jumping
|
||||
if (on_floor and Input.is_action_pressed("jump")):
|
||||
linear_vel.y=-JUMP_SPEED
|
||||
get_node("sound").play("jump")
|
||||
|
||||
# Shooting
|
||||
|
||||
|
||||
# Shooting
|
||||
|
||||
var shoot = Input.is_action_pressed("shoot")
|
||||
|
||||
|
||||
if (shoot and not shooting):
|
||||
|
||||
|
||||
var bullet = preload("res://bullet.tscn").instance()
|
||||
bullet.set_pos( get_node("sprite/bullet_shoot").get_global_pos() ) #use node for shoot position
|
||||
bullet.set_linear_velocity( Vector2( sprite.get_scale().x * BULLET_VELOCITY,0 ) )
|
||||
bullet.set_linear_velocity( Vector2( sprite.get_scale().x * BULLET_VELOCITY,0 ) )
|
||||
bullet.add_collision_exception_with(self) # don't want player to collide with bullet
|
||||
get_parent().add_child( bullet ) #don't want bullet to move with me, so add it as child of parent
|
||||
get_node("sound").play("shoot")
|
||||
shoot_time=0
|
||||
|
||||
|
||||
### ANIMATION ###
|
||||
|
||||
|
||||
var new_anim="idle"
|
||||
|
||||
|
||||
if (on_floor):
|
||||
if (linear_vel.x < -SIDING_CHANGE_SPEED):
|
||||
sprite.set_scale( Vector2( -1, 1 ) )
|
||||
new_anim="run"
|
||||
|
||||
|
||||
if (linear_vel.x > SIDING_CHANGE_SPEED):
|
||||
sprite.set_scale( Vector2( 1, 1 ) )
|
||||
new_anim="run"
|
||||
|
||||
|
||||
else:
|
||||
# We want the character to immediately change facing side when the player
|
||||
# tries to change direction, during air control.
|
||||
@@ -99,16 +98,16 @@ func _fixed_process(delta):
|
||||
new_anim="jumping"
|
||||
else:
|
||||
new_anim="falling"
|
||||
|
||||
|
||||
if (shoot_time < SHOOT_TIME_SHOW_WEAPON):
|
||||
new_anim+="_weapon"
|
||||
|
||||
|
||||
if (new_anim!=anim):
|
||||
anim=new_anim
|
||||
get_node("anim").play(anim)
|
||||
|
||||
|
||||
shooting = shoot
|
||||
|
||||
|
||||
func _ready():
|
||||
set_fixed_process(true)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
@@ -17,47 +16,47 @@ func _process(delta):
|
||||
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
|
||||
ball_pos += direction*ball_speed*delta
|
||||
|
||||
|
||||
# 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
|
||||
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
|
||||
if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
|
||||
ball_pos = screen_size*0.5
|
||||
ball_speed = INITIAL_BALL_SPEED
|
||||
direction = Vector2(-1, 0)
|
||||
|
||||
|
||||
get_node("ball").set_pos(ball_pos)
|
||||
|
||||
|
||||
# Move left pad
|
||||
var left_pos = get_node("left").get_pos()
|
||||
|
||||
|
||||
if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
|
||||
left_pos.y += -PAD_SPEED*delta
|
||||
if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")):
|
||||
left_pos.y += PAD_SPEED*delta
|
||||
|
||||
|
||||
get_node("left").set_pos(left_pos)
|
||||
|
||||
|
||||
# Move right pad
|
||||
var right_pos = get_node("right").get_pos()
|
||||
|
||||
|
||||
if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
|
||||
right_pos.y += -PAD_SPEED*delta
|
||||
if (right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")):
|
||||
right_pos.y += PAD_SPEED*delta
|
||||
|
||||
|
||||
get_node("right").set_pos(right_pos)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Control
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# This demo is an example of controling a high number of 2D objects with logic and collision without using scene nodes.
|
||||
@@ -35,37 +34,37 @@ func _process(delta):
|
||||
if (b.pos.x < -30):
|
||||
b.pos.x += width
|
||||
mat.o = b.pos
|
||||
|
||||
|
||||
Physics2DServer.body_set_state(b.body, Physics2DServer.BODY_STATE_TRANSFORM, mat)
|
||||
|
||||
|
||||
update()
|
||||
|
||||
|
||||
func _ready():
|
||||
shape = Physics2DServer.shape_create(Physics2DServer.SHAPE_CIRCLE)
|
||||
Physics2DServer.shape_set_data(shape, 8) # Radius
|
||||
|
||||
|
||||
for i in range(BULLET_COUNT):
|
||||
var b = Bullet.new()
|
||||
b.speed = rand_range(SPEED_MIN, SPEED_MAX)
|
||||
b.body = Physics2DServer.body_create(Physics2DServer.BODY_MODE_KINEMATIC)
|
||||
Physics2DServer.body_set_space(b.body, get_world_2d().get_space())
|
||||
Physics2DServer.body_add_shape(b.body, shape)
|
||||
|
||||
|
||||
b.pos = Vector2(get_viewport_rect().size * Vector2(randf()*2.0, randf())) # Twice as long
|
||||
b.pos.x += get_viewport_rect().size.x # Start outside
|
||||
var mat = Matrix32()
|
||||
mat.o = b.pos
|
||||
Physics2DServer.body_set_state(b.body, Physics2DServer.BODY_STATE_TRANSFORM, mat)
|
||||
|
||||
|
||||
bullets.append(b)
|
||||
|
||||
|
||||
set_process(true)
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
for b in bullets:
|
||||
Physics2DServer.free_rid(b.body)
|
||||
|
||||
|
||||
Physics2DServer.free_rid(shape)
|
||||
bullets.clear()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# Space Shooter
|
||||
|
||||
## Introduction
|
||||
In this on-rails shoot-em-up demo, the player gets to control a Space ship flying through a 2D version of Space, while firing their lasers by hitting the Space bar.
|
||||
Various enemies will enter the screen from the right and try their hardest to destroy the player's ship.
|
||||
Shooting these enemies will award points and the highest score achieved is kept in a one-entry leaderboard.
|
||||
In this on-rails shoot-em-up demo, the player gets to control a Space ship flying through a 2D version of Space, while firing their lasers by hitting the Space bar.
|
||||
Various enemies will enter the screen from the right and try their hardest to destroy the player's ship.
|
||||
Shooting these enemies will award points and the highest score achieved is kept in a one-entry leaderboard.
|
||||
Avoiding the blocky obstacles and the enemies is key to survival and high scores, so good luck and have fun!
|
||||
|
||||
## Controls
|
||||
|
||||
@@ -34,7 +34,7 @@ func destroy():
|
||||
# skip if already destroyed
|
||||
if (destroyed):
|
||||
return
|
||||
|
||||
|
||||
# set the state to destroyed
|
||||
destroyed = true
|
||||
# stop processing
|
||||
|
||||
@@ -35,14 +35,14 @@ func _ready():
|
||||
func _fixed_process(delta):
|
||||
# the enemy constantly moves
|
||||
translate(motion * delta)
|
||||
|
||||
|
||||
# count down the time until the next shot
|
||||
if shoot_timeout > 0.0:
|
||||
shoot_timeout -= delta
|
||||
|
||||
|
||||
if (shoot_timeout <= 0):
|
||||
shoot_timeout = SHOOT_INTERVAL
|
||||
|
||||
|
||||
if projectile_container != null:
|
||||
# Instance a shot
|
||||
var shot = Shot.instance()
|
||||
@@ -59,7 +59,7 @@ func destroy():
|
||||
if (destroyed):
|
||||
return
|
||||
destroyed = true
|
||||
|
||||
|
||||
# stop processing
|
||||
set_fixed_process(false)
|
||||
# play on-death effects
|
||||
|
||||
@@ -29,4 +29,4 @@ func _on_visibility_exit_screen():
|
||||
|
||||
func _on_enemy_shot_area_enter(area):
|
||||
if area.is_in_group("player"):
|
||||
area.take_damage()
|
||||
area.take_damage()
|
||||
|
||||
@@ -18,7 +18,7 @@ func destroy():
|
||||
# skip if already destroyed
|
||||
if (destroyed):
|
||||
return
|
||||
|
||||
|
||||
# set the state to destroyed
|
||||
destroyed = true
|
||||
# play on-death effects
|
||||
@@ -38,4 +38,3 @@ func _on_visibility_enter_screen():
|
||||
get_node("anim").seek(randf()*2.0)
|
||||
# as mentioned in _ready, show the node after seeking to the random start point in the animation
|
||||
show()
|
||||
|
||||
@@ -21,7 +21,7 @@ func _ready():
|
||||
# once the ship leaves the screen, remove the entire node
|
||||
visibility.connect("exit_screen", self, "queue_free")
|
||||
motion = Vector2(SPEED, 0)
|
||||
|
||||
|
||||
func _fixed_process(delta):
|
||||
# constant movement
|
||||
translate(motion * delta)
|
||||
|
||||
@@ -14,12 +14,12 @@ func _ready():
|
||||
func _process(delta):
|
||||
if Input.is_action_pressed("ui_cancel"):
|
||||
_on_return_to_menu()
|
||||
|
||||
|
||||
func update_score(score):
|
||||
score_label.set_text(str(score))
|
||||
|
||||
|
||||
func _on_return_to_menu():
|
||||
emit_signal("return_to_menu")
|
||||
|
||||
|
||||
func game_over():
|
||||
game_over_label.show()
|
||||
game_over_label.show()
|
||||
|
||||
@@ -28,6 +28,6 @@ func on_player_died():
|
||||
func on_enemy_died(score):
|
||||
game_state.points += score
|
||||
hud.update_score(game_state.points)
|
||||
|
||||
|
||||
func on_return_to_menu():
|
||||
game_state.abort_game()
|
||||
game_state.abort_game()
|
||||
|
||||
@@ -9,4 +9,4 @@ func _ready():
|
||||
# find all enemies who need a projectile container because they can shoot
|
||||
if enemy.has_method("set_projectile_container"):
|
||||
# tell those enemies about the container
|
||||
enemy.set_projectile_container(enemy_projectile_container)
|
||||
enemy.set_projectile_container(enemy_projectile_container)
|
||||
|
||||
@@ -35,7 +35,7 @@ func start_game():
|
||||
|
||||
func abort_game():
|
||||
_reset_game()
|
||||
|
||||
|
||||
menu = main_menu_scene.instance()
|
||||
get_tree().get_root().add_child(menu)
|
||||
|
||||
@@ -50,7 +50,7 @@ func _reset_game():
|
||||
game.hide()
|
||||
game.queue_free()
|
||||
game = null
|
||||
|
||||
|
||||
if menu != null:
|
||||
menu.hide()
|
||||
menu.queue_free()
|
||||
@@ -69,7 +69,7 @@ func _load_high_score():
|
||||
max_points = f.get_var()
|
||||
# always close the file handle
|
||||
f.close()
|
||||
|
||||
|
||||
func _save_high_score():
|
||||
var f = File.new()
|
||||
# try to open the highscore file in WRITE mode, which creates a new file if it doesn't exist
|
||||
@@ -77,4 +77,4 @@ func _save_high_score():
|
||||
# store the max points as a godot Variant
|
||||
f.store_var(max_points)
|
||||
# always close the file handle
|
||||
f.close()
|
||||
f.close()
|
||||
|
||||
@@ -15,4 +15,4 @@ func _ready():
|
||||
# the connection is set up on the "play" node, using the "Signals" sub-tab in the "Node" dock
|
||||
func _on_play_pressed():
|
||||
# tell the game_state to start a new game, which resets the current score to 0 and switches to the level scene
|
||||
game_state.start_game()
|
||||
game_state.start_game()
|
||||
|
||||
@@ -29,29 +29,29 @@ func _fixed_process(delta):
|
||||
if Input.is_action_pressed("move_right"):
|
||||
motion += Vector2(1, 0)
|
||||
var shooting = Input.is_action_pressed("shoot")
|
||||
|
||||
|
||||
var pos = get_pos()
|
||||
|
||||
|
||||
# normally you would normalize the motion vector using motion.normalized(), so diagonal movement isn't faster
|
||||
# in this case, the base speed would make dodging the tilemap impossible in some places
|
||||
# additionally, it could be explained as the ship using both horizontal and vertical thrusters at once
|
||||
# the better solution in the long run would be to playtest the level and make sure that every passage is playable
|
||||
# pos += motion.normalized() * delta * SPEED
|
||||
pos += motion * delta * SPEED
|
||||
|
||||
|
||||
# limit the resulting position to the screen's dimensions, so the player can't fly off screen
|
||||
pos.x = clamp(pos.x, 0, screen_size.x)
|
||||
pos.y = clamp(pos.y, 0, screen_size.y)
|
||||
|
||||
|
||||
set_pos(pos)
|
||||
|
||||
|
||||
# tick down the shot cooldown
|
||||
if shot_timer > 0.0:
|
||||
shot_timer -= delta
|
||||
|
||||
|
||||
# the player can shoot if the timer is back to zero
|
||||
can_shoot = shot_timer <= 0.0
|
||||
|
||||
|
||||
# if the player is alive, allowed to shoot and pressing space to shoot..
|
||||
if (can_shoot and shooting and not killed):
|
||||
# instance a shot
|
||||
@@ -82,7 +82,7 @@ func _hit_something():
|
||||
get_node("sfx").play("sound_explode")
|
||||
# notify listeners that the player died
|
||||
emit_signal("player_died")
|
||||
# disable processing
|
||||
# disable processing
|
||||
set_fixed_process(false)
|
||||
|
||||
# the block tiles in a level have StaticBody2D colliders, touching them kills the player ship
|
||||
@@ -102,4 +102,3 @@ func set_projectile_container(container):
|
||||
# other objects (enemy projectiles) use this to tell the player ship that it was hit
|
||||
func take_damage():
|
||||
_hit_something()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Member variables
|
||||
@@ -36,13 +35,13 @@ func _integrate_forces(s):
|
||||
new_anim = "explode"
|
||||
elif (state == STATE_WALKING):
|
||||
new_anim = "walk"
|
||||
|
||||
|
||||
var wall_side = 0.0
|
||||
|
||||
|
||||
for i in range(s.get_contact_count()):
|
||||
var cc = s.get_contact_collider_object(i)
|
||||
var dp = s.get_contact_local_normal(i)
|
||||
|
||||
|
||||
if (cc):
|
||||
if (cc extends bullet_class and not cc.disabled):
|
||||
set_mode(MODE_RIGID)
|
||||
@@ -53,12 +52,12 @@ func _integrate_forces(s):
|
||||
cc.disable()
|
||||
get_node("sound").play("hit")
|
||||
break
|
||||
|
||||
|
||||
if (dp.x > 0.9):
|
||||
wall_side = 1.0
|
||||
elif (dp.x < -0.9):
|
||||
wall_side = -1.0
|
||||
|
||||
|
||||
if (wall_side != 0 and wall_side != direction):
|
||||
direction = -direction
|
||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
||||
@@ -68,13 +67,13 @@ func _integrate_forces(s):
|
||||
elif (direction > 0 and not rc_right.is_colliding() and rc_left.is_colliding()):
|
||||
direction = -direction
|
||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
||||
|
||||
|
||||
lv.x = direction*WALK_SPEED
|
||||
|
||||
|
||||
if(anim != new_anim):
|
||||
anim = new_anim
|
||||
get_node("anim").play(anim)
|
||||
|
||||
|
||||
s.set_linear_velocity(lv)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
@@ -12,7 +11,7 @@ func _fixed_process(delta):
|
||||
accum = fmod(accum, PI*2.0)
|
||||
var d = sin(accum)
|
||||
var xf = Matrix32()
|
||||
xf[2]= motion*d
|
||||
xf[2]= motion*d
|
||||
get_node("platform").set_transform(xf)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Character Demo, written by Juan Linietsky.
|
||||
@@ -14,12 +13,12 @@ extends RigidBody2D
|
||||
# -Interaction with other physics-based objects is free
|
||||
# -Only have to deal with the object linear velocity, not position
|
||||
# -All collision/area framework available
|
||||
#
|
||||
#
|
||||
# But also has the following disadvantages:
|
||||
#
|
||||
#
|
||||
# -Objects may bounce a little bit sometimes
|
||||
# -Going up ramps sends the chracter flying up, small hack is needed.
|
||||
# -A ray collider is needed to avoid sliding down on ramps and
|
||||
# -A ray collider is needed to avoid sliding down on ramps and
|
||||
# undesiderd bumps, small steps and rare numerical precision errors.
|
||||
# (another alternative may be to turn on friction when the character is not moving).
|
||||
# -Friction cant be used, so floor velocity must be considered
|
||||
@@ -57,38 +56,38 @@ export(int, "Player 1", "Player 2") var index = 0
|
||||
func _integrate_forces(s):
|
||||
var lv = s.get_linear_velocity()
|
||||
var step = s.get_step()
|
||||
|
||||
|
||||
var new_anim = anim
|
||||
var new_siding_left = siding_left
|
||||
|
||||
|
||||
# Get the controls
|
||||
var move_left = Input.is_action_pressed("move_left" + str(index))
|
||||
var move_right = Input.is_action_pressed("move_right" + str(index))
|
||||
var jump = Input.is_action_pressed("jump" + str(index))
|
||||
var shoot = Input.is_action_pressed("shoot" + str(index))
|
||||
var spawn = Input.is_action_pressed("spawn" + str(index))
|
||||
|
||||
|
||||
if spawn:
|
||||
var e = enemy.instance()
|
||||
var p = get_pos()
|
||||
p.y = p.y - 100
|
||||
e.set_pos(p)
|
||||
get_parent().add_child(e)
|
||||
|
||||
|
||||
# Deapply prev floor velocity
|
||||
lv.x -= floor_h_velocity
|
||||
floor_h_velocity = 0.0
|
||||
|
||||
|
||||
# Find the floor (a contact with upwards facing collision normal)
|
||||
var found_floor = false
|
||||
var floor_index = -1
|
||||
|
||||
|
||||
for x in range(s.get_contact_count()):
|
||||
var ci = s.get_contact_local_normal(x)
|
||||
if (ci.dot(Vector2(0, -1)) > 0.6):
|
||||
found_floor = true
|
||||
floor_index = x
|
||||
|
||||
|
||||
# A good idea when impementing characters of all kinds,
|
||||
# compensates for physics imprecission, as well as human reaction delay.
|
||||
if (shoot and not shooting):
|
||||
@@ -100,22 +99,22 @@ func _integrate_forces(s):
|
||||
else:
|
||||
ss = 1.0
|
||||
var pos = get_pos() + get_node("bullet_shoot").get_pos()*Vector2(ss, 1.0)
|
||||
|
||||
|
||||
bi.set_pos(pos)
|
||||
get_parent().add_child(bi)
|
||||
|
||||
|
||||
bi.set_linear_velocity(Vector2(800.0*ss, -80))
|
||||
get_node("sprite/smoke").set_emitting(true)
|
||||
get_node("sound").play("shoot")
|
||||
PS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide
|
||||
else:
|
||||
shoot_time += step
|
||||
|
||||
|
||||
if (found_floor):
|
||||
airborne_time = 0.0
|
||||
else:
|
||||
airborne_time += step # Time it spent in the air
|
||||
|
||||
|
||||
var on_floor = airborne_time < MAX_FLOOR_AIRBORNE_TIME
|
||||
|
||||
# Process jump
|
||||
@@ -125,10 +124,10 @@ func _integrate_forces(s):
|
||||
jumping = false
|
||||
elif (not jump):
|
||||
stopping_jump = true
|
||||
|
||||
|
||||
if (stopping_jump):
|
||||
lv.y += STOP_JUMP_FORCE*step
|
||||
|
||||
|
||||
if (on_floor):
|
||||
# Process logic when character is on floor
|
||||
if (move_left and not move_right):
|
||||
@@ -143,14 +142,14 @@ func _integrate_forces(s):
|
||||
if (xv < 0):
|
||||
xv = 0
|
||||
lv.x = sign(lv.x)*xv
|
||||
|
||||
|
||||
# Check jump
|
||||
if (not jumping and jump):
|
||||
lv.y = -JUMP_VELOCITY
|
||||
jumping = true
|
||||
stopping_jump = false
|
||||
get_node("sound").play("jump")
|
||||
|
||||
|
||||
# Check siding
|
||||
if (lv.x < 0 and move_left):
|
||||
new_siding_left = true
|
||||
@@ -182,7 +181,7 @@ func _integrate_forces(s):
|
||||
if (xv < 0):
|
||||
xv = 0
|
||||
lv.x = sign(lv.x)*xv
|
||||
|
||||
|
||||
if (lv.y < 0):
|
||||
if (shoot_time < MAX_SHOOT_POSE_TIME):
|
||||
new_anim = "jumping_weapon"
|
||||
@@ -193,28 +192,28 @@ func _integrate_forces(s):
|
||||
new_anim = "falling_weapon"
|
||||
else:
|
||||
new_anim = "falling"
|
||||
|
||||
|
||||
# Update siding
|
||||
if (new_siding_left != siding_left):
|
||||
if (new_siding_left):
|
||||
get_node("sprite").set_scale(Vector2(-1, 1))
|
||||
else:
|
||||
get_node("sprite").set_scale(Vector2(1, 1))
|
||||
|
||||
|
||||
siding_left = new_siding_left
|
||||
|
||||
|
||||
# Change animation
|
||||
if (new_anim != anim):
|
||||
anim = new_anim
|
||||
get_node("anim").play(anim)
|
||||
|
||||
|
||||
shooting = shoot
|
||||
|
||||
|
||||
# Apply floor velocity
|
||||
if (found_floor):
|
||||
floor_h_velocity = s.get_contact_collider_velocity_at_pos(floor_index).x
|
||||
lv.x += floor_h_velocity
|
||||
|
||||
|
||||
# Finally, apply gravity and set back the linear velocity
|
||||
lv += s.get_total_gravity()*step
|
||||
s.set_linear_velocity(lv)
|
||||
@@ -222,7 +221,7 @@ func _integrate_forces(s):
|
||||
|
||||
func _ready():
|
||||
enemy = ResourceLoader.load("res://enemy.tscn")
|
||||
|
||||
|
||||
# if !Globals.has_singleton("Facebook"):
|
||||
# return
|
||||
# var Facebook = Globals.get_singleton("Facebook")
|
||||
|
||||
@@ -9,7 +9,7 @@ func _ready():
|
||||
var parallax_copy = get_node("top/viewport/stage/parallax_bg").duplicate()
|
||||
parallax_copy.set_custom_viewport( get_node("bottom/viewport") )
|
||||
get_node("top/viewport/stage").add_child(parallax_copy)
|
||||
|
||||
|
||||
#simple and alternatively, copy them to the other viewport, but they must be erased when level is unloaded
|
||||
#get_node("bottom/viewport").add_child( get_node("top/viewport/stage/parallax_bg").duplicate() )
|
||||
pass
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# Simple Tetris-like demo, (c) 2012 Juan Linietsky
|
||||
@@ -56,13 +55,13 @@ func piece_cell_xform(p, er = 0):
|
||||
func _draw():
|
||||
var sb = get_stylebox("bg", "Tree") # Use line edit bg
|
||||
draw_style_box(sb, Rect2(Vector2(), get_size()).grow(3))
|
||||
|
||||
|
||||
var bs = block.get_size()
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
if (Vector2(x, y) in cells):
|
||||
draw_texture_rect(block, Rect2(Vector2(x, y)*bs, bs), false, block_colors[cells[Vector2(x, y)]])
|
||||
|
||||
|
||||
if (piece_active):
|
||||
for c in block_shapes[piece_shape]:
|
||||
draw_texture_rect(block, Rect2(piece_cell_xform(c)*bs, bs), false, block_colors[piece_shape])
|
||||
@@ -81,7 +80,7 @@ func piece_check_fit(ofs, er = 0):
|
||||
return false
|
||||
if (pos in cells):
|
||||
return false
|
||||
|
||||
|
||||
return true
|
||||
|
||||
|
||||
@@ -92,11 +91,11 @@ func new_piece():
|
||||
piece_rot = 0
|
||||
if (piece_shape == 0):
|
||||
piece_pos.y += 1
|
||||
|
||||
|
||||
if (not piece_check_fit(Vector2())):
|
||||
# Game over
|
||||
game_over()
|
||||
|
||||
|
||||
update()
|
||||
|
||||
|
||||
@@ -113,10 +112,10 @@ func test_collapse_rows():
|
||||
collapse = false
|
||||
if (accum_down):
|
||||
cells.erase(Vector2(x, y + accum_down))
|
||||
|
||||
|
||||
if (collapse):
|
||||
accum_down += 1
|
||||
|
||||
|
||||
score += accum_down*100
|
||||
score_label.set_text(str(score))
|
||||
|
||||
@@ -190,5 +189,5 @@ func setup(w, h):
|
||||
func _ready():
|
||||
setup(10, 20)
|
||||
score_label = get_node("../score")
|
||||
|
||||
|
||||
set_process_input(true)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends BackBufferCopy
|
||||
|
||||
# Member variables
|
||||
@@ -10,17 +9,17 @@ var dir
|
||||
|
||||
func _process(delta):
|
||||
var pos = get_pos() + dir*delta*MOTION_SPEED
|
||||
|
||||
|
||||
if (pos.x < 0):
|
||||
dir.x = abs(dir.x)
|
||||
elif (pos.x > vsize.x):
|
||||
dir.x = -abs(dir.x)
|
||||
|
||||
|
||||
if (pos.y < 0):
|
||||
dir.y = abs(dir.y)
|
||||
elif (pos.y > vsize.y):
|
||||
dir.y = -abs(dir.y)
|
||||
|
||||
|
||||
set_pos(pos)
|
||||
|
||||
|
||||
|
||||
@@ -69,4 +69,4 @@
|
||||
</dictionary>
|
||||
|
||||
</main_resource>
|
||||
</resource_file>
|
||||
</resource_file>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends KinematicBody
|
||||
|
||||
# Member variables
|
||||
@@ -14,7 +13,7 @@ const MAX_SLOPE_ANGLE = 30
|
||||
func _fixed_process(delta):
|
||||
var dir = Vector3() # Where does the player intend to walk to
|
||||
var cam_xform = get_node("target/camera").get_global_transform()
|
||||
|
||||
|
||||
if (Input.is_action_pressed("move_forward")):
|
||||
dir += -cam_xform.basis[2]
|
||||
if (Input.is_action_pressed("move_backwards")):
|
||||
@@ -23,43 +22,43 @@ func _fixed_process(delta):
|
||||
dir += -cam_xform.basis[0]
|
||||
if (Input.is_action_pressed("move_right")):
|
||||
dir += cam_xform.basis[0]
|
||||
|
||||
|
||||
dir.y = 0
|
||||
dir = dir.normalized()
|
||||
|
||||
|
||||
vel.y += delta*g
|
||||
|
||||
|
||||
var hvel = vel
|
||||
hvel.y = 0
|
||||
|
||||
|
||||
var target = dir*MAX_SPEED
|
||||
var accel
|
||||
if (dir.dot(hvel) > 0):
|
||||
accel = ACCEL
|
||||
else:
|
||||
accel = DEACCEL
|
||||
|
||||
|
||||
hvel = hvel.linear_interpolate(target, accel*delta)
|
||||
|
||||
|
||||
vel.x = hvel.x
|
||||
vel.z = hvel.z
|
||||
|
||||
|
||||
var motion = move(vel*delta)
|
||||
|
||||
|
||||
var on_floor = false
|
||||
var original_vel = vel
|
||||
var floor_velocity = Vector3()
|
||||
var attempts = 4
|
||||
|
||||
|
||||
while(is_colliding() and attempts):
|
||||
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,
|
||||
# char is on floor
|
||||
floor_velocity = get_collider_velocity()
|
||||
on_floor = true
|
||||
|
||||
|
||||
motion = n.slide(motion)
|
||||
vel = n.slide(vel)
|
||||
if (original_vel.dot(vel) > 0):
|
||||
@@ -68,13 +67,13 @@ func _fixed_process(delta):
|
||||
if (motion.length() < 0.001):
|
||||
break
|
||||
attempts -= 1
|
||||
|
||||
|
||||
if (on_floor and floor_velocity != Vector3()):
|
||||
move(floor_velocity*delta)
|
||||
|
||||
|
||||
if (on_floor and Input.is_action_pressed("jump")):
|
||||
vel.y = JUMP_SPEED
|
||||
|
||||
|
||||
var crid = get_node("../elevator1").get_rid()
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Camera
|
||||
|
||||
# Member variables
|
||||
@@ -16,27 +15,27 @@ func _fixed_process(dt):
|
||||
var target = get_parent().get_global_transform().origin
|
||||
var pos = get_global_transform().origin
|
||||
var up = Vector3(0, 1, 0)
|
||||
|
||||
|
||||
var delta = pos - target
|
||||
|
||||
|
||||
# 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
|
||||
if (delta.y > max_height):
|
||||
delta.y = max_height
|
||||
if (delta.y < min_height):
|
||||
delta.y = min_height
|
||||
|
||||
|
||||
pos = target + delta
|
||||
|
||||
|
||||
look_at_from_pos(pos, target, up)
|
||||
|
||||
|
||||
# Turn a little up or down
|
||||
var t = get_transform()
|
||||
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody
|
||||
|
||||
# Member variables
|
||||
@@ -12,7 +11,7 @@ func _input_event(camera, event, pos, normal, shape):
|
||||
get_node("mesh").set_material_override(gray_mat)
|
||||
else:
|
||||
get_node("mesh").set_material_override(null)
|
||||
|
||||
|
||||
selected = not selected
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Navigation
|
||||
|
||||
# Member variables
|
||||
@@ -29,16 +28,16 @@ func _process(delta):
|
||||
else:
|
||||
path[path.size() - 1] = pfrom.linear_interpolate(pto, to_walk/d)
|
||||
to_walk = 0
|
||||
|
||||
|
||||
var atpos = path[path.size() - 1]
|
||||
var atdir = to_watch
|
||||
atdir.y = 0
|
||||
|
||||
|
||||
var t = Transform()
|
||||
t.origin = atpos
|
||||
t=t.looking_at(atpos + atdir, Vector3(0, 1, 0))
|
||||
get_node("robot_base").set_transform(t)
|
||||
|
||||
|
||||
if (path.size() < 2):
|
||||
path = []
|
||||
set_process(false)
|
||||
@@ -71,12 +70,12 @@ func _input(event):
|
||||
var from = get_node("cambase/Camera").project_ray_origin(event.pos)
|
||||
var to = from + get_node("cambase/Camera").project_ray_normal(event.pos)*100
|
||||
var p = get_closest_point_to_segment(from, to)
|
||||
|
||||
|
||||
begin = get_closest_point(get_node("robot_base").get_translation())
|
||||
end = p
|
||||
|
||||
_update_path()
|
||||
|
||||
|
||||
if (event.type == InputEvent.MOUSE_MOTION):
|
||||
if (event.button_mask&BUTTON_MASK_MIDDLE):
|
||||
camrot += event.relative_x*0.005
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Area
|
||||
|
||||
# Member variables
|
||||
@@ -14,4 +13,3 @@ func _on_coin_body_enter(body):
|
||||
func _on_anim_finished():
|
||||
if get_node("anim").get_current_animation() == "take":
|
||||
queue_free()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody
|
||||
|
||||
# Member variables
|
||||
@@ -22,15 +21,15 @@ func _integrate_forces(state):
|
||||
|
||||
lv += g*delta # Apply gravity
|
||||
var up = -g.normalized()
|
||||
|
||||
|
||||
if (dying):
|
||||
state.set_linear_velocity(lv)
|
||||
return
|
||||
|
||||
|
||||
for i in range(state.get_contact_count()):
|
||||
var cc = state.get_contact_collider_object(i)
|
||||
var dp = state.get_contact_local_normal(i)
|
||||
|
||||
|
||||
if (cc):
|
||||
if (cc extends preload("res://bullet.gd") and not cc.disabled):
|
||||
set_mode(MODE_RIGID)
|
||||
@@ -43,15 +42,15 @@ func _integrate_forces(state):
|
||||
cc.disabled = true
|
||||
get_node("sound").play("hit")
|
||||
return
|
||||
|
||||
|
||||
var col_floor = get_node("Armature/ray_floor").is_colliding()
|
||||
var col_wall = get_node("Armature/ray_wall").is_colliding()
|
||||
|
||||
|
||||
var advance = not col_wall and col_floor
|
||||
|
||||
|
||||
var dir = get_node("Armature").get_transform().basis[2].normalized()
|
||||
var deaccel_dir = dir
|
||||
|
||||
|
||||
if (advance):
|
||||
if (dir.dot(lv) < max_speed):
|
||||
lv += dir*accel*delta
|
||||
@@ -59,17 +58,17 @@ func _integrate_forces(state):
|
||||
else:
|
||||
if (prev_advance):
|
||||
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))
|
||||
|
||||
|
||||
var dspeed = deaccel_dir.dot(lv)
|
||||
dspeed -= deaccel*delta
|
||||
if (dspeed < 0):
|
||||
dspeed = 0
|
||||
|
||||
|
||||
lv = lv - deaccel_dir*deaccel_dir.dot(lv) + deaccel_dir*dspeed
|
||||
|
||||
|
||||
state.set_linear_velocity(lv)
|
||||
prev_advance = advance
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Camera
|
||||
|
||||
# Member variables
|
||||
@@ -15,33 +14,33 @@ func _fixed_process(dt):
|
||||
var target = get_parent().get_global_transform().origin
|
||||
var pos = get_global_transform().origin
|
||||
var up = Vector3(0, 1, 0)
|
||||
|
||||
|
||||
var delta = pos - target
|
||||
|
||||
|
||||
# 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
|
||||
if (delta.y > max_height):
|
||||
delta.y = max_height
|
||||
if (delta.y < min_height):
|
||||
delta.y = min_height
|
||||
|
||||
|
||||
# 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
|
||||
delta = col.position - target
|
||||
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
|
||||
delta = Matrix3(up, deg2rad(-dt*autoturn_speed)).xform(delta)
|
||||
@@ -51,15 +50,15 @@ func _fixed_process(dt):
|
||||
else:
|
||||
# Do nothing otherwise, left and right are occluded but center is not, so do not autoturn
|
||||
pass
|
||||
|
||||
|
||||
# Apply lookat
|
||||
if (delta == Vector3()):
|
||||
delta = (pos - target).normalized()*0.0001
|
||||
|
||||
pos = target + delta
|
||||
|
||||
|
||||
look_at_from_pos(pos, target, up)
|
||||
|
||||
|
||||
# Turn a little up or down
|
||||
var t = get_transform()
|
||||
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends RigidBody
|
||||
|
||||
# Member variables
|
||||
@@ -36,15 +35,15 @@ var shoot_blend = 0
|
||||
func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
|
||||
var n = p_target # Normal
|
||||
var t = n.cross(current_gn).normalized()
|
||||
|
||||
|
||||
var x = n.dot(p_facing)
|
||||
var y = t.dot(p_facing)
|
||||
|
||||
|
||||
var ang = atan2(y,x)
|
||||
|
||||
|
||||
if (abs(ang) < 0.001): # Too small
|
||||
return p_facing
|
||||
|
||||
|
||||
var s = sign(ang)
|
||||
ang = ang*s
|
||||
var turn = ang*p_adjust_rate*p_step
|
||||
@@ -54,7 +53,7 @@ func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
|
||||
else:
|
||||
a = turn
|
||||
ang = (ang - a)*s
|
||||
|
||||
|
||||
return (n*cos(ang) + t*sin(ang))*p_facing.length()
|
||||
|
||||
|
||||
@@ -66,33 +65,33 @@ func _integrate_forces(state):
|
||||
# if (d < 0):
|
||||
# d = 0
|
||||
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 hdir = hv.normalized() # Horizontal direction
|
||||
var hspeed = hv.length() # Horizontal speed
|
||||
|
||||
|
||||
var floor_velocity
|
||||
var onfloor = false
|
||||
|
||||
|
||||
if (state.get_contact_count() == 0):
|
||||
floor_velocity = last_floor_velocity
|
||||
else:
|
||||
for i in range(state.get_contact_count()):
|
||||
if (state.get_contact_local_shape(i) != 1):
|
||||
continue
|
||||
|
||||
|
||||
onfloor = true
|
||||
floor_velocity = state.get_contact_collider_velocity_at_pos(i)
|
||||
break
|
||||
|
||||
|
||||
var dir = Vector3() # Where does the player intend to walk to
|
||||
var cam_xform = get_node("target/camera").get_global_transform()
|
||||
|
||||
|
||||
if (Input.is_action_pressed("move_forward")):
|
||||
dir += -cam_xform.basis[2]
|
||||
if (Input.is_action_pressed("move_backwards")):
|
||||
@@ -101,15 +100,15 @@ func _integrate_forces(state):
|
||||
dir += -cam_xform.basis[0]
|
||||
if (Input.is_action_pressed("move_right")):
|
||||
dir += cam_xform.basis[0]
|
||||
|
||||
|
||||
var jump_attempt = Input.is_action_pressed("jump")
|
||||
var shoot_attempt = Input.is_action_pressed("shoot")
|
||||
|
||||
|
||||
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_threshold
|
||||
|
||||
|
||||
if (dir.length() > 0.1 and !sharp_turn):
|
||||
if (hspeed > 0.001):
|
||||
#linear_dir = linear_h_velocity/linear_vel
|
||||
@@ -120,24 +119,24 @@ func _integrate_forces(state):
|
||||
facing_dir = hdir
|
||||
else:
|
||||
hdir = target_dir
|
||||
|
||||
|
||||
if (hspeed < max_speed):
|
||||
hspeed += accel*delta
|
||||
else:
|
||||
hspeed -= deaccel*delta
|
||||
if (hspeed < 0):
|
||||
hspeed = 0
|
||||
|
||||
|
||||
hv = hdir*hspeed
|
||||
|
||||
|
||||
var mesh_xform = get_node("Armature").get_transform()
|
||||
var facing_mesh = -mesh_xform.basis[0].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)
|
||||
var m3 = Matrix3(-facing_mesh, up, -facing_mesh.cross(up).normalized()).scaled(CHAR_SCALE)
|
||||
|
||||
|
||||
get_node("Armature").set_transform(Transform(m3, mesh_xform.origin))
|
||||
|
||||
|
||||
if (not jumping and jump_attempt):
|
||||
vv = 7.0
|
||||
jumping = true
|
||||
@@ -147,7 +146,7 @@ func _integrate_forces(state):
|
||||
anim = ANIM_AIR_UP
|
||||
else:
|
||||
anim = ANIM_AIR_DOWN
|
||||
|
||||
|
||||
var hs
|
||||
if (dir.length() > 0.1):
|
||||
hv += target_dir*(accel*0.2)*delta
|
||||
@@ -158,14 +157,14 @@ func _integrate_forces(state):
|
||||
hspeed = hspeed - (deaccel*0.2)*delta
|
||||
if (hspeed < 0):
|
||||
hspeed = 0
|
||||
|
||||
|
||||
hv = hdir*hspeed
|
||||
|
||||
|
||||
if (jumping and vv < 0):
|
||||
jumping = false
|
||||
|
||||
|
||||
lv = hv + up*vv
|
||||
|
||||
|
||||
if (onfloor):
|
||||
movement_dir = lv
|
||||
#lv += floor_velocity
|
||||
@@ -175,19 +174,19 @@ func _integrate_forces(state):
|
||||
#if (keep_jump_inertia):
|
||||
# lv += last_floor_velocity
|
||||
pass
|
||||
|
||||
|
||||
last_floor_velocity = Vector3()
|
||||
movement_dir = lv
|
||||
|
||||
|
||||
on_floor = onfloor
|
||||
|
||||
|
||||
state.set_linear_velocity(lv)
|
||||
|
||||
|
||||
if (shoot_blend > 0):
|
||||
shoot_blend -= delta*SHOOT_SCALE
|
||||
if (shoot_blend < 0):
|
||||
shoot_blend = 0
|
||||
|
||||
|
||||
if (shoot_attempt and not prev_shoot):
|
||||
shoot_blend = SHOOT_TIME
|
||||
var bullet = preload("res://bullet.scn").instance()
|
||||
@@ -196,12 +195,12 @@ func _integrate_forces(state):
|
||||
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
|
||||
get_node("sfx").play("shoot")
|
||||
|
||||
|
||||
prev_shoot = shoot_attempt
|
||||
|
||||
|
||||
if (onfloor):
|
||||
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())
|
||||
|
||||
@@ -69,4 +69,4 @@
|
||||
</dictionary>
|
||||
|
||||
</main_resource>
|
||||
</resource_file>
|
||||
</resource_file>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Camera
|
||||
|
||||
# Member variables
|
||||
@@ -16,27 +15,27 @@ func _fixed_process(dt):
|
||||
var target = get_parent().get_global_transform().origin
|
||||
var pos = get_global_transform().origin
|
||||
var up = Vector3(0, 1, 0)
|
||||
|
||||
|
||||
var delta = pos - target
|
||||
|
||||
|
||||
# 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
|
||||
if ( delta.y > max_height):
|
||||
delta.y = max_height
|
||||
if ( delta.y < min_height):
|
||||
delta.y = min_height
|
||||
|
||||
|
||||
pos = target + delta
|
||||
|
||||
|
||||
look_at_from_pos(pos, target, up)
|
||||
|
||||
|
||||
# Turn a little up or down
|
||||
var t = get_transform()
|
||||
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends VehicleBody
|
||||
|
||||
# Member variables
|
||||
@@ -18,17 +17,17 @@ func _fixed_process(delta):
|
||||
steer_target = STEER_LIMIT
|
||||
else:
|
||||
steer_target = 0
|
||||
|
||||
|
||||
if (Input.is_action_pressed("ui_up")):
|
||||
set_engine_force(engine_force)
|
||||
else:
|
||||
set_engine_force(0)
|
||||
|
||||
|
||||
if (Input.is_action_pressed("ui_down")):
|
||||
set_brake(1)
|
||||
else:
|
||||
set_brake(0.0)
|
||||
|
||||
|
||||
if (steer_target < steer_angle):
|
||||
steer_angle -= STEER_SPEED*delta
|
||||
if (steer_target > steer_angle):
|
||||
@@ -37,7 +36,7 @@ func _fixed_process(delta):
|
||||
steer_angle += STEER_SPEED*delta
|
||||
if (steer_target < steer_angle):
|
||||
steer_angle = steer_target
|
||||
|
||||
|
||||
set_steering(steer_angle)
|
||||
|
||||
|
||||
|
||||
21
README.md
21
README.md
@@ -8,23 +8,10 @@ be used with [Godot Engine](https://godotengine.org), the open source
|
||||
|
||||
- The [`master`](https://github.com/godotengine/godot-demo-projects) branch is compatible with Godot's `master` development branch (next 4.x release).
|
||||
- The [`3.x`](https://github.com/godotengine/godot-demo-projects/tree/3.x) branch is compatible with Godot's `3.x` development branch (next 3.x release).
|
||||
- The other branches are compatible with the matching stable versions of Godot:
|
||||
- [`4.0`](https://github.com/godotengine/godot-demo-projects/tree/4.0)
|
||||
branch for Godot 4.0.x.
|
||||
- [`3.5`](https://github.com/godotengine/godot-demo-projects/tree/3.5)
|
||||
branch for Godot 3.5.x.
|
||||
- [`3.4`](https://github.com/godotengine/godot-demo-projects/tree/3.4)
|
||||
branch for Godot 3.4.x.
|
||||
- [`3.3`](https://github.com/godotengine/godot-demo-projects/tree/3.3)
|
||||
branch for Godot 3.3.x.
|
||||
- [`3.2`](https://github.com/godotengine/godot-demo-projects/tree/3.2)
|
||||
branch for Godot 3.2.x.
|
||||
- [`3.1`](https://github.com/godotengine/godot-demo-projects/tree/3.1)
|
||||
branch for Godot 3.1.x.
|
||||
- [`3.0`](https://github.com/godotengine/godot-demo-projects/tree/3.0)
|
||||
branch for Godot 3.0.x.
|
||||
- [***`2.1`***](https://github.com/godotengine/godot-demo-projects/tree/2.1)
|
||||
branch for Godot 2.1.x.
|
||||
- The other branches are compatible with the matching stable versions of Godot.
|
||||
- [Click here](https://github.com/godotengine/godot-demo-projects/branches) to see all branches.
|
||||
- For example, the [`2.1`](https://github.com/godotengine/godot-demo-projects/tree/2.1)
|
||||
branch is for demos compatible with Godot 2.1.x.
|
||||
|
||||
## Importing all demos
|
||||
|
||||
|
||||
55
file_format.sh
Executable file
55
file_format.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script ensures proper POSIX text file formatting and a few other things.
|
||||
|
||||
set -uo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# Loops through all text files tracked by Git.
|
||||
git grep -zIl '' |
|
||||
while IFS= read -rd '' f; do
|
||||
# Exclude some types of files.
|
||||
if [[ "$f" == *"csproj" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *"hdr" ]]; then
|
||||
continue
|
||||
fi
|
||||
# Ensure that files are UTF-8 formatted.
|
||||
recode UTF-8 "$f" 2> /dev/null
|
||||
# Ensure that files have LF line endings and do not contain a BOM.
|
||||
dos2unix "$f" 2> /dev/null
|
||||
# Remove trailing space characters and ensures that files end
|
||||
# with newline characters. -l option handles newlines conveniently.
|
||||
perl -i -ple 's/\s*$//g' "$f"
|
||||
# Remove the character sequence "== true" if it has a leading space.
|
||||
perl -i -pe 's/\x20== true//g' "$f"
|
||||
# We don't want to change lines around braces in godot/tscn files.
|
||||
if [[ "$f" == *"godot" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *"tscn" ]]; then
|
||||
continue
|
||||
fi
|
||||
# Disallow empty lines after the opening brace.
|
||||
sed -z -i 's/\x7B\x0A\x0A/\x7B\x0A/g' "$f"
|
||||
# Disallow some empty lines before the closing brace.
|
||||
sed -z -i 's/\x0A\x0A\x7D/\x0A\x7D/g' "$f"
|
||||
done
|
||||
|
||||
git diff > patch.patch
|
||||
FILESIZE="$(stat -c%s patch.patch)"
|
||||
MAXSIZE=5
|
||||
|
||||
# If no patch has been generated all is OK, clean up, and exit.
|
||||
if (( FILESIZE < MAXSIZE )); then
|
||||
printf "Files in this commit comply with the formatting rules.\n"
|
||||
rm -f patch.patch
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# A patch has been created, notify the user, clean up, and exit.
|
||||
printf "\n*** The following differences were found between the code "
|
||||
printf "and the formatting rules:\n\n"
|
||||
cat patch.patch
|
||||
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
|
||||
rm -f patch.patch
|
||||
exit 1
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends ColorPickerButton
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Panel
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Panel
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Panel
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
,en,es,ja
|
||||
KEY_HELLO,Hello!,Hola!,こんにちは
|
||||
KEY_PUSH,Push Me!,Aprétame!,私をプッシュ
|
||||
KEY_PUSH,Push Me!,Aprétame!,私をプッシュ
|
||||
|
||||
|
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node
|
||||
|
||||
signal purchase_success(item_name)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Control
|
||||
|
||||
onready var alert = get_node("alert")
|
||||
@@ -13,7 +12,7 @@ func _ready():
|
||||
iap.connect("consume_success", self, "on_consume_success")
|
||||
iap.connect("consume_fail", self, "on_consume_fail")
|
||||
iap.connect("sku_details_complete", self, "on_sku_details_complete")
|
||||
|
||||
|
||||
get_node("purchase").connect("pressed", self, "button_purchase")
|
||||
get_node("consume").connect("pressed", self, "button_consume")
|
||||
get_node("request").connect("pressed", self, "button_request")
|
||||
|
||||
@@ -12,25 +12,25 @@ func goto_scene(path):
|
||||
# Deleting the current scene at this point might be
|
||||
# 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 way around this is deferring the load to a later time, when
|
||||
# it is ensured that no code from the current scene is running:
|
||||
|
||||
|
||||
call_deferred("_deferred_goto_scene",path)
|
||||
|
||||
|
||||
func _deferred_goto_scene(path):
|
||||
# Immediately free the current scene, there is no risk here.
|
||||
get_tree().get_current_scene().free()
|
||||
|
||||
|
||||
# Load new scene
|
||||
var packed_scene = ResourceLoader.load(path)
|
||||
|
||||
|
||||
# Instance the new scene
|
||||
var instanced_scene = packed_scene.instance()
|
||||
|
||||
|
||||
# Add it to the scene tree, as direct child of root
|
||||
get_tree().get_root().add_child(instanced_scene)
|
||||
|
||||
|
||||
# Set it as the current scene, only after it has been added to the tree
|
||||
get_tree().set_current_scene(instanced_scene)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Spatial
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends VBoxContainer
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Panel
|
||||
|
||||
# Member variables here, example:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Panel
|
||||
|
||||
# Member variables here, example:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -16,26 +16,26 @@ func _ready():
|
||||
for index in range(trans.size()):
|
||||
var name = trans[index]
|
||||
get_node("trans/" + name).connect("pressed", self, "on_trans_changed", [name, index])
|
||||
|
||||
|
||||
for index in range(eases.size()):
|
||||
var name = eases[index]
|
||||
get_node("eases/" + name).connect("pressed", self, "on_eases_changed", [name, index])
|
||||
|
||||
|
||||
for index in range(modes.size()):
|
||||
var name = modes[index]
|
||||
get_node("modes/" + name).connect("pressed", self, "on_modes_changed", [name])
|
||||
|
||||
|
||||
get_node("colors/color_from/picker").set_color(Color(1, 0, 0, 1))
|
||||
get_node("colors/color_from/picker").connect("color_changed", self, "on_color_changed")
|
||||
|
||||
|
||||
get_node("colors/color_to/picker").set_color(Color(0, 1, 1, 1))
|
||||
get_node("colors/color_to/picker").connect("color_changed", self, "on_color_changed")
|
||||
|
||||
|
||||
get_node("trans/linear").set_pressed(true)
|
||||
get_node("eases/in").set_pressed(true)
|
||||
get_node("modes/move").set_pressed(true)
|
||||
get_node("modes/repeat").set_pressed(true)
|
||||
|
||||
|
||||
reset_tween()
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ func on_trans_changed(name, index):
|
||||
for index in range(trans.size()):
|
||||
var pressed = trans[index] == name
|
||||
var btn = get_node("trans/" + trans[index])
|
||||
|
||||
|
||||
btn.set_pressed(pressed)
|
||||
btn.set_ignore_mouse(pressed)
|
||||
|
||||
|
||||
state.trans = index
|
||||
reset_tween()
|
||||
|
||||
@@ -55,10 +55,10 @@ func on_eases_changed(name, index):
|
||||
for index in range(eases.size()):
|
||||
var pressed = eases[index] == name
|
||||
var btn = get_node("eases/" + eases[index])
|
||||
|
||||
|
||||
btn.set_pressed(pressed)
|
||||
btn.set_ignore_mouse(pressed)
|
||||
|
||||
|
||||
state.eases = index
|
||||
reset_tween()
|
||||
|
||||
@@ -85,7 +85,7 @@ func reset_tween():
|
||||
var pos = tween.tell()
|
||||
tween.reset_all()
|
||||
tween.remove_all()
|
||||
|
||||
|
||||
var sprite = get_node("tween/area/sprite")
|
||||
var follow = get_node("tween/area/follow")
|
||||
var follow_2 = get_node("tween/area/follow_2")
|
||||
@@ -94,44 +94,44 @@ func reset_tween():
|
||||
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_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():
|
||||
tween.interpolate_method(sprite, "set_modulate", get_node("colors/color_from/picker").get_color(), get_node("colors/color_to/picker").get_color(), 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "modulate", get_node("colors/color_to/picker").get_color(), get_node("colors/color_from/picker").get_color(), 2, state.trans, state.eases, 2)
|
||||
else:
|
||||
sprite.set_modulate(Color(1,1,1,1))
|
||||
|
||||
|
||||
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_property(sprite, "transform/scale", Vector2(1.5, 1.5), Vector2(0.5, 0.5), 2, state.trans, state.eases, 2)
|
||||
else:
|
||||
sprite.set_scale(Vector2(1,1))
|
||||
|
||||
|
||||
if get_node("modes/rotate").is_pressed():
|
||||
tween.interpolate_method(sprite, "set_rotd", 0, 360, 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "transform/rot", 360, 0, 2, state.trans, state.eases, 2)
|
||||
|
||||
|
||||
if get_node("modes/callback").is_pressed():
|
||||
tween.interpolate_callback(self, 0.5, "on_callback", "0.5 second's after")
|
||||
tween.interpolate_callback(self, 0.2, "on_callback", "1.2 second's after")
|
||||
|
||||
|
||||
if get_node("modes/follow").is_pressed():
|
||||
follow.show()
|
||||
follow_2.show()
|
||||
|
||||
|
||||
tween.follow_method(follow, "set_pos", Vector2(0, size.height), sprite, "get_pos", 2, state.trans, state.eases)
|
||||
tween.targeting_method(follow, "set_pos", sprite, "get_pos", Vector2(0, size.height), 2, state.trans, state.eases, 2)
|
||||
|
||||
|
||||
tween.targeting_property(follow_2, "transform/pos", sprite, "transform/pos", Vector2(size.width, 0), 2, state.trans, state.eases)
|
||||
tween.follow_property(follow_2, "transform/pos", Vector2(size.width, 0), sprite, "transform/pos", 2, state.trans, state.eases, 2)
|
||||
else:
|
||||
follow.hide()
|
||||
follow_2.hide()
|
||||
|
||||
|
||||
tween.set_repeat(get_node("modes/repeat").is_pressed())
|
||||
tween.start()
|
||||
tween.seek(pos)
|
||||
|
||||
|
||||
if get_node("modes/pause").is_pressed():
|
||||
tween.stop_all()
|
||||
get_node("timeline").set_ignore_mouse(false)
|
||||
@@ -143,10 +143,10 @@ func reset_tween():
|
||||
|
||||
func _on_tween_step(object, key, elapsed, value):
|
||||
var timeline = get_node("timeline")
|
||||
|
||||
|
||||
var tween = get_node("tween")
|
||||
var runtime = tween.get_runtime()
|
||||
|
||||
|
||||
var ratio = 100*(elapsed/runtime)
|
||||
timeline.set_value(ratio)
|
||||
|
||||
@@ -154,7 +154,7 @@ func _on_tween_step(object, key, elapsed, value):
|
||||
func _on_timeline_value_changed(value):
|
||||
if !get_node("modes/pause").is_pressed():
|
||||
return
|
||||
|
||||
|
||||
var tween = get_node("tween")
|
||||
var runtime = tween.get_runtime()
|
||||
tween.seek(runtime*value/100)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Panel
|
||||
|
||||
# Really simple UDP chat client, not intended as a comprehensive chat implementation.
|
||||
@@ -12,7 +11,7 @@ var udp = PacketPeerUDP.new()
|
||||
func _process(delta):
|
||||
if (not udp.is_listening()):
|
||||
return
|
||||
|
||||
|
||||
while(udp.get_available_packet_count() > 0):
|
||||
var packet = udp.get_var()
|
||||
if (typeof(packet) == TYPE_STRING):
|
||||
@@ -62,5 +61,5 @@ func _on_entry_button_pressed():
|
||||
if (msg == ""):
|
||||
return
|
||||
send_message(get_node("user_name").get_text() + "> " + msg)
|
||||
|
||||
|
||||
get_node("entry_line").set_text("")
|
||||
|
||||
@@ -7,45 +7,45 @@ onready var observer = get_node("../Observer")
|
||||
|
||||
func _fixed_process(delta):
|
||||
var modetext = "Mode:\n"
|
||||
|
||||
|
||||
if(OS.is_window_fullscreen()):
|
||||
modetext += "Fullscreen\n"
|
||||
else:
|
||||
modetext += "Windowed\n"
|
||||
|
||||
|
||||
if(!OS.is_window_resizable()):
|
||||
modetext += "FixedSize\n"
|
||||
|
||||
|
||||
if(OS.is_window_minimized()):
|
||||
modetext += "Minimized\n"
|
||||
|
||||
|
||||
if(OS.is_window_maximized()):
|
||||
modetext += "Maximized\n"
|
||||
|
||||
|
||||
if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED):
|
||||
modetext += "MouseGrab\n"
|
||||
get_node("Label_MouseModeCaptured_KeyInfo").show()
|
||||
else:
|
||||
get_node("Label_MouseModeCaptured_KeyInfo").hide()
|
||||
|
||||
|
||||
get_node("Label_Mode").set_text(modetext)
|
||||
|
||||
|
||||
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_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_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_Position").set_text(str("Screen0 Position:\n", OS.get_screen_position()))
|
||||
|
||||
get_node("Label_Screen0_DPI").set_text(str("Screen0 DPI:\n", OS.get_screen_dpi()))
|
||||
|
||||
|
||||
if(OS.get_screen_count() > 1):
|
||||
get_node("Button_Screen0").show()
|
||||
get_node("Button_Screen1").show()
|
||||
@@ -61,7 +61,7 @@ func _fixed_process(delta):
|
||||
get_node("Label_Screen1_Resolution").hide()
|
||||
get_node("Label_Screen1_Position").hide()
|
||||
get_node("Label_Screen1_DPI").hide()
|
||||
|
||||
|
||||
get_node("Button_Fullscreen").set_pressed(OS.is_window_fullscreen())
|
||||
get_node("Button_FixedSize").set_pressed(!OS.is_window_resizable())
|
||||
get_node("Button_Minimized").set_pressed(OS.is_window_minimized())
|
||||
@@ -75,55 +75,55 @@ func check_wm_api():
|
||||
var s = ""
|
||||
if(!OS.has_method("get_screen_count")):
|
||||
s += " - get_screen_count()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("get_current_screen")):
|
||||
s += " - get_current_screen()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("set_current_screen")):
|
||||
s += " - set_current_screen()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("get_screen_position")):
|
||||
s += " - get_screen_position()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("get_screen_size")):
|
||||
s += " - get_screen_size()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("get_window_position")):
|
||||
s += " - get_window_position()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("set_window_position")):
|
||||
s += " - set_window_position()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("get_window_size")):
|
||||
s += " - get_window_size()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("set_window_size")):
|
||||
s += " - set_window_size()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("set_window_fullscreen")):
|
||||
s += " - set_window_fullscreen()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("is_window_fullscreen")):
|
||||
s += " - is_window_fullscreen()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("set_window_resizable")):
|
||||
s += " - set_window_resizable()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("is_window_resizable")):
|
||||
s += " - is_window_resizable()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("set_window_minimized")):
|
||||
s += " - set_window_minimized()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("is_window_minimized")):
|
||||
s += " - is_window_minimized()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("set_window_maximized")):
|
||||
s += " - set_window_maximized()\n"
|
||||
|
||||
|
||||
if(!OS.has_method("is_window_maximized")):
|
||||
s += " - is_window_maximized()\n"
|
||||
|
||||
|
||||
if(s.length() == 0):
|
||||
return true
|
||||
else:
|
||||
@@ -142,16 +142,16 @@ func _ready():
|
||||
func _input(event):
|
||||
if (event.type == InputEvent.MOUSE_MOTION):
|
||||
mousepos = event.pos
|
||||
|
||||
|
||||
if (event.type == InputEvent.KEY):
|
||||
if Input.is_action_pressed("mouse_mode_visible"):
|
||||
observer.state = observer.STATE_MENU
|
||||
_on_Button_MouseModeVisible_pressed()
|
||||
|
||||
|
||||
if Input.is_action_pressed("mouse_mode_hidden"):
|
||||
observer.state = observer.STATE_MENU
|
||||
_on_Button_MouseModeHidden_pressed()
|
||||
|
||||
|
||||
if Input.is_action_pressed("mouse_mode_captured"):
|
||||
_on_Button_MouseModeCaptured_pressed()
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Spatial
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -10,14 +10,9 @@ func _enter_tree():
|
||||
|
||||
add_control_to_dock( DOCK_SLOT_LEFT_UL, dock )
|
||||
|
||||
func _exit_tree():
|
||||
|
||||
func _exit_tree():
|
||||
# Remove from docks (must be called so layout is updated and saved)
|
||||
remove_control_from_docks(dock)
|
||||
# Remove the node
|
||||
dock.free()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
tool
|
||||
|
||||
extends EditorImportPlugin
|
||||
|
||||
|
||||
|
||||
@@ -11,22 +11,22 @@ func configure(p_import_plugin,path,metadata):
|
||||
# metadata from previous import exists, fill in fields
|
||||
assert( metadata.get_source_count() > 0 )
|
||||
# Always expand the source paths
|
||||
var src_path = import_plugin.expand_source_path( metadata.get_source_path(0) )
|
||||
var src_path = import_plugin.expand_source_path( metadata.get_source_path(0) )
|
||||
get_node("src_file").set_text(src_path)
|
||||
get_node("dst_file").set_text(path)
|
||||
# Fill in from metadata options
|
||||
get_node("use_red_anyway").set_pressed( metadata.get_option("use_red_anyway") )
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
|
||||
|
||||
src_fs = FileDialog.new()
|
||||
src_fs.set_mode(FileDialog.MODE_OPEN_FILE)
|
||||
src_fs.set_access(FileDialog.ACCESS_FILESYSTEM) #access all filesystem, not only res://
|
||||
src_fs.add_filter("*.mtxt")
|
||||
src_fs.connect("file_selected",self,"_on_src_selected")
|
||||
|
||||
add_child(src_fs)
|
||||
|
||||
add_child(src_fs)
|
||||
|
||||
dst_fs = EditorFileDialog.new()
|
||||
dst_fs.set_mode(EditorFileDialog.MODE_SAVE_FILE)
|
||||
@@ -47,15 +47,15 @@ func _on_dst_browse_pressed():
|
||||
|
||||
func _on_src_selected(path):
|
||||
get_node("src_file").set_text(path)
|
||||
|
||||
|
||||
func _on_dst_selected(path):
|
||||
get_node("dst_file").set_text(path)
|
||||
get_node("dst_file").set_text(path)
|
||||
|
||||
func _on_MaterialImport_confirmed():
|
||||
# Create an import metadata
|
||||
var imd = ResourceImportMetadata.new()
|
||||
# Add the source files, always validate the source path
|
||||
imd.add_source( import_plugin.validate_source_path( get_node("src_file").get_text() ))
|
||||
imd.add_source( import_plugin.validate_source_path( get_node("src_file").get_text() ))
|
||||
# Add the options
|
||||
imd.set_option( "use_red_anyway", get_node("use_red_anyway").is_pressed() )
|
||||
# Perform regular import
|
||||
@@ -64,4 +64,4 @@ func _on_MaterialImport_confirmed():
|
||||
if (err!=OK):
|
||||
get_node("error").set_text("Error Importing!")
|
||||
get_node("error").popup_centered_minsize()
|
||||
|
||||
|
||||
|
||||
@@ -3,20 +3,15 @@ extends EditorPlugin
|
||||
|
||||
var import_plugin
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
|
||||
import_plugin = preload("res://addons/custom_import_plugin/import_plugin.gd").new()
|
||||
|
||||
# pass the GUI base control, so the dialog has a parent node
|
||||
import_plugin.config( get_base_control() )
|
||||
|
||||
add_import_plugin( import_plugin)
|
||||
add_import_plugin( import_plugin)
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
|
||||
remove_import_plugin( import_plugin )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
remove_import_plugin( import_plugin )
|
||||
|
||||
@@ -15,4 +15,3 @@ func _exit_tree():
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,4 +10,4 @@ addons/custom_node
|
||||
To distribute and install from UI, make a zip that contains the folder,
|
||||
example:
|
||||
|
||||
zip -r custom_node.zip custom_node/*
|
||||
zip -r custom_node.zip custom_node/*
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# Member variables
|
||||
@@ -16,47 +15,47 @@ func _process(delta):
|
||||
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
|
||||
ball_pos += direction*ball_speed*delta
|
||||
|
||||
|
||||
# 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
|
||||
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
|
||||
if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
|
||||
ball_pos = screen_size*0.5
|
||||
ball_speed = INITIAL_BALL_SPEED
|
||||
direction = Vector2(-1, 0)
|
||||
|
||||
|
||||
get_node("ball").set_pos(ball_pos)
|
||||
|
||||
|
||||
# Move left pad
|
||||
var left_pos = get_node("left").get_pos()
|
||||
|
||||
|
||||
if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
|
||||
left_pos.y += -PAD_SPEED*delta
|
||||
if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")):
|
||||
left_pos.y += PAD_SPEED*delta
|
||||
|
||||
|
||||
get_node("left").set_pos(left_pos)
|
||||
|
||||
|
||||
# Move right pad
|
||||
var right_pos = get_node("right").get_pos()
|
||||
|
||||
|
||||
if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
|
||||
right_pos.y += -PAD_SPEED*delta
|
||||
if (right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")):
|
||||
right_pos.y += PAD_SPEED*delta
|
||||
|
||||
|
||||
get_node("right").set_pos(right_pos)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Spatial
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Spatial
|
||||
|
||||
# Member variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
extends Control
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user