Skip to content

Commit

Permalink
Godot 101: Part 07, Part 08
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Bradfield committed Mar 20, 2017
1 parent 38bab09 commit eaca17f
Show file tree
Hide file tree
Showing 57 changed files with 898 additions and 5 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_duck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_hit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_jump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_stand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_swim1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_swim2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_walk1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/Player/alienGreen_walk2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/coinGold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/gemBlue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 07/art/gemYellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions Godot101/Part 07/engine.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[application]

name="godot101"
main_scene="res://main.tscn"
icon="res://icon.png"

[image_loader]

filter=false
gen_mipmaps=false
11 changes: 11 additions & 0 deletions Godot101/Part 07/gem.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends Area2D

signal gem_grabbed

func _ready():
pass

func _on_gem_area_enter( area ):
if area.get_name() == "player":
emit_signal("gem_grabbed")
queue_free()
38 changes: 38 additions & 0 deletions Godot101/Part 07/gem.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[gd_scene load_steps=4 format=1]

[ext_resource path="res://gem.gd" type="Script" id=1]
[ext_resource path="res://art/gemYellow.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]

custom_solver_bias = 0.0
extents = Vector2( 18.6712, 12.9027 )

[node name="gem" type="Area2D"]

transform/pos = Vector2( 484.001, 257 )
input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0
script/script = ExtResource( 1 )
__meta__ = { "_edit_group_":true }

[node name="sprite" type="Sprite" parent="."]

transform/scale = Vector2( 0.6, 0.6 )
texture = ExtResource( 2 )

[node name="collision" type="CollisionShape2D" parent="."]

shape = SubResource( 1 )
trigger = false
_update_shape_index = 0

[connection signal="area_enter" from="." to="." method="_on_gem_area_enter"]


Binary file added Godot101/Part 07/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Godot101/Part 07/icon.png.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gen_mipmaps=false
32 changes: 32 additions & 0 deletions Godot101/Part 07/main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
extends Node

onready var gem = preload("res://gem.tscn")
onready var gem_container = get_node("gem_container")
onready var score_label = get_node("HUD/score_label")

var screensize
var score = 0
var level = 1

func _ready():
randomize()
screensize = get_viewport().get_rect().size
set_process(true)
spawn_gems(10)

func _process(delta):
if gem_container.get_child_count() == 0:
level += 1
spawn_gems(level * 10)

func spawn_gems(num):
for i in range(num):
var g = gem.instance()
gem_container.add_child(g)
g.connect("gem_grabbed", self, "_on_gem_grabbed")
g.set_pos(Vector2(rand_range(40, screensize.width-40),
rand_range(40, screensize.height-40)))

func _on_gem_grabbed():
score += 10
score_label.set_text(str(score))
44 changes: 44 additions & 0 deletions Godot101/Part 07/main.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[gd_scene load_steps=3 format=1]

[ext_resource path="res://main.gd" type="Script" id=1]
[ext_resource path="res://player.tscn" type="PackedScene" id=2]

[node name="main" type="Node"]

script/script = ExtResource( 1 )

[node name="player" parent="." instance=ExtResource( 2 )]

[node name="gem_container" type="Node" parent="."]

[node name="HUD" type="Control" parent="."]

anchor/right = 1
anchor/bottom = 1
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 0.0
margin/top = 0.0
margin/right = 0.0
margin/bottom = 0.0
__meta__ = { "_edit_lock_":true }

[node name="score_label" type="Label" parent="HUD"]

rect/scale = Vector2( 4, 4 )
focus/ignore_mouse = true
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 0
margin/left = 62.0
margin/top = 28.0
margin/right = 141.0
margin/bottom = 68.0
text = "0"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1


23 changes: 23 additions & 0 deletions Godot101/Part 07/player.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends Area2D

export var speed = 400

var screensize
var extents
var vel = Vector2()

func _ready():
set_fixed_process(true)
screensize = get_viewport_rect().size
extents = get_node("collision").get_shape().get_extents()
set_pos(screensize / 2)

func _fixed_process(delta):
var input = Vector2(0, 0)
input.x = Input.is_action_pressed("ui_right") - Input.is_action_pressed("ui_left")
input.y = Input.is_action_pressed("ui_down") - Input.is_action_pressed("ui_up")
vel = input.normalized() * speed
var pos = get_pos() + vel * delta
pos.x = clamp(pos.x, extents.width, screensize.width - extents.width)
pos.y = clamp(pos.y, extents.height, screensize.height - extents.height)
set_pos(pos)
38 changes: 38 additions & 0 deletions Godot101/Part 07/player.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[gd_scene load_steps=4 format=1]

[ext_resource path="res://player.gd" type="Script" id=1]
[ext_resource path="res://art/Player/alienGreen_front.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]

custom_solver_bias = 0.0
extents = Vector2( 26.1949, 44.4182 )

[node name="player" type="Area2D"]

transform/pos = Vector2( 529.64, 277.008 )
input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0
script/script = ExtResource( 1 )
__meta__ = { "_edit_group_":true }
speed = 400

[node name="sprite" type="Sprite" parent="."]

transform/scale = Vector2( 0.6, 0.6 )
texture = ExtResource( 2 )
offset = Vector2( 0, -64 )

[node name="collision" type="CollisionShape2D" parent="."]

shape = SubResource( 1 )
trigger = false
_update_shape_index = 0


Binary file added Godot101/Part 08/art/Hack-Regular.otf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_duck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_hit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_jump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_stand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_swim1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_swim2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_walk1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Godot101/Part 08/art/Player/alienGreen_walk2.png
Binary file added Godot101/Part 08/art/coinGold.png
Binary file added Godot101/Part 08/art/gemBlue.png
Binary file added Godot101/Part 08/art/gemYellow.png
10 changes: 10 additions & 0 deletions Godot101/Part 08/engine.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[application]

name="godot101"
main_scene="res://main.tscn"
icon="res://icon.png"

[image_loader]

filter=false
gen_mipmaps=false
23 changes: 23 additions & 0 deletions Godot101/Part 08/gem.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends Area2D

onready var effect = get_node("effect")
onready var sprite = get_node("sprite")

signal gem_grabbed

func _ready():
effect.interpolate_property(sprite, 'transform/scale',
sprite.get_scale(), Vector2(2.0, 2.0), 0.3,
Tween.TRANS_QUAD, Tween.EASE_OUT)
effect.interpolate_property(sprite, 'visibility/opacity',
1, 0, 0.3,
Tween.TRANS_QUAD, Tween.EASE_OUT)

func _on_gem_area_enter( area ):
if area.get_name() == "player":
emit_signal("gem_grabbed")
clear_shapes()
effect.start()

func _on_effect_tween_complete( object, key ):
queue_free()
47 changes: 47 additions & 0 deletions Godot101/Part 08/gem.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[gd_scene load_steps=4 format=1]

[ext_resource path="res://gem.gd" type="Script" id=1]
[ext_resource path="res://art/gemYellow.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]

custom_solver_bias = 0.0
extents = Vector2( 18.6712, 12.9027 )

[node name="gem" type="Area2D"]

transform/pos = Vector2( 484.001, 257 )
input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0
script/script = ExtResource( 1 )
__meta__ = { "_edit_group_":true }

[node name="sprite" type="Sprite" parent="."]

transform/scale = Vector2( 0.6, 0.6 )
texture = ExtResource( 2 )

[node name="collision" type="CollisionShape2D" parent="."]

shape = SubResource( 1 )
trigger = false
_update_shape_index = 0

[node name="effect" type="Tween" parent="."]

playback/process_mode = 1
playback/active = false
playback/repeat = false
playback/speed = 1.0

[connection signal="area_enter" from="." to="." method="_on_gem_area_enter"]

[connection signal="tween_complete" from="effect" to="." method="_on_effect_tween_complete"]


Binary file added Godot101/Part 08/icon.png
1 change: 1 addition & 0 deletions Godot101/Part 08/icon.png.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gen_mipmaps=false
43 changes: 43 additions & 0 deletions Godot101/Part 08/main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
extends Node

onready var gem = preload("res://gem.tscn")
onready var gem_container = get_node("gem_container")
onready var score_label = get_node("HUD/score_label")
onready var time_label = get_node("HUD/time_label")
onready var go_label = get_node("HUD/game_over_label")
onready var game_timer = get_node("game_timer")

var screensize
var score = 0
var level = 1

func _ready():
randomize()
screensize = get_viewport().get_rect().size
set_process(true)
spawn_gems(10)
go_label.set_hidden(true)

func _process(delta):
time_label.set_text(str(int(game_timer.get_time_left())))
if gem_container.get_child_count() == 0:
level += 1
game_timer.set_wait_time(game_timer.get_time_left() + 10.0)
game_timer.start()
spawn_gems(level * 10)

func spawn_gems(num):
for i in range(num):
var g = gem.instance()
gem_container.add_child(g)
g.connect("gem_grabbed", self, "_on_gem_grabbed")
g.set_pos(Vector2(rand_range(40, screensize.width-40),
rand_range(40, screensize.height-40)))

func _on_gem_grabbed():
score += 10
score_label.set_text(str(score))

func _on_game_timer_timeout():
go_label.set_hidden(false)
get_node("player").set_process(false)
Loading

0 comments on commit eaca17f

Please sign in to comment.