Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded Screen #17

Merged
merged 4 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/forest/forestback-1.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
Expand Down
2 changes: 1 addition & 1 deletion assets/forest/forestback-2.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
Expand Down
2 changes: 1 addition & 1 deletion assets/forest/forestback-3.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
Expand Down
2 changes: 1 addition & 1 deletion assets/forest/treetop.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
Expand Down
8 changes: 7 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
config_version=4

_global_script_classes=[ {
"base": "ParallaxLayer",
"class": "ExpandingParallaxLayer",
"language": "GDScript",
"path": "res://src/Level/ExpandingParallaxLayer.gd"
}, {
"base": "Sprite",
"class": "MovingSprite",
"language": "GDScript",
Expand Down Expand Up @@ -40,6 +45,7 @@ _global_script_classes=[ {
"path": "res://src/Weapons/Weapon.gd"
} ]
_global_script_class_icons={
"ExpandingParallaxLayer": "",
"MovingSprite": "",
"Obstacle": "",
"Player": "",
Expand All @@ -64,7 +70,7 @@ window/size/width=640
window/size/height=480
window/dpi/allow_hidpi=true
window/stretch/mode="viewport"
window/stretch/aspect="keep"
window/stretch/aspect="keep_height"

[input]

Expand Down
37 changes: 34 additions & 3 deletions src/GUI/GameGUI.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=10 format=2]

[ext_resource path="res://src/GUI/HealthGUI.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/GUI/AmmoGUI.tscn" type="PackedScene" id=2]
Expand All @@ -8,6 +8,7 @@
[ext_resource path="res://src/GUI/MainMenu.tscn" type="PackedScene" id=6]
[ext_resource path="res://src/GUI/ScoreGUI.tscn" type="PackedScene" id=7]
[ext_resource path="res://src/GUI/GameOverMenu.tscn" type="PackedScene" id=8]
[ext_resource path="res://icon.png" type="Texture" id=9]

[node name="GameGUI" type="Control"]
anchor_right = 1.0
Expand Down Expand Up @@ -84,9 +85,39 @@ margin_bottom = 38.0
layer = 100

[node name="PauseMenu" parent="CanvasLayer" instance=ExtResource( 4 )]
visible = false

[node name="MainMenu" parent="CanvasLayer" instance=ExtResource( 6 )]
visible = false

[node name="GameOverMenu" parent="CanvasLayer" instance=ExtResource( 8 )]

[node name="MobileButtons" type="CanvasLayer" parent="."]
layer = 101

[node name="JumpButton" type="TouchScreenButton" parent="MobileButtons"]
modulate = Color( 0, 1, 0, 0.392157 )
position = Vector2( 32, 384 )
normal = ExtResource( 9 )
action = "jump"
visibility_mode = 1

[node name="RightAlignment" type="Control" parent="MobileButtons"]
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="AttackButton" type="TouchScreenButton" parent="MobileButtons/RightAlignment"]
modulate = Color( 1, 0, 0, 0.392157 )
position = Vector2( -96, 384 )
normal = ExtResource( 9 )
action = "attack"
visibility_mode = 1

[node name="PauseButton" type="TouchScreenButton" parent="MobileButtons/RightAlignment"]
modulate = Color( 0, 0, 1, 0.392157 )
position = Vector2( -80, 16 )
normal = ExtResource( 9 )
action = "pause"
visibility_mode = 1
1 change: 1 addition & 0 deletions src/GUI/GameOverMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func _input(event: InputEvent) -> void:
event.is_action_pressed("attack")
or event.is_action_pressed("jump")
or event.is_action_pressed("pause")
or event is InputEventMouseButton
):
get_tree().set_input_as_handled()
hide()
Expand Down
1 change: 1 addition & 0 deletions src/GUI/MainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func _input(event: InputEvent) -> void:
event.is_action_pressed("attack")
or event.is_action_pressed("jump")
or event.is_action_pressed("pause")
or event is InputEventMouseButton
):
get_tree().set_input_as_handled()
hide()
Expand Down
38 changes: 38 additions & 0 deletions src/Level/ExpandingParallaxLayer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
extends ParallaxLayer
class_name ExpandingParallaxLayer


func _ready() -> void:
expand_children()
var connected := get_tree().root.connect("size_changed", self, "_on_viewport_size_changed")
if connected != OK:
push_warning("Could not connect viewport size changed")


func _on_viewport_size_changed() -> void:
expand_children()


func expand_children() -> void:
var current_size := get_viewport().size
var largest_mirror := 0.0
for child in get_children():
if child is Sprite:
var sprite_child: Sprite = child
var sprite_child_size := sprite_child.texture.get_size()
# Get the total sprites that will fit on screen size rounded up
var sprite_count := Vector2(int(ceil(current_size.x / sprite_child_size.x)), 1)
var wanted_size := sprite_count * sprite_child_size
sprite_child.region_enabled = true
sprite_child.region_rect.size = wanted_size
largest_mirror = max(largest_mirror, wanted_size.x)
elif child is TextureRect:
var texture_child: TextureRect = child
# Get the total textures that will fit on screen size rounded up
var texture_count := Vector2(int(ceil(current_size.x / texture_child.rect_size.x)), 1)
var wanted_size := texture_count * texture_child.rect_size
texture_child.stretch_mode = TextureRect.STRETCH_TILE
texture_child.rect_size = wanted_size
largest_mirror = max(largest_mirror, wanted_size.x)
# Set the mirror to the largest sprite/texture found
motion_mirroring.x = largest_mirror
1 change: 1 addition & 0 deletions src/Level/SpriteSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func spawn_random_sprite() -> void:
if floor_raycast.is_colliding()
else global_position
)
floor_position.x = get_viewport().size.x + sprite_size.x
sprite.global_position = floor_position


Expand Down
19 changes: 14 additions & 5 deletions src/Level/TreeBackground.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=25 format=2]
[gd_scene load_steps=26 format=2]

[ext_resource path="res://src/Level/TreeBackground.gd" type="Script" id=1]
[ext_resource path="res://assets/forest/treetop.png" type="Texture" id=2]
Expand All @@ -22,9 +22,10 @@
[ext_resource path="res://assets/forest/foliage-1.png" type="Texture" id=20]
[ext_resource path="res://assets/forest/foliage-3.png" type="Texture" id=21]
[ext_resource path="res://assets/forest/foliage-4.png" type="Texture" id=22]
[ext_resource path="res://src/Level/ExpandingParallaxLayer.gd" type="Script" id=23]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 640, 68 )
extents = Vector2( 50000, 68 )

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 32, 240 )
Expand All @@ -35,13 +36,18 @@ extents = Vector2( 32, 240 )
scroll_limit_end = Vector2( 0, 480 )
script = ExtResource( 1 )

[node name="Background" type="Sprite" parent="ParallaxBackground"]
[node name="Background" type="TextureRect" parent="ParallaxBackground"]
anchor_right = 1.0
texture = ExtResource( 8 )
centered = false
stretch_mode = 2
__meta__ = {
"_edit_use_anchors_": false
}

[node name="FarTrees" type="ParallaxLayer" parent="ParallaxBackground"]
motion_scale = Vector2( 0.1, 0.1 )
motion_mirroring = Vector2( 640, 0 )
script = ExtResource( 23 )

[node name="Sprite" type="Sprite" parent="ParallaxBackground/FarTrees"]
texture = ExtResource( 5 )
Expand All @@ -50,6 +56,7 @@ centered = false
[node name="MidTrees" type="ParallaxLayer" parent="ParallaxBackground"]
motion_scale = Vector2( 0.25, 0.25 )
motion_mirroring = Vector2( 640, 0 )
script = ExtResource( 23 )

[node name="Sprite" type="Sprite" parent="ParallaxBackground/MidTrees"]
texture = ExtResource( 6 )
Expand All @@ -60,6 +67,7 @@ position = Vector2( 832, 320 )

[node name="TreeTops" type="ParallaxLayer" parent="ParallaxBackground"]
motion_mirroring = Vector2( 640, 0 )
script = ExtResource( 23 )

[node name="Sprite" type="Sprite" parent="ParallaxBackground/TreeTops"]
texture = ExtResource( 2 )
Expand All @@ -79,6 +87,7 @@ max_spawn_time = 2.0

[node name="Ground" type="ParallaxLayer" parent="ParallaxBackground"]
motion_mirroring = Vector2( 640, 0 )
script = ExtResource( 23 )

[node name="TextureRect" type="TextureRect" parent="ParallaxBackground/Ground"]
margin_top = 336.0
Expand Down Expand Up @@ -115,7 +124,7 @@ collision_layer = 4
collision_mask = 7

[node name="CollisionShape2D" type="CollisionShape2D" parent="Floor"]
position = Vector2( 640, 412 )
position = Vector2( 50000, 412 )
shape = SubResource( 1 )

[node name="Wall" type="StaticBody2D" parent="."]
Expand Down
1 change: 1 addition & 0 deletions src/Objects/ObstacleSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func spawn_random_obstacle() -> void:
if floor_raycast.is_colliding()
else global_position
)
floor_position.x = get_viewport().size.x
obstacle.global_position = floor_position


Expand Down