Improve code formatting
The scripts were streamlined using more or less the following conventions: - space after a comma in lists of arguments - spaces around weak operators (+, -), no spaces around strong operators (*, /) - spaces around comparison operators and compound assignment operators - space after a comment start (#) - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now) - function blocks separate by two newlines - comment sentences start with an upper-case letter
This commit is contained in:
@ -1,16 +1,15 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
#virtual from CollisionObject2D (also available as signal)
|
||||
|
||||
# Virtual from CollisionObject2D (also available as signal)
|
||||
func _input_event(viewport, event, shape_idx):
|
||||
#convert event to local coordinates
|
||||
# Convert event to local coordinates
|
||||
if (event.type == InputEvent.MOUSE_MOTION):
|
||||
event = make_input_local(event)
|
||||
get_node("label").set_text(str(event.pos))
|
||||
|
||||
#virtual from CollisionObject2D (also available as signal)
|
||||
|
||||
# Virtual from CollisionObject2D (also available as signal)
|
||||
func _mouse_exit():
|
||||
get_node("label").set_text("")
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,21 +1,18 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
var timeout = 5
|
||||
|
||||
|
||||
func _process(delta):
|
||||
timeout -= delta
|
||||
if (timeout < 1):
|
||||
set_opacity(timeout)
|
||||
if (timeout < 0):
|
||||
queue_free()
|
||||
|
||||
|
||||
func _ready():
|
||||
set_process(true)
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
set_process(true)
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
# Member variables
|
||||
const EMIT_INTERVAL = 0.1
|
||||
var timeout = EMIT_INTERVAL
|
||||
|
||||
|
||||
func _process(delta):
|
||||
timeout -= delta
|
||||
if (timeout < 0):
|
||||
@ -15,9 +14,7 @@ func _process(delta):
|
||||
ball.set_pos(Vector2(randf()*get_viewport_rect().size.x, 0))
|
||||
add_child(ball)
|
||||
|
||||
|
||||
func _ready():
|
||||
set_process(true)
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
set_process(true)
|
||||
|
||||
@ -1,64 +1,62 @@
|
||||
|
||||
extends TileMap
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
# Member variables
|
||||
|
||||
# boundarys for the fog rectangle
|
||||
var x_min = -20 # left start tile
|
||||
var x_max = 20 # right end tile
|
||||
var y_min = -20 # top start tile
|
||||
var y_max = 20 # bottom end tile
|
||||
# Boundaries for the fog rectangle
|
||||
var x_min = -20 # Left start tile
|
||||
var x_max = 20 # Right end tile
|
||||
var y_min = -20 # Top start tile
|
||||
var y_max = 20 # Bottom end tile
|
||||
|
||||
var position # players position
|
||||
var position # Player's position
|
||||
|
||||
# iteration variables
|
||||
# Iteration variables
|
||||
var x
|
||||
var y
|
||||
|
||||
# variable to check if player moved
|
||||
# Variables to check if the player moved
|
||||
var x_old
|
||||
var y_old
|
||||
|
||||
# array to build up the visible area like a square
|
||||
# first value determines the width/height of the tip
|
||||
# here it would be 2*2 + 1 = 5 tiles wide/high
|
||||
# second value determines the total squares size
|
||||
# here it would be 5*2 + 1 = 10 tiles wide/high
|
||||
# Array to build up the visible area like a square.
|
||||
# First value determines the width/height of the tip.
|
||||
# Here it would be 2*2 + 1 = 5 tiles wide/high.
|
||||
# Second value determines the total squares size.
|
||||
# Here it would be 5*2 + 1 = 10 tiles wide/high.
|
||||
var l = range(2, 5)
|
||||
|
||||
# process that runs in realtime
|
||||
|
||||
# Process that runs in realtime
|
||||
func _fixed_process(delta):
|
||||
position = get_node("../troll").get_pos()
|
||||
|
||||
# calculate the corresponding tile
|
||||
# Calculate the corresponding tile
|
||||
# from the players position
|
||||
x = int(position.x/get_cell_size().x)
|
||||
# switching from positive to negative tile positions
|
||||
# Switching from positive to negative tile positions
|
||||
# causes problems because of rounding problems
|
||||
if position.x < 0:
|
||||
x -= 1 # correct negative values
|
||||
x -= 1 # Correct negative values
|
||||
|
||||
y = int(position.y/get_cell_size().y)
|
||||
if position.y < 0:
|
||||
if (position.y < 0):
|
||||
y -= 1
|
||||
|
||||
# check if the player moved one tile further
|
||||
if (x_old != x) or (y_old != y):
|
||||
|
||||
# create the transparent part (visited area)
|
||||
# Check if the player moved one tile further
|
||||
if ((x_old != x) or (y_old != y)):
|
||||
# Create the transparent part (visited area)
|
||||
var end = l.size() - 1
|
||||
var start = 0
|
||||
for steps in range(l.size()):
|
||||
for m in range(x - l[end] - 1, x + l[end] + 2):
|
||||
for n in range(y - l[start] - 1, y + l[start] + 2):
|
||||
if get_cell(m,n) != 0:
|
||||
if (get_cell(m, n) != 0):
|
||||
set_cell(m, n, 1, 0, 0)
|
||||
end -= 1
|
||||
start += 1
|
||||
|
||||
# create the actual and active visible part
|
||||
# Create the actual and active visible part
|
||||
var end = l.size() - 1
|
||||
var start = 0
|
||||
for steps in range(l.size()):
|
||||
@ -71,16 +69,11 @@ func _fixed_process(delta):
|
||||
x_old = x
|
||||
y_old = y
|
||||
|
||||
pass
|
||||
|
||||
func _ready():
|
||||
# Initalization here
|
||||
|
||||
# create a square filled with the 100% opaque fog
|
||||
# Create a square filled with the 100% opaque fog
|
||||
for x in range(x_min, x_max):
|
||||
for y in range(y_min, y_max):
|
||||
set_cell(x, y, 0, 0, 0)
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -2,17 +2,16 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
# the kinematic cotroller works.
|
||||
# the kinematic controller works.
|
||||
# move() will allow to move the node, and will
|
||||
# always move it to a non-colliding spot,
|
||||
# as long as it starts from a non-colliding spot too.
|
||||
|
||||
# Member variables
|
||||
const MOTION_SPEED = 160 # Pixels/second
|
||||
|
||||
#pixels / second
|
||||
const MOTION_SPEED=160
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
var motion = Vector2()
|
||||
|
||||
if (Input.is_action_pressed("move_up")):
|
||||
@ -27,7 +26,7 @@ func _fixed_process(delta):
|
||||
motion = motion.normalized()*MOTION_SPEED*delta
|
||||
motion = move(motion)
|
||||
|
||||
#make character slide nicely through the world
|
||||
# Make character slide nicely through the world
|
||||
var slide_attempts = 4
|
||||
while(is_colliding() and slide_attempts > 0):
|
||||
motion = get_collision_normal().slide(motion)
|
||||
@ -38,6 +37,3 @@ func _fixed_process(delta):
|
||||
func _ready():
|
||||
# Initalization here
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
# Member variables
|
||||
const CAVE_LIMIT = 1000
|
||||
|
||||
func _input(ev):
|
||||
if (ev.type==InputEvent.MOUSE_MOTION and ev.button_mask&1):
|
||||
var rel_x = ev.relative_x
|
||||
|
||||
func _input(event):
|
||||
if (event.type == InputEvent.MOUSE_MOTION and event.button_mask&1):
|
||||
var rel_x = event.relative_x
|
||||
var cavepos = get_node("cave").get_pos()
|
||||
cavepos.x += rel_x
|
||||
if (cavepos.x < -CAVE_LIMIT):
|
||||
@ -19,8 +18,5 @@ func _input(ev):
|
||||
|
||||
|
||||
func _ready():
|
||||
set_process_input(true)
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
set_process_input(true)
|
||||
|
||||
@ -2,17 +2,16 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
# the kinematic cotroller works.
|
||||
# the kinematic controller works.
|
||||
# move() will allow to move the node, and will
|
||||
# always move it to a non-colliding spot,
|
||||
# as long as it starts from a non-colliding spot too.
|
||||
|
||||
# Member variables
|
||||
const MOTION_SPEED = 160 # Pixels/second
|
||||
|
||||
#pixels / second
|
||||
const MOTION_SPEED=160
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
var motion = Vector2()
|
||||
|
||||
if (Input.is_action_pressed("move_up")):
|
||||
@ -27,7 +26,7 @@ func _fixed_process(delta):
|
||||
motion = motion.normalized()*MOTION_SPEED*delta
|
||||
motion = move(motion)
|
||||
|
||||
#make character slide nicely through the world
|
||||
# Make character slide nicely through the world
|
||||
var slide_attempts = 4
|
||||
while(is_colliding() and slide_attempts > 0):
|
||||
motion = get_collision_normal().slide(motion)
|
||||
@ -38,6 +37,3 @@ func _fixed_process(delta):
|
||||
func _ready():
|
||||
# Initalization here
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -2,17 +2,16 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
# the kinematic cotroller works.
|
||||
# the kinematic controller works.
|
||||
# move() will allow to move the node, and will
|
||||
# always move it to a non-colliding spot,
|
||||
# as long as it starts from a non-colliding spot too.
|
||||
|
||||
# Member variables
|
||||
const MOTION_SPEED = 160 # Pixels/seconds
|
||||
|
||||
#pixels / second
|
||||
const MOTION_SPEED=160
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
var motion = Vector2()
|
||||
|
||||
if (Input.is_action_pressed("move_up")):
|
||||
@ -27,7 +26,7 @@ func _fixed_process(delta):
|
||||
motion = motion.normalized()*MOTION_SPEED*delta
|
||||
motion = move(motion)
|
||||
|
||||
#make character slide nicely through the world
|
||||
# Make character slide nicely through the world
|
||||
var slide_attempts = 4
|
||||
while(is_colliding() and slide_attempts > 0):
|
||||
motion = get_collision_normal().slide(motion)
|
||||
@ -38,6 +37,3 @@ func _fixed_process(delta):
|
||||
func _ready():
|
||||
# Initalization here
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const MAX_SPEED = 300.0
|
||||
const IDLE_SPEED = 10.0
|
||||
const ACCEL = 5.0
|
||||
@ -17,9 +14,10 @@ var current_mirror=false
|
||||
|
||||
var shoot_countdown = 0
|
||||
|
||||
func _input(ev):
|
||||
if (ev.type==InputEvent.MOUSE_BUTTON and ev.button_index==1 and ev.pressed and shoot_countdown<=0):
|
||||
var pos = get_canvas_transform().affine_inverse() * ev.pos
|
||||
|
||||
func _input(event):
|
||||
if (event.type == InputEvent.MOUSE_BUTTON and event.button_index == 1 and event.pressed and shoot_countdown <= 0):
|
||||
var pos = get_canvas_transform().affine_inverse()*event.pos
|
||||
var dir = (pos - get_global_pos()).normalized()
|
||||
var bullet = preload("res://shoot.scn").instance()
|
||||
bullet.advance_dir = dir
|
||||
@ -28,10 +26,7 @@ func _input(ev):
|
||||
shoot_countdown = SHOOT_INTERVAL
|
||||
|
||||
|
||||
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
shoot_countdown -= delta
|
||||
var dir = Vector2()
|
||||
if (Input.is_action_pressed("up")):
|
||||
@ -78,7 +73,6 @@ func _fixed_process(delta):
|
||||
next_anim = "top"
|
||||
next_mirror = false
|
||||
|
||||
|
||||
if (next_anim != current_anim or next_mirror != current_mirror):
|
||||
get_node("frames").set_flip_h(next_mirror)
|
||||
get_node("anim").play(next_anim)
|
||||
@ -86,11 +80,7 @@ func _fixed_process(delta):
|
||||
current_mirror = next_mirror
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
set_fixed_process(true)
|
||||
set_process_input(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,18 +1,7 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_prince_area_body_enter(body):
|
||||
if (body.get_name() == "cubio"):
|
||||
get_node("message").show()
|
||||
pass # replace with function body
|
||||
|
||||
@ -1,17 +1,14 @@
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
var advance_dir=Vector2(1,0)
|
||||
# Member variables
|
||||
const ADVANCE_SPEED = 500.0
|
||||
|
||||
var advance_dir = Vector2(1, 0)
|
||||
var hit = false
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
func _fixed_process(delta):
|
||||
if (hit):
|
||||
return
|
||||
move(advance_dir*delta*ADVANCE_SPEED)
|
||||
@ -19,9 +16,7 @@ func _fixed_process(delta):
|
||||
get_node("anim").play("explode")
|
||||
hit = true
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,18 +1,8 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
#member variables here, example:
|
||||
#var a=2
|
||||
#var b="textvar"
|
||||
|
||||
func _ready():
|
||||
#Initalization here
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_princess_body_enter(body):
|
||||
#the name of this editor-generated callback is unfortunate
|
||||
# The name of this editor-generated callback is unfortunate
|
||||
if (body.get_name() == "player"):
|
||||
get_node("youwin").show()
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[application]
|
||||
|
||||
name="Kinematic Collision"
|
||||
name="Kinematic Character"
|
||||
main_scene="res://colworld.scn"
|
||||
icon="res://icon.png"
|
||||
|
||||
|
||||
@ -2,17 +2,15 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
#the kinematic cotroller works.
|
||||
# the kinematic controller works.
|
||||
# move() will allow to move the node, and will
|
||||
# always move it to a non-colliding spot,
|
||||
# as long as it starts from a non-colliding spot too.
|
||||
|
||||
# Member variables
|
||||
const GRAVITY = 500.0 # Pixels/second
|
||||
|
||||
#pixels / second
|
||||
const GRAVITY = 500.0
|
||||
|
||||
#Angle in degrees towards either side that the player can
|
||||
#consider "floor".
|
||||
# Angle in degrees towards either side that the player can consider "floor"
|
||||
const FLOOR_ANGLE_TOLERANCE = 40
|
||||
const WALK_FORCE = 600
|
||||
const WALK_MIN_SPEED = 10
|
||||
@ -21,8 +19,8 @@ const STOP_FORCE = 1300
|
||||
const JUMP_SPEED = 200
|
||||
const JUMP_MAX_AIRBORNE_TIME = 0.2
|
||||
|
||||
const SLIDE_STOP_VELOCITY=1.0 #one pixel per second
|
||||
const SLIDE_STOP_MIN_TRAVEL=1.0 #one pixel
|
||||
const SLIDE_STOP_VELOCITY = 1.0 # One pixel per second
|
||||
const SLIDE_STOP_MIN_TRAVEL = 1.0 # One pixel
|
||||
|
||||
var velocity = Vector2()
|
||||
var on_air_time = 100
|
||||
@ -30,9 +28,9 @@ var jumping=false
|
||||
|
||||
var prev_jump_pressed = false
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
#create forces
|
||||
func _fixed_process(delta):
|
||||
# Create forces
|
||||
var force = Vector2(0, GRAVITY)
|
||||
|
||||
var walk_left = Input.is_action_pressed("move_left")
|
||||
@ -45,7 +43,6 @@ func _fixed_process(delta):
|
||||
if (velocity.x <= WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED):
|
||||
force.x -= WALK_FORCE
|
||||
stop = false
|
||||
|
||||
elif (walk_right):
|
||||
if (velocity.x >= -WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED):
|
||||
force.x += WALK_FORCE
|
||||
@ -61,34 +58,30 @@ func _fixed_process(delta):
|
||||
|
||||
velocity.x = vlen*vsign
|
||||
|
||||
|
||||
|
||||
#integrate forces to velocity
|
||||
# Integrate forces to velocity
|
||||
velocity += force*delta
|
||||
|
||||
#integrate velocity into motion and move
|
||||
# Integrate velocity into motion and move
|
||||
var motion = velocity*delta
|
||||
|
||||
#move and consume motion
|
||||
# Move and consume motion
|
||||
motion = move(motion)
|
||||
|
||||
|
||||
var floor_velocity = Vector2()
|
||||
|
||||
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())
|
||||
|
||||
#ran against something, is it the floor? get normal
|
||||
# Ran against something, is it the floor? Get normal
|
||||
var n = get_collision_normal()
|
||||
|
||||
if (rad2deg(acos(n.dot(Vector2(0, -1)))) < FLOOR_ANGLE_TOLERANCE):
|
||||
#if angle to the "up" vectors is < angle tolerance
|
||||
# If angle to the "up" vectors is < angle tolerance
|
||||
# char is on floor
|
||||
on_air_time = 0
|
||||
floor_velocity = get_collider_velocity()
|
||||
|
||||
|
||||
if (on_air_time == 0 and force.x == 0 and get_travel().length() < SLIDE_STOP_MIN_TRAVEL and abs(velocity.x) < SLIDE_STOP_VELOCITY and get_collider_velocity() == Vector2()):
|
||||
# Since this formula will always slide the character around,
|
||||
# a special case must be considered to to stop it from moving
|
||||
@ -100,28 +93,24 @@ func _fixed_process(delta):
|
||||
|
||||
revert_motion()
|
||||
velocity.y = 0.0
|
||||
|
||||
else:
|
||||
# For every other case of motion, our motion was interrupted.
|
||||
#Try to complete the motion by "sliding"
|
||||
#by the normal
|
||||
|
||||
# Try to complete the motion by "sliding" by the normal
|
||||
motion = n.slide(motion)
|
||||
velocity = n.slide(velocity)
|
||||
#then move again
|
||||
# Then move again
|
||||
move(motion)
|
||||
|
||||
if (floor_velocity != Vector2()):
|
||||
#if floor moves, move with floor
|
||||
# If floor moves, move with floor
|
||||
move(floor_velocity*delta)
|
||||
|
||||
if (jumping and velocity.y > 0):
|
||||
#if falling, no longer jumping
|
||||
# If falling, no longer jumping
|
||||
jumping = false
|
||||
|
||||
if (on_air_time < JUMP_MAX_AIRBORNE_TIME and jump and not prev_jump_pressed and not jumping):
|
||||
# Jump must also be allowed to happen if the
|
||||
# character left the floor a little bit ago.
|
||||
# Jump must also be allowed to happen if the character left the floor a little bit ago.
|
||||
# Makes controls more snappy.
|
||||
velocity.y = -JUMP_SPEED
|
||||
jumping = true
|
||||
@ -129,9 +118,7 @@ func _fixed_process(delta):
|
||||
on_air_time += delta
|
||||
prev_jump_pressed = jump
|
||||
|
||||
|
||||
func _ready():
|
||||
#Initalization here
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -2,17 +2,16 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
# This is a simple collision demo showing how
|
||||
# the kinematic cotroller works.
|
||||
# the kinematic controller works.
|
||||
# move() will allow to move the node, and will
|
||||
# always move it to a non-colliding spot,
|
||||
# as long as it starts from a non-colliding spot too.
|
||||
|
||||
# Member variables
|
||||
const MOTION_SPEED = 160 # Pixels/second
|
||||
|
||||
#pixels / second
|
||||
const MOTION_SPEED=160
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
var motion = Vector2()
|
||||
|
||||
if (Input.is_action_pressed("move_up")):
|
||||
@ -31,6 +30,3 @@ func _fixed_process(delta):
|
||||
func _ready():
|
||||
# Initalization here
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
|
||||
extends Sprite
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const MODE_DIRECT = 0
|
||||
const MODE_CONSTANT = 1
|
||||
const MODE_SMOOTH = 2
|
||||
@ -14,30 +11,24 @@ const SMOOTH_SPEED = 2.0
|
||||
|
||||
export(int, "Direct", "Constant", "Smooth") var mode = MODE_DIRECT
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var mpos = get_viewport().get_mouse_pos()
|
||||
|
||||
if (mode == MODE_DIRECT):
|
||||
|
||||
look_at(mpos)
|
||||
|
||||
elif (mode == MODE_CONSTANT):
|
||||
|
||||
var ang = get_angle_to(mpos)
|
||||
var s = sign(ang)
|
||||
ang = abs(ang)
|
||||
|
||||
rotate(min(ang, ROTATION_SPEED*delta)*s)
|
||||
|
||||
elif (mode == MODE_SMOOTH):
|
||||
|
||||
var ang = get_angle_to(mpos)
|
||||
|
||||
rotate(ang*delta*SMOOTH_SPEED)
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
set_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
|
||||
extends Sprite
|
||||
|
||||
# Member variables
|
||||
const BEGIN = -113
|
||||
const END = 907
|
||||
const TIME = 5.0 # Seconds
|
||||
const SPEED = (END - BEGIN)/TIME
|
||||
|
||||
export var use_idle = true
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
const BEGIN = -113
|
||||
const END = 907
|
||||
const TIME = 5.0 # seconds
|
||||
const SPEED = (END-BEGIN)/TIME
|
||||
|
||||
func _process(delta):
|
||||
var ofs = get_pos()
|
||||
@ -19,6 +17,7 @@ func _process(delta):
|
||||
ofs.x = BEGIN
|
||||
set_pos(ofs)
|
||||
|
||||
|
||||
func _fixed_process(delta):
|
||||
var ofs = get_pos()
|
||||
ofs.x += delta*SPEED
|
||||
@ -33,6 +32,3 @@ func _ready():
|
||||
set_process(true)
|
||||
else:
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,20 +1,16 @@
|
||||
|
||||
extends Navigation2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
# Member variables
|
||||
const SPEED = 200.0
|
||||
|
||||
var begin = Vector2()
|
||||
var end = Vector2()
|
||||
var path = []
|
||||
|
||||
const SPEED=200.0
|
||||
|
||||
func _process(delta):
|
||||
|
||||
|
||||
if (path.size() > 1):
|
||||
|
||||
var to_walk = delta*SPEED
|
||||
while(to_walk > 0 and path.size() >= 2):
|
||||
var pfrom = path[path.size() - 1]
|
||||
@ -33,31 +29,26 @@ func _process(delta):
|
||||
if (path.size() < 2):
|
||||
path = []
|
||||
set_process(false)
|
||||
|
||||
else:
|
||||
set_process(false)
|
||||
|
||||
|
||||
|
||||
func _update_path():
|
||||
|
||||
var p = get_simple_path(begin, end, true)
|
||||
path=Array(p) # Vector2array to complex to use, convert to regular array
|
||||
path = Array(p) # Vector2array too complex to use, convert to regular array
|
||||
path.invert()
|
||||
|
||||
set_process(true)
|
||||
|
||||
|
||||
func _input(ev):
|
||||
if (ev.type==InputEvent.MOUSE_BUTTON and ev.pressed and ev.button_index==1):
|
||||
func _input(event):
|
||||
if (event.type == InputEvent.MOUSE_BUTTON and event.pressed and event.button_index == 1):
|
||||
begin = get_node("agent").get_pos()
|
||||
#mouse to local navigatio cooards
|
||||
end=ev.pos - get_pos()
|
||||
# Mouse to local navigation coordinates
|
||||
end = event.pos - get_pos()
|
||||
_update_path()
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
set_process_input(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,21 +1,17 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
var disabled = false
|
||||
|
||||
|
||||
func disable():
|
||||
if (disabled):
|
||||
return
|
||||
get_node("anim").play("shutdown")
|
||||
disabled = true
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initalization here
|
||||
get_node("Timer").start()
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
var taken = false
|
||||
|
||||
|
||||
@ -14,12 +11,6 @@ func _on_body_enter( body ):
|
||||
taken = true
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initalization here
|
||||
pass
|
||||
|
||||
|
||||
|
||||
func _on_coin_area_enter(area):
|
||||
pass # replace with function body
|
||||
|
||||
|
||||
@ -1,17 +1,12 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const STATE_WALKING = 0
|
||||
const STATE_DYING = 1
|
||||
|
||||
|
||||
var state = STATE_WALKING
|
||||
|
||||
|
||||
var direction = -1
|
||||
var anim = ""
|
||||
|
||||
@ -21,25 +16,25 @@ var WALK_SPEED = 50
|
||||
|
||||
var bullet_class = preload("res://bullet.gd")
|
||||
|
||||
|
||||
func _die():
|
||||
queue_free()
|
||||
|
||||
|
||||
func _pre_explode():
|
||||
#stay there
|
||||
# Stay there
|
||||
clear_shapes()
|
||||
set_mode(MODE_STATIC)
|
||||
get_node("sound").play("explode")
|
||||
|
||||
|
||||
func _integrate_forces(s):
|
||||
|
||||
var lv = s.get_linear_velocity()
|
||||
var new_anim = anim
|
||||
|
||||
if (state == STATE_DYING):
|
||||
new_anim = "explode"
|
||||
elif (state == STATE_WALKING):
|
||||
|
||||
new_anim = "walk"
|
||||
|
||||
var wall_side = 0.0
|
||||
@ -49,8 +44,6 @@ func _integrate_forces(s):
|
||||
var dp = s.get_contact_local_normal(i)
|
||||
|
||||
if (cc):
|
||||
|
||||
|
||||
if (cc extends bullet_class and not cc.disabled):
|
||||
set_mode(MODE_RIGID)
|
||||
state = STATE_DYING
|
||||
@ -59,17 +52,14 @@ func _integrate_forces(s):
|
||||
set_friction(1)
|
||||
cc.disable()
|
||||
get_node("sound").play("hit")
|
||||
|
||||
break
|
||||
|
||||
|
||||
if (dp.x > 0.9):
|
||||
wall_side = 1.0
|
||||
elif (dp.x < -0.9):
|
||||
wall_side = -1.0
|
||||
|
||||
if (wall_side != 0 and wall_side != direction):
|
||||
|
||||
direction = -direction
|
||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
||||
if (direction < 0 and not rc_left.is_colliding() and rc_right.is_colliding()):
|
||||
@ -79,7 +69,6 @@ func _integrate_forces(s):
|
||||
direction = -direction
|
||||
get_node("sprite").set_scale(Vector2(-direction, 1))
|
||||
|
||||
|
||||
lv.x = direction*WALK_SPEED
|
||||
|
||||
if(anim != new_anim):
|
||||
@ -93,6 +82,3 @@ func _ready():
|
||||
# Initalization here
|
||||
rc_left = get_node("raycast_left")
|
||||
rc_right = get_node("raycast_right")
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
export var motion = Vector2()
|
||||
export var cycle = 1.0
|
||||
var accum = 0.0
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
func _fixed_process(delta):
|
||||
accum += delta*(1.0/cycle)*PI*2.0
|
||||
accum = fmod(accum, PI*2.0)
|
||||
var d = sin(accum)
|
||||
@ -22,6 +19,3 @@ func _fixed_process(delta):
|
||||
func _ready():
|
||||
# Initalization here
|
||||
set_fixed_process(true)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
|
||||
extends RigidBody2D
|
||||
|
||||
# Character Demo, written by Juan Linietsky.
|
||||
@ -24,6 +25,7 @@ extends RigidBody2D
|
||||
# -Friction cant be used, so floor velocity must be considered
|
||||
# for moving platforms.
|
||||
|
||||
# Member variables
|
||||
var anim = ""
|
||||
var siding_left = false
|
||||
var jumping = false
|
||||
@ -50,17 +52,14 @@ var bullet = preload("res://bullet.xml")
|
||||
var floor_h_velocity = 0.0
|
||||
var enemy
|
||||
|
||||
|
||||
func _integrate_forces(s):
|
||||
|
||||
|
||||
|
||||
var lv = s.get_linear_velocity()
|
||||
var step = s.get_step()
|
||||
|
||||
var new_anim = anim
|
||||
var new_siding_left = siding_left
|
||||
|
||||
|
||||
# Get the controls
|
||||
var move_left = Input.is_action_pressed("move_left")
|
||||
var move_right = Input.is_action_pressed("move_right")
|
||||
@ -75,27 +74,22 @@ func _integrate_forces(s):
|
||||
e.set_pos(p)
|
||||
get_parent().add_child(e)
|
||||
|
||||
|
||||
#deapply prev floor velocity
|
||||
# Deapply prev floor velocity
|
||||
lv.x -= floor_h_velocity
|
||||
floor_h_velocity = 0.0
|
||||
|
||||
|
||||
# Find the floor (a contact with upwards facing collision normal)
|
||||
var found_floor = false
|
||||
var floor_index = -1
|
||||
|
||||
for x in range(s.get_contact_count()):
|
||||
|
||||
var ci = s.get_contact_local_normal(x)
|
||||
if (ci.dot(Vector2(0, -1)) > 0.6):
|
||||
found_floor = true
|
||||
floor_index = x
|
||||
|
||||
# A good idea when impementing characters of all kinds,
|
||||
# Compensates for physics imprecission, as well as human
|
||||
# reaction delay.
|
||||
|
||||
# compensates for physics imprecission, as well as human reaction delay.
|
||||
if (shoot and not shooting):
|
||||
shoot_time = 0
|
||||
var bi = bullet.instance()
|
||||
@ -112,24 +106,21 @@ func _integrate_forces(s):
|
||||
bi.set_linear_velocity(Vector2(800.0*ss, -80))
|
||||
get_node("sprite/smoke").set_emitting(true)
|
||||
get_node("sound").play("shoot")
|
||||
PS2D.body_add_collision_exception(bi.get_rid(),get_rid()) # make bullet and this not collide
|
||||
|
||||
|
||||
PS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide
|
||||
else:
|
||||
shoot_time += step
|
||||
|
||||
|
||||
if (found_floor):
|
||||
airborne_time = 0.0
|
||||
else:
|
||||
airborne_time+=step #time it spent in the air
|
||||
airborne_time += step # Time it spent in the air
|
||||
|
||||
var on_floor = airborne_time < MAX_FLOOR_AIRBORNE_TIME
|
||||
|
||||
# Process jump
|
||||
if (jumping):
|
||||
if (lv.y > 0):
|
||||
#set off the jumping flag if going down
|
||||
# Set off the jumping flag if going down
|
||||
jumping = false
|
||||
elif (not jump):
|
||||
stopping_jump = true
|
||||
@ -138,9 +129,7 @@ func _integrate_forces(s):
|
||||
lv.y += STOP_JUMP_FORCE*step
|
||||
|
||||
if (on_floor):
|
||||
|
||||
# Process logic when character is on floor
|
||||
|
||||
if (move_left and not move_right):
|
||||
if (lv.x > -WALK_MAX_VELOCITY):
|
||||
lv.x -= WALK_ACCEL*step
|
||||
@ -161,8 +150,7 @@ func _integrate_forces(s):
|
||||
stopping_jump = false
|
||||
get_node("sound").play("jump")
|
||||
|
||||
#check siding
|
||||
|
||||
# Check siding
|
||||
if (lv.x < 0 and move_left):
|
||||
new_siding_left = true
|
||||
elif (lv.x > 0 and move_right):
|
||||
@ -180,9 +168,7 @@ func _integrate_forces(s):
|
||||
else:
|
||||
new_anim = "run"
|
||||
else:
|
||||
|
||||
# Process logic when the character is in the air
|
||||
|
||||
if (move_left and not move_right):
|
||||
if (lv.x > -WALK_MAX_VELOCITY):
|
||||
lv.x -= AIR_ACCEL*step
|
||||
@ -207,9 +193,7 @@ func _integrate_forces(s):
|
||||
else:
|
||||
new_anim = "falling"
|
||||
|
||||
|
||||
# Update siding
|
||||
|
||||
if (new_siding_left != siding_left):
|
||||
if (new_siding_left):
|
||||
get_node("sprite").set_scale(Vector2(-1, 1))
|
||||
@ -229,22 +213,15 @@ func _integrate_forces(s):
|
||||
if (found_floor):
|
||||
floor_h_velocity = s.get_contact_collider_velocity_at_pos(floor_index).x
|
||||
lv.x += floor_h_velocity
|
||||
|
||||
|
||||
|
||||
|
||||
# Finally, apply gravity and set back the linear velocity
|
||||
lv += s.get_total_gravity()*step
|
||||
s.set_linear_velocity(lv)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initalization here
|
||||
enemy = ResourceLoader.load("res://enemy.xml")
|
||||
|
||||
# if !Globals.has_singleton("Facebook"):
|
||||
# return
|
||||
@ -254,8 +231,3 @@ func _ready():
|
||||
# var msg = "I just sneezed on your wall! Beat my score and Stop the Running nose!"
|
||||
# var title = "I just sneezed on your wall!"
|
||||
# Facebook.post("feed", msg, title, link, icon)
|
||||
enemy = ResourceLoader.load("res://enemy.xml")
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,32 +1,33 @@
|
||||
|
||||
extends Spatial
|
||||
|
||||
|
||||
func _ready():
|
||||
var pf = PolygonPathFinder.new()
|
||||
|
||||
var points = Vector2Array()
|
||||
var connections = IntArray()
|
||||
|
||||
# poly 1
|
||||
# Poly 1
|
||||
points.push_back(Vector2(0, 0)) # 0
|
||||
points.push_back(Vector2(10, 0)) # 1
|
||||
points.push_back(Vector2(10, 10)) # 2
|
||||
points.push_back(Vector2(0, 10)) # 3
|
||||
|
||||
connections.push_back(0) # connect vertex 0 ...
|
||||
connections.push_back(0) # Connect vertex 0...
|
||||
connections.push_back(1) # ... to 1
|
||||
drawLine(points[0], points[1], get_node("/root/Spatial/Polys"))
|
||||
connections.push_back(1) # connect vertex 1 ...
|
||||
connections.push_back(1) # Connect vertex 1...
|
||||
connections.push_back(2) # ... to 2
|
||||
drawLine(points[1], points[2], get_node("/root/Spatial/Polys"))
|
||||
connections.push_back(2) # etc.
|
||||
connections.push_back(2) # Etc.
|
||||
connections.push_back(3)
|
||||
drawLine(points[2], points[3], get_node("/root/Spatial/Polys"))
|
||||
connections.push_back(3) # connect vertex 3 ...
|
||||
connections.push_back(0) # back to vertex 0, to close the polygon
|
||||
connections.push_back(3) # Connect vertex 3...
|
||||
connections.push_back(0) # ... back to vertex 0, to close the polygon
|
||||
drawLine(points[3], points[0], get_node("/root/Spatial/Polys"))
|
||||
|
||||
# poly 2, as obstacle inside poly 1
|
||||
# Poly 2, as obstacle inside poly 1
|
||||
points.push_back(Vector2(2, 0.5)) # 4
|
||||
points.push_back(Vector2(4, 0.5)) # 5
|
||||
points.push_back(Vector2(4, 9.5)) # 6
|
||||
@ -45,7 +46,6 @@ func _ready():
|
||||
connections.push_back(4)
|
||||
drawLine(points[7], points[4], get_node("/root/Spatial/Polys"))
|
||||
|
||||
|
||||
print("points: ", points)
|
||||
print("connections: ", connections)
|
||||
|
||||
@ -63,7 +63,6 @@ func _ready():
|
||||
lastStep = step
|
||||
|
||||
|
||||
|
||||
func drawLine(pointA, pointB, immediateGeo):
|
||||
var drawPosY = 0.1
|
||||
var im = immediateGeo
|
||||
@ -76,5 +75,3 @@ func drawLine(pointA, pointB, immediateGeo):
|
||||
im.add_vertex(Vector3(pointA.x, drawPosY, pointA.y))
|
||||
im.add_vertex(Vector3(pointB.x, drawPosY, pointB.y))
|
||||
im.end()
|
||||
|
||||
|
||||
|
||||
@ -1,50 +1,46 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
#member variables here, example:
|
||||
#var a=2
|
||||
#var b="textvar"
|
||||
# Member variables
|
||||
const INITIAL_BALL_SPEED = 80
|
||||
var ball_speed = INITIAL_BALL_SPEED
|
||||
var screen_size = Vector2(640, 400)
|
||||
#default ball direction
|
||||
|
||||
# Default ball direction
|
||||
var direction = Vector2(-1, 0)
|
||||
var pad_size = Vector2(8, 32)
|
||||
const PAD_SPEED = 150
|
||||
|
||||
|
||||
func _process(delta):
|
||||
|
||||
|
||||
#get ball position and pad rectangles
|
||||
# Get ball position and pad rectangles
|
||||
var ball_pos = get_node("ball").get_pos()
|
||||
var left_rect = Rect2(get_node("left").get_pos() - pad_size*0.5, pad_size)
|
||||
var right_rect = Rect2(get_node("right").get_pos() - pad_size*0.5, pad_size)
|
||||
|
||||
#integrate new ball postion
|
||||
# Integrate new ball postion
|
||||
ball_pos += direction*ball_speed*delta
|
||||
|
||||
#flip when touching roof or floor
|
||||
# Flip when touching roof or floor
|
||||
if ((ball_pos.y < 0 and direction.y < 0) or (ball_pos.y > screen_size.y and direction.y > 0)):
|
||||
direction.y = -direction.y
|
||||
|
||||
#flip, change direction and increase speed when touching pads
|
||||
# Flip, change direction and increase speed when touching pads
|
||||
if ((left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)):
|
||||
direction.x = -direction.x
|
||||
ball_speed *= 1.1
|
||||
direction.y = randf()*2.0 - 1
|
||||
direction = direction.normalized()
|
||||
|
||||
#check gameover
|
||||
# Check gameover
|
||||
if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
|
||||
ball_pos = screen_size*0.5
|
||||
ball_speed = INITIAL_BALL_SPEED
|
||||
direction = Vector2(-1, 0)
|
||||
|
||||
|
||||
get_node("ball").set_pos(ball_pos)
|
||||
|
||||
#move left pad
|
||||
# Move left pad
|
||||
var left_pos = get_node("left").get_pos()
|
||||
|
||||
if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
|
||||
@ -54,7 +50,7 @@ func _process(delta):
|
||||
|
||||
get_node("left").set_pos(left_pos)
|
||||
|
||||
#move right pad
|
||||
# Move right pad
|
||||
var right_pos = get_node("right").get_pos()
|
||||
|
||||
if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
|
||||
@ -65,9 +61,8 @@ func _process(delta):
|
||||
get_node("right").set_pos(right_pos)
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
screen_size = get_viewport_rect().size #get actual size
|
||||
# Initalization here
|
||||
screen_size = get_viewport_rect().size # Get actual size
|
||||
pad_size = get_node("left").get_texture().get_size()
|
||||
set_process(true)
|
||||
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
@ -11,9 +8,6 @@ func _ready():
|
||||
get_node("picture").add_item("PIC: " + c.get_name())
|
||||
for c in get_node("effects").get_children():
|
||||
get_node("effect").add_item("FX: " + c.get_name())
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_picture_item_selected(ID):
|
||||
|
||||
@ -4,6 +4,7 @@ extends Node2D
|
||||
# This demo is an example of controling a high number of 2D objects with logic and collision without using scene nodes.
|
||||
# This technique is a lot more efficient than using instancing and nodes, but requires more programming and is less visual
|
||||
|
||||
# Member variables
|
||||
const BULLET_COUNT = 500
|
||||
const SPEED_MIN = 20
|
||||
const SPEED_MAX = 50
|
||||
@ -11,6 +12,8 @@ const SPEED_MAX = 50
|
||||
var bullets = []
|
||||
var shape
|
||||
|
||||
|
||||
# Inner classes
|
||||
class Bullet:
|
||||
var pos = Vector2()
|
||||
var speed = 1.0
|
||||
@ -18,7 +21,6 @@ class Bullet:
|
||||
|
||||
|
||||
func _draw():
|
||||
|
||||
var t = preload("res://bullet.png")
|
||||
var tofs = -t.get_size()*0.5
|
||||
for b in bullets:
|
||||
@ -40,9 +42,9 @@ func _process(delta):
|
||||
|
||||
|
||||
func _ready():
|
||||
|
||||
# Initialization here
|
||||
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):
|
||||
var b = Bullet.new()
|
||||
@ -51,15 +53,14 @@ func _ready():
|
||||
Physics2DServer.body_set_space(b.body, get_world_2d().get_space())
|
||||
Physics2DServer.body_add_shape(b.body, shape)
|
||||
|
||||
b.pos = Vector2( get_viewport_rect().size * Vector2(randf()*2.0,randf()) ) #twice as long
|
||||
b.pos.x += get_viewport_rect().size.x # start outside
|
||||
b.pos = Vector2(get_viewport_rect().size * Vector2(randf()*2.0, randf())) # Twice as long
|
||||
b.pos.x += get_viewport_rect().size.x # Start outside
|
||||
var mat = Matrix32()
|
||||
mat.o = b.pos
|
||||
Physics2DServer.body_set_state(b.body, Physics2DServer.BODY_STATE_TRANSFORM, mat)
|
||||
|
||||
bullets.append(b)
|
||||
|
||||
|
||||
set_process(true)
|
||||
|
||||
|
||||
@ -68,9 +69,4 @@ func _exit_tree():
|
||||
Physics2DServer.free_rid(b.body)
|
||||
|
||||
Physics2DServer.free_rid(shape)
|
||||
# Initalization here
|
||||
bullets.clear()
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,32 +1,26 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
var touching = 0
|
||||
|
||||
func _input(ev):
|
||||
|
||||
if (ev.type==InputEvent.MOUSE_MOTION):
|
||||
get_node("player").set_pos(ev.pos-Vector2(0,16))
|
||||
func _input(event):
|
||||
if (event.type == InputEvent.MOUSE_MOTION):
|
||||
get_node("player").set_pos(event.pos - Vector2(0, 16))
|
||||
|
||||
|
||||
func _on_player_body_enter_shape(body_id, body, body_shape, area_shape):
|
||||
|
||||
touching += 1
|
||||
if (touching == 1):
|
||||
get_node("player/sprite").set_frame(1)
|
||||
|
||||
|
||||
func _on_player_body_exit_shape(body_id, body, body_shape, area_shape):
|
||||
|
||||
touching -= 1
|
||||
if (touching == 0):
|
||||
get_node("player/sprite").set_frame(0)
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
set_process_input(true)
|
||||
pass
|
||||
|
||||
@ -1,28 +1,23 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const SPEED = -200
|
||||
const Y_RANDOM = 10
|
||||
|
||||
var points = 1
|
||||
|
||||
|
||||
var speed_y = 0.0
|
||||
var destroyed = false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
|
||||
translate(Vector2(SPEED, speed_y)*delta)
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
speed_y = rand_range(-Y_RANDOM, Y_RANDOM)
|
||||
pass
|
||||
|
||||
var destroyed=false
|
||||
|
||||
func destroy():
|
||||
if (destroyed):
|
||||
@ -31,19 +26,19 @@ func destroy():
|
||||
get_node("anim").play("explode")
|
||||
set_process(false)
|
||||
get_node("sfx").play("sound_explode")
|
||||
#accum points
|
||||
# Accumulate points
|
||||
get_node("/root/game_state").points += 1
|
||||
|
||||
|
||||
func is_enemy():
|
||||
return not destroyed
|
||||
|
||||
|
||||
func _on_visibility_enter_screen():
|
||||
set_process(true)
|
||||
#make it spin!
|
||||
# Make it spin!
|
||||
get_node("anim").play("spin")
|
||||
|
||||
|
||||
func _on_visibility_exit_screen():
|
||||
queue_free()
|
||||
pass # replace with function body
|
||||
|
||||
@ -1,18 +1,16 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const SPEED = -200
|
||||
|
||||
var destroyed=false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
get_parent().translate(Vector2(SPEED*delta, 0))
|
||||
|
||||
|
||||
var destroyed=false
|
||||
|
||||
func is_enemy():
|
||||
return not destroyed
|
||||
|
||||
@ -24,14 +22,15 @@ func destroy():
|
||||
get_node("anim").play("explode")
|
||||
set_process(false)
|
||||
get_node("sfx").play("sound_explode")
|
||||
#accum points
|
||||
# Accumulate points
|
||||
get_node("/root/game_state").points += 5
|
||||
|
||||
|
||||
func _on_visibility_enter_screen():
|
||||
set_process(true)
|
||||
get_node("anim").play("zigzag")
|
||||
get_node("anim").seek(randf()*2.0) #make it start from any pos
|
||||
get_node("anim").seek(randf()*2.0) # Make it start from any pos
|
||||
|
||||
|
||||
func _on_visibility_exit_screen():
|
||||
queue_free()
|
||||
|
||||
|
||||
@ -1,33 +1,33 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
# Member variables
|
||||
const SPEED = -220
|
||||
const SHOOT_INTERVAL = 1
|
||||
|
||||
var shoot_timeout = 0
|
||||
var destroyed=false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
translate(Vector2(SPEED*delta, 0))
|
||||
shoot_timeout -= delta
|
||||
|
||||
if (shoot_timeout < 0):
|
||||
|
||||
shoot_timeout = SHOOT_INTERVAL
|
||||
|
||||
#instance a shot
|
||||
# Instance a shot
|
||||
var shot = preload("res://enemy_shot.scn").instance()
|
||||
#set pos as "shoot_from" Position2D node
|
||||
# Set pos as "shoot_from" Position2D node
|
||||
shot.set_pos(get_node("shoot_from").get_global_pos())
|
||||
#add it to parent, so it has world coordinates
|
||||
# Add it to parent, so it has world coordinates
|
||||
get_parent().add_child(shot)
|
||||
|
||||
var destroyed=false
|
||||
|
||||
func is_enemy():
|
||||
return not destroyed
|
||||
|
||||
|
||||
func destroy():
|
||||
if (destroyed):
|
||||
return
|
||||
@ -35,22 +35,18 @@ func destroy():
|
||||
get_node("anim").play("explode")
|
||||
set_process(false)
|
||||
get_node("sfx").play("sound_explode")
|
||||
#accum points
|
||||
# Accumulate points
|
||||
get_node("/root/game_state").points += 10
|
||||
|
||||
|
||||
func _ready():
|
||||
set_fixed_process(true)
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
set_fixed_process(true)
|
||||
|
||||
|
||||
func _on_visibility_enter_screen():
|
||||
set_process(true)
|
||||
pass # replace with function body
|
||||
|
||||
|
||||
func _on_visibility_exit_screen():
|
||||
queue_free()
|
||||
pass # replace with function body
|
||||
|
||||
@ -1,25 +1,25 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const SPEED = -800
|
||||
|
||||
var hit = false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
translate(Vector2(delta*SPEED, 0))
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
set_process(true)
|
||||
|
||||
|
||||
var hit=false
|
||||
|
||||
func is_enemy():
|
||||
return true
|
||||
|
||||
|
||||
func _hit_something():
|
||||
if (hit):
|
||||
return
|
||||
@ -27,6 +27,6 @@ func _hit_something():
|
||||
set_process(false)
|
||||
get_node("anim").play("splash")
|
||||
|
||||
|
||||
func _on_visibility_exit_screen():
|
||||
queue_free()
|
||||
|
||||
|
||||
@ -1,24 +1,22 @@
|
||||
|
||||
extends Node
|
||||
|
||||
|
||||
# Member variables
|
||||
var points = 0
|
||||
var max_points = 0
|
||||
|
||||
|
||||
func _ready():
|
||||
var f = File.new()
|
||||
#load high score
|
||||
|
||||
# Load high score
|
||||
if (f.open("user://highscore", File.READ) == OK):
|
||||
|
||||
max_points = f.get_var()
|
||||
|
||||
|
||||
func game_over():
|
||||
if (points > max_points):
|
||||
max_points = points
|
||||
#save high score
|
||||
# Save high score
|
||||
var f = File.new()
|
||||
f.open("user://highscore", File.WRITE)
|
||||
f.store_var(max_points)
|
||||
|
||||
@ -1,20 +1,12 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
func _ready():
|
||||
|
||||
get_node("score").set_text( "HIGH SCORE: "+str( get_node("/root/game_state").max_points ) )
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
get_node("score").set_text("HIGH SCORE: " + str(get_node("/root/game_state").max_points))
|
||||
|
||||
|
||||
func _on_play_pressed():
|
||||
get_node("/root/game_state").points = 0
|
||||
get_tree().change_scene("res://level.scn")
|
||||
pass # replace with function body
|
||||
|
||||
@ -1,25 +1,20 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
|
||||
# Member variables
|
||||
const SPEED = 200
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
var offset = 0
|
||||
|
||||
|
||||
func stop():
|
||||
set_process(false)
|
||||
|
||||
var offset=0
|
||||
|
||||
|
||||
func _process(delta):
|
||||
offset += delta*SPEED
|
||||
set_pos(Vector2(offset, 0))
|
||||
|
||||
|
||||
func _ready():
|
||||
set_process(true)
|
||||
# Initialization here
|
||||
|
||||
|
||||
|
||||
set_process(true)
|
||||
|
||||
@ -1,18 +1,15 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const SPEED = 200
|
||||
|
||||
var screen_size
|
||||
|
||||
var prev_shooting = false
|
||||
var killed = false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
|
||||
var motion = Vector2()
|
||||
if Input.is_action_pressed("move_up"):
|
||||
motion += Vector2(0, -1)
|
||||
@ -39,28 +36,26 @@ func _process(delta):
|
||||
set_pos(pos)
|
||||
|
||||
if (shooting and not prev_shooting):
|
||||
# just pressed
|
||||
# Just pressed
|
||||
var shot = preload("res://shot.scn").instance()
|
||||
#use the position3d as reference
|
||||
# Use the Position2D as reference
|
||||
shot.set_pos(get_node("shootfrom").get_global_pos())
|
||||
#put it two parents above, so it is not moved by us
|
||||
# Put it two parents above, so it is not moved by us
|
||||
get_node("../..").add_child(shot)
|
||||
#play sound
|
||||
# Play sound
|
||||
get_node("sfx").play("shoot")
|
||||
|
||||
|
||||
prev_shooting = shooting
|
||||
|
||||
#update points counter
|
||||
# Update points counter
|
||||
get_node("../hud/score_points").set_text(str(get_node("/root/game_state").points))
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
screen_size = get_viewport().get_rect().size
|
||||
set_process(true)
|
||||
pass
|
||||
|
||||
var killed=false
|
||||
|
||||
func _hit_something():
|
||||
if (killed):
|
||||
@ -85,4 +80,3 @@ func _on_ship_area_enter( area ):
|
||||
|
||||
func _on_back_to_menu_pressed():
|
||||
get_tree().change_scene("res://main_menu.scn")
|
||||
pass # replace with function body
|
||||
|
||||
@ -1,21 +1,20 @@
|
||||
|
||||
extends Area2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const SPEED = 800
|
||||
|
||||
var hit = false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
translate(Vector2(delta*SPEED, 0))
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
set_process(true)
|
||||
pass
|
||||
|
||||
var hit=false
|
||||
|
||||
func _hit_something():
|
||||
if (hit):
|
||||
@ -24,25 +23,19 @@ func _hit_something():
|
||||
set_process(false)
|
||||
get_node("anim").play("splash")
|
||||
|
||||
|
||||
func _on_visibility_exit_screen():
|
||||
queue_free()
|
||||
pass # replace with function body
|
||||
|
||||
|
||||
|
||||
func _on_shot_area_enter(area):
|
||||
#hit an enemy or asteroid
|
||||
# Hit an enemy or asteroid
|
||||
if (area.has_method("destroy")):
|
||||
#duck typing at it's best
|
||||
# Duck typing at it's best
|
||||
area.destroy()
|
||||
_hit_something()
|
||||
|
||||
|
||||
pass
|
||||
|
||||
|
||||
func _on_shot_body_enter(body):
|
||||
#hit the tilemap
|
||||
# Hit the tilemap
|
||||
_hit_something()
|
||||
pass # replace with function body
|
||||
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
|
||||
|
||||
extends Control
|
||||
|
||||
# Simple Tetris-like demo, (c) 2012 Juan Linietsky
|
||||
# Implemented by using a regular Control and drawing on it during the _draw() callback.
|
||||
# The drawing surface is updated only when changes happen (by calling update())
|
||||
|
||||
|
||||
# Member variables
|
||||
var score = 0
|
||||
var score_label = null
|
||||
|
||||
@ -32,14 +31,11 @@ var block_shapes=[
|
||||
[ Vector2(1, 1), Vector2(1, 0), Vector2(0, 0), Vector2(-1, 0) ], # J
|
||||
[ Vector2(0, 1), Vector2(1, 0), Vector2(0, 0), Vector2(-1, 0) ]] # T
|
||||
|
||||
|
||||
var block_rotations = [
|
||||
Matrix32(Vector2(1, 0), Vector2(0, 1), Vector2()),
|
||||
Matrix32(Vector2(0, 1), Vector2(-1, 0), Vector2()),
|
||||
Matrix32(Vector2(-1, 0), Vector2(0, -1), Vector2()),
|
||||
Matrix32( Vector2(0,-1),Vector2(1,0), Vector2() )
|
||||
]
|
||||
|
||||
Matrix32(Vector2(0, -1), Vector2(1, 0), Vector2())]
|
||||
|
||||
var width = 0
|
||||
var height = 0
|
||||
@ -56,9 +52,9 @@ func piece_cell_xform(p,er=0):
|
||||
var r = (4 + er + piece_rot) % 4
|
||||
return piece_pos + block_rotations[r].xform(p)
|
||||
|
||||
func _draw():
|
||||
|
||||
var sb = get_stylebox("bg","Tree") # use line edit bg
|
||||
func _draw():
|
||||
var sb = get_stylebox("bg", "Tree") # Use line edit bg
|
||||
draw_style_box(sb, Rect2(Vector2(), get_size()).grow(3))
|
||||
|
||||
var bs = block.get_size()
|
||||
@ -68,13 +64,11 @@ func _draw():
|
||||
draw_texture_rect(block, Rect2(Vector2(x, y)*bs, bs), false, block_colors[cells[Vector2(x, y)]])
|
||||
|
||||
if (piece_active):
|
||||
|
||||
for c in block_shapes[piece_shape]:
|
||||
draw_texture_rect(block, Rect2(piece_cell_xform(c)*bs, bs), false, block_colors[piece_shape])
|
||||
|
||||
|
||||
func piece_check_fit(ofs, er = 0):
|
||||
|
||||
for c in block_shapes[piece_shape]:
|
||||
var pos = piece_cell_xform(c, er) + ofs
|
||||
if (pos.x < 0):
|
||||
@ -90,8 +84,8 @@ func piece_check_fit(ofs,er=0):
|
||||
|
||||
return true
|
||||
|
||||
func new_piece():
|
||||
|
||||
func new_piece():
|
||||
piece_shape = randi() % MAX_SHAPES
|
||||
piece_pos = Vector2(width/2, 0)
|
||||
piece_active = true
|
||||
@ -100,8 +94,7 @@ func new_piece():
|
||||
piece_pos.y += 1
|
||||
|
||||
if (not piece_check_fit(Vector2())):
|
||||
#game over
|
||||
#print("GAME OVER!")
|
||||
# Game over
|
||||
game_over()
|
||||
|
||||
update()
|
||||
@ -124,20 +117,17 @@ func test_collapse_rows():
|
||||
if (collapse):
|
||||
accum_down += 1
|
||||
|
||||
|
||||
score += accum_down*100
|
||||
score_label.set_text(str(score))
|
||||
|
||||
|
||||
func game_over():
|
||||
|
||||
piece_active = false
|
||||
get_node("gameover").set_text("Game Over")
|
||||
get_node("gameover").set_text("Game over!")
|
||||
update()
|
||||
|
||||
|
||||
func restart_pressed():
|
||||
|
||||
score = 0
|
||||
score_label.set_text("0")
|
||||
cells.clear()
|
||||
@ -147,16 +137,13 @@ func restart_pressed():
|
||||
update()
|
||||
|
||||
|
||||
|
||||
func piece_move_down():
|
||||
|
||||
if (!piece_active):
|
||||
return
|
||||
if (piece_check_fit(Vector2(0, 1))):
|
||||
piece_pos.y += 1
|
||||
update()
|
||||
else:
|
||||
|
||||
for c in block_shapes[piece_shape]:
|
||||
var pos = piece_cell_xform(c)
|
||||
cells[pos] = piece_shape
|
||||
@ -165,7 +152,6 @@ func piece_move_down():
|
||||
|
||||
|
||||
func piece_rotate():
|
||||
|
||||
var adv = 1
|
||||
if (not piece_check_fit(Vector2(), 1)):
|
||||
return
|
||||
@ -173,10 +159,7 @@ func piece_rotate():
|
||||
update()
|
||||
|
||||
|
||||
|
||||
func _input(ie):
|
||||
|
||||
|
||||
if (not piece_active):
|
||||
return
|
||||
if (!ie.is_pressed()):
|
||||
@ -206,12 +189,7 @@ func setup(w,h):
|
||||
|
||||
func _ready():
|
||||
# Initalization here
|
||||
|
||||
setup(10, 20)
|
||||
score_label = get_node("../score")
|
||||
|
||||
set_process_input(true)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,17 +1,12 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
# Member variables
|
||||
const MAX_BUBBLES = 10
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
for i in range(MAX_BUBBLES):
|
||||
var bubble = preload("res://lens.scn").instance()
|
||||
add_child(bubble)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
|
||||
extends BackBufferCopy
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
# Member variables
|
||||
const MOTION_SPEED = 150
|
||||
|
||||
var vsize;
|
||||
var dir;
|
||||
var vsize
|
||||
var dir
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var pos = get_pos() + dir*delta*MOTION_SPEED
|
||||
@ -24,14 +23,10 @@ func _process(delta):
|
||||
|
||||
set_pos(pos)
|
||||
|
||||
|
||||
func _ready():
|
||||
vsize = get_viewport_rect().size
|
||||
var pos = vsize * Vector2(randf(),randf());
|
||||
set_pos(pos);
|
||||
var pos = vsize*Vector2(randf(), randf())
|
||||
set_pos(pos)
|
||||
dir = Vector2(randf()*2.0 - 1, randf()*2.0 - 1).normalized()
|
||||
set_process(true)
|
||||
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user