Permalink
Browse files

Godot 101 - Part 12

  • Loading branch information...
Chris Bradfield
Chris Bradfield committed Apr 24, 2017
1 parent 0b53bc4 commit 1aa83b81c01e71d28c458b7398ad529e9047fed5
View
Binary file not shown.
View
Binary file not shown.
@@ -0,0 +1,2 @@
gen_mipmaps=true
repeat=true
View
Binary file not shown.
@@ -0,0 +1,2 @@
gen_mipmaps=true
repeat=true
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,10 @@
[application]
name="godot101"
main_scene="res://main.tscn"
icon="res://icon.png"
[image_loader]
filter=false
gen_mipmaps=false
View
Binary file not shown.
@@ -0,0 +1 @@
gen_mipmaps=false
View
@@ -0,0 +1,56 @@
[gd_scene load_steps=4 format=1]
[ext_resource path="res://art/background.png" type="Texture" id=1]
[ext_resource path="res://player.tscn" type="PackedScene" id=2]
[ext_resource path="res://platform.tscn" type="PackedScene" id=3]
[node name="main" type="Node"]
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
layer = -1
offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )
scroll/offset = Vector2( 0, 0 )
scroll/base_offset = Vector2( 0, 0 )
scroll/base_scale = Vector2( 1, 1 )
scroll/limit_begin = Vector2( 0, 0 )
scroll/limit_end = Vector2( 0, 0 )
scroll/ignore_camera_zoom = true
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"]
motion/scale = Vector2( 0.2, 0.2 )
motion/offset = Vector2( 0, 0 )
motion/mirroring = Vector2( 0, 0 )
[node name="background" type="Sprite" parent="ParallaxBackground/ParallaxLayer"]
transform/pos = Vector2( 2464.11, 305.435 )
transform/scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 1 )
region = true
region_rect = Rect2( 0, 0, 12288, 1536 )
[node name="player" parent="." instance=ExtResource( 2 )]
transform/pos = Vector2( 314.954, 301.802 )
[node name="platform" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 520.536, 506.032 )
[node name="platform 1" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 1062.19, 313.835 )
[node name="platform 2" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 2300.82, 316.353 )
[node name="platform 3" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 1704.16, 500.133 )
@@ -0,0 +1,39 @@
[gd_scene load_steps=3 format=1]
[ext_resource path="res://art/grass_main_64x64.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=1]
custom_solver_bias = 0.0
extents = Vector2( 318.496, 29.8811 )
[node name="platform" type="StaticBody2D"]
transform/pos = Vector2( 491.968, 472.023 )
input/pickable = false
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
collision/layers = 1
collision/mask = 1
one_way_collision/direction = Vector2( 0, 1 )
one_way_collision/max_depth = 16.0
constant_linear_velocity = Vector2( 0, 0 )
constant_angular_velocity = 0.0
friction = 1.0
bounce = 0.0
__meta__ = { "_edit_group_":true }
[node name="sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
region = true
region_rect = Rect2( 0, 0, 640, 64 )
[node name="collision" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0
View
@@ -0,0 +1,55 @@
extends KinematicBody2D
onready var ground_ray = get_node("ground_ray")
onready var sprite = get_node("sprite")
const ACCEL = 1500
const MAX_SPEED = 500
const FRICTION = -500
const GRAVITY = 4000
const JUMP_SPEED = -1400
const MIN_JUMP = -500
var acc = Vector2()
var vel = Vector2()
var anim = "idle"
func _ready():
set_fixed_process(true)
set_process_input(true)
func _input(event):
if event.is_action_pressed("ui_up") and ground_ray.is_colliding():
vel.y = JUMP_SPEED
if event.is_action_released("ui_up"):
vel.y = clamp(vel.y, MIN_JUMP, vel.y)
func _fixed_process(delta):
acc.y = GRAVITY
acc.x = Input.is_action_pressed("ui_right") - Input.is_action_pressed("ui_left")
acc.x *= ACCEL
if acc.x == 0:
acc.x = vel.x * FRICTION * delta
vel += acc * delta
vel.x = clamp(vel.x, -MAX_SPEED, MAX_SPEED)
var motion = move(vel * delta)
if is_colliding():
var n = get_collision_normal()
motion = n.slide(motion)
vel = n.slide(vel)
move(motion)
if abs(vel.x) < 20:
vel.x = 0
# set animation
if vel.x == 0:
anim = "idle"
else:
anim = "running"
if vel.x > 0:
sprite.set_flip_h(false)
elif vel.x < 0:
sprite.set_flip_h(true)
sprite.play(anim)
@@ -0,0 +1,92 @@
[gd_scene load_steps=12 format=1]
[ext_resource path="res://player.gd" type="Script" id=1]
[ext_resource path="res://art/player/idle/idle-frame-1.png" type="Texture" id=2]
[ext_resource path="res://art/player/idle/idle-frame-2.png" type="Texture" id=3]
[ext_resource path="res://art/player/running/run-frame-1.png" type="Texture" id=4]
[ext_resource path="res://art/player/running/run-frame-2.png" type="Texture" id=5]
[ext_resource path="res://art/player/running/run-frame-3.png" type="Texture" id=6]
[ext_resource path="res://art/player/running/run-frame-4.png" type="Texture" id=7]
[ext_resource path="res://art/player/running/run-frame-5.png" type="Texture" id=8]
[ext_resource path="res://art/player/running/run-frame-6.png" type="Texture" id=9]
[sub_resource type="CapsuleShape2D" id=1]
custom_solver_bias = 0.0
radius = 39.1715
height = 54.173
[sub_resource type="SpriteFrames" id=2]
animations = [ {
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
"loop": true,
"name": "idle",
"speed": 3.0
}, {
"frames": [ ExtResource( 4 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ) ],
"loop": true,
"name": "running",
"speed": 8.0
} ]
[node name="player" type="KinematicBody2D"]
transform/pos = Vector2( 544.083, 270.191 )
z/z = 1
input/pickable = false
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1.01736, 0, 1.20241 )
shapes/0/trigger = false
collision/layers = 1
collision/mask = 1
collision/margin = 0.08
script/script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
[node name="sprite" type="AnimatedSprite" parent="."]
transform/scale = Vector2( 0.2, 0.2 )
frames = SubResource( 2 )
animation = "running"
frame = 1
flip_h = true
[node name="collision" type="CollisionShape2D" parent="."]
transform/pos = Vector2( 0, 1.20241 )
transform/scale = Vector2( 1, 1.01736 )
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0
[node name="ground_ray" type="RayCast2D" parent="."]
transform/pos = Vector2( 0, 50 )
enabled = true
cast_to = Vector2( 0, 20 )
layer_mask = 1
type_mask = 15
[node name="camera" type="Camera2D" parent="."]
anchor_mode = 1
rotating = false
current = true
zoom = Vector2( 1, 1 )
limit/left = -10000000
limit/top = -10000000
limit/right = 10000000
limit/bottom = 10000000
drag_margin/h_enabled = true
drag_margin/v_enabled = true
smoothing/enable = true
smoothing/speed = 5.0
drag_margin/left = 0.2
drag_margin/top = 0.2
drag_margin/right = 0.2
drag_margin/bottom = 0.2
View
@@ -6,11 +6,32 @@
[node name="main" type="Node"]
[node name="background" type="Sprite" parent="."]
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
transform/pos = Vector2( 741.521, 269.32 )
layer = -1
offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )
scroll/offset = Vector2( 0, 0 )
scroll/base_offset = Vector2( 0, 0 )
scroll/base_scale = Vector2( 1, 1 )
scroll/limit_begin = Vector2( 0, 0 )
scroll/limit_end = Vector2( 0, 0 )
scroll/ignore_camera_zoom = true
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"]
motion/scale = Vector2( 0.2, 0.2 )
motion/offset = Vector2( 0, 0 )
motion/mirroring = Vector2( 0, 0 )
[node name="background" type="Sprite" parent="ParallaxBackground/ParallaxLayer"]
transform/pos = Vector2( 2464.11, 305.435 )
transform/scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 1 )
region = true
region_rect = Rect2( 0, 0, 12288, 1536 )
[node name="player" parent="." instance=ExtResource( 2 )]
@@ -24,4 +45,12 @@ transform/pos = Vector2( 520.536, 506.032 )
transform/pos = Vector2( 1062.19, 313.835 )
[node name="platform 2" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 2300.82, 316.353 )
[node name="platform 3" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 1704.16, 500.133 )
@@ -18,7 +18,17 @@ height = 54.173
[sub_resource type="SpriteFrames" id=2]
animations = [ { "frames":[ ExtResource( 2 ), ExtResource( 3 ) ], "loop":true, "name":"idle", "speed":3.0 }, { "frames":[ ExtResource( 4 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ) ], "loop":true, "name":"running", "speed":8.0 } ]
animations = [ {
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
"loop": true,
"name": "idle",
"speed": 3.0
}, {
"frames": [ ExtResource( 4 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ) ],
"loop": true,
"name": "running",
"speed": 8.0
} ]
[node name="player" type="KinematicBody2D"]
@@ -32,7 +42,9 @@ collision/layers = 1
collision/mask = 1
collision/margin = 0.08
script/script = ExtResource( 1 )
__meta__ = { "_edit_group_":true }
__meta__ = {
"_edit_group_": true
}
[node name="sprite" type="AnimatedSprite" parent="."]
@@ -58,4 +70,23 @@ cast_to = Vector2( 0, 20 )
layer_mask = 1
type_mask = 15
[node name="camera" type="Camera2D" parent="."]
anchor_mode = 1
rotating = false
current = true
zoom = Vector2( 1, 1 )
limit/left = -10000000
limit/top = -10000000
limit/right = 10000000
limit/bottom = 10000000
drag_margin/h_enabled = true
drag_margin/v_enabled = true
smoothing/enable = true
smoothing/speed = 5.0
drag_margin/left = 0.2
drag_margin/top = 0.2
drag_margin/right = 0.2
drag_margin/bottom = 0.2

0 comments on commit 1aa83b8

Please sign in to comment.