Permalink
Browse files

Godot 101 - Part 11

  • Loading branch information...
Chris Bradfield
Chris Bradfield committed Apr 11, 2017
1 parent 0fbd373 commit f9aba0b6d63fc1a3f1918aa9c671a8822e12cc89
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,27 @@
[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="background" type="Sprite" parent="."]
transform/pos = Vector2( 741.521, 269.32 )
transform/scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 1 )
[node name="player" parent="." instance=ExtResource( 2 )]
transform/pos = Vector2( 387.962, 294.249 )
[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( 1054.6, 294.861 )
@@ -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) < 10:
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,61 @@
[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
@@ -1 +1,2 @@
gen_mipmaps=true
repeat=true
View
@@ -1,19 +1,26 @@
[gd_scene load_steps=3 format=1]
[gd_scene load_steps=4 format=1]
[ext_resource path="res://player.tscn" type="PackedScene" id=1]
[ext_resource path="res://platform.tscn" type="PackedScene" id=2]
[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="player" parent="." instance=ExtResource( 1 )]
[node name="background" type="Sprite" parent="."]
transform/pos = Vector2( 741.521, 269.32 )
transform/scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 1 )
[node name="player" parent="." instance=ExtResource( 2 )]
transform/pos = Vector2( 387.962, 294.249 )
[node name="platform" parent="." instance=ExtResource( 2 )]
[node name="platform" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 520.536, 506.032 )
[node name="platform 1" parent="." instance=ExtResource( 2 )]
[node name="platform 1" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 1054.6, 294.861 )
@@ -1,11 +1,11 @@
[gd_scene load_steps=3 format=1]
[ext_resource path="res://art/green_square.png" type="Texture" id=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, 14.508 )
extents = Vector2( 318.496, 29.8811 )
[node name="platform" type="StaticBody2D"]
@@ -26,8 +26,9 @@ __meta__ = { "_edit_group_":true }
[node name="sprite" type="Sprite" parent="."]
transform/scale = Vector2( 20, 1 )
texture = ExtResource( 1 )
region = true
region_rect = Rect2( 0, 0, 640, 64 )
[node name="collision" type="CollisionShape2D" parent="."]
View
@@ -1,6 +1,7 @@
extends KinematicBody2D
onready var ground_ray = get_node("ground_ray")
onready var sprite = get_node("sprite")
const ACCEL = 1500
const MAX_SPEED = 500
@@ -11,6 +12,7 @@ const MIN_JUMP = -500
var acc = Vector2()
var vel = Vector2()
var anim = "idle"
func _ready():
set_fixed_process(true)
@@ -38,3 +40,16 @@ func _fixed_process(delta):
motion = n.slide(motion)
vel = n.slide(vel)
move(motion)
if abs(vel.x) < 10:
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)
@@ -1,14 +1,25 @@
[gd_scene load_steps=4 format=1]
[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 )
@@ -23,10 +34,13 @@ collision/margin = 0.08
script/script = ExtResource( 1 )
__meta__ = { "_edit_group_":true }
[node name="sprite" type="Sprite" parent="."]
[node name="sprite" type="AnimatedSprite" parent="."]
transform/scale = Vector2( 0.2, 0.2 )
texture = ExtResource( 2 )
frames = SubResource( 2 )
animation = "running"
frame = 1
flip_h = true
[node name="collision" type="CollisionShape2D" parent="."]

0 comments on commit f9aba0b

Please sign in to comment.