player and level
This commit is contained in:
parent
27b9bb4777
commit
5a321ed45b
@ -1,3 +1,11 @@
|
||||
[gd_scene format=3 uid="uid://c2ceksy5q1g8w"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://c2ceksy5q1g8w"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dp67krj08qdxb" path="res://level_bg/level_bg.tscn" id="1_636ji"]
|
||||
[ext_resource type="PackedScene" uid="uid://c6h48t3c4xja" path="res://player/player.tscn" id="2_wkub7"]
|
||||
|
||||
[node name="Level" type="Node2D"]
|
||||
|
||||
[node name="LevelBg" parent="." instance=ExtResource("1_636ji")]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("2_wkub7")]
|
||||
position = Vector2(326, 397)
|
||||
|
17
level_bg/level_bg.gd
Normal file
17
level_bg/level_bg.gd
Normal file
@ -0,0 +1,17 @@
|
||||
extends ParallaxBackground
|
||||
@onready var parallax_layer = $ParallaxLayer
|
||||
@onready var parallax_layer_2 = $ParallaxLayer2
|
||||
@onready var parallax_layer_3 = $ParallaxLayer3
|
||||
|
||||
const SPEED: float = 200.0
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
parallax_layer.motion_offset.y += SPEED * delta * 0.2
|
||||
parallax_layer_2.motion_offset.y += SPEED * delta * 0.3
|
||||
parallax_layer_3.motion_offset.y += SPEED * delta * 0.33
|
||||
|
||||
func set_running(running: bool) -> void:
|
||||
set_process(running)
|
35
level_bg/level_bg.tscn
Normal file
35
level_bg/level_bg.tscn
Normal file
@ -0,0 +1,35 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dp67krj08qdxb"]
|
||||
|
||||
[ext_resource type="Script" path="res://level_bg/level_bg.gd" id="1_kebk5"]
|
||||
[ext_resource type="Texture2D" uid="uid://d3q42ga40cxwc" path="res://assets/backgrounds/spr_stars01.png" id="1_or7w4"]
|
||||
[ext_resource type="Texture2D" uid="uid://dh40gp276y6p6" path="res://assets/backgrounds/spr_stars02.png" id="2_vqmxu"]
|
||||
|
||||
[node name="LevelBg" type="ParallaxBackground"]
|
||||
script = ExtResource("1_kebk5")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="ParallaxLayer" type="ParallaxLayer" parent="."]
|
||||
motion_mirroring = Vector2(2.08165e-12, 2560)
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="ParallaxLayer"]
|
||||
texture = ExtResource("1_or7w4")
|
||||
|
||||
[node name="ParallaxLayer2" type="ParallaxLayer" parent="."]
|
||||
motion_mirroring = Vector2(2.08165e-12, 2560)
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="ParallaxLayer2"]
|
||||
texture = ExtResource("2_vqmxu")
|
||||
|
||||
[node name="ParallaxLayer3" type="ParallaxLayer" parent="."]
|
||||
motion_offset = Vector2(2.08165e-12, 600)
|
||||
motion_mirroring = Vector2(2.08165e-12, 2560)
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="ParallaxLayer3"]
|
||||
texture = ExtResource("2_vqmxu")
|
57
player/player.gd
Normal file
57
player/player.gd
Normal file
@ -0,0 +1,57 @@
|
||||
extends Area2D
|
||||
|
||||
class_name Player
|
||||
|
||||
@onready var sprite_2d = $Sprite2D
|
||||
@onready var animation_player = $AnimationPlayer
|
||||
|
||||
@export var speed: float = 250.0
|
||||
|
||||
const MARGIN: float = 32.0
|
||||
|
||||
var _upper_left: Vector2
|
||||
var _lower_right: Vector2
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
var vp = get_viewport_rect()
|
||||
_lower_right = Vector2(
|
||||
vp.size.x - MARGIN,
|
||||
vp.size.y - MARGIN
|
||||
)
|
||||
|
||||
_upper_left = Vector2(MARGIN, MARGIN)
|
||||
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
var input = get_input()
|
||||
|
||||
global_position += input * delta * speed
|
||||
global_position = global_position.clamp(
|
||||
_upper_left,
|
||||
_lower_right
|
||||
)
|
||||
|
||||
|
||||
func get_input() -> Vector2:
|
||||
var v = Vector2(
|
||||
Input.get_axis("left", "right"),
|
||||
Input.get_axis("up", "down")
|
||||
)
|
||||
|
||||
if v.x != 0:
|
||||
animation_player.play("turn")
|
||||
if v.x > 0:
|
||||
sprite_2d.flip_h = true
|
||||
else:
|
||||
sprite_2d.flip_h = false
|
||||
else:
|
||||
animation_player.play("fly")
|
||||
|
||||
return v.normalized()
|
||||
|
||||
|
78
player/player.tscn
Normal file
78
player/player.tscn
Normal file
@ -0,0 +1,78 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://c6h48t3c4xja"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dblif3743kgka" path="res://assets/ships/ships_human_1.png" id="1_2i5ry"]
|
||||
[ext_resource type="Script" path="res://player/player.gd" id="1_sh380"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_3fimp"]
|
||||
radius = 14.0
|
||||
|
||||
[sub_resource type="Animation" id="Animation_qjn2v"]
|
||||
resource_name = "fly"
|
||||
length = 0.2
|
||||
loop_mode = 1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_w83h7"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_bctg6"]
|
||||
resource_name = "turn"
|
||||
length = 0.2
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [2, 3]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_6dw4b"]
|
||||
_data = {
|
||||
"RESET": SubResource("Animation_w83h7"),
|
||||
"fly": SubResource("Animation_qjn2v"),
|
||||
"turn": SubResource("Animation_bctg6")
|
||||
}
|
||||
|
||||
[node name="Player" type="Area2D"]
|
||||
script = ExtResource("1_sh380")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_2i5ry")
|
||||
hframes = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_3fimp")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_6dw4b")
|
||||
}
|
||||
autoplay = "fly"
|
@ -11,6 +11,7 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="AceSpace"
|
||||
run/main_scene="res://main/main.tscn"
|
||||
config/features=PackedStringArray("4.2", "Mobile")
|
||||
run/stretch/mode="canvas_items"
|
||||
run/size/viewport_height=480
|
||||
@ -26,6 +27,35 @@ window/size/viewport_width=640
|
||||
window/size/viewport_height=480
|
||||
window/stretch/mode="canvas_items"
|
||||
|
||||
[input]
|
||||
|
||||
up={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
left={
|
||||
"deadzone": 0.5,
|
||||
"events": [null, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
right={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
down={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
shoot={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
textures/canvas_textures/default_texture_filter=0
|
||||
renderer/rendering_method="mobile"
|
||||
|
Loading…
x
Reference in New Issue
Block a user