From cae3ed1a479e19ab1f4803925d4ded1770e35119 Mon Sep 17 00:00:00 2001 From: as4s4hetic Date: Sat, 5 Feb 2022 15:45:02 +1100 Subject: [PATCH] update car object --- Scenes/LodgeOutside.tscn | 124 +++++++++++++++++++++++++++++++++++++++ Scripts/Car.gd | 19 +++--- Scripts/Ch1S1.gd | 4 ++ Scripts/Ch1S2.gd | 11 ++++ Scripts/ScrollCamera.gd | 7 +++ Story/Ch1S2.tscn | 17 +++++- 6 files changed, 171 insertions(+), 11 deletions(-) create mode 100644 Scenes/LodgeOutside.tscn create mode 100644 Scripts/Ch1S2.gd diff --git a/Scenes/LodgeOutside.tscn b/Scenes/LodgeOutside.tscn new file mode 100644 index 0000000..ac4e2b5 --- /dev/null +++ b/Scenes/LodgeOutside.tscn @@ -0,0 +1,124 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Resources/woods.tres" type="TileSet" id=1] + +[node name="LodgeOutside" type="Node2D"] + +[node name="Background" type="ParallaxBackground" parent="."] + +[node name="SkyUpper" type="ParallaxLayer" parent="Background"] +motion_scale = Vector2( 0, 1 ) + +[node name="TileMap" type="TileMap" parent="Background/SkyUpper"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +cell_quadrant_size = 15 +format = 1 +tile_data = PoolIntArray( -196608, 1, 0, -196604, 1, 0, -196600, 1, 0, -196596, 1, 0, -196592, 1, 0, -196588, 1, 0, 196608, 2, 0, 196612, 2, 0, 196616, 2, 0, 196620, 2, 0, 196624, 2, 0, 196628, 2, 0 ) + +[node name="Sky" type="ParallaxLayer" parent="Background"] +motion_scale = Vector2( 0.1, 1 ) + +[node name="TileMap" type="TileMap" parent="Background/Sky"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +cell_quadrant_size = 15 +format = 1 +tile_data = PoolIntArray( 0, 0, 0, 4, 0, 0, 8, 0, 0, 12, 0, 0, 16, 0, 0, 20, 0, 0, 196608, 2, 0, 196612, 2, 0, 196616, 2, 0, 196620, 2, 0, 196624, 2, 0, 196628, 2, 0 ) + +[node name="Mountains" type="TileMap" parent="Background/Sky"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +cell_quadrant_size = 15 +format = 1 +tile_data = PoolIntArray( 131072, 3, 0, 131084, 4, 0 ) + +[node name="Pines" type="ParallaxLayer" parent="Background"] +motion_scale = Vector2( 0.2, 1 ) + +[node name="Trees" type="TileMap" parent="Background/Pines"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 30, 30 ) +format = 1 +tile_data = PoolIntArray( 196611, 6, 0, 196618, 6, 0, 196620, 6, 0, 196623, 6, 0, 196624, 6, 0, 196628, 6, 0, 196630, 6, 0, 196632, 6, 0, 196633, 6, 0, 196636, 6, 0, 196637, 6, 0, 196638, 6, 0, 196645, 6, 0, 196646, 6, 0, 196650, 6, 0, 196653, 6, 0, 196655, 6, 0 ) + +[node name="Grass" type="TileMap" parent="Background/Pines"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( 196608, 8, 0, 196612, 8, 0, 196616, 8, 0, 196620, 8, 0, 196624, 8, 0, 196625, 8, 0, 196628, 8, 0 ) + +[node name="Furthest" type="ParallaxLayer" parent="Background"] +motion_scale = Vector2( 0.35, 1 ) + +[node name="Trees" type="TileMap" parent="Background/Furthest"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( -65532, 27, 0, 0, 536870942, 0, 13, 536870942, 0, 16, 536870941, 0, 22, 29, 0 ) + +[node name="Grass" type="TileMap" parent="Background/Furthest"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( 196608, 9, 0, 196612, 9, 0, 196616, 9, 0, 196620, 9, 0, 196624, 9, 0, 196628, 9, 0 ) + +[node name="Far" type="ParallaxLayer" parent="Background"] +motion_scale = Vector2( 0.5, 1 ) + +[node name="Trees" type="TileMap" parent="Background/Far"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( -65529, 536870929, 0, 19, 27, 0 ) + +[node name="Grass" type="TileMap" parent="Background/Far"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( 196608, 10, 0, 196612, 10, 0, 196616, 10, 0, 196620, 10, 0, 196624, 10, 0, 196628, 10, 0 ) + +[node name="Mid" type="ParallaxLayer" parent="Background"] +motion_scale = Vector2( 0.65, 1 ) + +[node name="Trees" type="TileMap" parent="Background/Mid"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( -196601, 536870935, 0, -65522, 26, 0 ) + +[node name="TileMap" type="TileMap" parent="Background/Mid"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( 196608, 11, 0, 196612, 11, 0, 196616, 11, 0, 196620, 11, 0, 196624, 11, 0, 196628, 11, 0 ) + +[node name="Close" type="ParallaxLayer" parent="Background"] +motion_scale = Vector2( 0.8, 1 ) + +[node name="Trees" type="TileMap" parent="Background/Close"] +tile_set = ExtResource( 1 ) +cell_y_sort = true +format = 1 +tile_data = PoolIntArray( -262132, 536870935, 0, -196608, 24, 0, 8, 28, 0 ) + +[node name="Grass" type="TileMap" parent="Background/Close"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( 196608, 12, 0, 196612, 12, 0, 196616, 12, 0, 196620, 12, 0, 196624, 12, 0, 196628, 12, 0 ) + +[node name="Road" type="ParallaxLayer" parent="Background"] + +[node name="Road" type="TileMap" parent="Background/Road"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 60, 60 ) +format = 1 +tile_data = PoolIntArray( 393216, 14, 0, 393220, 14, 0, 393224, 14, 0, 393228, 14, 0, 393232, 14, 0, 393236, 14, 0, 589844, 2, 0, 786448, 2, 0, 983052, 2, 0, 1179656, 2, 0, 1376260, 2, 0 ) + +[node name="PolesShrubs" type="TileMap" parent="Background/Road"] +tile_set = ExtResource( 1 ) +cell_size = Vector2( 30, 30 ) +cell_custom_transform = Transform2D( 30, 0, 0, 0, 0, 0 ) +format = 1 +tile_data = PoolIntArray( 65536, 7, 0, 65538, 15, 0, 65540, 15, 0, 65542, 15, 0, 65544, 15, 0, 65546, 15, 0, 65548, 15, 0, 65550, 15, 0, 65552, 15, 0, 65554, 15, 0, 65556, 15, 0, 65558, 15, 0, 65560, 15, 0, 65562, 15, 0, 65564, 15, 0, 65566, 15, 0, 65568, 15, 0, 65570, 15, 0, 65572, 15, 0, 65574, 15, 0, 65576, 15, 0, 65578, 15, 0, 65580, 15, 0, 65582, 15, 0, 393218, 21, 0, 393230, 20, 0, 655394, 536870928, 0, 720896, 16, 0, 720937, 25, 0 ) diff --git a/Scripts/Car.gd b/Scripts/Car.gd index 3746632..1822669 100644 --- a/Scripts/Car.gd +++ b/Scripts/Car.gd @@ -1,15 +1,16 @@ extends KinematicBody2D - # Declare member variables here. Examples: # var a = 2 # var b = "text" - # Called when the node enters the scene tree for the first time. var moveSpeed : int = 280 -var vel = Vector2() +var initVel = Vector2() var facingDir = Vector2() +var yVel = 1 +var xVel = 1 +var reverse = true onready var rayCast = $RayCast2D onready var anim = $AnimatedSprite @@ -20,19 +21,21 @@ func _physics_process(delta): handle_movements() manage_animations() -func handle_movements(): - vel = Vector2(-1, 0) - +func handle_movements(): + var vel = initVel # inputs if Input.is_action_pressed("move_up"): - vel.y = -0.2 + vel.y = -yVel if Input.is_action_pressed("move_down"): - vel.y = 0.2 + vel.y = yVel if Input.is_action_pressed("move_left"): + vel.x = -xVel moveSpeed += moveSpeed/100 else: moveSpeed -= moveSpeed/200 if Input.is_action_pressed("move_right"): + if reverse: + vel.x = 0.5 * xVel moveSpeed -= 5 moveSpeed = clamp(moveSpeed, 280, 840) diff --git a/Scripts/Ch1S1.gd b/Scripts/Ch1S1.gd index 2d58ca6..8c8135b 100644 --- a/Scripts/Ch1S1.gd +++ b/Scripts/Ch1S1.gd @@ -8,6 +8,10 @@ onready var player = get_node("Player") # Called when the node enters the scene tree for the first time. func _ready(): + var car = get_node("Player") + car.initVel = Vector2(-1, 0) + car.yVel = 0.2 + car.reverse = false pass # Replace with function body. diff --git a/Scripts/Ch1S2.gd b/Scripts/Ch1S2.gd new file mode 100644 index 0000000..a0e5cc2 --- /dev/null +++ b/Scripts/Ch1S2.gd @@ -0,0 +1,11 @@ +extends Node2D + +func _ready(): + var car = get_node("Player") + car.yVel = 0.5 + car.xVel = 0.5 + pass + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Scripts/ScrollCamera.gd b/Scripts/ScrollCamera.gd index 6bf7beb..42a0f8f 100644 --- a/Scripts/ScrollCamera.gd +++ b/Scripts/ScrollCamera.gd @@ -15,7 +15,14 @@ func _ready(): onready var target = get_node("../Player") +func move_camera(): + var cam_min = 1100 + pass + + func _process (delta): position = target.position position.y -= 240 position.x -= 480 + if target.position.y > 500: + move_camera() diff --git a/Story/Ch1S2.tscn b/Story/Ch1S2.tscn index 260e461..d11e92b 100644 --- a/Story/Ch1S2.tscn +++ b/Story/Ch1S2.tscn @@ -1,8 +1,16 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://Resources/woods.tres" type="TileSet" id=1] +[ext_resource path="res://Scenes/Car.tscn" type="PackedScene" id=2] +[ext_resource path="res://Scripts/ScrollCamera.gd" type="Script" id=3] +[ext_resource path="res://Scripts/Ch1S2.gd" type="Script" id=4] -[node name="LodgeOutside" type="Node2D"] +[node name="Ch1S2" type="Node2D"] +script = ExtResource( 4 ) + +[node name="ScrollCamera" type="Camera2D" parent="."] +current = true +script = ExtResource( 3 ) [node name="Background" type="ParallaxBackground" parent="."] @@ -114,7 +122,7 @@ tile_data = PoolIntArray( 196608, 12, 0, 196612, 12, 0, 196616, 12, 0, 196620, 1 tile_set = ExtResource( 1 ) cell_size = Vector2( 60, 60 ) format = 1 -tile_data = PoolIntArray( 393216, 14, 0, 393220, 14, 0, 393224, 14, 0, 393228, 14, 0, 393232, 14, 0, 393236, 14, 0, 589844, 2, 0, 786448, 2, 0, 983052, 2, 0, 1179656, 2, 0, 1376260, 2, 0, 1572864, 2, 0 ) +tile_data = PoolIntArray( 393216, 14, 0, 393220, 14, 0, 393224, 14, 0, 393228, 14, 0, 393232, 14, 0, 393236, 14, 0, 589844, 2, 0, 786448, 2, 0, 983052, 2, 0, 1179648, 2, 0, 1179652, 2, 0, 1179656, 2, 0 ) [node name="PolesShrubs" type="TileMap" parent="Background/Road"] tile_set = ExtResource( 1 ) @@ -122,3 +130,6 @@ cell_size = Vector2( 30, 30 ) cell_custom_transform = Transform2D( 30, 0, 0, 0, 0, 0 ) format = 1 tile_data = PoolIntArray( 65536, 7, 0, 65538, 15, 0, 65540, 15, 0, 65542, 15, 0, 65544, 15, 0, 65546, 15, 0, 65548, 15, 0, 65550, 15, 0, 65552, 15, 0, 65554, 15, 0, 65556, 15, 0, 65558, 15, 0, 65560, 15, 0, 65562, 15, 0, 65564, 15, 0, 65566, 15, 0, 65568, 15, 0, 65570, 15, 0, 65572, 15, 0, 65574, 15, 0, 65576, 15, 0, 65578, 15, 0, 65580, 15, 0, 65582, 15, 0, 393218, 21, 0, 393230, 20, 0, 655394, 536870928, 0, 720896, 16, 0, 720937, 25, 0 ) + +[node name="Player" parent="." instance=ExtResource( 2 )] +position = Vector2( 1295, 489 )