base platformer
This commit is contained in:
parent
51be54d905
commit
499b2416e1
10 changed files with 129 additions and 12 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://ct8axfbvd2wn4"]
|
[gd_scene load_steps=6 format=3 uid="uid://ct8axfbvd2wn4"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://63rik2noj8id" path="res://base modules/test_channel.tscn" id="1_mlf6e"]
|
[ext_resource type="PackedScene" uid="uid://63rik2noj8id" path="res://base modules/test_channel.tscn" id="1_mlf6e"]
|
||||||
[ext_resource type="PackedScene" uid="uid://ch1x8pfdu2b1g" path="res://test_game.tscn" id="2_mixcd"]
|
[ext_resource type="PackedScene" uid="uid://ch1x8pfdu2b1g" path="res://test_game.tscn" id="2_mixcd"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cyo0wl4dt3td1" path="res://sprites/offline_channel.png" id="2_po0ka"]
|
[ext_resource type="Texture2D" uid="uid://cyo0wl4dt3td1" path="res://sprites/offline_channel.png" id="2_po0ka"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bw1hhx7lyfonr" path="res://games/asteroids/asteroids.tscn" id="3_mj2jn"]
|
[ext_resource type="PackedScene" uid="uid://bw1hhx7lyfonr" path="res://games/asteroids/asteroids.tscn" id="3_mj2jn"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://ckbyiwy0dxbsd" path="res://games/platformer/platformer.tscn" id="4_mj2jn"]
|
||||||
|
|
||||||
[node name="GameScene" type="Control"]
|
[node name="GameScene" type="Control"]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
|
|
@ -54,6 +55,11 @@ size_flags_vertical = 3
|
||||||
texture = ExtResource("2_po0ka")
|
texture = ExtResource("2_po0ka")
|
||||||
expand_mode = 1
|
expand_mode = 1
|
||||||
|
|
||||||
|
[node name="Control3" parent="GridContainer" instance=ExtResource("1_mlf6e")]
|
||||||
|
layout_mode = 2
|
||||||
|
channel_name = "Platformer"
|
||||||
|
channel_scene = ExtResource("4_mj2jn")
|
||||||
|
|
||||||
[node name="ColorRect3" type="TextureRect" parent="GridContainer"]
|
[node name="ColorRect3" type="TextureRect" parent="GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
|
|
@ -82,12 +88,5 @@ size_flags_vertical = 3
|
||||||
texture = ExtResource("2_po0ka")
|
texture = ExtResource("2_po0ka")
|
||||||
expand_mode = 1
|
expand_mode = 1
|
||||||
|
|
||||||
[node name="ColorRect7" type="TextureRect" parent="GridContainer"]
|
|
||||||
layout_mode = 2
|
|
||||||
size_flags_horizontal = 3
|
|
||||||
size_flags_vertical = 3
|
|
||||||
texture = ExtResource("2_po0ka")
|
|
||||||
expand_mode = 1
|
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
offset = Vector2(320, 180)
|
offset = Vector2(320, 180)
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,14 @@ grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
texture = SubResource("NoiseTexture2D_f07rl")
|
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)
|
position = Vector2(327, 183)
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
script = ExtResource("1_6dc0m")
|
script = ExtResource("1_6dc0m")
|
||||||
rotation_force = 10
|
rotation_force = 10
|
||||||
drag = 10
|
drag = 10
|
||||||
|
bullet_goal = NodePath("BulletGoal")
|
||||||
|
bullet_spawn = NodePath("Shooter")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="Ship"]
|
[node name="Sprite2D" type="Sprite2D" parent="Ship"]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
|
|
@ -45,3 +47,6 @@ shape = SubResource("CircleShape2D_dtqgl")
|
||||||
|
|
||||||
[node name="Shooter" type="Marker2D" parent="Ship"]
|
[node name="Shooter" type="Marker2D" parent="Ship"]
|
||||||
position = Vector2(30, 0)
|
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="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"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_bvcl6"]
|
||||||
radius = 13.0
|
radius = 7.0
|
||||||
|
|
||||||
[node name="Bullet" type="Area2D"]
|
[node name="Bullet" type="Area2D"]
|
||||||
|
script = ExtResource("1_hy4j0")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("CircleShape2D_bvcl6")
|
shape = SubResource("CircleShape2D_bvcl6")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
|
scale = Vector2(0.5, 0.5)
|
||||||
texture = ExtResource("1_bvcl6")
|
texture = ExtResource("1_bvcl6")
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,31 @@ extends RigidBody2D
|
||||||
@export var rotation_force = 1
|
@export var rotation_force = 1
|
||||||
@export var drag = 2
|
@export var drag = 2
|
||||||
@export var top_speed = 6
|
@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:
|
func _process(delta: float) -> void:
|
||||||
var input = Input.get_axis("asteroids_left","asteroids_right")
|
var input = Input.get_axis("asteroids_left","asteroids_right")
|
||||||
angular_velocity += rotation_force * delta * input
|
angular_velocity += rotation_force * delta * input
|
||||||
print(angular_velocity)
|
#print(angular_velocity)
|
||||||
angular_velocity = clampf(angular_velocity, -top_speed, top_speed)
|
angular_velocity = clampf(angular_velocity, -top_speed, top_speed)
|
||||||
if(input == 0):
|
if(input == 0):
|
||||||
angular_velocity = move_toward(angular_velocity, 0, delta * drag)
|
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
|
||||||
|
|
@ -33,6 +33,26 @@ asteroids_right={
|
||||||
"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":86,"key_label":0,"unicode":118,"location":0,"echo":false,"script":null)
|
"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":86,"key_label":0,"unicode":118,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
platformer_left={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
platformer_right={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
platformer_jump={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
platformer_drop={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue