mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2025-12-16 13:30:07 +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.
|
# Top-most EditorConfig file.
|
||||||
root = true
|
root = true
|
||||||
|
|
||||||
|
# Unix-style newlines with a newline ending every file.
|
||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
end_of_line = lf
|
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
|
# System/tool-specific ignores
|
||||||
.directory
|
.directory
|
||||||
|
.DS_Store
|
||||||
*~
|
*~
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends TileMap
|
extends TileMap
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -30,7 +29,7 @@ var l = range(2, 5)
|
|||||||
# Process that runs in realtime
|
# Process that runs in realtime
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
position = get_node("../troll").get_pos()
|
position = get_node("../troll").get_pos()
|
||||||
|
|
||||||
# Calculate the corresponding tile
|
# Calculate the corresponding tile
|
||||||
# from the players position
|
# from the players position
|
||||||
x = int(position.x/get_cell_size().x)
|
x = int(position.x/get_cell_size().x)
|
||||||
@@ -38,11 +37,11 @@ func _fixed_process(delta):
|
|||||||
# causes problems because of rounding problems
|
# causes problems because of rounding problems
|
||||||
if position.x < 0:
|
if position.x < 0:
|
||||||
x -= 1 # Correct negative values
|
x -= 1 # Correct negative values
|
||||||
|
|
||||||
y = int(position.y/get_cell_size().y)
|
y = int(position.y/get_cell_size().y)
|
||||||
if (position.y < 0):
|
if (position.y < 0):
|
||||||
y -= 1
|
y -= 1
|
||||||
|
|
||||||
# Check if the player moved one tile further
|
# Check if the player moved one tile further
|
||||||
if ((x_old != x) or (y_old != y)):
|
if ((x_old != x) or (y_old != y)):
|
||||||
# Create the transparent part (visited area)
|
# Create the transparent part (visited area)
|
||||||
@@ -55,7 +54,7 @@ func _fixed_process(delta):
|
|||||||
set_cell(m, n, 1, 0, 0)
|
set_cell(m, n, 1, 0, 0)
|
||||||
end -= 1
|
end -= 1
|
||||||
start += 1
|
start += 1
|
||||||
|
|
||||||
# Create the actual and active visible part
|
# Create the actual and active visible part
|
||||||
var end = l.size() - 1
|
var end = l.size() - 1
|
||||||
var start = 0
|
var start = 0
|
||||||
@@ -65,7 +64,7 @@ func _fixed_process(delta):
|
|||||||
set_cell(m, n, -1)
|
set_cell(m, n, -1)
|
||||||
end -= 1
|
end -= 1
|
||||||
start += 1
|
start += 1
|
||||||
|
|
||||||
x_old = x
|
x_old = x
|
||||||
y_old = y
|
y_old = y
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
# This is a simple collision demo showing how
|
# This is a simple collision demo showing how
|
||||||
@@ -13,7 +12,7 @@ const MOTION_SPEED = 160 # Pixels/second
|
|||||||
|
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
var motion = Vector2()
|
var motion = Vector2()
|
||||||
|
|
||||||
if (Input.is_action_pressed("move_up")):
|
if (Input.is_action_pressed("move_up")):
|
||||||
motion += Vector2(0, -1)
|
motion += Vector2(0, -1)
|
||||||
if (Input.is_action_pressed("move_bottom")):
|
if (Input.is_action_pressed("move_bottom")):
|
||||||
@@ -22,10 +21,10 @@ func _fixed_process(delta):
|
|||||||
motion += Vector2(-1, 0)
|
motion += Vector2(-1, 0)
|
||||||
if (Input.is_action_pressed("move_right")):
|
if (Input.is_action_pressed("move_right")):
|
||||||
motion += Vector2(1, 0)
|
motion += Vector2(1, 0)
|
||||||
|
|
||||||
motion = motion.normalized()*MOTION_SPEED*delta
|
motion = motion.normalized()*MOTION_SPEED*delta
|
||||||
motion = move(motion)
|
motion = move(motion)
|
||||||
|
|
||||||
# Make character slide nicely through the world
|
# Make character slide nicely through the world
|
||||||
var slide_attempts = 4
|
var slide_attempts = 4
|
||||||
while(is_colliding() and slide_attempts > 0):
|
while(is_colliding() and slide_attempts > 0):
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
# This is a simple collision demo showing how
|
# This is a simple collision demo showing how
|
||||||
# the kinematic controller works.
|
# the kinematic controller works.
|
||||||
# move() will allow to move the node, and will
|
# 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.
|
# as long as it starts from a non-colliding spot too.
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -13,7 +12,7 @@ const MOTION_SPEED = 160 # Pixels/second
|
|||||||
|
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
var motion = Vector2()
|
var motion = Vector2()
|
||||||
|
|
||||||
if (Input.is_action_pressed("move_up")):
|
if (Input.is_action_pressed("move_up")):
|
||||||
motion += Vector2(0, -1)
|
motion += Vector2(0, -1)
|
||||||
if (Input.is_action_pressed("move_bottom")):
|
if (Input.is_action_pressed("move_bottom")):
|
||||||
@@ -22,10 +21,10 @@ func _fixed_process(delta):
|
|||||||
motion += Vector2(-1, 0)
|
motion += Vector2(-1, 0)
|
||||||
if (Input.is_action_pressed("move_right")):
|
if (Input.is_action_pressed("move_right")):
|
||||||
motion += Vector2(1, 0)
|
motion += Vector2(1, 0)
|
||||||
|
|
||||||
motion = motion.normalized()*MOTION_SPEED*delta
|
motion = motion.normalized()*MOTION_SPEED*delta
|
||||||
motion = move(motion)
|
motion = move(motion)
|
||||||
|
|
||||||
# Make character slide nicely through the world
|
# Make character slide nicely through the world
|
||||||
var slide_attempts = 4
|
var slide_attempts = 4
|
||||||
while(is_colliding() and slide_attempts > 0):
|
while(is_colliding() and slide_attempts > 0):
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
# This is a simple collision demo showing how
|
# This is a simple collision demo showing how
|
||||||
# the kinematic controller works.
|
# the kinematic controller works.
|
||||||
# move() will allow to move the node, and will
|
# 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.
|
# as long as it starts from a non-colliding spot too.
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -13,7 +12,7 @@ const MOTION_SPEED = 160 # Pixels/seconds
|
|||||||
|
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
var motion = Vector2()
|
var motion = Vector2()
|
||||||
|
|
||||||
if (Input.is_action_pressed("move_up")):
|
if (Input.is_action_pressed("move_up")):
|
||||||
motion += Vector2(0, -1)
|
motion += Vector2(0, -1)
|
||||||
if (Input.is_action_pressed("move_bottom")):
|
if (Input.is_action_pressed("move_bottom")):
|
||||||
@@ -22,10 +21,10 @@ func _fixed_process(delta):
|
|||||||
motion += Vector2(-1, 0)
|
motion += Vector2(-1, 0)
|
||||||
if (Input.is_action_pressed("move_right")):
|
if (Input.is_action_pressed("move_right")):
|
||||||
motion += Vector2(1, 0)
|
motion += Vector2(1, 0)
|
||||||
|
|
||||||
motion = motion.normalized()*MOTION_SPEED*delta
|
motion = motion.normalized()*MOTION_SPEED*delta
|
||||||
motion = move(motion)
|
motion = move(motion)
|
||||||
|
|
||||||
# Make character slide nicely through the world
|
# Make character slide nicely through the world
|
||||||
var slide_attempts = 4
|
var slide_attempts = 4
|
||||||
while(is_colliding() and slide_attempts > 0):
|
while(is_colliding() and slide_attempts > 0):
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -37,14 +36,14 @@ func _fixed_process(delta):
|
|||||||
dir += Vector2(-1, 0)
|
dir += Vector2(-1, 0)
|
||||||
if (Input.is_action_pressed("right")):
|
if (Input.is_action_pressed("right")):
|
||||||
dir += Vector2(1, 0)
|
dir += Vector2(1, 0)
|
||||||
|
|
||||||
if (dir != Vector2()):
|
if (dir != Vector2()):
|
||||||
dir = dir.normalized()
|
dir = dir.normalized()
|
||||||
speed = speed.linear_interpolate(dir*MAX_SPEED, delta*ACCEL)
|
speed = speed.linear_interpolate(dir*MAX_SPEED, delta*ACCEL)
|
||||||
var motion = speed*delta
|
var motion = speed*delta
|
||||||
motion.y *= VSCALE
|
motion.y *= VSCALE
|
||||||
motion = move(motion)
|
motion = move(motion)
|
||||||
|
|
||||||
if (is_colliding()):
|
if (is_colliding()):
|
||||||
var n = get_collision_normal()
|
var n = get_collision_normal()
|
||||||
motion = n.slide(motion)
|
motion = n.slide(motion)
|
||||||
@@ -52,13 +51,13 @@ func _fixed_process(delta):
|
|||||||
|
|
||||||
var next_anim = ""
|
var next_anim = ""
|
||||||
var next_mirror = false
|
var next_mirror = false
|
||||||
|
|
||||||
if (dir == Vector2() and speed.length() < IDLE_SPEED):
|
if (dir == Vector2() and speed.length() < IDLE_SPEED):
|
||||||
next_anim = "idle"
|
next_anim = "idle"
|
||||||
next_mirror = false
|
next_mirror = false
|
||||||
elif (speed.length() > IDLE_SPEED*0.1):
|
elif (speed.length() > IDLE_SPEED*0.1):
|
||||||
var angle = atan2(abs(speed.x), speed.y)
|
var angle = atan2(abs(speed.x), speed.y)
|
||||||
|
|
||||||
next_mirror = speed.x > 0
|
next_mirror = speed.x > 0
|
||||||
if (angle < PI/8):
|
if (angle < PI/8):
|
||||||
next_anim = "bottom"
|
next_anim = "bottom"
|
||||||
@@ -72,7 +71,7 @@ func _fixed_process(delta):
|
|||||||
else:
|
else:
|
||||||
next_anim = "top"
|
next_anim = "top"
|
||||||
next_mirror = false
|
next_mirror = false
|
||||||
|
|
||||||
if (next_anim != current_anim or next_mirror != current_mirror):
|
if (next_anim != current_anim or next_mirror != current_mirror):
|
||||||
get_node("frames").set_flip_h(next_mirror)
|
get_node("frames").set_flip_h(next_mirror)
|
||||||
get_node("anim").play(next_anim)
|
get_node("anim").play(next_anim)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
# This is a simple collision demo showing how
|
# This is a simple collision demo showing how
|
||||||
@@ -32,13 +31,13 @@ var prev_jump_pressed = false
|
|||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
# Create forces
|
# Create forces
|
||||||
var force = Vector2(0, GRAVITY)
|
var force = Vector2(0, GRAVITY)
|
||||||
|
|
||||||
var walk_left = Input.is_action_pressed("move_left")
|
var walk_left = Input.is_action_pressed("move_left")
|
||||||
var walk_right = Input.is_action_pressed("move_right")
|
var walk_right = Input.is_action_pressed("move_right")
|
||||||
var jump = Input.is_action_pressed("jump")
|
var jump = Input.is_action_pressed("jump")
|
||||||
|
|
||||||
var stop = true
|
var stop = true
|
||||||
|
|
||||||
if (walk_left):
|
if (walk_left):
|
||||||
if (velocity.x <= WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED):
|
if (velocity.x <= WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED):
|
||||||
force.x -= WALK_FORCE
|
force.x -= WALK_FORCE
|
||||||
@@ -47,50 +46,50 @@ func _fixed_process(delta):
|
|||||||
if (velocity.x >= -WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED):
|
if (velocity.x >= -WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED):
|
||||||
force.x += WALK_FORCE
|
force.x += WALK_FORCE
|
||||||
stop = false
|
stop = false
|
||||||
|
|
||||||
if (stop):
|
if (stop):
|
||||||
var vsign = sign(velocity.x)
|
var vsign = sign(velocity.x)
|
||||||
var vlen = abs(velocity.x)
|
var vlen = abs(velocity.x)
|
||||||
|
|
||||||
vlen -= STOP_FORCE*delta
|
vlen -= STOP_FORCE*delta
|
||||||
if (vlen < 0):
|
if (vlen < 0):
|
||||||
vlen = 0
|
vlen = 0
|
||||||
|
|
||||||
velocity.x = vlen*vsign
|
velocity.x = vlen*vsign
|
||||||
|
|
||||||
# Integrate forces to velocity
|
# Integrate forces to velocity
|
||||||
velocity += force*delta
|
velocity += force*delta
|
||||||
|
|
||||||
# Integrate velocity into motion and move
|
# Integrate velocity into motion and move
|
||||||
var motion = velocity*delta
|
var motion = velocity*delta
|
||||||
|
|
||||||
# Move and consume motion
|
# Move and consume motion
|
||||||
motion = move(motion)
|
motion = move(motion)
|
||||||
|
|
||||||
var floor_velocity = Vector2()
|
var floor_velocity = Vector2()
|
||||||
|
|
||||||
if (is_colliding()):
|
if (is_colliding()):
|
||||||
# You can check which tile was collision against with this
|
# You can check which tile was collision against with this
|
||||||
# print(get_collider_metadata())
|
# print(get_collider_metadata())
|
||||||
|
|
||||||
# Ran against something, is it the floor? Get normal
|
# Ran against something, is it the floor? Get normal
|
||||||
var n = get_collision_normal()
|
var n = get_collision_normal()
|
||||||
|
|
||||||
if (rad2deg(acos(n.dot(Vector2(0, -1)))) < FLOOR_ANGLE_TOLERANCE):
|
if (rad2deg(acos(n.dot(Vector2(0, -1)))) < FLOOR_ANGLE_TOLERANCE):
|
||||||
# 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
|
||||||
on_air_time = 0
|
on_air_time = 0
|
||||||
floor_velocity = get_collider_velocity()
|
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()):
|
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,
|
# Since this formula will always slide the character around,
|
||||||
# a special case must be considered to to stop it from moving
|
# a special case must be considered to to stop it from moving
|
||||||
# if standing on an inclined floor. Conditions are:
|
# if standing on an inclined floor. Conditions are:
|
||||||
# 1) Standing on floor (on_air_time == 0)
|
# 1) Standing on floor (on_air_time == 0)
|
||||||
# 2) Did not move more than one pixel (get_travel().length() < SLIDE_STOP_MIN_TRAVEL)
|
# 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)
|
# 3) Not moving horizontally (abs(velocity.x) < SLIDE_STOP_VELOCITY)
|
||||||
# 4) Collider is not moving
|
# 4) Collider is not moving
|
||||||
|
|
||||||
revert_motion()
|
revert_motion()
|
||||||
velocity.y = 0.0
|
velocity.y = 0.0
|
||||||
else:
|
else:
|
||||||
@@ -100,21 +99,21 @@ func _fixed_process(delta):
|
|||||||
velocity = n.slide(velocity)
|
velocity = n.slide(velocity)
|
||||||
# Then move again
|
# Then move again
|
||||||
move(motion)
|
move(motion)
|
||||||
|
|
||||||
if (floor_velocity != Vector2()):
|
if (floor_velocity != Vector2()):
|
||||||
# If floor moves, move with floor
|
# If floor moves, move with floor
|
||||||
move(floor_velocity*delta)
|
move(floor_velocity*delta)
|
||||||
|
|
||||||
if (jumping and velocity.y > 0):
|
if (jumping and velocity.y > 0):
|
||||||
# If falling, no longer jumping
|
# If falling, no longer jumping
|
||||||
jumping = false
|
jumping = false
|
||||||
|
|
||||||
if (on_air_time < JUMP_MAX_AIRBORNE_TIME and jump and not prev_jump_pressed and not jumping):
|
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.
|
# Jump must also be allowed to happen if the character left the floor a little bit ago.
|
||||||
# Makes controls more snappy.
|
# Makes controls more snappy.
|
||||||
velocity.y = -JUMP_SPEED
|
velocity.y = -JUMP_SPEED
|
||||||
jumping = true
|
jumping = true
|
||||||
|
|
||||||
on_air_time += delta
|
on_air_time += delta
|
||||||
prev_jump_pressed = jump
|
prev_jump_pressed = jump
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
# This is a simple collision demo showing how
|
# This is a simple collision demo showing how
|
||||||
# the kinematic controller works.
|
# the kinematic controller works.
|
||||||
# move() will allow to move the node, and will
|
# 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.
|
# as long as it starts from a non-colliding spot too.
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -13,7 +12,7 @@ const MOTION_SPEED = 160 # Pixels/second
|
|||||||
|
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
var motion = Vector2()
|
var motion = Vector2()
|
||||||
|
|
||||||
if (Input.is_action_pressed("move_up")):
|
if (Input.is_action_pressed("move_up")):
|
||||||
motion += Vector2(0, -1)
|
motion += Vector2(0, -1)
|
||||||
if (Input.is_action_pressed("move_bottom")):
|
if (Input.is_action_pressed("move_bottom")):
|
||||||
@@ -22,7 +21,7 @@ func _fixed_process(delta):
|
|||||||
motion += Vector2(-1, 0)
|
motion += Vector2(-1, 0)
|
||||||
if (Input.is_action_pressed("move_right")):
|
if (Input.is_action_pressed("move_right")):
|
||||||
motion += Vector2(1, 0)
|
motion += Vector2(1, 0)
|
||||||
|
|
||||||
motion = motion.normalized()*MOTION_SPEED*delta
|
motion = motion.normalized()*MOTION_SPEED*delta
|
||||||
move(motion)
|
move(motion)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Sprite
|
extends Sprite
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -14,18 +13,18 @@ export(int, "Direct", "Constant", "Smooth") var mode = MODE_DIRECT
|
|||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var mpos = get_viewport().get_mouse_pos()
|
var mpos = get_viewport().get_mouse_pos()
|
||||||
|
|
||||||
if (mode == MODE_DIRECT):
|
if (mode == MODE_DIRECT):
|
||||||
look_at(mpos)
|
look_at(mpos)
|
||||||
elif (mode == MODE_CONSTANT):
|
elif (mode == MODE_CONSTANT):
|
||||||
var ang = get_angle_to(mpos)
|
var ang = get_angle_to(mpos)
|
||||||
var s = sign(ang)
|
var s = sign(ang)
|
||||||
ang = abs(ang)
|
ang = abs(ang)
|
||||||
|
|
||||||
rotate(min(ang, ROTATION_SPEED*delta)*s)
|
rotate(min(ang, ROTATION_SPEED*delta)*s)
|
||||||
elif (mode == MODE_SMOOTH):
|
elif (mode == MODE_SMOOTH):
|
||||||
var ang = get_angle_to(mpos)
|
var ang = get_angle_to(mpos)
|
||||||
|
|
||||||
rotate(ang*delta*SMOOTH_SPEED)
|
rotate(ang*delta*SMOOTH_SPEED)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Sprite
|
extends Sprite
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Navigation2D
|
extends Navigation2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -22,10 +21,10 @@ func _process(delta):
|
|||||||
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]
|
||||||
get_node("agent").set_pos(atpos)
|
get_node("agent").set_pos(atpos)
|
||||||
|
|
||||||
if (path.size() < 2):
|
if (path.size() < 2):
|
||||||
path = []
|
path = []
|
||||||
set_process(false)
|
set_process(false)
|
||||||
@@ -37,7 +36,7 @@ func _update_path():
|
|||||||
var p = get_simple_path(begin, end, true)
|
var p = get_simple_path(begin, end, true)
|
||||||
path = Array(p) # Vector2array too complex to use, convert to regular array
|
path = Array(p) # Vector2array too complex to use, convert to regular array
|
||||||
path.invert()
|
path.invert()
|
||||||
|
|
||||||
set_process(true)
|
set_process(true)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -36,13 +35,13 @@ func _integrate_forces(s):
|
|||||||
new_anim = "explode"
|
new_anim = "explode"
|
||||||
elif (state == STATE_WALKING):
|
elif (state == STATE_WALKING):
|
||||||
new_anim = "walk"
|
new_anim = "walk"
|
||||||
|
|
||||||
var wall_side = 0.0
|
var wall_side = 0.0
|
||||||
|
|
||||||
for i in range(s.get_contact_count()):
|
for i in range(s.get_contact_count()):
|
||||||
var cc = s.get_contact_collider_object(i)
|
var cc = s.get_contact_collider_object(i)
|
||||||
var dp = s.get_contact_local_normal(i)
|
var dp = s.get_contact_local_normal(i)
|
||||||
|
|
||||||
if (cc):
|
if (cc):
|
||||||
if (cc extends bullet_class and not cc.disabled):
|
if (cc extends bullet_class and not cc.disabled):
|
||||||
set_mode(MODE_RIGID)
|
set_mode(MODE_RIGID)
|
||||||
@@ -53,12 +52,12 @@ func _integrate_forces(s):
|
|||||||
cc.disable()
|
cc.disable()
|
||||||
get_node("sound").play("hit")
|
get_node("sound").play("hit")
|
||||||
break
|
break
|
||||||
|
|
||||||
if (dp.x > 0.9):
|
if (dp.x > 0.9):
|
||||||
wall_side = 1.0
|
wall_side = 1.0
|
||||||
elif (dp.x < -0.9):
|
elif (dp.x < -0.9):
|
||||||
wall_side = -1.0
|
wall_side = -1.0
|
||||||
|
|
||||||
if (wall_side != 0 and wall_side != direction):
|
if (wall_side != 0 and wall_side != direction):
|
||||||
direction = -direction
|
direction = -direction
|
||||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
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()):
|
elif (direction > 0 and not rc_right.is_colliding() and rc_left.is_colliding()):
|
||||||
direction = -direction
|
direction = -direction
|
||||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
get_node("sprite").set_scale(Vector2(-direction, 1))
|
||||||
|
|
||||||
lv.x = direction*WALK_SPEED
|
lv.x = direction*WALK_SPEED
|
||||||
|
|
||||||
if(anim != new_anim):
|
if(anim != new_anim):
|
||||||
anim = new_anim
|
anim = new_anim
|
||||||
get_node("anim").play(anim)
|
get_node("anim").play(anim)
|
||||||
|
|
||||||
s.set_linear_velocity(lv)
|
s.set_linear_velocity(lv)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -12,7 +11,7 @@ func _fixed_process(delta):
|
|||||||
accum = fmod(accum, PI*2.0)
|
accum = fmod(accum, PI*2.0)
|
||||||
var d = sin(accum)
|
var d = sin(accum)
|
||||||
var xf = Matrix32()
|
var xf = Matrix32()
|
||||||
xf[2]= motion*d
|
xf[2]= motion*d
|
||||||
get_node("platform").set_transform(xf)
|
get_node("platform").set_transform(xf)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
# Character Demo, written by Juan Linietsky.
|
# Character Demo, written by Juan Linietsky.
|
||||||
@@ -14,12 +13,12 @@ extends RigidBody2D
|
|||||||
# -Interaction with other physics-based objects is free
|
# -Interaction with other physics-based objects is free
|
||||||
# -Only have to deal with the object linear velocity, not position
|
# -Only have to deal with the object linear velocity, not position
|
||||||
# -All collision/area framework available
|
# -All collision/area framework available
|
||||||
#
|
#
|
||||||
# But also has the following disadvantages:
|
# But also has the following disadvantages:
|
||||||
#
|
#
|
||||||
# -Objects may bounce a little bit sometimes
|
# -Objects may bounce a little bit sometimes
|
||||||
# -Going up ramps sends the chracter flying up, small hack is needed.
|
# -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.
|
# undesiderd bumps, small steps and rare numerical precision errors.
|
||||||
# (another alternative may be to turn on friction when the character is not moving).
|
# (another alternative may be to turn on friction when the character is not moving).
|
||||||
# -Friction cant be used, so floor velocity must be considered
|
# -Friction cant be used, so floor velocity must be considered
|
||||||
@@ -56,38 +55,38 @@ var enemy
|
|||||||
func _integrate_forces(s):
|
func _integrate_forces(s):
|
||||||
var lv = s.get_linear_velocity()
|
var lv = s.get_linear_velocity()
|
||||||
var step = s.get_step()
|
var step = s.get_step()
|
||||||
|
|
||||||
var new_anim = anim
|
var new_anim = anim
|
||||||
var new_siding_left = siding_left
|
var new_siding_left = siding_left
|
||||||
|
|
||||||
# Get the controls
|
# Get the controls
|
||||||
var move_left = Input.is_action_pressed("move_left")
|
var move_left = Input.is_action_pressed("move_left")
|
||||||
var move_right = Input.is_action_pressed("move_right")
|
var move_right = Input.is_action_pressed("move_right")
|
||||||
var jump = Input.is_action_pressed("jump")
|
var jump = Input.is_action_pressed("jump")
|
||||||
var shoot = Input.is_action_pressed("shoot")
|
var shoot = Input.is_action_pressed("shoot")
|
||||||
var spawn = Input.is_action_pressed("spawn")
|
var spawn = Input.is_action_pressed("spawn")
|
||||||
|
|
||||||
if spawn:
|
if spawn:
|
||||||
var e = enemy.instance()
|
var e = enemy.instance()
|
||||||
var p = get_pos()
|
var p = get_pos()
|
||||||
p.y = p.y - 100
|
p.y = p.y - 100
|
||||||
e.set_pos(p)
|
e.set_pos(p)
|
||||||
get_parent().add_child(e)
|
get_parent().add_child(e)
|
||||||
|
|
||||||
# Deapply prev floor velocity
|
# Deapply prev floor velocity
|
||||||
lv.x -= floor_h_velocity
|
lv.x -= floor_h_velocity
|
||||||
floor_h_velocity = 0.0
|
floor_h_velocity = 0.0
|
||||||
|
|
||||||
# Find the floor (a contact with upwards facing collision normal)
|
# Find the floor (a contact with upwards facing collision normal)
|
||||||
var found_floor = false
|
var found_floor = false
|
||||||
var floor_index = -1
|
var floor_index = -1
|
||||||
|
|
||||||
for x in range(s.get_contact_count()):
|
for x in range(s.get_contact_count()):
|
||||||
var ci = s.get_contact_local_normal(x)
|
var ci = s.get_contact_local_normal(x)
|
||||||
if (ci.dot(Vector2(0, -1)) > 0.6):
|
if (ci.dot(Vector2(0, -1)) > 0.6):
|
||||||
found_floor = true
|
found_floor = true
|
||||||
floor_index = x
|
floor_index = x
|
||||||
|
|
||||||
# A good idea when impementing characters of all kinds,
|
# A good idea when impementing characters of all kinds,
|
||||||
# compensates for physics imprecission, as well as human reaction delay.
|
# compensates for physics imprecission, as well as human reaction delay.
|
||||||
if (shoot and not shooting):
|
if (shoot and not shooting):
|
||||||
@@ -99,22 +98,22 @@ func _integrate_forces(s):
|
|||||||
else:
|
else:
|
||||||
ss = 1.0
|
ss = 1.0
|
||||||
var pos = get_pos() + get_node("bullet_shoot").get_pos()*Vector2(ss, 1.0)
|
var pos = get_pos() + get_node("bullet_shoot").get_pos()*Vector2(ss, 1.0)
|
||||||
|
|
||||||
bi.set_pos(pos)
|
bi.set_pos(pos)
|
||||||
get_parent().add_child(bi)
|
get_parent().add_child(bi)
|
||||||
|
|
||||||
bi.set_linear_velocity(Vector2(800.0*ss, -80))
|
bi.set_linear_velocity(Vector2(800.0*ss, -80))
|
||||||
get_node("sprite/smoke").set_emitting(true)
|
get_node("sprite/smoke").set_emitting(true)
|
||||||
get_node("sound").play("shoot")
|
get_node("sound").play("shoot")
|
||||||
PS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide
|
PS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide
|
||||||
else:
|
else:
|
||||||
shoot_time += step
|
shoot_time += step
|
||||||
|
|
||||||
if (found_floor):
|
if (found_floor):
|
||||||
airborne_time = 0.0
|
airborne_time = 0.0
|
||||||
else:
|
else:
|
||||||
airborne_time += step # Time it spent in the air
|
airborne_time += step # Time it spent in the air
|
||||||
|
|
||||||
var on_floor = airborne_time < MAX_FLOOR_AIRBORNE_TIME
|
var on_floor = airborne_time < MAX_FLOOR_AIRBORNE_TIME
|
||||||
|
|
||||||
# Process jump
|
# Process jump
|
||||||
@@ -132,10 +131,10 @@ func _integrate_forces(s):
|
|||||||
jumping = false
|
jumping = false
|
||||||
elif (not jump):
|
elif (not jump):
|
||||||
stopping_jump = true
|
stopping_jump = true
|
||||||
|
|
||||||
if (stopping_jump):
|
if (stopping_jump):
|
||||||
lv.y += STOP_JUMP_FORCE*step
|
lv.y += STOP_JUMP_FORCE*step
|
||||||
|
|
||||||
if (on_floor):
|
if (on_floor):
|
||||||
# Process logic when character is on floor
|
# Process logic when character is on floor
|
||||||
if (move_left and not move_right):
|
if (move_left and not move_right):
|
||||||
@@ -150,14 +149,14 @@ func _integrate_forces(s):
|
|||||||
if (xv < 0):
|
if (xv < 0):
|
||||||
xv = 0
|
xv = 0
|
||||||
lv.x = sign(lv.x)*xv
|
lv.x = sign(lv.x)*xv
|
||||||
|
|
||||||
# Check jump
|
# Check jump
|
||||||
if (not jumping and jump):
|
if (not jumping and jump):
|
||||||
lv.y = -JUMP_VELOCITY
|
lv.y = -JUMP_VELOCITY
|
||||||
jumping = true
|
jumping = true
|
||||||
stopping_jump = false
|
stopping_jump = false
|
||||||
get_node("sound").play("jump")
|
get_node("sound").play("jump")
|
||||||
|
|
||||||
# Check siding
|
# Check siding
|
||||||
if (lv.x < 0 and move_left):
|
if (lv.x < 0 and move_left):
|
||||||
new_siding_left = true
|
new_siding_left = true
|
||||||
@@ -189,7 +188,7 @@ func _integrate_forces(s):
|
|||||||
if (xv < 0):
|
if (xv < 0):
|
||||||
xv = 0
|
xv = 0
|
||||||
lv.x = sign(lv.x)*xv
|
lv.x = sign(lv.x)*xv
|
||||||
|
|
||||||
if (lv.y < 0):
|
if (lv.y < 0):
|
||||||
if (shoot_time < MAX_SHOOT_POSE_TIME):
|
if (shoot_time < MAX_SHOOT_POSE_TIME):
|
||||||
new_anim = "jumping_weapon"
|
new_anim = "jumping_weapon"
|
||||||
@@ -200,28 +199,28 @@ func _integrate_forces(s):
|
|||||||
new_anim = "falling_weapon"
|
new_anim = "falling_weapon"
|
||||||
else:
|
else:
|
||||||
new_anim = "falling"
|
new_anim = "falling"
|
||||||
|
|
||||||
# Update siding
|
# Update siding
|
||||||
if (new_siding_left != siding_left):
|
if (new_siding_left != siding_left):
|
||||||
if (new_siding_left):
|
if (new_siding_left):
|
||||||
get_node("sprite").set_scale(Vector2(-1, 1))
|
get_node("sprite").set_scale(Vector2(-1, 1))
|
||||||
else:
|
else:
|
||||||
get_node("sprite").set_scale(Vector2(1, 1))
|
get_node("sprite").set_scale(Vector2(1, 1))
|
||||||
|
|
||||||
siding_left = new_siding_left
|
siding_left = new_siding_left
|
||||||
|
|
||||||
# Change animation
|
# Change animation
|
||||||
if (new_anim != anim):
|
if (new_anim != anim):
|
||||||
anim = new_anim
|
anim = new_anim
|
||||||
get_node("anim").play(anim)
|
get_node("anim").play(anim)
|
||||||
|
|
||||||
shooting = shoot
|
shooting = shoot
|
||||||
|
|
||||||
# Apply floor velocity
|
# Apply floor velocity
|
||||||
if (found_floor):
|
if (found_floor):
|
||||||
floor_h_velocity = s.get_contact_collider_velocity_at_pos(floor_index).x
|
floor_h_velocity = s.get_contact_collider_velocity_at_pos(floor_index).x
|
||||||
lv.x += floor_h_velocity
|
lv.x += floor_h_velocity
|
||||||
|
|
||||||
# Finally, apply gravity and set back the linear velocity
|
# Finally, apply gravity and set back the linear velocity
|
||||||
lv += s.get_total_gravity()*step
|
lv += s.get_total_gravity()*step
|
||||||
s.set_linear_velocity(lv)
|
s.set_linear_velocity(lv)
|
||||||
@@ -229,7 +228,7 @@ func _integrate_forces(s):
|
|||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
enemy = ResourceLoader.load("res://enemy.tscn")
|
enemy = ResourceLoader.load("res://enemy.tscn")
|
||||||
|
|
||||||
# if !Globals.has_singleton("Facebook"):
|
# if !Globals.has_singleton("Facebook"):
|
||||||
# return
|
# return
|
||||||
# var Facebook = Globals.get_singleton("Facebook")
|
# var Facebook = Globals.get_singleton("Facebook")
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
func _on_bullet_body_enter( body ):
|
func _on_bullet_body_enter( body ):
|
||||||
if (body.has_method("hit_by_bullet")):
|
if (body.has_method("hit_by_bullet")):
|
||||||
body.call("hit_by_bullet")
|
body.call("hit_by_bullet")
|
||||||
|
|
||||||
func _on_Timer_timeout():
|
func _on_Timer_timeout():
|
||||||
get_node("anim").play("shutdown")
|
get_node("anim").play("shutdown")
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
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("taken")
|
get_node("anim").play("taken")
|
||||||
taken=true
|
taken=true
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
|
|
||||||
@@ -22,35 +21,35 @@ onready var detect_wall_right = get_node("detect_wall_right")
|
|||||||
onready var sprite = get_node("sprite")
|
onready var sprite = get_node("sprite")
|
||||||
|
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
|
|
||||||
var new_anim="idle"
|
var new_anim="idle"
|
||||||
|
|
||||||
if (state==STATE_WALKING):
|
if (state==STATE_WALKING):
|
||||||
|
|
||||||
linear_velocity+= GRAVITY_VEC*delta
|
linear_velocity+= GRAVITY_VEC*delta
|
||||||
linear_velocity.x = direction * WALK_SPEED
|
linear_velocity.x = direction * WALK_SPEED
|
||||||
linear_velocity = move_and_slide( linear_velocity, FLOOR_NORMAL )
|
linear_velocity = move_and_slide( linear_velocity, FLOOR_NORMAL )
|
||||||
|
|
||||||
if (not detect_floor_left.is_colliding() or detect_wall_left.is_colliding()):
|
if (not detect_floor_left.is_colliding() or detect_wall_left.is_colliding()):
|
||||||
direction=1.0
|
direction=1.0
|
||||||
|
|
||||||
if (not detect_floor_right.is_colliding() or detect_wall_right.is_colliding()):
|
if (not detect_floor_right.is_colliding() or detect_wall_right.is_colliding()):
|
||||||
direction=-1.0
|
direction=-1.0
|
||||||
|
|
||||||
sprite.set_scale( Vector2(direction,1.0) )
|
sprite.set_scale( Vector2(direction,1.0) )
|
||||||
|
|
||||||
new_anim="walk"
|
new_anim="walk"
|
||||||
else:
|
else:
|
||||||
new_anim="explode"
|
new_anim="explode"
|
||||||
|
|
||||||
if (anim!=new_anim):
|
if (anim!=new_anim):
|
||||||
anim=new_anim
|
anim=new_anim
|
||||||
get_node("anim").play(anim)
|
get_node("anim").play(anim)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func hit_by_bullet():
|
func hit_by_bullet():
|
||||||
state=STATE_KILLED
|
state=STATE_KILLED
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
set_fixed_process(true)
|
set_fixed_process(true)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -12,7 +11,7 @@ func _fixed_process(delta):
|
|||||||
accum = fmod(accum, PI*2.0)
|
accum = fmod(accum, PI*2.0)
|
||||||
var d = sin(accum)
|
var d = sin(accum)
|
||||||
var xf = Matrix32()
|
var xf = Matrix32()
|
||||||
xf[2]= motion*d
|
xf[2]= motion*d
|
||||||
get_node("platform").set_transform(xf)
|
get_node("platform").set_transform(xf)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
const GRAVITY_VEC = Vector2(0,900)
|
const GRAVITY_VEC = Vector2(0,900)
|
||||||
@@ -12,7 +11,7 @@ const BULLET_VELOCITY = 1000
|
|||||||
const SHOOT_TIME_SHOW_WEAPON = 0.2
|
const SHOOT_TIME_SHOW_WEAPON = 0.2
|
||||||
|
|
||||||
var linear_vel = Vector2()
|
var linear_vel = Vector2()
|
||||||
var onair_time = 0 #
|
var onair_time = 0 #
|
||||||
var on_floor = false
|
var on_floor = false
|
||||||
var shoot_time=99999 #time since last shot
|
var shoot_time=99999 #time since last shot
|
||||||
var shooting = false
|
var shooting = false
|
||||||
@@ -23,69 +22,69 @@ var anim=""
|
|||||||
onready var sprite = get_node("sprite")
|
onready var sprite = get_node("sprite")
|
||||||
|
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
|
|
||||||
#increment counters
|
#increment counters
|
||||||
|
|
||||||
onair_time+=delta
|
onair_time+=delta
|
||||||
shoot_time+=delta
|
shoot_time+=delta
|
||||||
|
|
||||||
|
|
||||||
### MOVEMENT ###
|
### MOVEMENT ###
|
||||||
|
|
||||||
# Apply Gravity
|
# Apply Gravity
|
||||||
linear_vel += delta * GRAVITY_VEC
|
linear_vel += delta * GRAVITY_VEC
|
||||||
# Move and Slide
|
# Move and Slide
|
||||||
linear_vel = move_and_slide( linear_vel, FLOOR_NORMAL, SLOPE_SLIDE_STOP )
|
linear_vel = move_and_slide( linear_vel, FLOOR_NORMAL, SLOPE_SLIDE_STOP )
|
||||||
# Detect Floor
|
# Detect Floor
|
||||||
if (is_move_and_slide_on_floor()):
|
if (is_move_and_slide_on_floor()):
|
||||||
onair_time=0
|
onair_time=0
|
||||||
|
|
||||||
on_floor = onair_time < MIN_ONAIR_TIME
|
on_floor = onair_time < MIN_ONAIR_TIME
|
||||||
|
|
||||||
### CONTROL ###
|
### CONTROL ###
|
||||||
|
|
||||||
# Horizontal Movement
|
# Horizontal Movement
|
||||||
var target_speed = 0
|
var target_speed = 0
|
||||||
if (Input.is_action_pressed("move_left")):
|
if (Input.is_action_pressed("move_left")):
|
||||||
target_speed += -1
|
target_speed += -1
|
||||||
if (Input.is_action_pressed("move_right")):
|
if (Input.is_action_pressed("move_right")):
|
||||||
target_speed += 1
|
target_speed += 1
|
||||||
|
|
||||||
target_speed *= WALK_SPEED
|
target_speed *= WALK_SPEED
|
||||||
linear_vel.x = lerp( linear_vel.x, target_speed, 0.1 )
|
linear_vel.x = lerp( linear_vel.x, target_speed, 0.1 )
|
||||||
|
|
||||||
# Jumping
|
# Jumping
|
||||||
if (on_floor and Input.is_action_pressed("jump")):
|
if (on_floor and Input.is_action_pressed("jump")):
|
||||||
linear_vel.y=-JUMP_SPEED
|
linear_vel.y=-JUMP_SPEED
|
||||||
get_node("sound").play("jump")
|
get_node("sound").play("jump")
|
||||||
|
|
||||||
# Shooting
|
# Shooting
|
||||||
|
|
||||||
var shoot = Input.is_action_pressed("shoot")
|
var shoot = Input.is_action_pressed("shoot")
|
||||||
|
|
||||||
if (shoot and not shooting):
|
if (shoot and not shooting):
|
||||||
|
|
||||||
var bullet = preload("res://bullet.tscn").instance()
|
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_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
|
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_parent().add_child( bullet ) #don't want bullet to move with me, so add it as child of parent
|
||||||
get_node("sound").play("shoot")
|
get_node("sound").play("shoot")
|
||||||
shoot_time=0
|
shoot_time=0
|
||||||
|
|
||||||
### ANIMATION ###
|
### ANIMATION ###
|
||||||
|
|
||||||
var new_anim="idle"
|
var new_anim="idle"
|
||||||
|
|
||||||
if (on_floor):
|
if (on_floor):
|
||||||
if (linear_vel.x < -SIDING_CHANGE_SPEED):
|
if (linear_vel.x < -SIDING_CHANGE_SPEED):
|
||||||
sprite.set_scale( Vector2( -1, 1 ) )
|
sprite.set_scale( Vector2( -1, 1 ) )
|
||||||
new_anim="run"
|
new_anim="run"
|
||||||
|
|
||||||
if (linear_vel.x > SIDING_CHANGE_SPEED):
|
if (linear_vel.x > SIDING_CHANGE_SPEED):
|
||||||
sprite.set_scale( Vector2( 1, 1 ) )
|
sprite.set_scale( Vector2( 1, 1 ) )
|
||||||
new_anim="run"
|
new_anim="run"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# We want the character to immediately change facing side when the player
|
# We want the character to immediately change facing side when the player
|
||||||
# tries to change direction, during air control.
|
# tries to change direction, during air control.
|
||||||
@@ -99,16 +98,16 @@ func _fixed_process(delta):
|
|||||||
new_anim="jumping"
|
new_anim="jumping"
|
||||||
else:
|
else:
|
||||||
new_anim="falling"
|
new_anim="falling"
|
||||||
|
|
||||||
if (shoot_time < SHOOT_TIME_SHOW_WEAPON):
|
if (shoot_time < SHOOT_TIME_SHOW_WEAPON):
|
||||||
new_anim+="_weapon"
|
new_anim+="_weapon"
|
||||||
|
|
||||||
if (new_anim!=anim):
|
if (new_anim!=anim):
|
||||||
anim=new_anim
|
anim=new_anim
|
||||||
get_node("anim").play(anim)
|
get_node("anim").play(anim)
|
||||||
|
|
||||||
shooting = shoot
|
shooting = shoot
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
set_fixed_process(true)
|
set_fixed_process(true)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -17,47 +16,47 @@ func _process(delta):
|
|||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# This demo is an example of controling a high number of 2D objects with logic and collision without using scene nodes.
|
# 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):
|
if (b.pos.x < -30):
|
||||||
b.pos.x += width
|
b.pos.x += width
|
||||||
mat.o = b.pos
|
mat.o = b.pos
|
||||||
|
|
||||||
Physics2DServer.body_set_state(b.body, Physics2DServer.BODY_STATE_TRANSFORM, mat)
|
Physics2DServer.body_set_state(b.body, Physics2DServer.BODY_STATE_TRANSFORM, mat)
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
shape = Physics2DServer.shape_create(Physics2DServer.SHAPE_CIRCLE)
|
shape = Physics2DServer.shape_create(Physics2DServer.SHAPE_CIRCLE)
|
||||||
Physics2DServer.shape_set_data(shape, 8) # Radius
|
Physics2DServer.shape_set_data(shape, 8) # Radius
|
||||||
|
|
||||||
for i in range(BULLET_COUNT):
|
for i in range(BULLET_COUNT):
|
||||||
var b = Bullet.new()
|
var b = Bullet.new()
|
||||||
b.speed = rand_range(SPEED_MIN, SPEED_MAX)
|
b.speed = rand_range(SPEED_MIN, SPEED_MAX)
|
||||||
b.body = Physics2DServer.body_create(Physics2DServer.BODY_MODE_KINEMATIC)
|
b.body = Physics2DServer.body_create(Physics2DServer.BODY_MODE_KINEMATIC)
|
||||||
Physics2DServer.body_set_space(b.body, get_world_2d().get_space())
|
Physics2DServer.body_set_space(b.body, get_world_2d().get_space())
|
||||||
Physics2DServer.body_add_shape(b.body, shape)
|
Physics2DServer.body_add_shape(b.body, shape)
|
||||||
|
|
||||||
b.pos = Vector2(get_viewport_rect().size * Vector2(randf()*2.0, randf())) # Twice as long
|
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
|
b.pos.x += get_viewport_rect().size.x # Start outside
|
||||||
var mat = Matrix32()
|
var mat = Matrix32()
|
||||||
mat.o = b.pos
|
mat.o = b.pos
|
||||||
Physics2DServer.body_set_state(b.body, Physics2DServer.BODY_STATE_TRANSFORM, mat)
|
Physics2DServer.body_set_state(b.body, Physics2DServer.BODY_STATE_TRANSFORM, mat)
|
||||||
|
|
||||||
bullets.append(b)
|
bullets.append(b)
|
||||||
|
|
||||||
set_process(true)
|
set_process(true)
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
for b in bullets:
|
for b in bullets:
|
||||||
Physics2DServer.free_rid(b.body)
|
Physics2DServer.free_rid(b.body)
|
||||||
|
|
||||||
Physics2DServer.free_rid(shape)
|
Physics2DServer.free_rid(shape)
|
||||||
bullets.clear()
|
bullets.clear()
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
# Space Shooter
|
# Space Shooter
|
||||||
|
|
||||||
## Introduction
|
## 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.
|
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.
|
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.
|
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!
|
Avoiding the blocky obstacles and the enemies is key to survival and high scores, so good luck and have fun!
|
||||||
|
|
||||||
## Controls
|
## Controls
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func destroy():
|
|||||||
# skip if already destroyed
|
# skip if already destroyed
|
||||||
if (destroyed):
|
if (destroyed):
|
||||||
return
|
return
|
||||||
|
|
||||||
# set the state to destroyed
|
# set the state to destroyed
|
||||||
destroyed = true
|
destroyed = true
|
||||||
# stop processing
|
# stop processing
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ func _ready():
|
|||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
# the enemy constantly moves
|
# the enemy constantly moves
|
||||||
translate(motion * delta)
|
translate(motion * delta)
|
||||||
|
|
||||||
# count down the time until the next shot
|
# count down the time until the next shot
|
||||||
if shoot_timeout > 0.0:
|
if shoot_timeout > 0.0:
|
||||||
shoot_timeout -= delta
|
shoot_timeout -= delta
|
||||||
|
|
||||||
if (shoot_timeout <= 0):
|
if (shoot_timeout <= 0):
|
||||||
shoot_timeout = SHOOT_INTERVAL
|
shoot_timeout = SHOOT_INTERVAL
|
||||||
|
|
||||||
if projectile_container != null:
|
if projectile_container != null:
|
||||||
# Instance a shot
|
# Instance a shot
|
||||||
var shot = Shot.instance()
|
var shot = Shot.instance()
|
||||||
@@ -59,7 +59,7 @@ func destroy():
|
|||||||
if (destroyed):
|
if (destroyed):
|
||||||
return
|
return
|
||||||
destroyed = true
|
destroyed = true
|
||||||
|
|
||||||
# stop processing
|
# stop processing
|
||||||
set_fixed_process(false)
|
set_fixed_process(false)
|
||||||
# play on-death effects
|
# play on-death effects
|
||||||
|
|||||||
@@ -29,4 +29,4 @@ func _on_visibility_exit_screen():
|
|||||||
|
|
||||||
func _on_enemy_shot_area_enter(area):
|
func _on_enemy_shot_area_enter(area):
|
||||||
if area.is_in_group("player"):
|
if area.is_in_group("player"):
|
||||||
area.take_damage()
|
area.take_damage()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func destroy():
|
|||||||
# skip if already destroyed
|
# skip if already destroyed
|
||||||
if (destroyed):
|
if (destroyed):
|
||||||
return
|
return
|
||||||
|
|
||||||
# set the state to destroyed
|
# set the state to destroyed
|
||||||
destroyed = true
|
destroyed = true
|
||||||
# play on-death effects
|
# play on-death effects
|
||||||
@@ -38,4 +38,3 @@ func _on_visibility_enter_screen():
|
|||||||
get_node("anim").seek(randf()*2.0)
|
get_node("anim").seek(randf()*2.0)
|
||||||
# as mentioned in _ready, show the node after seeking to the random start point in the animation
|
# as mentioned in _ready, show the node after seeking to the random start point in the animation
|
||||||
show()
|
show()
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ func _ready():
|
|||||||
# once the ship leaves the screen, remove the entire node
|
# once the ship leaves the screen, remove the entire node
|
||||||
visibility.connect("exit_screen", self, "queue_free")
|
visibility.connect("exit_screen", self, "queue_free")
|
||||||
motion = Vector2(SPEED, 0)
|
motion = Vector2(SPEED, 0)
|
||||||
|
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
# constant movement
|
# constant movement
|
||||||
translate(motion * delta)
|
translate(motion * delta)
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ func _ready():
|
|||||||
func _process(delta):
|
func _process(delta):
|
||||||
if Input.is_action_pressed("ui_cancel"):
|
if Input.is_action_pressed("ui_cancel"):
|
||||||
_on_return_to_menu()
|
_on_return_to_menu()
|
||||||
|
|
||||||
func update_score(score):
|
func update_score(score):
|
||||||
score_label.set_text(str(score))
|
score_label.set_text(str(score))
|
||||||
|
|
||||||
func _on_return_to_menu():
|
func _on_return_to_menu():
|
||||||
emit_signal("return_to_menu")
|
emit_signal("return_to_menu")
|
||||||
|
|
||||||
func game_over():
|
func game_over():
|
||||||
game_over_label.show()
|
game_over_label.show()
|
||||||
|
|||||||
@@ -28,6 +28,6 @@ func on_player_died():
|
|||||||
func on_enemy_died(score):
|
func on_enemy_died(score):
|
||||||
game_state.points += score
|
game_state.points += score
|
||||||
hud.update_score(game_state.points)
|
hud.update_score(game_state.points)
|
||||||
|
|
||||||
func on_return_to_menu():
|
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
|
# find all enemies who need a projectile container because they can shoot
|
||||||
if enemy.has_method("set_projectile_container"):
|
if enemy.has_method("set_projectile_container"):
|
||||||
# tell those enemies about the 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():
|
func abort_game():
|
||||||
_reset_game()
|
_reset_game()
|
||||||
|
|
||||||
menu = main_menu_scene.instance()
|
menu = main_menu_scene.instance()
|
||||||
get_tree().get_root().add_child(menu)
|
get_tree().get_root().add_child(menu)
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ func _reset_game():
|
|||||||
game.hide()
|
game.hide()
|
||||||
game.queue_free()
|
game.queue_free()
|
||||||
game = null
|
game = null
|
||||||
|
|
||||||
if menu != null:
|
if menu != null:
|
||||||
menu.hide()
|
menu.hide()
|
||||||
menu.queue_free()
|
menu.queue_free()
|
||||||
@@ -69,7 +69,7 @@ func _load_high_score():
|
|||||||
max_points = f.get_var()
|
max_points = f.get_var()
|
||||||
# always close the file handle
|
# always close the file handle
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
func _save_high_score():
|
func _save_high_score():
|
||||||
var f = File.new()
|
var f = File.new()
|
||||||
# try to open the highscore file in WRITE mode, which creates a new file if it doesn't exist
|
# 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
|
# store the max points as a godot Variant
|
||||||
f.store_var(max_points)
|
f.store_var(max_points)
|
||||||
# always close the file handle
|
# 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
|
# the connection is set up on the "play" node, using the "Signals" sub-tab in the "Node" dock
|
||||||
func _on_play_pressed():
|
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
|
# 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"):
|
if Input.is_action_pressed("move_right"):
|
||||||
motion += Vector2(1, 0)
|
motion += Vector2(1, 0)
|
||||||
var shooting = Input.is_action_pressed("shoot")
|
var shooting = Input.is_action_pressed("shoot")
|
||||||
|
|
||||||
var pos = get_pos()
|
var pos = get_pos()
|
||||||
|
|
||||||
# normally you would normalize the motion vector using motion.normalized(), so diagonal movement isn't faster
|
# 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
|
# 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
|
# 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
|
# 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.normalized() * delta * SPEED
|
||||||
pos += motion * delta * SPEED
|
pos += motion * delta * SPEED
|
||||||
|
|
||||||
# limit the resulting position to the screen's dimensions, so the player can't fly off screen
|
# 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.x = clamp(pos.x, 0, screen_size.x)
|
||||||
pos.y = clamp(pos.y, 0, screen_size.y)
|
pos.y = clamp(pos.y, 0, screen_size.y)
|
||||||
|
|
||||||
set_pos(pos)
|
set_pos(pos)
|
||||||
|
|
||||||
# tick down the shot cooldown
|
# tick down the shot cooldown
|
||||||
if shot_timer > 0.0:
|
if shot_timer > 0.0:
|
||||||
shot_timer -= delta
|
shot_timer -= delta
|
||||||
|
|
||||||
# the player can shoot if the timer is back to zero
|
# the player can shoot if the timer is back to zero
|
||||||
can_shoot = shot_timer <= 0.0
|
can_shoot = shot_timer <= 0.0
|
||||||
|
|
||||||
# if the player is alive, allowed to shoot and pressing space to shoot..
|
# if the player is alive, allowed to shoot and pressing space to shoot..
|
||||||
if (can_shoot and shooting and not killed):
|
if (can_shoot and shooting and not killed):
|
||||||
# instance a shot
|
# instance a shot
|
||||||
@@ -82,7 +82,7 @@ func _hit_something():
|
|||||||
get_node("sfx").play("sound_explode")
|
get_node("sfx").play("sound_explode")
|
||||||
# notify listeners that the player died
|
# notify listeners that the player died
|
||||||
emit_signal("player_died")
|
emit_signal("player_died")
|
||||||
# disable processing
|
# disable processing
|
||||||
set_fixed_process(false)
|
set_fixed_process(false)
|
||||||
|
|
||||||
# the block tiles in a level have StaticBody2D colliders, touching them kills the player ship
|
# 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
|
# other objects (enemy projectiles) use this to tell the player ship that it was hit
|
||||||
func take_damage():
|
func take_damage():
|
||||||
_hit_something()
|
_hit_something()
|
||||||
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -36,13 +35,13 @@ func _integrate_forces(s):
|
|||||||
new_anim = "explode"
|
new_anim = "explode"
|
||||||
elif (state == STATE_WALKING):
|
elif (state == STATE_WALKING):
|
||||||
new_anim = "walk"
|
new_anim = "walk"
|
||||||
|
|
||||||
var wall_side = 0.0
|
var wall_side = 0.0
|
||||||
|
|
||||||
for i in range(s.get_contact_count()):
|
for i in range(s.get_contact_count()):
|
||||||
var cc = s.get_contact_collider_object(i)
|
var cc = s.get_contact_collider_object(i)
|
||||||
var dp = s.get_contact_local_normal(i)
|
var dp = s.get_contact_local_normal(i)
|
||||||
|
|
||||||
if (cc):
|
if (cc):
|
||||||
if (cc extends bullet_class and not cc.disabled):
|
if (cc extends bullet_class and not cc.disabled):
|
||||||
set_mode(MODE_RIGID)
|
set_mode(MODE_RIGID)
|
||||||
@@ -53,12 +52,12 @@ func _integrate_forces(s):
|
|||||||
cc.disable()
|
cc.disable()
|
||||||
get_node("sound").play("hit")
|
get_node("sound").play("hit")
|
||||||
break
|
break
|
||||||
|
|
||||||
if (dp.x > 0.9):
|
if (dp.x > 0.9):
|
||||||
wall_side = 1.0
|
wall_side = 1.0
|
||||||
elif (dp.x < -0.9):
|
elif (dp.x < -0.9):
|
||||||
wall_side = -1.0
|
wall_side = -1.0
|
||||||
|
|
||||||
if (wall_side != 0 and wall_side != direction):
|
if (wall_side != 0 and wall_side != direction):
|
||||||
direction = -direction
|
direction = -direction
|
||||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
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()):
|
elif (direction > 0 and not rc_right.is_colliding() and rc_left.is_colliding()):
|
||||||
direction = -direction
|
direction = -direction
|
||||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
get_node("sprite").set_scale(Vector2(-direction, 1))
|
||||||
|
|
||||||
lv.x = direction*WALK_SPEED
|
lv.x = direction*WALK_SPEED
|
||||||
|
|
||||||
if(anim != new_anim):
|
if(anim != new_anim):
|
||||||
anim = new_anim
|
anim = new_anim
|
||||||
get_node("anim").play(anim)
|
get_node("anim").play(anim)
|
||||||
|
|
||||||
s.set_linear_velocity(lv)
|
s.set_linear_velocity(lv)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -12,7 +11,7 @@ func _fixed_process(delta):
|
|||||||
accum = fmod(accum, PI*2.0)
|
accum = fmod(accum, PI*2.0)
|
||||||
var d = sin(accum)
|
var d = sin(accum)
|
||||||
var xf = Matrix32()
|
var xf = Matrix32()
|
||||||
xf[2]= motion*d
|
xf[2]= motion*d
|
||||||
get_node("platform").set_transform(xf)
|
get_node("platform").set_transform(xf)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody2D
|
extends RigidBody2D
|
||||||
|
|
||||||
# Character Demo, written by Juan Linietsky.
|
# Character Demo, written by Juan Linietsky.
|
||||||
@@ -14,12 +13,12 @@ extends RigidBody2D
|
|||||||
# -Interaction with other physics-based objects is free
|
# -Interaction with other physics-based objects is free
|
||||||
# -Only have to deal with the object linear velocity, not position
|
# -Only have to deal with the object linear velocity, not position
|
||||||
# -All collision/area framework available
|
# -All collision/area framework available
|
||||||
#
|
#
|
||||||
# But also has the following disadvantages:
|
# But also has the following disadvantages:
|
||||||
#
|
#
|
||||||
# -Objects may bounce a little bit sometimes
|
# -Objects may bounce a little bit sometimes
|
||||||
# -Going up ramps sends the chracter flying up, small hack is needed.
|
# -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.
|
# undesiderd bumps, small steps and rare numerical precision errors.
|
||||||
# (another alternative may be to turn on friction when the character is not moving).
|
# (another alternative may be to turn on friction when the character is not moving).
|
||||||
# -Friction cant be used, so floor velocity must be considered
|
# -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):
|
func _integrate_forces(s):
|
||||||
var lv = s.get_linear_velocity()
|
var lv = s.get_linear_velocity()
|
||||||
var step = s.get_step()
|
var step = s.get_step()
|
||||||
|
|
||||||
var new_anim = anim
|
var new_anim = anim
|
||||||
var new_siding_left = siding_left
|
var new_siding_left = siding_left
|
||||||
|
|
||||||
# Get the controls
|
# Get the controls
|
||||||
var move_left = Input.is_action_pressed("move_left" + str(index))
|
var move_left = Input.is_action_pressed("move_left" + str(index))
|
||||||
var move_right = Input.is_action_pressed("move_right" + str(index))
|
var move_right = Input.is_action_pressed("move_right" + str(index))
|
||||||
var jump = Input.is_action_pressed("jump" + str(index))
|
var jump = Input.is_action_pressed("jump" + str(index))
|
||||||
var shoot = Input.is_action_pressed("shoot" + str(index))
|
var shoot = Input.is_action_pressed("shoot" + str(index))
|
||||||
var spawn = Input.is_action_pressed("spawn" + str(index))
|
var spawn = Input.is_action_pressed("spawn" + str(index))
|
||||||
|
|
||||||
if spawn:
|
if spawn:
|
||||||
var e = enemy.instance()
|
var e = enemy.instance()
|
||||||
var p = get_pos()
|
var p = get_pos()
|
||||||
p.y = p.y - 100
|
p.y = p.y - 100
|
||||||
e.set_pos(p)
|
e.set_pos(p)
|
||||||
get_parent().add_child(e)
|
get_parent().add_child(e)
|
||||||
|
|
||||||
# Deapply prev floor velocity
|
# Deapply prev floor velocity
|
||||||
lv.x -= floor_h_velocity
|
lv.x -= floor_h_velocity
|
||||||
floor_h_velocity = 0.0
|
floor_h_velocity = 0.0
|
||||||
|
|
||||||
# Find the floor (a contact with upwards facing collision normal)
|
# Find the floor (a contact with upwards facing collision normal)
|
||||||
var found_floor = false
|
var found_floor = false
|
||||||
var floor_index = -1
|
var floor_index = -1
|
||||||
|
|
||||||
for x in range(s.get_contact_count()):
|
for x in range(s.get_contact_count()):
|
||||||
var ci = s.get_contact_local_normal(x)
|
var ci = s.get_contact_local_normal(x)
|
||||||
if (ci.dot(Vector2(0, -1)) > 0.6):
|
if (ci.dot(Vector2(0, -1)) > 0.6):
|
||||||
found_floor = true
|
found_floor = true
|
||||||
floor_index = x
|
floor_index = x
|
||||||
|
|
||||||
# A good idea when impementing characters of all kinds,
|
# A good idea when impementing characters of all kinds,
|
||||||
# compensates for physics imprecission, as well as human reaction delay.
|
# compensates for physics imprecission, as well as human reaction delay.
|
||||||
if (shoot and not shooting):
|
if (shoot and not shooting):
|
||||||
@@ -100,22 +99,22 @@ func _integrate_forces(s):
|
|||||||
else:
|
else:
|
||||||
ss = 1.0
|
ss = 1.0
|
||||||
var pos = get_pos() + get_node("bullet_shoot").get_pos()*Vector2(ss, 1.0)
|
var pos = get_pos() + get_node("bullet_shoot").get_pos()*Vector2(ss, 1.0)
|
||||||
|
|
||||||
bi.set_pos(pos)
|
bi.set_pos(pos)
|
||||||
get_parent().add_child(bi)
|
get_parent().add_child(bi)
|
||||||
|
|
||||||
bi.set_linear_velocity(Vector2(800.0*ss, -80))
|
bi.set_linear_velocity(Vector2(800.0*ss, -80))
|
||||||
get_node("sprite/smoke").set_emitting(true)
|
get_node("sprite/smoke").set_emitting(true)
|
||||||
get_node("sound").play("shoot")
|
get_node("sound").play("shoot")
|
||||||
PS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide
|
PS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide
|
||||||
else:
|
else:
|
||||||
shoot_time += step
|
shoot_time += step
|
||||||
|
|
||||||
if (found_floor):
|
if (found_floor):
|
||||||
airborne_time = 0.0
|
airborne_time = 0.0
|
||||||
else:
|
else:
|
||||||
airborne_time += step # Time it spent in the air
|
airborne_time += step # Time it spent in the air
|
||||||
|
|
||||||
var on_floor = airborne_time < MAX_FLOOR_AIRBORNE_TIME
|
var on_floor = airborne_time < MAX_FLOOR_AIRBORNE_TIME
|
||||||
|
|
||||||
# Process jump
|
# Process jump
|
||||||
@@ -125,10 +124,10 @@ func _integrate_forces(s):
|
|||||||
jumping = false
|
jumping = false
|
||||||
elif (not jump):
|
elif (not jump):
|
||||||
stopping_jump = true
|
stopping_jump = true
|
||||||
|
|
||||||
if (stopping_jump):
|
if (stopping_jump):
|
||||||
lv.y += STOP_JUMP_FORCE*step
|
lv.y += STOP_JUMP_FORCE*step
|
||||||
|
|
||||||
if (on_floor):
|
if (on_floor):
|
||||||
# Process logic when character is on floor
|
# Process logic when character is on floor
|
||||||
if (move_left and not move_right):
|
if (move_left and not move_right):
|
||||||
@@ -143,14 +142,14 @@ func _integrate_forces(s):
|
|||||||
if (xv < 0):
|
if (xv < 0):
|
||||||
xv = 0
|
xv = 0
|
||||||
lv.x = sign(lv.x)*xv
|
lv.x = sign(lv.x)*xv
|
||||||
|
|
||||||
# Check jump
|
# Check jump
|
||||||
if (not jumping and jump):
|
if (not jumping and jump):
|
||||||
lv.y = -JUMP_VELOCITY
|
lv.y = -JUMP_VELOCITY
|
||||||
jumping = true
|
jumping = true
|
||||||
stopping_jump = false
|
stopping_jump = false
|
||||||
get_node("sound").play("jump")
|
get_node("sound").play("jump")
|
||||||
|
|
||||||
# Check siding
|
# Check siding
|
||||||
if (lv.x < 0 and move_left):
|
if (lv.x < 0 and move_left):
|
||||||
new_siding_left = true
|
new_siding_left = true
|
||||||
@@ -182,7 +181,7 @@ func _integrate_forces(s):
|
|||||||
if (xv < 0):
|
if (xv < 0):
|
||||||
xv = 0
|
xv = 0
|
||||||
lv.x = sign(lv.x)*xv
|
lv.x = sign(lv.x)*xv
|
||||||
|
|
||||||
if (lv.y < 0):
|
if (lv.y < 0):
|
||||||
if (shoot_time < MAX_SHOOT_POSE_TIME):
|
if (shoot_time < MAX_SHOOT_POSE_TIME):
|
||||||
new_anim = "jumping_weapon"
|
new_anim = "jumping_weapon"
|
||||||
@@ -193,28 +192,28 @@ func _integrate_forces(s):
|
|||||||
new_anim = "falling_weapon"
|
new_anim = "falling_weapon"
|
||||||
else:
|
else:
|
||||||
new_anim = "falling"
|
new_anim = "falling"
|
||||||
|
|
||||||
# Update siding
|
# Update siding
|
||||||
if (new_siding_left != siding_left):
|
if (new_siding_left != siding_left):
|
||||||
if (new_siding_left):
|
if (new_siding_left):
|
||||||
get_node("sprite").set_scale(Vector2(-1, 1))
|
get_node("sprite").set_scale(Vector2(-1, 1))
|
||||||
else:
|
else:
|
||||||
get_node("sprite").set_scale(Vector2(1, 1))
|
get_node("sprite").set_scale(Vector2(1, 1))
|
||||||
|
|
||||||
siding_left = new_siding_left
|
siding_left = new_siding_left
|
||||||
|
|
||||||
# Change animation
|
# Change animation
|
||||||
if (new_anim != anim):
|
if (new_anim != anim):
|
||||||
anim = new_anim
|
anim = new_anim
|
||||||
get_node("anim").play(anim)
|
get_node("anim").play(anim)
|
||||||
|
|
||||||
shooting = shoot
|
shooting = shoot
|
||||||
|
|
||||||
# Apply floor velocity
|
# Apply floor velocity
|
||||||
if (found_floor):
|
if (found_floor):
|
||||||
floor_h_velocity = s.get_contact_collider_velocity_at_pos(floor_index).x
|
floor_h_velocity = s.get_contact_collider_velocity_at_pos(floor_index).x
|
||||||
lv.x += floor_h_velocity
|
lv.x += floor_h_velocity
|
||||||
|
|
||||||
# Finally, apply gravity and set back the linear velocity
|
# Finally, apply gravity and set back the linear velocity
|
||||||
lv += s.get_total_gravity()*step
|
lv += s.get_total_gravity()*step
|
||||||
s.set_linear_velocity(lv)
|
s.set_linear_velocity(lv)
|
||||||
@@ -222,7 +221,7 @@ func _integrate_forces(s):
|
|||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
enemy = ResourceLoader.load("res://enemy.tscn")
|
enemy = ResourceLoader.load("res://enemy.tscn")
|
||||||
|
|
||||||
# if !Globals.has_singleton("Facebook"):
|
# if !Globals.has_singleton("Facebook"):
|
||||||
# return
|
# return
|
||||||
# var Facebook = Globals.get_singleton("Facebook")
|
# var Facebook = Globals.get_singleton("Facebook")
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ func _ready():
|
|||||||
var parallax_copy = get_node("top/viewport/stage/parallax_bg").duplicate()
|
var parallax_copy = get_node("top/viewport/stage/parallax_bg").duplicate()
|
||||||
parallax_copy.set_custom_viewport( get_node("bottom/viewport") )
|
parallax_copy.set_custom_viewport( get_node("bottom/viewport") )
|
||||||
get_node("top/viewport/stage").add_child(parallax_copy)
|
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
|
#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() )
|
#get_node("bottom/viewport").add_child( get_node("top/viewport/stage/parallax_bg").duplicate() )
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
# Simple Tetris-like demo, (c) 2012 Juan Linietsky
|
# Simple Tetris-like demo, (c) 2012 Juan Linietsky
|
||||||
@@ -56,13 +55,13 @@ func piece_cell_xform(p, er = 0):
|
|||||||
func _draw():
|
func _draw():
|
||||||
var sb = get_stylebox("bg", "Tree") # Use line edit bg
|
var sb = get_stylebox("bg", "Tree") # Use line edit bg
|
||||||
draw_style_box(sb, Rect2(Vector2(), get_size()).grow(3))
|
draw_style_box(sb, Rect2(Vector2(), get_size()).grow(3))
|
||||||
|
|
||||||
var bs = block.get_size()
|
var bs = block.get_size()
|
||||||
for y in range(height):
|
for y in range(height):
|
||||||
for x in range(width):
|
for x in range(width):
|
||||||
if (Vector2(x, y) in cells):
|
if (Vector2(x, y) in cells):
|
||||||
draw_texture_rect(block, Rect2(Vector2(x, y)*bs, bs), false, block_colors[cells[Vector2(x, y)]])
|
draw_texture_rect(block, Rect2(Vector2(x, y)*bs, bs), false, block_colors[cells[Vector2(x, y)]])
|
||||||
|
|
||||||
if (piece_active):
|
if (piece_active):
|
||||||
for c in block_shapes[piece_shape]:
|
for c in block_shapes[piece_shape]:
|
||||||
draw_texture_rect(block, Rect2(piece_cell_xform(c)*bs, bs), false, block_colors[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
|
return false
|
||||||
if (pos in cells):
|
if (pos in cells):
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
@@ -92,11 +91,11 @@ func new_piece():
|
|||||||
piece_rot = 0
|
piece_rot = 0
|
||||||
if (piece_shape == 0):
|
if (piece_shape == 0):
|
||||||
piece_pos.y += 1
|
piece_pos.y += 1
|
||||||
|
|
||||||
if (not piece_check_fit(Vector2())):
|
if (not piece_check_fit(Vector2())):
|
||||||
# Game over
|
# Game over
|
||||||
game_over()
|
game_over()
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
|
||||||
@@ -113,10 +112,10 @@ func test_collapse_rows():
|
|||||||
collapse = false
|
collapse = false
|
||||||
if (accum_down):
|
if (accum_down):
|
||||||
cells.erase(Vector2(x, y + accum_down))
|
cells.erase(Vector2(x, y + accum_down))
|
||||||
|
|
||||||
if (collapse):
|
if (collapse):
|
||||||
accum_down += 1
|
accum_down += 1
|
||||||
|
|
||||||
score += accum_down*100
|
score += accum_down*100
|
||||||
score_label.set_text(str(score))
|
score_label.set_text(str(score))
|
||||||
|
|
||||||
@@ -190,5 +189,5 @@ func setup(w, h):
|
|||||||
func _ready():
|
func _ready():
|
||||||
setup(10, 20)
|
setup(10, 20)
|
||||||
score_label = get_node("../score")
|
score_label = get_node("../score")
|
||||||
|
|
||||||
set_process_input(true)
|
set_process_input(true)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends BackBufferCopy
|
extends BackBufferCopy
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -10,17 +9,17 @@ var dir
|
|||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var pos = get_pos() + dir*delta*MOTION_SPEED
|
var pos = get_pos() + dir*delta*MOTION_SPEED
|
||||||
|
|
||||||
if (pos.x < 0):
|
if (pos.x < 0):
|
||||||
dir.x = abs(dir.x)
|
dir.x = abs(dir.x)
|
||||||
elif (pos.x > vsize.x):
|
elif (pos.x > vsize.x):
|
||||||
dir.x = -abs(dir.x)
|
dir.x = -abs(dir.x)
|
||||||
|
|
||||||
if (pos.y < 0):
|
if (pos.y < 0):
|
||||||
dir.y = abs(dir.y)
|
dir.y = abs(dir.y)
|
||||||
elif (pos.y > vsize.y):
|
elif (pos.y > vsize.y):
|
||||||
dir.y = -abs(dir.y)
|
dir.y = -abs(dir.y)
|
||||||
|
|
||||||
set_pos(pos)
|
set_pos(pos)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -69,4 +69,4 @@
|
|||||||
</dictionary>
|
</dictionary>
|
||||||
|
|
||||||
</main_resource>
|
</main_resource>
|
||||||
</resource_file>
|
</resource_file>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends KinematicBody
|
extends KinematicBody
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -14,7 +13,7 @@ const MAX_SLOPE_ANGLE = 30
|
|||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
var dir = Vector3() # Where does the player intend to walk to
|
var dir = Vector3() # Where does the player intend to walk to
|
||||||
var cam_xform = get_node("target/camera").get_global_transform()
|
var cam_xform = get_node("target/camera").get_global_transform()
|
||||||
|
|
||||||
if (Input.is_action_pressed("move_forward")):
|
if (Input.is_action_pressed("move_forward")):
|
||||||
dir += -cam_xform.basis[2]
|
dir += -cam_xform.basis[2]
|
||||||
if (Input.is_action_pressed("move_backwards")):
|
if (Input.is_action_pressed("move_backwards")):
|
||||||
@@ -23,43 +22,43 @@ func _fixed_process(delta):
|
|||||||
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.x = hvel.x
|
||||||
vel.z = hvel.z
|
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):
|
||||||
@@ -68,13 +67,13 @@ func _fixed_process(delta):
|
|||||||
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()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Camera
|
extends Camera
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -16,27 +15,27 @@ 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
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody
|
extends RigidBody
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -12,7 +11,7 @@ func _input_event(camera, event, pos, normal, shape):
|
|||||||
get_node("mesh").set_material_override(gray_mat)
|
get_node("mesh").set_material_override(gray_mat)
|
||||||
else:
|
else:
|
||||||
get_node("mesh").set_material_override(null)
|
get_node("mesh").set_material_override(null)
|
||||||
|
|
||||||
selected = not selected
|
selected = not selected
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Navigation
|
extends Navigation
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -29,16 +28,16 @@ func _process(delta):
|
|||||||
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)
|
||||||
@@ -71,12 +70,12 @@ func _input(event):
|
|||||||
var from = get_node("cambase/Camera").project_ray_origin(event.pos)
|
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 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 (event.type == InputEvent.MOUSE_MOTION):
|
if (event.type == InputEvent.MOUSE_MOTION):
|
||||||
if (event.button_mask&BUTTON_MASK_MIDDLE):
|
if (event.button_mask&BUTTON_MASK_MIDDLE):
|
||||||
camrot += event.relative_x*0.005
|
camrot += event.relative_x*0.005
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody
|
extends RigidBody
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Area
|
extends Area
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -14,4 +13,3 @@ func _on_coin_body_enter(body):
|
|||||||
func _on_anim_finished():
|
func _on_anim_finished():
|
||||||
if get_node("anim").get_current_animation() == "take":
|
if get_node("anim").get_current_animation() == "take":
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody
|
extends RigidBody
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -22,15 +21,15 @@ func _integrate_forces(state):
|
|||||||
|
|
||||||
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)
|
||||||
@@ -43,15 +42,15 @@ func _integrate_forces(state):
|
|||||||
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
|
||||||
@@ -59,17 +58,17 @@ func _integrate_forces(state):
|
|||||||
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)
|
dir = Matrix3(up, rot_dir*rot_speed*delta).xform(dir)
|
||||||
get_node("Armature").set_transform(Transform().looking_at(-dir, up))
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Camera
|
extends Camera
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -15,33 +14,33 @@ func _fixed_process(dt):
|
|||||||
var target = get_parent().get_global_transform().origin
|
var target = get_parent().get_global_transform().origin
|
||||||
var pos = get_global_transform().origin
|
var pos = get_global_transform().origin
|
||||||
var up = Vector3(0, 1, 0)
|
var up = Vector3(0, 1, 0)
|
||||||
|
|
||||||
var delta = pos - target
|
var delta = pos - target
|
||||||
|
|
||||||
# Regular delta follow
|
# Regular delta follow
|
||||||
|
|
||||||
# Check ranges
|
# Check ranges
|
||||||
if (delta.length() < min_distance):
|
if (delta.length() < min_distance):
|
||||||
delta = delta.normalized()*min_distance
|
delta = delta.normalized()*min_distance
|
||||||
elif (delta.length() > max_distance):
|
elif (delta.length() > max_distance):
|
||||||
delta = delta.normalized()*max_distance
|
delta = delta.normalized()*max_distance
|
||||||
|
|
||||||
# Check upper and lower height
|
# Check upper and lower height
|
||||||
if (delta.y > max_height):
|
if (delta.y > max_height):
|
||||||
delta.y = max_height
|
delta.y = max_height
|
||||||
if (delta.y < min_height):
|
if (delta.y < min_height):
|
||||||
delta.y = min_height
|
delta.y = min_height
|
||||||
|
|
||||||
# Check autoturn
|
# Check autoturn
|
||||||
var ds = PhysicsServer.space_get_direct_state(get_world().get_space())
|
var ds = PhysicsServer.space_get_direct_state(get_world().get_space())
|
||||||
|
|
||||||
var col_left = ds.intersect_ray(target, target + Matrix3(up, deg2rad(autoturn_ray_aperture)).xform(delta), collision_exception)
|
var col_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 = ds.intersect_ray(target, target + delta, collision_exception)
|
||||||
var col_right = ds.intersect_ray(target, target + Matrix3(up, deg2rad(-autoturn_ray_aperture)).xform(delta), collision_exception)
|
var col_right = ds.intersect_ray(target, target + Matrix3(up, deg2rad(-autoturn_ray_aperture)).xform(delta), collision_exception)
|
||||||
|
|
||||||
if (!col.empty()):
|
if (!col.empty()):
|
||||||
# If main ray was occluded, get camera closer, this is the worst case scenario
|
# If main ray was occluded, get camera closer, this is the worst case scenario
|
||||||
delta = col.position - target
|
delta = col.position - target
|
||||||
elif (!col_left.empty() and col_right.empty()):
|
elif (!col_left.empty() and col_right.empty()):
|
||||||
# If only left ray is occluded, turn the camera around to the right
|
# If only left ray is occluded, turn the camera around to the right
|
||||||
delta = Matrix3(up, deg2rad(-dt*autoturn_speed)).xform(delta)
|
delta = Matrix3(up, deg2rad(-dt*autoturn_speed)).xform(delta)
|
||||||
@@ -51,15 +50,15 @@ func _fixed_process(dt):
|
|||||||
else:
|
else:
|
||||||
# Do nothing otherwise, left and right are occluded but center is not, so do not autoturn
|
# Do nothing otherwise, left and right are occluded but center is not, so do not autoturn
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Apply lookat
|
# Apply lookat
|
||||||
if (delta == Vector3()):
|
if (delta == Vector3()):
|
||||||
delta = (pos - target).normalized()*0.0001
|
delta = (pos - target).normalized()*0.0001
|
||||||
|
|
||||||
pos = target + delta
|
pos = target + delta
|
||||||
|
|
||||||
look_at_from_pos(pos, target, up)
|
look_at_from_pos(pos, target, up)
|
||||||
|
|
||||||
# Turn a little up or down
|
# Turn a little up or down
|
||||||
var t = get_transform()
|
var t = get_transform()
|
||||||
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends RigidBody
|
extends RigidBody
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -36,15 +35,15 @@ var shoot_blend = 0
|
|||||||
func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
|
func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
|
||||||
var n = p_target # Normal
|
var n = p_target # Normal
|
||||||
var t = n.cross(current_gn).normalized()
|
var t = n.cross(current_gn).normalized()
|
||||||
|
|
||||||
var x = n.dot(p_facing)
|
var x = n.dot(p_facing)
|
||||||
var y = t.dot(p_facing)
|
var y = t.dot(p_facing)
|
||||||
|
|
||||||
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
|
||||||
@@ -54,7 +53,7 @@ func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
|
|||||||
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()
|
||||||
|
|
||||||
|
|
||||||
@@ -66,33 +65,33 @@ func _integrate_forces(state):
|
|||||||
# 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:
|
||||||
for i in range(state.get_contact_count()):
|
for i in range(state.get_contact_count()):
|
||||||
if (state.get_contact_local_shape(i) != 1):
|
if (state.get_contact_local_shape(i) != 1):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
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")):
|
||||||
@@ -101,15 +100,15 @@ func _integrate_forces(state):
|
|||||||
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_threshold
|
var sharp_turn = hspeed > 0.1 and rad2deg(acos(target_dir.dot(hdir))) > sharp_turn_threshold
|
||||||
|
|
||||||
if (dir.length() > 0.1 and !sharp_turn):
|
if (dir.length() > 0.1 and !sharp_turn):
|
||||||
if (hspeed > 0.001):
|
if (hspeed > 0.001):
|
||||||
#linear_dir = linear_h_velocity/linear_vel
|
#linear_dir = linear_h_velocity/linear_vel
|
||||||
@@ -120,24 +119,24 @@ func _integrate_forces(state):
|
|||||||
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
|
||||||
@@ -147,7 +146,7 @@ func _integrate_forces(state):
|
|||||||
anim = ANIM_AIR_UP
|
anim = ANIM_AIR_UP
|
||||||
else:
|
else:
|
||||||
anim = ANIM_AIR_DOWN
|
anim = ANIM_AIR_DOWN
|
||||||
|
|
||||||
var hs
|
var hs
|
||||||
if (dir.length() > 0.1):
|
if (dir.length() > 0.1):
|
||||||
hv += target_dir*(accel*0.2)*delta
|
hv += target_dir*(accel*0.2)*delta
|
||||||
@@ -158,14 +157,14 @@ func _integrate_forces(state):
|
|||||||
hspeed = hspeed - (deaccel*0.2)*delta
|
hspeed = hspeed - (deaccel*0.2)*delta
|
||||||
if (hspeed < 0):
|
if (hspeed < 0):
|
||||||
hspeed = 0
|
hspeed = 0
|
||||||
|
|
||||||
hv = hdir*hspeed
|
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
|
||||||
@@ -175,19 +174,19 @@ func _integrate_forces(state):
|
|||||||
#if (keep_jump_inertia):
|
#if (keep_jump_inertia):
|
||||||
# lv += last_floor_velocity
|
# lv += last_floor_velocity
|
||||||
pass
|
pass
|
||||||
|
|
||||||
last_floor_velocity = Vector3()
|
last_floor_velocity = Vector3()
|
||||||
movement_dir = lv
|
movement_dir = lv
|
||||||
|
|
||||||
on_floor = onfloor
|
on_floor = onfloor
|
||||||
|
|
||||||
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()
|
||||||
@@ -196,12 +195,12 @@ func _integrate_forces(state):
|
|||||||
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").transition_node_set_current("state", anim)
|
||||||
get_node("AnimationTreePlayer").blend2_node_set_amount("gun", min(shoot_blend, 1.0))
|
get_node("AnimationTreePlayer").blend2_node_set_amount("gun", min(shoot_blend, 1.0))
|
||||||
# state.set_angular_velocity(Vector3())
|
# state.set_angular_velocity(Vector3())
|
||||||
|
|||||||
@@ -69,4 +69,4 @@
|
|||||||
</dictionary>
|
</dictionary>
|
||||||
|
|
||||||
</main_resource>
|
</main_resource>
|
||||||
</resource_file>
|
</resource_file>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Camera
|
extends Camera
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -16,27 +15,27 @@ 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
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends VehicleBody
|
extends VehicleBody
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -18,17 +17,17 @@ func _fixed_process(delta):
|
|||||||
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):
|
||||||
@@ -37,7 +36,7 @@ func _fixed_process(delta):
|
|||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
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 [`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 [`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:
|
- The other branches are compatible with the matching stable versions of Godot.
|
||||||
- [`4.0`](https://github.com/godotengine/godot-demo-projects/tree/4.0)
|
- [Click here](https://github.com/godotengine/godot-demo-projects/branches) to see all branches.
|
||||||
branch for Godot 4.0.x.
|
- For example, the [`2.1`](https://github.com/godotengine/godot-demo-projects/tree/2.1)
|
||||||
- [`3.5`](https://github.com/godotengine/godot-demo-projects/tree/3.5)
|
branch is for demos compatible with Godot 2.1.x.
|
||||||
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.
|
|
||||||
|
|
||||||
## Importing all demos
|
## 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
|
extends ColorPickerButton
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ with others.
|
|||||||
|
|
||||||
The OFL allows the licensed fonts to be used, studied, modified and
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
redistributed freely as long as they are not sold by themselves. The
|
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
|
redistributed and/or sold with any software provided that any reserved
|
||||||
names are not used by derivative works. The fonts and derivatives,
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
however, cannot be released under any other type of license. The
|
however, cannot be released under any other type of license. The
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
,en,es,ja
|
,en,es,ja
|
||||||
KEY_HELLO,Hello!,Hola!,こんにちは
|
KEY_HELLO,Hello!,Hola!,こんにちは
|
||||||
KEY_PUSH,Push Me!,Aprétame!,私をプッシュ
|
KEY_PUSH,Push Me!,Aprétame!,私をプッシュ
|
||||||
|
|||||||
|
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
signal purchase_success(item_name)
|
signal purchase_success(item_name)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
onready var alert = get_node("alert")
|
onready var alert = get_node("alert")
|
||||||
@@ -13,7 +12,7 @@ func _ready():
|
|||||||
iap.connect("consume_success", self, "on_consume_success")
|
iap.connect("consume_success", self, "on_consume_success")
|
||||||
iap.connect("consume_fail", self, "on_consume_fail")
|
iap.connect("consume_fail", self, "on_consume_fail")
|
||||||
iap.connect("sku_details_complete", self, "on_sku_details_complete")
|
iap.connect("sku_details_complete", self, "on_sku_details_complete")
|
||||||
|
|
||||||
get_node("purchase").connect("pressed", self, "button_purchase")
|
get_node("purchase").connect("pressed", self, "button_purchase")
|
||||||
get_node("consume").connect("pressed", self, "button_consume")
|
get_node("consume").connect("pressed", self, "button_consume")
|
||||||
get_node("request").connect("pressed", self, "button_request")
|
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
|
# 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, there is no risk here.
|
# Immediately free the current scene, there is no risk here.
|
||||||
get_tree().get_current_scene().free()
|
get_tree().get_current_scene().free()
|
||||||
|
|
||||||
# Load new scene
|
# Load new scene
|
||||||
var packed_scene = ResourceLoader.load(path)
|
var packed_scene = ResourceLoader.load(path)
|
||||||
|
|
||||||
# Instance the new scene
|
# Instance the new scene
|
||||||
var instanced_scene = packed_scene.instance()
|
var instanced_scene = packed_scene.instance()
|
||||||
|
|
||||||
# Add it to the scene tree, as direct child of root
|
# Add it to the scene tree, as direct child of root
|
||||||
get_tree().get_root().add_child(instanced_scene)
|
get_tree().get_root().add_child(instanced_scene)
|
||||||
|
|
||||||
# Set it as the current scene, only after it has been added to the tree
|
# Set it as the current scene, only after it has been added to the tree
|
||||||
get_tree().set_current_scene(instanced_scene)
|
get_tree().set_current_scene(instanced_scene)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Spatial
|
extends Spatial
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends VBoxContainer
|
extends VBoxContainer
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
# Member variables here, example:
|
# Member variables here, example:
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
# Member variables here, example:
|
# Member variables here, example:
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -16,26 +16,26 @@ func _ready():
|
|||||||
for index in range(trans.size()):
|
for index in range(trans.size()):
|
||||||
var name = trans[index]
|
var name = trans[index]
|
||||||
get_node("trans/" + name).connect("pressed", self, "on_trans_changed", [name, index])
|
get_node("trans/" + name).connect("pressed", self, "on_trans_changed", [name, index])
|
||||||
|
|
||||||
for index in range(eases.size()):
|
for index in range(eases.size()):
|
||||||
var name = eases[index]
|
var name = eases[index]
|
||||||
get_node("eases/" + name).connect("pressed", self, "on_eases_changed", [name, index])
|
get_node("eases/" + name).connect("pressed", self, "on_eases_changed", [name, index])
|
||||||
|
|
||||||
for index in range(modes.size()):
|
for index in range(modes.size()):
|
||||||
var name = modes[index]
|
var name = modes[index]
|
||||||
get_node("modes/" + name).connect("pressed", self, "on_modes_changed", [name])
|
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").set_color(Color(1, 0, 0, 1))
|
||||||
get_node("colors/color_from/picker").connect("color_changed", self, "on_color_changed")
|
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").set_color(Color(0, 1, 1, 1))
|
||||||
get_node("colors/color_to/picker").connect("color_changed", self, "on_color_changed")
|
get_node("colors/color_to/picker").connect("color_changed", self, "on_color_changed")
|
||||||
|
|
||||||
get_node("trans/linear").set_pressed(true)
|
get_node("trans/linear").set_pressed(true)
|
||||||
get_node("eases/in").set_pressed(true)
|
get_node("eases/in").set_pressed(true)
|
||||||
get_node("modes/move").set_pressed(true)
|
get_node("modes/move").set_pressed(true)
|
||||||
get_node("modes/repeat").set_pressed(true)
|
get_node("modes/repeat").set_pressed(true)
|
||||||
|
|
||||||
reset_tween()
|
reset_tween()
|
||||||
|
|
||||||
|
|
||||||
@@ -43,10 +43,10 @@ func on_trans_changed(name, index):
|
|||||||
for index in range(trans.size()):
|
for index in range(trans.size()):
|
||||||
var pressed = trans[index] == name
|
var pressed = trans[index] == name
|
||||||
var btn = get_node("trans/" + trans[index])
|
var btn = get_node("trans/" + trans[index])
|
||||||
|
|
||||||
btn.set_pressed(pressed)
|
btn.set_pressed(pressed)
|
||||||
btn.set_ignore_mouse(pressed)
|
btn.set_ignore_mouse(pressed)
|
||||||
|
|
||||||
state.trans = index
|
state.trans = index
|
||||||
reset_tween()
|
reset_tween()
|
||||||
|
|
||||||
@@ -55,10 +55,10 @@ 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
|
||||||
var btn = get_node("eases/" + eases[index])
|
var btn = get_node("eases/" + eases[index])
|
||||||
|
|
||||||
btn.set_pressed(pressed)
|
btn.set_pressed(pressed)
|
||||||
btn.set_ignore_mouse(pressed)
|
btn.set_ignore_mouse(pressed)
|
||||||
|
|
||||||
state.eases = index
|
state.eases = index
|
||||||
reset_tween()
|
reset_tween()
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ func reset_tween():
|
|||||||
var pos = tween.tell()
|
var pos = tween.tell()
|
||||||
tween.reset_all()
|
tween.reset_all()
|
||||||
tween.remove_all()
|
tween.remove_all()
|
||||||
|
|
||||||
var sprite = get_node("tween/area/sprite")
|
var sprite = get_node("tween/area/sprite")
|
||||||
var follow = get_node("tween/area/follow")
|
var follow = get_node("tween/area/follow")
|
||||||
var follow_2 = get_node("tween/area/follow_2")
|
var follow_2 = get_node("tween/area/follow_2")
|
||||||
@@ -94,44 +94,44 @@ func reset_tween():
|
|||||||
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("colors/color_from/picker").get_color(), get_node("colors/color_to/picker").get_color(), 2, state.trans, state.eases)
|
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)
|
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:
|
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)
|
||||||
tween.interpolate_property(sprite, "transform/rot", 360, 0, 2, state.trans, state.eases, 2)
|
tween.interpolate_property(sprite, "transform/rot", 360, 0, 2, state.trans, state.eases, 2)
|
||||||
|
|
||||||
if get_node("modes/callback").is_pressed():
|
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.5, "on_callback", "0.5 second's after")
|
||||||
tween.interpolate_callback(self, 0.2, "on_callback", "1.2 second's after")
|
tween.interpolate_callback(self, 0.2, "on_callback", "1.2 second's after")
|
||||||
|
|
||||||
if get_node("modes/follow").is_pressed():
|
if get_node("modes/follow").is_pressed():
|
||||||
follow.show()
|
follow.show()
|
||||||
follow_2.show()
|
follow_2.show()
|
||||||
|
|
||||||
tween.follow_method(follow, "set_pos", Vector2(0, size.height), sprite, "get_pos", 2, state.trans, state.eases)
|
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_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.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)
|
tween.follow_property(follow_2, "transform/pos", Vector2(size.width, 0), sprite, "transform/pos", 2, state.trans, state.eases, 2)
|
||||||
else:
|
else:
|
||||||
follow.hide()
|
follow.hide()
|
||||||
follow_2.hide()
|
follow_2.hide()
|
||||||
|
|
||||||
tween.set_repeat(get_node("modes/repeat").is_pressed())
|
tween.set_repeat(get_node("modes/repeat").is_pressed())
|
||||||
tween.start()
|
tween.start()
|
||||||
tween.seek(pos)
|
tween.seek(pos)
|
||||||
|
|
||||||
if get_node("modes/pause").is_pressed():
|
if get_node("modes/pause").is_pressed():
|
||||||
tween.stop_all()
|
tween.stop_all()
|
||||||
get_node("timeline").set_ignore_mouse(false)
|
get_node("timeline").set_ignore_mouse(false)
|
||||||
@@ -143,10 +143,10 @@ func reset_tween():
|
|||||||
|
|
||||||
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)
|
var ratio = 100*(elapsed/runtime)
|
||||||
timeline.set_value(ratio)
|
timeline.set_value(ratio)
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ func _on_tween_step(object, key, elapsed, value):
|
|||||||
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)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
# Really simple UDP chat client, not intended as a comprehensive chat implementation.
|
# Really simple UDP chat client, not intended as a comprehensive chat implementation.
|
||||||
@@ -12,7 +11,7 @@ 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):
|
||||||
@@ -62,5 +61,5 @@ func _on_entry_button_pressed():
|
|||||||
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("")
|
||||||
|
|||||||
@@ -7,45 +7,45 @@ onready var observer = get_node("../Observer")
|
|||||||
|
|
||||||
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"
|
||||||
|
|
||||||
if(OS.is_window_minimized()):
|
if(OS.is_window_minimized()):
|
||||||
modetext += "Minimized\n"
|
modetext += "Minimized\n"
|
||||||
|
|
||||||
if(OS.is_window_maximized()):
|
if(OS.is_window_maximized()):
|
||||||
modetext += "Maximized\n"
|
modetext += "Maximized\n"
|
||||||
|
|
||||||
if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED):
|
if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED):
|
||||||
modetext += "MouseGrab\n"
|
modetext += "MouseGrab\n"
|
||||||
get_node("Label_MouseModeCaptured_KeyInfo").show()
|
get_node("Label_MouseModeCaptured_KeyInfo").show()
|
||||||
else:
|
else:
|
||||||
get_node("Label_MouseModeCaptured_KeyInfo").hide()
|
get_node("Label_MouseModeCaptured_KeyInfo").hide()
|
||||||
|
|
||||||
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()))
|
||||||
|
|
||||||
get_node("Label_Screen0_DPI").set_text(str("Screen0 DPI:\n", OS.get_screen_dpi()))
|
get_node("Label_Screen0_DPI").set_text(str("Screen0 DPI:\n", OS.get_screen_dpi()))
|
||||||
|
|
||||||
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()
|
||||||
@@ -61,7 +61,7 @@ func _fixed_process(delta):
|
|||||||
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("Label_Screen1_DPI").hide()
|
get_node("Label_Screen1_DPI").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())
|
||||||
@@ -75,55 +75,55 @@ 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:
|
||||||
@@ -142,16 +142,16 @@ func _ready():
|
|||||||
func _input(event):
|
func _input(event):
|
||||||
if (event.type == InputEvent.MOUSE_MOTION):
|
if (event.type == InputEvent.MOUSE_MOTION):
|
||||||
mousepos = event.pos
|
mousepos = event.pos
|
||||||
|
|
||||||
if (event.type == InputEvent.KEY):
|
if (event.type == InputEvent.KEY):
|
||||||
if Input.is_action_pressed("mouse_mode_visible"):
|
if Input.is_action_pressed("mouse_mode_visible"):
|
||||||
observer.state = observer.STATE_MENU
|
observer.state = observer.STATE_MENU
|
||||||
_on_Button_MouseModeVisible_pressed()
|
_on_Button_MouseModeVisible_pressed()
|
||||||
|
|
||||||
if Input.is_action_pressed("mouse_mode_hidden"):
|
if Input.is_action_pressed("mouse_mode_hidden"):
|
||||||
observer.state = observer.STATE_MENU
|
observer.state = observer.STATE_MENU
|
||||||
_on_Button_MouseModeHidden_pressed()
|
_on_Button_MouseModeHidden_pressed()
|
||||||
|
|
||||||
if Input.is_action_pressed("mouse_mode_captured"):
|
if Input.is_action_pressed("mouse_mode_captured"):
|
||||||
_on_Button_MouseModeCaptured_pressed()
|
_on_Button_MouseModeCaptured_pressed()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Spatial
|
extends Spatial
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -10,14 +10,9 @@ func _enter_tree():
|
|||||||
|
|
||||||
add_control_to_dock( DOCK_SLOT_LEFT_UL, dock )
|
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 from docks (must be called so layout is updated and saved)
|
||||||
remove_control_from_docks(dock)
|
remove_control_from_docks(dock)
|
||||||
# Remove the node
|
# Remove the node
|
||||||
dock.free()
|
dock.free()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
tool
|
tool
|
||||||
|
|
||||||
extends EditorImportPlugin
|
extends EditorImportPlugin
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,22 +11,22 @@ func configure(p_import_plugin,path,metadata):
|
|||||||
# metadata from previous import exists, fill in fields
|
# metadata from previous import exists, fill in fields
|
||||||
assert( metadata.get_source_count() > 0 )
|
assert( metadata.get_source_count() > 0 )
|
||||||
# Always expand the source paths
|
# 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("src_file").set_text(src_path)
|
||||||
get_node("dst_file").set_text(path)
|
get_node("dst_file").set_text(path)
|
||||||
# Fill in from metadata options
|
# Fill in from metadata options
|
||||||
get_node("use_red_anyway").set_pressed( metadata.get_option("use_red_anyway") )
|
get_node("use_red_anyway").set_pressed( metadata.get_option("use_red_anyway") )
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
||||||
src_fs = FileDialog.new()
|
src_fs = FileDialog.new()
|
||||||
src_fs.set_mode(FileDialog.MODE_OPEN_FILE)
|
src_fs.set_mode(FileDialog.MODE_OPEN_FILE)
|
||||||
src_fs.set_access(FileDialog.ACCESS_FILESYSTEM) #access all filesystem, not only res://
|
src_fs.set_access(FileDialog.ACCESS_FILESYSTEM) #access all filesystem, not only res://
|
||||||
src_fs.add_filter("*.mtxt")
|
src_fs.add_filter("*.mtxt")
|
||||||
src_fs.connect("file_selected",self,"_on_src_selected")
|
src_fs.connect("file_selected",self,"_on_src_selected")
|
||||||
|
|
||||||
add_child(src_fs)
|
add_child(src_fs)
|
||||||
|
|
||||||
dst_fs = EditorFileDialog.new()
|
dst_fs = EditorFileDialog.new()
|
||||||
dst_fs.set_mode(EditorFileDialog.MODE_SAVE_FILE)
|
dst_fs.set_mode(EditorFileDialog.MODE_SAVE_FILE)
|
||||||
@@ -47,15 +47,15 @@ func _on_dst_browse_pressed():
|
|||||||
|
|
||||||
func _on_src_selected(path):
|
func _on_src_selected(path):
|
||||||
get_node("src_file").set_text(path)
|
get_node("src_file").set_text(path)
|
||||||
|
|
||||||
func _on_dst_selected(path):
|
func _on_dst_selected(path):
|
||||||
get_node("dst_file").set_text(path)
|
get_node("dst_file").set_text(path)
|
||||||
|
|
||||||
func _on_MaterialImport_confirmed():
|
func _on_MaterialImport_confirmed():
|
||||||
# Create an import metadata
|
# Create an import metadata
|
||||||
var imd = ResourceImportMetadata.new()
|
var imd = ResourceImportMetadata.new()
|
||||||
# Add the source files, always validate the source path
|
# 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
|
# Add the options
|
||||||
imd.set_option( "use_red_anyway", get_node("use_red_anyway").is_pressed() )
|
imd.set_option( "use_red_anyway", get_node("use_red_anyway").is_pressed() )
|
||||||
# Perform regular import
|
# Perform regular import
|
||||||
@@ -64,4 +64,4 @@ func _on_MaterialImport_confirmed():
|
|||||||
if (err!=OK):
|
if (err!=OK):
|
||||||
get_node("error").set_text("Error Importing!")
|
get_node("error").set_text("Error Importing!")
|
||||||
get_node("error").popup_centered_minsize()
|
get_node("error").popup_centered_minsize()
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,15 @@ extends EditorPlugin
|
|||||||
|
|
||||||
var import_plugin
|
var import_plugin
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
|
|
||||||
import_plugin = preload("res://addons/custom_import_plugin/import_plugin.gd").new()
|
import_plugin = preload("res://addons/custom_import_plugin/import_plugin.gd").new()
|
||||||
|
|
||||||
# pass the GUI base control, so the dialog has a parent node
|
# pass the GUI base control, so the dialog has a parent node
|
||||||
import_plugin.config( get_base_control() )
|
import_plugin.config( get_base_control() )
|
||||||
|
|
||||||
add_import_plugin( import_plugin)
|
add_import_plugin( import_plugin)
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree():
|
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,
|
To distribute and install from UI, make a zip that contains the folder,
|
||||||
example:
|
example:
|
||||||
|
|
||||||
zip -r custom_node.zip custom_node/*
|
zip -r custom_node.zip custom_node/*
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
@@ -16,47 +15,47 @@ func _process(delta):
|
|||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Spatial
|
extends Spatial
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Spatial
|
extends Spatial
|
||||||
|
|
||||||
# Member variables
|
# Member variables
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user