More Cleanup
This commit is contained in:
parent
e4159c58b9
commit
4bb970187d
|
|
@ -1,98 +0,0 @@
|
||||||
extends KinematicBody2D
|
|
||||||
|
|
||||||
enum STATE {IDLE, RUN, JUMP, FALL, HURT}
|
|
||||||
enum STATE_SECONDARY {NONE, SHOOT}
|
|
||||||
|
|
||||||
class StateMachine:
|
|
||||||
var primary = STATE.IDLE
|
|
||||||
var secondary = STATE_SECONDARY.NONE
|
|
||||||
|
|
||||||
onready var player_state = StateMachine.new()
|
|
||||||
onready var player_last_state = StateMachine.new()
|
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
onready var gravity = 60*9.8
|
|
||||||
|
|
||||||
onready var speed = Vector2((30*5), (gravity * 1/2))
|
|
||||||
#onready var gravity = ProjectSettings.get("physics/2d/default_gravity")
|
|
||||||
|
|
||||||
onready var _animated_sprite = $AnimatedSprite
|
|
||||||
|
|
||||||
var velocity = Vector2.ZERO
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
func get_direction():
|
|
||||||
return Vector2(
|
|
||||||
Input.get_axis("ui_left", "ui_right"),
|
|
||||||
-1 if is_on_floor() and Input.is_action_just_pressed("ui_accept") else 0
|
|
||||||
)
|
|
||||||
|
|
||||||
func calculate_move_velocity(
|
|
||||||
linear_velocity,
|
|
||||||
direction,
|
|
||||||
speed
|
|
||||||
):
|
|
||||||
var velocity = linear_velocity
|
|
||||||
velocity.x = speed.x * direction.x
|
|
||||||
if direction.y != 0.0:
|
|
||||||
velocity.y = speed.y * direction.y
|
|
||||||
return velocity
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _physics_process(delta):
|
|
||||||
var direction = get_direction()
|
|
||||||
# if not is_on_floor():
|
|
||||||
# velocity.y += gravity * delta
|
|
||||||
#
|
|
||||||
# # Handle jump.
|
|
||||||
# if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
|
||||||
# velocity.y += (gravity * -1) * delta
|
|
||||||
#
|
|
||||||
# # Get the input direction and handle the movement/deceleration.
|
|
||||||
# # As good practice, you should replace UI actions with custom gameplay actions.
|
|
||||||
# var direction = Input.get_axis("ui_left", "ui_right")
|
|
||||||
# if direction:
|
|
||||||
# velocity.x = direction * SPEED
|
|
||||||
# else:
|
|
||||||
# velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
||||||
velocity = calculate_move_velocity(velocity, direction, speed)
|
|
||||||
move_and_slide(velocity, Vector2(0, -1))
|
|
||||||
# Apply Gravity
|
|
||||||
velocity.y += gravity * delta
|
|
||||||
|
|
||||||
#Animation
|
|
||||||
|
|
||||||
if direction.x > 0 and _animated_sprite.flip_h != true:
|
|
||||||
_animated_sprite.flip_h = true
|
|
||||||
if direction.x < 0 and _animated_sprite.flip_h != false:
|
|
||||||
_animated_sprite.flip_h = false
|
|
||||||
|
|
||||||
|
|
||||||
player_state.primary = STATE.IDLE
|
|
||||||
|
|
||||||
match player_state.primary:
|
|
||||||
STATE.IDLE:
|
|
||||||
if direction.y == 0:
|
|
||||||
player_state.primary = STATE.FALL
|
|
||||||
STATE.FALL:
|
|
||||||
print("Fall")
|
|
||||||
STATE.RUN:
|
|
||||||
print("Idle")
|
|
||||||
|
|
||||||
if not is_on_floor():
|
|
||||||
if _animated_sprite.animation != "jump":
|
|
||||||
_animated_sprite.play("jump")
|
|
||||||
else:
|
|
||||||
if direction and _animated_sprite.animation != "run":
|
|
||||||
print(_animated_sprite.animation, direction)
|
|
||||||
_animated_sprite.play("run")
|
|
||||||
elif not direction:
|
|
||||||
_animated_sprite.play("idle")
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[ext_resource path="res://src/playerB/Player.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://src/playerB/Player.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://assets/Tiles/Assets/Assets.png" type="Texture" id=3]
|
[ext_resource path="res://assets/Tiles/Assets/Assets.png" type="Texture" id=3]
|
||||||
[ext_resource path="res://Position2D.gd" type="Script" id=5]
|
[ext_resource path="res://src/CameraControl-Position2D.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://src/enemyB/Enemy2.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://src/enemyB/Enemy2.tscn" type="PackedScene" id=6]
|
||||||
|
|
||||||
[sub_resource type="ConvexPolygonShape2D" id=2]
|
[sub_resource type="ConvexPolygonShape2D" id=2]
|
||||||
|
|
|
||||||
BIN
Smiley.png
BIN
Smiley.png
Binary file not shown.
|
Before Width: | Height: | Size: 508 B |
|
|
@ -1,35 +0,0 @@
|
||||||
[remap]
|
|
||||||
|
|
||||||
importer="texture"
|
|
||||||
type="StreamTexture"
|
|
||||||
path="res://.import/Smiley.png-21025cc2924b94a90cc7095293287091.stex"
|
|
||||||
metadata={
|
|
||||||
"vram_texture": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[deps]
|
|
||||||
|
|
||||||
source_file="res://Smiley.png"
|
|
||||||
dest_files=[ "res://.import/Smiley.png-21025cc2924b94a90cc7095293287091.stex" ]
|
|
||||||
|
|
||||||
[params]
|
|
||||||
|
|
||||||
compress/mode=0
|
|
||||||
compress/lossy_quality=0.7
|
|
||||||
compress/hdr_mode=0
|
|
||||||
compress/bptc_ldr=0
|
|
||||||
compress/normal_map=0
|
|
||||||
flags/repeat=0
|
|
||||||
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
|
|
||||||
|
|
@ -12,24 +12,24 @@ _global_script_classes=[ {
|
||||||
"base": "KinematicBody2D",
|
"base": "KinematicBody2D",
|
||||||
"class": "Enemy",
|
"class": "Enemy",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://Enemy-KinematicBody2D.gd"
|
"path": "res://src/enemy/Enemy-KinematicBody2D.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "KinematicBody2D",
|
"base": "Reference",
|
||||||
"class": "Enemy2",
|
"class": "Enemy2",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/enemyB/Enemy2-KinematicBody2D.gd"
|
"path": "res://src/enemyB/Enemy2-KinematicBody2D.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Position2D",
|
||||||
"class": "Gun",
|
"class": "Gun",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/playerB/Gun.gd"
|
"path": "res://src/playerB/Gun.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Node",
|
"base": "Reference",
|
||||||
"class": "Movement",
|
"class": "Movement",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/playerB/player_move_component.gd"
|
"path": "res://src/playerB/player_move_component.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "KinematicBody2D",
|
"base": "Reference",
|
||||||
"class": "Player",
|
"class": "Player",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/playerB/Player-KinematicBody2D.gd"
|
"path": "res://src/playerB/Player-KinematicBody2D.gd"
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://assets/bullet.png" type="Texture" id=1]
|
[ext_resource path="res://src/Projectile.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Projectile.gd" type="Script" id=2]
|
[ext_resource path="res://assets/bullet.png" type="Texture" id=2]
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id=1]
|
[sub_resource type="SpriteFrames" id=1]
|
||||||
animations = [ {
|
animations = [ {
|
||||||
"frames": [ ExtResource( 1 ) ],
|
"frames": [ ExtResource( 2 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "default",
|
"name": "default",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
|
|
@ -20,7 +20,7 @@ collision_mask = 33
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
contacts_reported = 2
|
contacts_reported = 2
|
||||||
contact_monitor = true
|
contact_monitor = true
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 1 )
|
frames = SubResource( 1 )
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_scene load_steps=24 format=2]
|
[gd_scene load_steps=24 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Enemy-KinematicBody2D.gd" type="Script" id=1]
|
[ext_resource path="res://src/enemy/Enemy-KinematicBody2D.gd" type="Script" id=1]
|
||||||
|
|
||||||
[sub_resource type="StreamTexture" id=75]
|
[sub_resource type="StreamTexture" id=75]
|
||||||
load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex"
|
load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex"
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
[gd_scene load_steps=35 format=2]
|
[gd_scene load_steps=35 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/enemyB/Enemy2-KinematicBody2D.gd" type="Script" id=1]
|
[ext_resource path="res://src/enemyB/Enemy2-KinematicBody2D.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://src/states/enemy/fall.gd" type="Script" id=2]
|
[ext_resource path="res://src/enemyB/states/fall.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://src/state_machine.gd" type="Script" id=3]
|
[ext_resource path="res://src/state_machine.gd" type="Script" id=3]
|
||||||
[ext_resource path="res://src/states/enemy/jump.gd" type="Script" id=4]
|
[ext_resource path="res://src/enemyB/states/jump.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://src/states/enemy/move.gd" type="Script" id=5]
|
[ext_resource path="res://src/enemyB/states/move.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://src/states/enemy/wander.gd" type="Script" id=6]
|
[ext_resource path="res://src/enemyB/states/wander.gd" type="Script" id=6]
|
||||||
[ext_resource path="res://src/states/enemy/idle.gd" type="Script" id=7]
|
[ext_resource path="res://src/enemyB/states/idle.gd" type="Script" id=7]
|
||||||
[ext_resource path="res://src/states/enemy/attack.gd" type="Script" id=8]
|
[ext_resource path="res://src/enemyB/states/attack.gd" type="Script" id=8]
|
||||||
[ext_resource path="res://src/playerB/Gun.gd" type="Script" id=9]
|
[ext_resource path="res://src/playerB/Gun.gd" type="Script" id=9]
|
||||||
[ext_resource path="res://src/states/enemy/hurt.gd" type="Script" id=10]
|
[ext_resource path="res://src/enemyB/states/hurt.gd" type="Script" id=10]
|
||||||
[ext_resource path="res://src/enemyB/enemy_move_component.gd" type="Script" id=11]
|
[ext_resource path="res://src/enemyB/enemy_move_component.gd" type="Script" id=11]
|
||||||
|
|
||||||
[sub_resource type="StreamTexture" id=149]
|
[sub_resource type="StreamTexture" id=149]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ extends Position2D
|
||||||
|
|
||||||
|
|
||||||
const BULLET_VELOCITY = 350
|
const BULLET_VELOCITY = 350
|
||||||
const Bullet = preload("res://Projectile.tscn")
|
const Bullet = preload("res://src/Projectile.tscn")
|
||||||
|
|
||||||
#onready var sound_shoot = $Shoot
|
#onready var sound_shoot = $Shoot
|
||||||
onready var timer = $Cooldown
|
onready var timer = $Cooldown
|
||||||
|
|
|
||||||
61
wander.gd
61
wander.gd
|
|
@ -1,61 +0,0 @@
|
||||||
extends State
|
|
||||||
|
|
||||||
export (NodePath) var jump_node
|
|
||||||
export (NodePath) var fall_node
|
|
||||||
export (NodePath) var idle_node
|
|
||||||
export (NodePath) var dash_node
|
|
||||||
|
|
||||||
onready var jump_state: State = get_node(jump_node)
|
|
||||||
onready var fall_state: State = get_node(fall_node)
|
|
||||||
onready var idle_state: State = get_node(idle_node)
|
|
||||||
onready var dash_state: State = get_node(dash_node)
|
|
||||||
|
|
||||||
func process_input(_event: InputEvent) -> State:
|
|
||||||
if move_component.wants_jump() and parent.is_on_floor():
|
|
||||||
return jump_state
|
|
||||||
|
|
||||||
move_component.get_movement_direction()
|
|
||||||
|
|
||||||
return null
|
|
||||||
|
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
|
||||||
# if move_component.wants_jump() and parent.is_on_floor():
|
|
||||||
# return jump_state
|
|
||||||
|
|
||||||
parent.velocity.y += gravity * delta
|
|
||||||
|
|
||||||
# var movement = move_component.get_movement_direction() * move_speed
|
|
||||||
#
|
|
||||||
# # only detecting input not actual movement
|
|
||||||
# if movement == 0:
|
|
||||||
# return idle_state
|
|
||||||
|
|
||||||
# parent.velocity.x = movement
|
|
||||||
# parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
||||||
|
|
||||||
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
||||||
|
|
||||||
if parent.velocity.x == 0.0:
|
|
||||||
return idle_state
|
|
||||||
else:
|
|
||||||
if parent.velocity.x > 0:
|
|
||||||
parent.direction.x = 1
|
|
||||||
elif parent.velocity.x < 0:
|
|
||||||
parent.direction.x = -1
|
|
||||||
|
|
||||||
|
|
||||||
if move_component.flipped_sprite == true:
|
|
||||||
animations.flip_h = parent.direction.x > 0
|
|
||||||
else:
|
|
||||||
animations.flip_h = parent.direction.x < 0
|
|
||||||
|
|
||||||
|
|
||||||
# Another approach of changing state based on actual achieved velocity
|
|
||||||
# if parent.velocity.x == 0:
|
|
||||||
# return idle_state
|
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
|
||||||
return fall_state
|
|
||||||
return null
|
|
||||||
Loading…
Reference in New Issue
Block a user