From 0fdf6eebba1723f3d05e668d78bdc7669e679486 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 5 Aug 2022 20:27:02 -0400 Subject: Fixed switching scene problem --- game/Characters/Player/Player.gd | 34 ----------------------- game/Characters/Player/Player.tscn | 38 -------------------------- game/Game.tscn | 2 +- game/characters/player/Player.gd | 34 +++++++++++++++++++++++ game/characters/player/Player.tscn | 38 ++++++++++++++++++++++++++ menu/Menu.gd | 2 +- menu/Menu.tscn | 55 +++++++++++++++++++++----------------- 7 files changed, 105 insertions(+), 98 deletions(-) delete mode 100644 game/Characters/Player/Player.gd delete mode 100644 game/Characters/Player/Player.tscn create mode 100644 game/characters/player/Player.gd create mode 100644 game/characters/player/Player.tscn diff --git a/game/Characters/Player/Player.gd b/game/Characters/Player/Player.gd deleted file mode 100644 index f764015..0000000 --- a/game/Characters/Player/Player.gd +++ /dev/null @@ -1,34 +0,0 @@ -extends KinematicBody2D - -const UP = Vector2(0,-1) -export var GRAVITY = 20 -export var MAXFALLSPEED = 200 -export var MAXSPEED = 80 -export var JUMPFORCE = 300 -export var ACCEL = 10 - -var motion = Vector2() - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - - -func _physics_process(_delta): - - motion.y += GRAVITY - - if motion.y > MAXFALLSPEED: - motion.y = MAXFALLSPEED - - if is_on_floor(): - if Input.is_action_just_released("jump"): - motion.y = -JUMPFORCE - pass - - motion.x = clamp(motion.x,-MAXSPEED,MAXSPEED) - - motion.x += ACCEL - motion = move_and_slide(motion,UP) - - pass diff --git a/game/Characters/Player/Player.tscn b/game/Characters/Player/Player.tscn deleted file mode 100644 index a7ee0e4..0000000 --- a/game/Characters/Player/Player.tscn +++ /dev/null @@ -1,38 +0,0 @@ -[gd_scene load_steps=4 format=2] - -[ext_resource path="res://assets/images/white.png" type="Texture" id=2] - -[sub_resource type="GDScript" id=2] -script/source = "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. -func _ready(): - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass -" - -[sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 160, 160 ) - -[node name="Player" type="KinematicBody2D"] -script = SubResource( 2 ) - -[node name="White" type="Sprite" parent="."] -position = Vector2( -4.76837e-07, 0 ) -scale = Vector2( 20, 20 ) -texture = ExtResource( 2 ) - -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -shape = SubResource( 1 ) - -[node name="Camera2D" type="Camera2D" parent="."] diff --git a/game/Game.tscn b/game/Game.tscn index 426b2ae..d46136b 100644 --- a/game/Game.tscn +++ b/game/Game.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://game/Interface.tscn" type="PackedScene" id=2] [ext_resource path="res://assets/tilemap.tres" type="TileSet" id=3] [ext_resource path="res://assets/images/white.png" type="Texture" id=4] -[ext_resource path="res://game/Characters/Player/Player.gd" type="Script" id=5] +[ext_resource path="res://game/characters/player/Player.gd" type="Script" id=5] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 8, 8 ) diff --git a/game/characters/player/Player.gd b/game/characters/player/Player.gd new file mode 100644 index 0000000..f764015 --- /dev/null +++ b/game/characters/player/Player.gd @@ -0,0 +1,34 @@ +extends KinematicBody2D + +const UP = Vector2(0,-1) +export var GRAVITY = 20 +export var MAXFALLSPEED = 200 +export var MAXSPEED = 80 +export var JUMPFORCE = 300 +export var ACCEL = 10 + +var motion = Vector2() + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +func _physics_process(_delta): + + motion.y += GRAVITY + + if motion.y > MAXFALLSPEED: + motion.y = MAXFALLSPEED + + if is_on_floor(): + if Input.is_action_just_released("jump"): + motion.y = -JUMPFORCE + pass + + motion.x = clamp(motion.x,-MAXSPEED,MAXSPEED) + + motion.x += ACCEL + motion = move_and_slide(motion,UP) + + pass diff --git a/game/characters/player/Player.tscn b/game/characters/player/Player.tscn new file mode 100644 index 0000000..a7ee0e4 --- /dev/null +++ b/game/characters/player/Player.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://assets/images/white.png" type="Texture" id=2] + +[sub_resource type="GDScript" id=2] +script/source = "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. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass +" + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 160, 160 ) + +[node name="Player" type="KinematicBody2D"] +script = SubResource( 2 ) + +[node name="White" type="Sprite" parent="."] +position = Vector2( -4.76837e-07, 0 ) +scale = Vector2( 20, 20 ) +texture = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[node name="Camera2D" type="Camera2D" parent="."] diff --git a/menu/Menu.gd b/menu/Menu.gd index d04aad7..fa895da 100644 --- a/menu/Menu.gd +++ b/menu/Menu.gd @@ -17,7 +17,7 @@ func _ready(): func _on_Play_button_up(): - if get_tree().change_scene("res://game/game.tscn") != OK: + if get_tree().change_scene("res://game/Game.tscn") != OK: print("There was an error trying to load the scene...") pass # Replace with function body. diff --git a/menu/Menu.tscn b/menu/Menu.tscn index b7d3a05..888312c 100644 --- a/menu/Menu.tscn +++ b/menu/Menu.tscn @@ -15,45 +15,52 @@ margin_right = 1280.0 margin_bottom = 720.0 [node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"] -margin_left = 448.0 -margin_top = 308.0 -margin_right = 832.0 -margin_bottom = 412.0 - -[node name="Logo" type="Sprite" parent="CenterContainer/VBoxContainer"] -position = Vector2( 505, 64 ) -scale = Vector2( 0.991787, 1.0997 ) +margin_left = 429.0 +margin_top = 272.0 +margin_right = 850.0 +margin_bottom = 448.0 + +[node name="Logo" type="TextureRect" parent="CenterContainer/VBoxContainer"] +margin_right = 421.0 +margin_bottom = 60.0 texture = ExtResource( 2 ) [node name="Play" type="Button" parent="CenterContainer/VBoxContainer"] -margin_right = 384.0 -margin_bottom = 20.0 +margin_top = 64.0 +margin_right = 421.0 +margin_bottom = 84.0 text = "Play" [node name="Credits" type="Button" parent="CenterContainer/VBoxContainer"] -margin_top = 24.0 -margin_right = 384.0 -margin_bottom = 44.0 +margin_top = 88.0 +margin_right = 421.0 +margin_bottom = 108.0 text = "Credits" [node name="Quit" type="Button" parent="CenterContainer/VBoxContainer"] -margin_top = 48.0 -margin_right = 384.0 -margin_bottom = 68.0 +margin_top = 112.0 +margin_right = 421.0 +margin_bottom = 132.0 text = "Quit" +[node name="HSeparator" type="HSeparator" parent="CenterContainer/VBoxContainer"] +modulate = Color( 1, 1, 1, 0 ) +margin_top = 136.0 +margin_right = 421.0 +margin_bottom = 140.0 + [node name="About" type="Label" parent="CenterContainer/VBoxContainer"] -margin_top = 72.0 -margin_right = 384.0 -margin_bottom = 86.0 -text = "Made for the bits & Bytes Unofficial Game Jam! August 2022" +margin_top = 144.0 +margin_right = 421.0 +margin_bottom = 158.0 +text = "Made for the bits & Bytes Unofficial Game Jam! August 2022." align = 1 [node name="Copyright" type="Label" parent="CenterContainer/VBoxContainer"] -margin_top = 90.0 -margin_right = 384.0 -margin_bottom = 104.0 -text = "Copyright 2022 Andrew Lee. Powered by the Godot Engine" +margin_top = 162.0 +margin_right = 421.0 +margin_bottom = 176.0 +text = "(c) Copyright 2022 Andrew Lee. Powered by the Godot Engine." align = 1 [connection signal="button_up" from="CenterContainer/VBoxContainer/Play" to="." method="_on_Play_button_up"] -- cgit v1.2.3