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)
|
||||
|
|
|
|||
36
games/platformer/platformer.tscn
Normal file
36
games/platformer/platformer.tscn
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://ckbyiwy0dxbsd"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dqyddqx8xm0gw" path="res://games/platformer/player.gd" id="1_1wj3w"]
|
||||
[ext_resource type="Texture2D" uid="uid://diilj7xuttpqu" path="res://icon.svg" id="1_oyf6i"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_oyf6i"]
|
||||
size = Vector2(32, 32)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1wj3w"]
|
||||
size = Vector2(608, 46)
|
||||
|
||||
[node name="Platformer" type="Node"]
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Player" type="CharacterBody2D" parent="."]
|
||||
position = Vector2(124, 155)
|
||||
script = ExtResource("1_1wj3w")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="Player"]
|
||||
scale = Vector2(0.25, 0.25)
|
||||
texture = ExtResource("1_oyf6i")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"]
|
||||
shape = SubResource("RectangleShape2D_oyf6i")
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||
position = Vector2(317, 384)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
shape = SubResource("RectangleShape2D_1wj3w")
|
||||
25
games/platformer/player.gd
Normal file
25
games/platformer/player.gd
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("platformer_jump") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction := Input.get_axis("platformer_left", "platformer_right")
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
1
games/platformer/player.gd.uid
Normal file
1
games/platformer/player.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dqyddqx8xm0gw
|
||||
Loading…
Add table
Add a link
Reference in a new issue