base platformer
This commit is contained in:
parent
51be54d905
commit
499b2416e1
10 changed files with 129 additions and 12 deletions
|
|
@ -29,12 +29,14 @@ grow_horizontal = 2
|
|||
grow_vertical = 2
|
||||
texture = SubResource("NoiseTexture2D_f07rl")
|
||||
|
||||
[node name="Ship" type="RigidBody2D" parent="."]
|
||||
[node name="Ship" type="RigidBody2D" parent="." node_paths=PackedStringArray("bullet_goal", "bullet_spawn")]
|
||||
position = Vector2(327, 183)
|
||||
gravity_scale = 0.0
|
||||
script = ExtResource("1_6dc0m")
|
||||
rotation_force = 10
|
||||
drag = 10
|
||||
bullet_goal = NodePath("BulletGoal")
|
||||
bullet_spawn = NodePath("Shooter")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Ship"]
|
||||
texture_filter = 1
|
||||
|
|
@ -45,3 +47,6 @@ shape = SubResource("CircleShape2D_dtqgl")
|
|||
|
||||
[node name="Shooter" type="Marker2D" parent="Ship"]
|
||||
position = Vector2(30, 0)
|
||||
|
||||
[node name="BulletGoal" type="Marker2D" parent="Ship"]
|
||||
position = Vector2(459, 0)
|
||||
|
|
|
|||
7
games/asteroids/bullet.gd
Normal file
7
games/asteroids/bullet.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extends Area2D
|
||||
|
||||
@export var speed : float = 100
|
||||
var goal : Vector2
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
position = position.move_toward(goal,delta * speed)
|
||||
1
games/asteroids/bullet.gd.uid
Normal file
1
games/asteroids/bullet.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://04qgt5gangt2
|
||||
|
|
@ -1,15 +1,18 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://i4us3nam2kn5"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://i4us3nam2kn5"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://b775cji263ifl" path="res://sprites/asteroids_bullet.png" id="1_bvcl6"]
|
||||
[ext_resource type="Script" uid="uid://04qgt5gangt2" path="res://games/asteroids/bullet.gd" id="1_hy4j0"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_bvcl6"]
|
||||
radius = 13.0
|
||||
radius = 7.0
|
||||
|
||||
[node name="Bullet" type="Area2D"]
|
||||
script = ExtResource("1_hy4j0")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_bvcl6")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture_filter = 1
|
||||
scale = Vector2(0.5, 0.5)
|
||||
texture = ExtResource("1_bvcl6")
|
||||
|
|
|
|||
|
|
@ -3,11 +3,31 @@ extends RigidBody2D
|
|||
@export var rotation_force = 1
|
||||
@export var drag = 2
|
||||
@export var top_speed = 6
|
||||
@export var time_per_shot : float = 1
|
||||
var reload_time : float = 99
|
||||
@export var bullet_goal : Marker2D
|
||||
@export var bullet_spawn : Marker2D
|
||||
|
||||
func _ready() -> void:
|
||||
reload_time = time_per_shot
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var input = Input.get_axis("asteroids_left","asteroids_right")
|
||||
angular_velocity += rotation_force * delta * input
|
||||
print(angular_velocity)
|
||||
#print(angular_velocity)
|
||||
angular_velocity = clampf(angular_velocity, -top_speed, top_speed)
|
||||
if(input == 0):
|
||||
angular_velocity = move_toward(angular_velocity, 0, delta * drag)
|
||||
|
||||
reload_time -= delta
|
||||
if reload_time <= 0:
|
||||
reload_time = time_per_shot
|
||||
shoot()
|
||||
|
||||
func shoot():
|
||||
# instantiate bullet
|
||||
#print("meow")
|
||||
var new_bullet : Node2D = load("res://games/asteroids/bullet.tscn").instantiate() as Node2D
|
||||
new_bullet.goal = bullet_goal.global_position
|
||||
new_bullet.position = bullet_spawn.global_position
|
||||
get_parent().add_child(new_bullet)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue