diff --git a/assets/coin.svg b/assets/coin.svg new file mode 100644 index 0000000..01bcceb --- /dev/null +++ b/assets/coin.svg @@ -0,0 +1,81 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/assets/coin.svg.import b/assets/coin.svg.import new file mode 100644 index 0000000..1acc8f9 --- /dev/null +++ b/assets/coin.svg.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/coin.svg-4f408cc0c27738ba7d156f441f501d5e.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/coin.svg" +dest_files=[ "res://.import/coin.svg-4f408cc0c27738ba7d156f441f501d5e.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/scenes/Coin.gd b/scenes/Coin.gd new file mode 100644 index 0000000..4ebf2d7 --- /dev/null +++ b/scenes/Coin.gd @@ -0,0 +1,41 @@ +extends Node2D + + +onready var coin_sprite = get_node("CoinSprite") + +var velocity = Vector2(0, 0) +var z_pos = 0 +var z_vel = 0 +var gravity = 1500 +var bounciness = 0.5 + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func _draw(): + coin_sprite.offset.y = -z_pos + draw_circle(Vector2.ZERO, 5, Color("88000000")) + pass + +func _process(delta): + z_vel = z_vel - gravity * delta + z_pos = z_pos + z_vel * delta + + if z_pos < 0: + z_vel = - z_vel * bounciness + z_pos = 0 + + if z_vel < 0.01: + z_vel = 0 + + velocity = velocity * 0.5 + + position = position + velocity * delta + update() + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/scenes/Coin.tscn b/scenes/Coin.tscn new file mode 100644 index 0000000..ac9858e --- /dev/null +++ b/scenes/Coin.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/coin.svg" type="Texture" id=1] +[ext_resource path="res://scenes/Coin.gd" type="Script" id=2] + +[node name="Node2D" type="Node2D"] +script = ExtResource( 2 ) + +[node name="CoinSprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) diff --git a/scenes/CoinSpawner.gd b/scenes/CoinSpawner.gd new file mode 100644 index 0000000..ec06f76 --- /dev/null +++ b/scenes/CoinSpawner.gd @@ -0,0 +1,40 @@ +extends Node2D + + +onready var Coin = preload("./Coin.tscn") +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" +var coin_spread = 50 + +# Called when the node enters the scene tree for the first time. +func _ready(): + assert (Coin != null) + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass + +func emit_coins (num, _position = null): + for i in range (num): + var coin = Coin.instance() + + coin.position = position + if _position != null: + coin.position = _position + + coin.velocity = Vector2 (rand_range(-coin_spread, coin_spread), rand_range (-coin_spread, coin_spread)) + coin.z_pos = 0 + coin.z_vel = rand_range(300, 800) + add_child(coin) + + +func _unhandled_input(event): + if 'position' in event: + var relative_pos = self.transform.affine_inverse() * event.position + + if event is InputEventMouseButton: + if event.button_index == BUTTON_LEFT and event.pressed: + emit_coins(25, relative_pos) diff --git a/scenes/CoinSpawner.tscn b/scenes/CoinSpawner.tscn new file mode 100644 index 0000000..bdb17cb --- /dev/null +++ b/scenes/CoinSpawner.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://scenes/CoinSpawner.gd" type="Script" id=1] + +[node name="CoinSpawner" type="Node2D"] +script = ExtResource( 1 )