added moving platform

This commit is contained in:
penelope 2023-02-02 02:38:20 -05:00
parent d5999d41c7
commit c9ce22b112
8 changed files with 175 additions and 18 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/moving_platform.png-9f4dacf0fea7d199f190d8298e4c7b54.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://graphics/moving_platform/moving_platform.png"
dest_files=[ "res://.import/moving_platform.png-9f4dacf0fea7d199f190d8298e4c7b54.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 386 B

Before After
Before After

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://objects/Camera2D.tscn" type="PackedScene" id=1]
[ext_resource path="res://maps/map.gd" type="Script" id=2]
@ -7,26 +7,15 @@
[ext_resource path="res://graphics/backgrounds/mountain_sunset.png" type="Texture" id=5]
[ext_resource path="res://objects/player/player.tscn" type="PackedScene" id=6]
[ext_resource path="res://tilesets/t_mountain.tres" type="TileSet" id=7]
[ext_resource path="res://objects/enemy/rolling_fiend.tscn" type="PackedScene" id=8]
[ext_resource path="res://objects/environment/moving_platform/moving_platform.tscn" type="PackedScene" id=9]
[node name="Map" type="Node2D" groups=["map"]]
script = ExtResource( 2 )
[node name="Camera2D" parent="." instance=ExtResource( 1 )]
[node name="Sunset" type="Sprite" parent="Camera2D"]
position = Vector2( 128, 96 )
z_index = -2
texture = ExtResource( 5 )
[node name="Mountain" type="Sprite" parent="Camera2D"]
position = Vector2( 128, 96 )
z_index = -2
texture = ExtResource( 3 )
[node name="Clouds" type="Sprite" parent="Camera2D"]
position = Vector2( 128, 96 )
z_index = -2
texture = ExtResource( 4 )
scroll_v = true
respawn_h = false
[node name="Player" parent="." instance=ExtResource( 6 )]
position = Vector2( 32, 160 )
@ -35,4 +24,48 @@ position = Vector2( 32, 160 )
tile_set = ExtResource( 7 )
cell_size = Vector2( 8, 8 )
format = 1
tile_data = PoolIntArray( 1245196, 0, 65536, 1245197, 0, 65537, 1245198, 0, 65537, 1245199, 0, 65538, 1441792, 0, 65536, 1441793, 0, 65537, 1441794, 0, 65537, 1441795, 0, 65537, 1441796, 0, 65537, 1441797, 0, 65537, 1441798, 0, 65537, 1441799, 0, 65537, 1441800, 0, 65537, 1441801, 0, 65537, 1441802, 0, 65537, 1441803, 0, 65537, 1441804, 0, 65537, 1441805, 0, 65537, 1441806, 0, 65537, 1441807, 0, 65537, 1441808, 0, 65537, 1441809, 0, 65537, 1441810, 0, 65537, 1441811, 0, 65537, 1441812, 0, 65537, 1441813, 0, 65537, 1441814, 0, 65537, 1441815, 0, 65537, 1441816, 0, 65537, 1441817, 0, 65537, 1441818, 0, 65537, 1441819, 0, 65537, 1441820, 0, 65537, 1441821, 0, 65537, 1441822, 0, 65537, 1441823, 0, 65538 )
tile_data = PoolIntArray( 1245189, 0, 196609, 1245190, 0, 196609, 1441794, 0, 65536, 1441795, 0, 65537, 1441796, 0, 65537, 1441797, 0, 65537, 1441798, 0, 65537, 1441799, 0, 65538 )
[node name="Node" type="Node" parent="."]
[node name="Background" type="CanvasLayer" parent="Node"]
layer = -101
[node name="Sunset" type="Sprite" parent="Node/Background"]
position = Vector2( 128, 96 )
z_index = -2
texture = ExtResource( 5 )
[node name="BackgroundMountain" type="CanvasLayer" parent="Node"]
layer = -100
follow_viewport_enable = true
follow_viewport_scale = 0.25
[node name="Mountain" type="Sprite" parent="Node/BackgroundMountain"]
visible = false
position = Vector2( 128, 96 )
scale = Vector2( 4, 4 )
z_index = -2
texture = ExtResource( 3 )
[node name="Background2" type="CanvasLayer" parent="Node"]
layer = -100
[node name="Clouds" type="Sprite" parent="Node/Background2"]
pause_mode = 1
position = Vector2( 128, 96 )
z_index = -2
texture = ExtResource( 4 )
[node name="Enemies" type="Node2D" parent="."]
[node name="RollingFiend" parent="." instance=ExtResource( 8 )]
position = Vector2( 96, 112 )
[node name="MovingPlatform" parent="." instance=ExtResource( 9 )]
position = Vector2( 88, 176 )
scale = Vector2( 2, 1 )
left_up_boundry = 2.0
right_down_boundry = 2.0
[connection signal="tree_entered" from="Node/BackgroundMountain/Mountain" to="Node/BackgroundMountain/Mountain" method="set_visible" binds= [ true ]]

View file

@ -0,0 +1,43 @@
extends KinematicBody2D
export var direction = 1
export var speed = 20
#How far to move
export var left_up_boundry = 0.0
export var right_down_boundry = 0.0
#Move horizontal or vertical
export(int, "Horizontal", "Vertical") var move_direction
#Onreadys
onready var startpos = position
onready var sprite = $Sprite
onready var hitbox = $CollisionShape2D
func _ready():
sprite.set_region_rect(Rect2(0,0,8 * scale.x,4))
hitbox.scale.x = scale.x
scale.x = 1
left_up_boundry *= 8
right_down_boundry *= 8
func _physics_process(delta):
if move_direction == 0:
move_side_to_side(delta)
else: move_up_and_down(delta)
func move_side_to_side(delta):
#Move
position.x += direction * (speed * delta)
#Switch dir
if position.x >= startpos.x + (right_down_boundry):
direction = -1
if position.x <= startpos.x + (-left_up_boundry):
direction = 1
func move_up_and_down(delta):
#Move
position.y += direction * (speed * delta)
#Switch dir
if position.y >= startpos.y + (right_down_boundry):
direction = -1
if position.y <= startpos.y + (-left_up_boundry):
direction = 1

View file

@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://graphics/moving_platform/moving_platform.png" type="Texture" id=1]
[ext_resource path="res://objects/environment/moving_platform/moving_platform.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 4, 2 )
[node name="MovingPlatform" type="KinematicBody2D"]
motion/sync_to_physics = true
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 4, 2 )
texture = ExtResource( 1 )
region_enabled = true
region_rect = Rect2( 0, 0, 8, 4 )
region_filter_clip = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 4, 2 )
shape = SubResource( 1 )
one_way_collision = true

View file

@ -1,4 +1,4 @@
[gd_resource type="TileSet" load_steps=16 format=2]
[gd_resource type="TileSet" load_steps=17 format=2]
[ext_resource path="res://graphics/tiles/mountain.png" type="Texture" id=1]
@ -44,6 +44,9 @@ points = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 )
[sub_resource type="ConvexPolygonShape2D" id=16]
points = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 )
[sub_resource type="ConvexPolygonShape2D" id=17]
points = PoolVector2Array( 8, 6, 0, 6, 0, 2, 8, 2 )
[resource]
0/name = "grass.png 0"
0/texture = ExtResource( 1 )
@ -149,6 +152,12 @@ points = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 )
"one_way_margin": 1.0,
"shape": SubResource( 16 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 1, 3 ),
"one_way": true,
"one_way_margin": 1.0,
"shape": SubResource( 17 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
} ]
0/z_index = 0
1/name = "grass.png 1"
@ -193,3 +202,17 @@ points = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 )
2/shape_one_way_margin = 0.0
2/shapes = [ ]
2/z_index = 0
3/name = "mountain.png 3"
3/texture = ExtResource( 1 )
3/tex_offset = Vector2( 0, 0 )
3/modulate = Color( 1, 1, 1, 1 )
3/region = Rect2( 0, 0, 32, 32 )
3/tile_mode = 0
3/occluder_offset = Vector2( 0, 0 )
3/navigation_offset = Vector2( 0, 0 )
3/shape_offset = Vector2( 0, 0 )
3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
3/shape_one_way = false
3/shape_one_way_margin = 0.0
3/shapes = [ ]
3/z_index = 0