mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 07:50:22 +01:00
[2D Platformer] Move Player out of Level, set limits in a script
This commit is contained in:
@@ -236,6 +236,7 @@ anims/standing_weapon_ready = SubResource( 10 )
|
||||
[node name="Camera" type="Camera2D" parent="."]
|
||||
position = Vector2( 0, -28 )
|
||||
current = true
|
||||
zoom = Vector2( 0.5, 0.5 )
|
||||
process_mode = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
||||
15
2d/platformer/src/Level/Level.gd
Normal file
15
2d/platformer/src/Level/Level.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends Node2D
|
||||
|
||||
const LIMIT_LEFT = -315
|
||||
const LIMIT_TOP = -250
|
||||
const LIMIT_RIGHT = 955
|
||||
const LIMIT_BOTTOM = 690
|
||||
|
||||
func _ready():
|
||||
for child in get_children():
|
||||
if child is Player:
|
||||
var camera = child.get_node("Camera")
|
||||
camera.limit_left = LIMIT_LEFT
|
||||
camera.limit_top = LIMIT_TOP
|
||||
camera.limit_right = LIMIT_RIGHT
|
||||
camera.limit_bottom = LIMIT_BOTTOM
|
||||
@@ -4,7 +4,7 @@
|
||||
[ext_resource path="res://src/Actors/Enemy.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://src/Platforms/Platform.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://src/Objects/Coin.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://src/Actors/Player.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://src/Level/Level.gd" type="Script" id=5]
|
||||
[ext_resource path="res://assets/art/platforms/moving_platform.png" type="Texture" id=6]
|
||||
[ext_resource path="res://src/Level/ParallaxBackground.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://assets/audio/music/music.ogg" type="AudioStream" id=8]
|
||||
@@ -44,6 +44,7 @@ tracks/0/keys = {
|
||||
|
||||
[node name="Level" type="Node2D"]
|
||||
pause_mode = 1
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="TileMap" type="TileMap" parent="."]
|
||||
tile_set = ExtResource( 1 )
|
||||
@@ -257,25 +258,8 @@ position = Vector2( 632.725, 78.5545 )
|
||||
[node name="Enemy4" parent="Enemies" instance=ExtResource( 2 )]
|
||||
position = Vector2( 828.515, 77.262 )
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource( 5 )]
|
||||
position = Vector2( 86.647, 546.51 )
|
||||
|
||||
[node name="Sprite" parent="Player" index="2"]
|
||||
frame = 22
|
||||
|
||||
[node name="Camera" parent="Player" index="4"]
|
||||
zoom = Vector2( 0.5, 0.5 )
|
||||
limit_left = -315
|
||||
limit_top = -250
|
||||
limit_right = 955
|
||||
limit_bottom = 690
|
||||
limit_smoothed = true
|
||||
editor_draw_limits = true
|
||||
|
||||
[node name="ParallaxBackground" parent="." instance=ExtResource( 7 )]
|
||||
|
||||
[node name="Music" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 8 )
|
||||
autoplay = true
|
||||
|
||||
[editable path="Player"]
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://src/UserInterface/PauseMenu.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://src/Main/Game.gd" type="Script" id=2]
|
||||
[ext_resource path="res://src/Level/Level.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://src/Actors/Player.tscn" type="PackedScene" id=4]
|
||||
|
||||
[node name="Game" type="Node"]
|
||||
pause_mode = 2
|
||||
@@ -10,6 +11,9 @@ script = ExtResource( 2 )
|
||||
|
||||
[node name="Level" parent="." instance=ExtResource( 3 )]
|
||||
|
||||
[node name="Player" parent="Level" instance=ExtResource( 4 )]
|
||||
position = Vector2( 90, 546 )
|
||||
|
||||
[node name="InterfaceLayer" type="CanvasLayer" parent="."]
|
||||
layer = 100
|
||||
|
||||
|
||||
Reference in New Issue
Block a user