Commit d35f2d5a authored by Nathan Lovato's avatar Nathan Lovato
Browse files

Add score and animated score label

parent 64950735
extends Node2D
onready var pillar_spawner = get_node("PillarSpawner")
onready var score_label = get_node("BackgroundLayer/ScoreLabel")
var score = 0
func _ready():
pillar_spawner.connect("pillar_checkpoint_reached", self, "increase_score")
func _unhandled_input(event):
if event.is_action_pressed("reset"):
get_tree().reload_current_scene()
func increase_score():
score_label.score += 1
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Game.gd" type="Script" id=1]
[ext_resource path="res://Gnu/Gnu.tscn" type="PackedScene" id=2]
[ext_resource path="res://PillarSpawner/PillarSpawner.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/bg.png" type="Texture" id=4]
[ext_resource path="res://ScoreLabel/ScoreLabel.tscn" type="PackedScene" id=5]
[node name="Game" type="Node2D"]
script = ExtResource( 1 )
......@@ -13,3 +15,12 @@ position = Vector2( 190, 960 )
[node name="PillarSpawner" parent="." instance=ExtResource( 3 )]
position = Vector2( -10, 950 )
[node name="BackgroundLayer" type="CanvasLayer" parent="."]
layer = -10
[node name="Sky" type="Sprite" parent="BackgroundLayer"]
texture = ExtResource( 4 )
offset = Vector2( 540, 960 )
[node name="ScoreLabel" parent="BackgroundLayer" instance=ExtResource( 5 )]
......@@ -2,6 +2,7 @@ extends KinematicBody2D
onready var tween = get_node("Tween")
onready var sprite = get_node("Sprite")
onready var collision_shape = get_node("CollisionShape2D")
export(float) var gravity = 4000.0
export(float) var flap_force = 1200.0
......@@ -15,6 +16,8 @@ var _angular_velocity = 0.0
var _idle = true setget set_idle
var _target_angle = 0.0
var _active = true setget _set_active
func _ready():
self._idle = true
......@@ -37,7 +40,10 @@ func flap():
_velocity.y = -flap_force
_target_angle = -PI / 5.0
if not tween.is_active():
tween.interpolate_property(sprite, 'rotation', sprite.rotation, _target_angle, 0.12, Tween.TRANS_CUBIC, Tween.EASE_OUT)
tween.interpolate_property(
sprite, 'rotation',
sprite.rotation, _target_angle, 0.12,
Tween.TRANS_CUBIC, Tween.EASE_OUT)
tween.start()
......@@ -59,10 +65,19 @@ func _physics_process(delta):
func die():
set_physics_process(false)
set_process_unhandled_input(false)
tween.interpolate_property(sprite, 'scale', sprite.scale, Vector2(), 0.4, Tween.TRANS_QUAD, Tween.EASE_OUT)
tween.interpolate_property(
sprite, 'scale',
sprite.scale, Vector2(), 0.4,
Tween.TRANS_QUAD, Tween.EASE_OUT)
tween.start()
func _on_Tween_tween_completed(object, key):
if key == ':scale':
queue_free()
self._active = false
func _set_active(value):
_active = value
visible = value
collision_shape.disabled = not value
......@@ -8,6 +8,7 @@
radius = 55.8274
[node name="Gnu" type="KinematicBody2D"]
collision_mask = 6
script = ExtResource( 1 )
[node name="Camera2D" type="Camera2D" parent="."]
......
......@@ -12,4 +12,8 @@ func _ready():
position = pos
visibility_notifier_2d.connect("screen_exited", self, "queue_free")
checkpoint.connect("body_entered", self, "emit_signal", ["checkpoint_reached"])
checkpoint.connect("body_entered", self, "_on_Checkpoint_body_entered")
func _on_Checkpoint_body_entered(body):
emit_signal("checkpoint_reached")
......@@ -8,6 +8,8 @@
extents = Vector2( 20, 240 )
[node name="Pillar" type="StaticBody2D"]
collision_layer = 2
collision_mask = 0
script = ExtResource( 1 )
[node name="pillar_top" type="Sprite" parent="."]
......@@ -28,6 +30,7 @@ polygon = PoolVector2Array( -120, -240, 100, -240, 100, -1060, -120, -1060 )
[node name="Checkpoint" type="Area2D" parent="."]
position = Vector2( 119.5, -20 )
collision_layer = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="Checkpoint"]
shape = SubResource( 1 )
......
......@@ -7,6 +7,8 @@ TODO: To increase the difficulty, we can slowly expand the spawn area,
and increase the Gnu's horizontal move speed
"""
signal pillar_checkpoint_reached
onready var spawn_area = get_node("SpawnArea")
export(float) var spawn_interval = 400.0
......@@ -26,6 +28,7 @@ func spawn_pillar():
var obstacle = pillar_scene.instance()
obstacle.global_position = get_random_position()
obstacle.connect("tree_exited", self, "spawn_pillar")
obstacle.connect("checkpoint_reached", self, "emit_signal", ["pillar_checkpoint_reached"])
add_child(obstacle)
position.x += spawn_interval
......
extends Label
onready var tween = get_node("Tween")
const WHITE_OPAQUE = Color('aaffffff')
const WHITE_TRANSPARENT = Color('44ffffff')
var score = 0 setget set_score
func _ready():
modulate = WHITE_TRANSPARENT
func set_score(value):
score = value
text = str(score)
tween.interpolate_property(
self, 'modulate',
WHITE_OPAQUE, WHITE_TRANSPARENT, 0.8,
Tween.TRANS_QUAD, Tween.EASE_IN)
tween.start()
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/fonts/Cabin-SemiBold.otf" type="DynamicFontData" id=1]
[ext_resource path="res://ScoreLabel/ScoreLabel.gd" type="Script" id=2]
[sub_resource type="DynamicFont" id=1]
size = 300
use_filter = true
font_data = ExtResource( 1 )
[node name="ScoreLabel" type="Label"]
modulate = Color( 1, 1, 1, 0.34902 )
anchor_right = 1.0
anchor_bottom = 1.0
custom_fonts/font = SubResource( 1 )
text = "0"
align = 1
valign = 1
script = ExtResource( 2 )
[node name="Tween" type="Tween" parent="."]
Copyright (c) 2011, Pablo Impallari (www.impallari.com|impallari@gmail.com),
Copyright (c) 2011, Igino Marini. (www.ikern.com|mail@iginomarini.com),
with Reserved Font Name Cabin.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
\ No newline at end of file
......@@ -47,6 +47,12 @@ reset={
pointing/emulate_touch_from_mouse=true
[layer_names]
2d_physics/layer_1="gnu"
2d_physics/layer_2="pillar"
2d_physics/layer_3="checkpoint"
[rendering]
environment/default_environment="res://default_env.tres"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment