Browse Source

FlyingEnemy

master
Felipe M 10 months ago
parent
commit
3d940d26c0
Signed by: fmartingr GPG Key ID: 716BC147715E716F
  1. 5
      metroidvania/MainInstances.gd
  2. 6
      metroidvania/MainInstances.tres
  3. 1
      metroidvania/ResourceLoader.gd
  4. 45
      metroidvania/Scenes/Effects/WallDustEffect.tscn
  5. 2
      metroidvania/Scenes/Enemies/Enemy.tscn
  6. 19
      metroidvania/Scenes/Enemies/FlyingEnemy.gd
  7. 62
      metroidvania/Scenes/Enemies/FlyingEnemy.tscn
  8. 33
      metroidvania/Scenes/Player/Player.gd
  9. 2732
      metroidvania/Scenes/UI/DefaultTheme.tres
  10. 6
      metroidvania/Scenes/World/MainInstances.tres
  11. 6
      metroidvania/Scenes/World/World.tscn
  12. 6
      metroidvania/project.godot

5
metroidvania/MainInstances.gd

@ -0,0 +1,5 @@
extends Resource
class_name MainInstances
var Player = null
var WorldCamera = null

6
metroidvania/MainInstances.tres

@ -0,0 +1,6 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://MainInstances.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )

1
metroidvania/ResourceLoader.gd

@ -2,3 +2,4 @@ extends Node
# warning-ignore-all:unused_class_variables
var PlayerStats = preload("res://Scenes/Player/PlayetStats.tres")
var MainInstances = preload("res://MainInstances.tres")

45
metroidvania/Scenes/Effects/WallDustEffect.tscn

@ -0,0 +1,45 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Scenes/Effects/Effect.tscn" type="PackedScene" id=1]
[ext_resource path="res://Assets/Effects/WallDustEffect.png" type="Texture" id=2]
[sub_resource type="Animation" id=1]
resource_name = "Animate"
length = 0.5
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 0, 0, 1, 2, 3 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.5 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "queue_free"
} ]
}
[node name="WallDustEffect" instance=ExtResource( 1 )]
[node name="Sprite" parent="." index="0"]
texture = ExtResource( 2 )
hframes = 5
frame = 3
[node name="AnimationPlayer" parent="." index="1"]
autoplay = "Animate"
anims/Animate = SubResource( 1 )

2
metroidvania/Scenes/Enemies/Enemy.tscn

@ -17,7 +17,7 @@ script = ExtResource( 1 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
[node name="Hurtbox" parent="." instance=ExtResource( 2 )]
collision_mask = 8
collision_layer = 8
[node name="Hitbox" parent="." instance=ExtResource( 4 )]
collision_mask = 4

19
metroidvania/Scenes/Enemies/FlyingEnemy.gd

@ -0,0 +1,19 @@
extends "res://Scenes/Enemies/Enemy.gd"
export (int) var ACCELERATION = 100
var MainInstances = ResourceLoader.MainInstances
onready var sprite = $Sprite
func _physics_process(delta):
var player = MainInstances.Player
if player != null:
chase_player(player, delta)
func chase_player(player, delta):
var direction = (player.global_position - global_position).normalized()
motion += direction * ACCELERATION * delta
motion = motion.clamped(MAX_SPEED)
sprite.flip_h = global_position < player.global_position
motion = move_and_slide(motion)

62
metroidvania/Scenes/Enemies/FlyingEnemy.tscn

@ -0,0 +1,62 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://Scenes/Enemies/Enemy.tscn" type="PackedScene" id=1]
[ext_resource path="res://Scenes/Enemies/FlyingEnemy.gd" type="Script" id=2]
[ext_resource path="res://Assets/Enemies/FlyingEnemy.png" type="Texture" id=3]
[sub_resource type="CircleShape2D" id=1]
radius = 4.0
[sub_resource type="Animation" id=2]
resource_name = "Fly"
length = 0.6
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4, 0.5 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 0, 1, 2, 3, 4, 5 ]
}
[sub_resource type="CircleShape2D" id=3]
radius = 4.0
[sub_resource type="CircleShape2D" id=4]
radius = 4.0
[node name="FlyingEnemy" instance=ExtResource( 1 )]
script = ExtResource( 2 )
MAX_SPEED = 40
[node name="Sprite" parent="." index="0"]
texture = ExtResource( 3 )
flip_h = true
hframes = 6
frame = 1
[node name="Collider" parent="." index="1"]
shape = SubResource( 1 )
[node name="AnimationPlayer" parent="." index="2"]
autoplay = "Fly"
anims/Fly = SubResource( 2 )
[node name="Hurtbox" parent="." index="3"]
collision_layer = 8
collision_mask = 0
[node name="Collider" parent="Hurtbox" index="0"]
shape = SubResource( 3 )
[node name="Collider" parent="Hitbox" index="0"]
shape = SubResource( 4 )
[editable path="Hurtbox"]
[editable path="Hitbox"]

33
metroidvania/Scenes/Player/Player.gd

@ -1,17 +1,19 @@
extends KinematicBody2D
const DustEffect = preload("res://Scenes/Effects/DustEffect.tscn")
const WallDustEffect = preload("res://Scenes/Effects/WallDustEffect.tscn")
const PlayerBullet = preload("res://Scenes/Player/PlayerBullet.tscn")
const JumpEffect = preload("res://Scenes/Effects/JumpEffect.tscn")
var PlayerStats = ResourceLoader.PlayerStats
var MainInstances = ResourceLoader.MainInstances
export (int) var acceleration = 512
export (int) var max_speed = 64
export (float) var friction = 0.25
export (int) var gravity = 200
export (int) var jump_force = 128
export (int) var wall_slide_speed = 48
export (int) var wall_slide_speed = 42
export (int) var max_wall_slide_speed = 128
export (int) var max_slope = 46
export (int) var bullet_speed = 250
@ -42,6 +44,10 @@ func set_invincible(value):
func _ready():
PlayerStats.connect("player_died", self, "_on_died")
MainInstances.Player = self
func _exit_tree():
MainInstances.Player = null
func _physics_process(delta):
just_jumped = false
@ -67,10 +73,9 @@ func _physics_process(delta):
sprite.scale.x = wall_axis
wall_slide_jump_check(wall_axis)
wall_slide_drop_check(delta)
wall_slide_fast_slide_check(delta)
wall_slide_drop(delta)
move()
wall_detach_check(wall_axis)
wall_detach(delta, wall_axis)
if Input.is_action_pressed("fire") and fireBulletTimer.time_left == 0:
fire_bullet()
@ -174,6 +179,7 @@ func wall_slide_check():
if !is_on_floor() and is_on_wall():
state = WALL_SLIDE
double_jump = true
create_dust_effect()
func get_wall_axis():
var is_right_wall = test_move(transform, Vector2.RIGHT)
@ -185,8 +191,18 @@ func wall_slide_jump_check(wall_axis):
motion.x = wall_axis * max_speed
motion.y = -jump_force/1.25
state = MOVE
var dust_position = global_position + Vector2(wall_axis*3, 0)
var dust = Utils.instance_scene_on_main(WallDustEffect, dust_position)
dust.scale.x = wall_axis
func wall_slide_drop_check(delta):
func wall_slide_drop(delta):
var max_slide_speed = wall_slide_speed
if Input.is_action_pressed("ui_down"):
max_slide_speed = max_wall_slide_speed
motion.y = min(motion.y + gravity * delta, max_slide_speed)
func wall_detach(delta, wall_axis):
if Input.is_action_just_pressed("ui_right"):
motion.x = acceleration * delta
state = MOVE
@ -195,13 +211,6 @@ func wall_slide_drop_check(delta):
motion.x = -acceleration * delta
state = MOVE
func wall_slide_fast_slide_check(delta):
var max_slide_speed = wall_slide_speed
if Input.is_action_just_pressed("ui_down"):
max_slide_speed = max_wall_slide_speed
motion.y = min(motion.y + gravity * delta, max_wall_slide_speed)
func wall_detach_check(wall_axis):
if wall_axis == 0 or is_on_floor():
state = MOVE

2732
metroidvania/Scenes/UI/DefaultTheme.tres

File diff suppressed because one or more lines are too long

6
metroidvania/Scenes/World/MainInstances.tres

@ -0,0 +1,6 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://MainInstances.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )

6
metroidvania/Scenes/World/World.tscn

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://Scenes/World/TileMap.tscn" type="PackedScene" id=1]
[ext_resource path="res://Scenes/Player/Player.tscn" type="PackedScene" id=2]
@ -7,6 +7,7 @@
[ext_resource path="res://Scenes/Enemies/WalkingEnemy.tscn" type="PackedScene" id=5]
[ext_resource path="res://Scenes/World/Camera.tscn" type="PackedScene" id=6]
[ext_resource path="res://Scenes/UI/UI.tscn" type="PackedScene" id=7]
[ext_resource path="res://Scenes/Enemies/FlyingEnemy.tscn" type="PackedScene" id=8]
[node name="World" type="Node"]
script = ExtResource( 3 )
@ -37,4 +38,7 @@ position = Vector2( 448, 80 )
[node name="UI" parent="." instance=ExtResource( 7 )]
[node name="FlyingEnemy" parent="." instance=ExtResource( 8 )]
position = Vector2( 224, 88 )
[editable path="Player"]

6
metroidvania/project.godot

@ -10,11 +10,17 @@ config_version=4
_global_script_classes=[ {
"base": "Resource",
"class": "MainInstances",
"language": "GDScript",
"path": "res://MainInstances.gd"
}, {
"base": "Resource",
"class": "PlayerStats",
"language": "GDScript",
"path": "res://Scenes/Player/PlayerStats.gd"
} ]
_global_script_class_icons={
"MainInstances": "",
"PlayerStats": ""
}

Loading…
Cancel
Save