finished for lesson 6: animation
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 345 B After Width: | Height: | Size: 420 B |
@ -2,7 +2,7 @@
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c8v1702r7x6u0"
|
||||
uid="uid://dfuim8wosxlf6"
|
||||
path="res://.godot/imported/star2.png-a8da2aefc14c7956b80c236cd1d26ae7.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 370 B After Width: | Height: | Size: 419 B |
@ -2,7 +2,7 @@
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cdbqio5x3gctt"
|
||||
uid="uid://svpvjp4tn6sh"
|
||||
path="res://.godot/imported/star3.png-a788aeb564f38183a190461aebb57397.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
|
8
laser.gd
8
laser.gd
@ -5,10 +5,10 @@ extends Area2D
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
var tween = create_tween()
|
||||
tween.tween_property($Sprite2D,'scale',Vector2(1,1),0.3).from(Vector2(0,0))
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
position += Vector2(0,-speed) * delta
|
||||
speed += accel * delta
|
||||
position += Vector2(0,-speed) * delta
|
||||
speed += accel * delta
|
||||
|
26
level.gd
26
level.gd
@ -2,13 +2,29 @@ extends Node2D
|
||||
|
||||
var meteor_scene: PackedScene = load('res://meteor.tscn')
|
||||
var laser_scene: PackedScene = load("res://laser.tscn")
|
||||
var star_scene: PackedScene = load("res://star.tscn")
|
||||
var num_stars = 100
|
||||
|
||||
func _ready():
|
||||
var rng := RandomNumberGenerator.new()
|
||||
var width = get_viewport().get_visible_rect().size[0]
|
||||
var height = get_viewport().get_visible_rect().size[1]
|
||||
for i in num_stars:
|
||||
var star = star_scene.instantiate()
|
||||
star.position.x = rng.randi_range(0,width)
|
||||
star.position.y = rng.randi_range(0,height)
|
||||
var random_scale = rng.randf_range(0.8,1.3)
|
||||
star.scale = Vector2(random_scale,random_scale)
|
||||
star.speed_scale = rng.randf_range(0.5,2)
|
||||
$Stars.add_child(star)
|
||||
|
||||
|
||||
func _on_meteor_timer_timeout() -> void:
|
||||
var meteor = meteor_scene.instantiate()
|
||||
$Meteors.add_child(meteor)
|
||||
var meteor = meteor_scene.instantiate()
|
||||
$Meteors.add_child(meteor)
|
||||
|
||||
func _on_player_laser(pos) -> void:
|
||||
var laser = laser_scene.instantiate()
|
||||
$Lasers.add_child(laser)
|
||||
laser.position = pos
|
||||
var laser = laser_scene.instantiate()
|
||||
$Lasers.add_child(laser)
|
||||
laser.position = pos
|
||||
|
||||
|
@ -26,11 +26,12 @@ size = Vector2(1944, 40)
|
||||
script = ExtResource("1_6hg4u")
|
||||
|
||||
[node name="BG" type="Sprite2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2(960.328, 542.684)
|
||||
scale = Vector2(1.02466, 1.05614)
|
||||
texture = SubResource("NoiseTexture2D_emidv")
|
||||
|
||||
[node name="Stars" type="Node2D" parent="."]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_48d8j")]
|
||||
position = Vector2(960, 541)
|
||||
|
||||
|
@ -13,7 +13,7 @@ texture = ExtResource("1_atygw")
|
||||
polygon = PackedVector2Array(-7, -38, 8, -38, 13, -13, 35, 2, 47, -7, 46, 24, 14, 28, 9, 38, -7, 38, -14, 28, -45, 22, -48, -5, -36, 2, -12, -12)
|
||||
|
||||
[node name="LaserSpawnPos" type="Marker2D" parent="."]
|
||||
position = Vector2(0, -61)
|
||||
position = Vector2(0, -42)
|
||||
|
||||
[node name="LaserCooldown" type="Timer" parent="."]
|
||||
wait_time = 0.5
|
||||
|
7
star.gd
Normal file
7
star.gd
Normal file
@ -0,0 +1,7 @@
|
||||
extends AnimatedSprite2D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
self.play()
|
||||
|
31
star.tscn
Normal file
31
star.tscn
Normal file
@ -0,0 +1,31 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://dig4tkq61hqip"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://c6trmwwrqgjqt" path="res://assets/PNG/Effects/star1.png" id="1_sulif"]
|
||||
[ext_resource type="Texture2D" uid="uid://dfuim8wosxlf6" path="res://assets/PNG/Effects/star2.png" id="2_vgvua"]
|
||||
[ext_resource type="Texture2D" uid="uid://svpvjp4tn6sh" path="res://assets/PNG/Effects/star3.png" id="3_6t4o4"]
|
||||
[ext_resource type="Script" path="res://star.gd" id="3_onsr2"]
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_kvvtk"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("1_sulif")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_vgvua")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("3_6t4o4")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_vgvua")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 10.0
|
||||
}]
|
||||
|
||||
[node name="Star" type="AnimatedSprite2D"]
|
||||
sprite_frames = SubResource("SpriteFrames_kvvtk")
|
||||
frame_progress = 0.525576
|
||||
script = ExtResource("3_onsr2")
|
Reference in New Issue
Block a user