Skip to content

Commit 464a0d7

Browse files
committed
Initial commit
1 parent 9da26a6 commit 464a0d7

File tree

950 files changed

+37618
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

950 files changed

+37618
-21
lines changed

2d-lighting/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[![thumbnail](thumbnail.jpg)]()
2+
3+
# Godot Tutorial: Xbox Controller Support
4+
5+
In this tutorial I am going to guide you through the process of adding 2D lighting to your Godot Engine game!

2d-lighting/demo/DayLabel.gd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extends Label
2+
3+
export(NodePath) var day_night_cycle_path
4+
5+
var day_night_cycle : DayNightCycle
6+
7+
func _ready():
8+
day_night_cycle = get_node(day_night_cycle_path) as DayNightCycle
9+
day_night_cycle.connect("day_tick", self, "_day_tick")
10+
11+
func _day_tick(day) -> void:
12+
text = "Day " + str(day)

2d-lighting/demo/DayNightCycle.gd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class_name DayNightCycle
2+
extends CanvasModulate
3+
4+
signal day_tick(day)
5+
6+
const NIGHT_COLOR = Color("#091d3a")
7+
const DAY_COLOR = Color("#ffffff")
8+
const EVENING_COLOR = Color("#ff3300")
9+
const TIME_SCALE = 0.1
10+
11+
var time = 0
12+
var last_day = 0
13+
14+
func _process(delta:float) -> void:
15+
self.time += delta * TIME_SCALE
16+
var value = (sin(time) + 1) / 2
17+
self.color = get_source_colour(value).linear_interpolate(get_target_colour(value), value)
18+
var new_day = _get_day()
19+
if new_day != last_day:
20+
last_day = new_day
21+
emit_signal("day_tick", new_day)
22+
23+
func get_source_colour(value):
24+
return NIGHT_COLOR.linear_interpolate(EVENING_COLOR, value)
25+
26+
func get_target_colour(value):
27+
return EVENING_COLOR.linear_interpolate(DAY_COLOR, value)
28+
29+
func _get_day() -> int:
30+
# this is required as midnight is not perfectly dark
31+
var offset = 0.15
32+
return 1 + int(offset + ceil(0.5 * time) / PI)

2d-lighting/demo/InputControl.gd

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
extends Control
2+
3+
const XBOX_BUTTON_TO_INDEX_MAPPING = {
4+
JOY_XBOX_A: 0,
5+
JOY_XBOX_B: 1,
6+
JOY_XBOX_X: 2,
7+
JOY_XBOX_Y: 3,
8+
JOY_START: 6,
9+
JOY_SELECT: 7
10+
}
11+
12+
const KEYBOARD_BUTTON_TO_INDEX_MAPPING = {
13+
KEY_A: 13,
14+
KEY_B: 14,
15+
KEY_C: 15,
16+
KEY_D: 16,
17+
KEY_E: 17,
18+
KEY_F: 18,
19+
KEY_G: 19,
20+
KEY_H: 20,
21+
KEY_I: 21,
22+
KEY_J: 22,
23+
KEY_K: 23,
24+
KEY_L: 24,
25+
KEY_M: 25,
26+
KEY_N: 26,
27+
KEY_O: 27,
28+
KEY_P: 28,
29+
KEY_Q: 29,
30+
KEY_R: 30,
31+
KEY_S: 31,
32+
KEY_T: 32,
33+
KEY_U: 33,
34+
KEY_V: 34,
35+
KEY_W: 35,
36+
KEY_X: 36,
37+
KEY_Y: 37,
38+
KEY_Z: 38,
39+
KEY_ENTER: 39,
40+
KEY_SPACE: 40,
41+
KEY_ESCAPE: 41,
42+
}

2d-lighting/demo/Orb.gd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends Node2D
2+
3+
4+
# Declare member variables here. Examples:
5+
# var a = 2
6+
# var b = "text"
7+
8+
9+
# Called when the node enters the scene tree for the first time.
10+
func _ready():
11+
pass # Replace with function body.
12+
13+
14+
# Called every frame. 'delta' is the elapsed time since the previous frame.
15+
#func _process(delta):
16+
# pass

2d-lighting/demo/Orb.tscn

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[gd_scene load_steps=10 format=2]
2+
3+
[ext_resource path="res://assets/dungeon.png" type="Texture" id=1]
4+
[ext_resource path="res://assets/light.png" type="Texture" id=2]
5+
[ext_resource path="res://Orb.gd" type="Script" id=3]
6+
7+
[sub_resource type="CanvasItemMaterial" id=1]
8+
light_mode = 1
9+
10+
[sub_resource type="AtlasTexture" id=2]
11+
atlas = ExtResource( 1 )
12+
region = Rect2( 32, 16, 16, 16 )
13+
14+
[sub_resource type="CanvasItemMaterial" id=3]
15+
light_mode = 1
16+
17+
[sub_resource type="Curve" id=4]
18+
_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.161932, 1 ), 1.91598, 1.91598, 0, 0, Vector2( 0.553977, 0.15625 ), -1.1541, -1.1541, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
19+
20+
[sub_resource type="CurveTexture" id=5]
21+
curve = SubResource( 4 )
22+
23+
[sub_resource type="ParticlesMaterial" id=6]
24+
emission_shape = 1
25+
emission_sphere_radius = 3.0
26+
flag_disable_z = true
27+
spread = 0.0
28+
gravity = Vector3( 0, 0, 0 )
29+
orbit_velocity = 0.0
30+
orbit_velocity_random = 0.0
31+
linear_accel = 20.0
32+
radial_accel = 10.0
33+
tangential_accel_random = 1.0
34+
angle = -720.0
35+
angle_random = 1.0
36+
scale = 1.5
37+
scale_curve = SubResource( 5 )
38+
color = Color( 0.968627, 0.376471, 0.576471, 1 )
39+
hue_variation = 0.02
40+
hue_variation_random = 1.0
41+
42+
[node name="Orb" type="Node2D"]
43+
script = ExtResource( 3 )
44+
45+
[node name="Sprite" type="Sprite" parent="."]
46+
material = SubResource( 1 )
47+
texture = SubResource( 2 )
48+
49+
[node name="Light1" type="Light2D" parent="."]
50+
position = Vector2( -0.820454, -0.520168 )
51+
scale = Vector2( 0.586486, 0.588037 )
52+
texture = ExtResource( 2 )
53+
color = Color( 0.8, 0.184314, 0.482353, 1 )
54+
energy = 0.8
55+
shadow_enabled = true
56+
shadow_gradient_length = 2.0
57+
shadow_filter = 2
58+
shadow_filter_smooth = 22.4
59+
60+
[node name="Light2" type="Light2D" parent="."]
61+
position = Vector2( -0.0758057, -1.5384 )
62+
scale = Vector2( 0.428781, 0.428781 )
63+
texture = ExtResource( 2 )
64+
color = Color( 1, 0.321569, 0.466667, 1 )
65+
energy = 0.6
66+
67+
[node name="AttachedParticles" type="Particles2D" parent="."]
68+
material = SubResource( 3 )
69+
position = Vector2( -0.236233, -1.85051 )
70+
amount = 9
71+
lifetime = 1.5
72+
process_material = SubResource( 6 )
73+
74+
[node name="DetachedParticles" type="Particles2D" parent="."]
75+
material = SubResource( 3 )
76+
position = Vector2( -0.236233, -1.85051 )
77+
amount = 4
78+
lifetime = 1.5
79+
local_coords = false
80+
process_material = SubResource( 6 )

2d-lighting/demo/Player.gd

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
extends KinematicBody2D
2+
3+
export var ACCELERATION = 350
4+
export var FRICTION = 850
5+
export var MAX_SPEED = 100
6+
export var ROLL_SPEED = 180
7+
8+
enum {
9+
RUN,
10+
ROLL,
11+
JUMP
12+
}
13+
14+
onready var animation_tree = $AnimationTree
15+
onready var animation_state = animation_tree.get("parameters/playback")
16+
17+
var velocity = Vector2.ZERO
18+
var roll_vector = Vector2.DOWN
19+
var state = RUN
20+
var roll_finished = false
21+
22+
func _ready():
23+
animation_tree.active = true
24+
25+
func _physics_process(delta):
26+
match state:
27+
RUN:
28+
run_state(delta)
29+
ROLL:
30+
roll_state(delta)
31+
32+
func run_state(delta):
33+
var input_vector = Vector2.ZERO
34+
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
35+
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
36+
input_vector = input_vector.normalized()
37+
38+
if input_vector != Vector2.ZERO:
39+
roll_vector = input_vector
40+
animation_tree.set("parameters/Idle/blend_position", input_vector)
41+
animation_tree.set("parameters/Run/blend_position", input_vector)
42+
animation_tree.set("parameters/Jump/blend_position", input_vector)
43+
animation_tree.set("parameters/Roll/blend_position", input_vector)
44+
animation_state.travel("Run")
45+
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
46+
else:
47+
animation_state.travel("Idle")
48+
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
49+
50+
velocity = move_and_slide(velocity)
51+
52+
if velocity.length() > 0 && Input.is_action_just_pressed("roll"):
53+
state = ROLL
54+
roll_finished = false
55+
56+
func roll_state(delta):
57+
if !roll_finished:
58+
velocity = roll_vector * ROLL_SPEED
59+
else:
60+
velocity = velocity * 0.9
61+
animation_state.travel("Roll")
62+
velocity = move_and_slide(velocity)
63+
64+
func jump_finished():
65+
state = RUN
66+
velocity = Vector2.ZERO
67+
68+
func roll_prefinished():
69+
roll_finished = true
70+
71+
func roll_finished():
72+
state = RUN
73+
velocity = velocity * 0.5

0 commit comments

Comments
 (0)