1
Fork 0
mirror of https://github.com/Steffo99/watermelonkeys-patched-ld51.git synced 2024-11-21 23:54:19 +00:00

Added dumbass falena

This commit is contained in:
AndreaTerenz 2022-10-03 15:27:12 +02:00
parent 8895df48d4
commit 67c5b9b9e2
7 changed files with 366 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/enemy_spritesheet.png-19f607fcb568e42bb08c4d53fd65c460.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ASSETS/enemy_spritesheet.png"
dest_files=[ "res://.import/enemy_spritesheet.png-19f607fcb568e42bb08c4d53fd65c460.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

View file

@ -1,11 +1,17 @@
class_name Giovanna
extends KinematicBody2D extends KinematicBody2D
export(float, 0.01, 2.0, 0.01) var stopping_force = 1.0
var ammo = 6 var ammo = 6
var velocity = Vector2(0,0) var velocity = Vector2(0,0)
const max_speed = 150 const max_speed = 150
const GRAVITY = 30 const GRAVITY = 30
const JUMPFORCE = -500 const JUMPFORCE = -500
func _ready():
owner.set_meta("player", self)
func _physics_process(delta): func _physics_process(delta):
if Input.is_action_pressed("right"): if Input.is_action_pressed("right"):
velocity.x = max_speed velocity.x = max_speed
@ -26,5 +32,5 @@ func _physics_process(delta):
if Input.is_action_just_pressed("jump") and is_on_floor(): if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMPFORCE velocity.y = JUMPFORCE
velocity = move_and_slide(velocity,Vector2.UP) velocity = move_and_slide(velocity,Vector2.UP)
velocity.x = lerp(velocity.x,0,0.2) velocity.x = lerp(velocity.x,0,stopping_force)

File diff suppressed because one or more lines are too long

174
enemies/Enemy.gd Normal file
View file

@ -0,0 +1,174 @@
class_name Enemy
extends KinematicBody2D
enum STATES {
SPAWN,
ROAM, # fly around until player is in reach
AGGRO, # get mad because you saw the player
CHARGE, #RUN to the player
ATTACK #fuck up the player if the sucker didnt run away
}
export(float, 2.0, 150.0, 0.1) var attack_dist = 150.0
export(float, 1.0, 500.0, 0.1) var roam_max_speed = 100.0
export(float, 1.0, 200.0, 0.1) var attack_speed_mul = 10.0
export(float, 0.01, 1.0, 0.01) var roam_acceleration = 0.4
export(float, 0.01, 5.0, 0.01) var aggro_timer_len = 2.0
onready var ray := $RayCast2D
onready var anim_sprite := $AnimatedSprite
var aggro_timer := Timer.new()
var noise_idx := 0.0
var noise := OpenSimplexNoise.new()
var state = STATES.SPAWN
var player : Giovanna = null
var velocity := Vector2.ZERO
var dir := Vector2.RIGHT
var charge_target := Vector2.ZERO
var charge_collision : KinematicCollision2D = null
var charge_done := false
var spawn_done := false
func _ready():
add_child(aggro_timer)
aggro_timer.one_shot = true
aggro_timer.wait_time = aggro_timer_len
anim_sprite.animation = "spawning"
anim_sprite.playing = true
# Configure noise
randomize()
noise.seed = randi()
noise.octaves = 2
noise.period = 20.0
noise.persistence = 0.8
# yield(get_tree(), "idle_frame")
# Gets reference to the player from the root node
player = owner.get_meta("player")
func _physics_process(delta):
var new_s = check_state()
if state != new_s:
state = new_s
init_state()
run_state(delta)
func check_state():
if not player:
return STATES.ROAM
match state:
STATES.SPAWN:
if spawn_done:
return STATES.ROAM
STATES.ROAM:
var p_pos = player.global_position
# let's be efficient and use the squared distance
var dist = global_position.distance_squared_to(p_pos)
if dist <= pow(attack_dist, 2):
# it's in range
ray.cast_to = ray.to_local(p_pos)
ray.force_raycast_update()
var coll = ray.get_collider()
if coll and coll == player:
# LADIES N GENTLEMEN WE GOT HIM
return STATES.AGGRO
STATES.AGGRO:
if aggro_timer.time_left <= 0.0:
return STATES.CHARGE
STATES.CHARGE:
charge_done = charge_collision and charge_collision.collider == player
if charge_done:
return STATES.ATTACK
STATES.ATTACK:
return state
if dist_to_player() > 20.0:
return STATES.ROAM
return state
func init_state():
# Things to do when the state changes
match state:
STATES.SPAWN:
# nothing to do
pass
STATES.ROAM:
anim_sprite.modulate = Color.white
velocity *= 0.0
dir = Vector2.RIGHT
anim_sprite.animation = "roaming"
anim_sprite.playing = true
STATES.AGGRO:
velocity *= 0.0
dir = Vector2.RIGHT
aggro_timer.start()
charge_target = player.position
STATES.CHARGE:
charge_done = false
anim_sprite.offset *= 0.0
STATES.ATTACK:
## TEMP
velocity *= 0.0
anim_sprite.modulate = Color.red
func run_state(delta):
match state:
STATES.SPAWN:
# nothing to do
pass
STATES.ROAM:
noise_idx += delta * 100
var _n = noise.get_noise_1d(noise_idx)
var n = range_lerp(_n, -1.0, 1.0, -TAU/4.0, TAU/4.0)
dir = dir.linear_interpolate(dir.rotated(n * 0.1), 0.5)
velocity = velocity.linear_interpolate(dir * roam_max_speed, roam_acceleration)
var coll = move_and_collide(velocity * delta)
var coll_horizontal := false
if coll:
var norm = coll.normal
if norm.y == 0:
# vertical wall
dir.x *= -1
velocity.x *= -1
else:
dir.y *= -1
velocity.y *= -1
anim_sprite.flip_h = (velocity.x > 0)
STATES.AGGRO:
var r = 2.0
anim_sprite.offset = Vector2(rand_range(-r, r), rand_range(-r, r))
STATES.CHARGE:
var target_dist = position.distance_squared_to(charge_target)
var target_dir = position.direction_to(charge_target)
var speed = roam_max_speed * attack_speed_mul
var fac = target_dist/pow(attack_dist, 2)
velocity = velocity.linear_interpolate(target_dir * speed, fac)
move_and_slide(velocity)
if get_slide_count() > 0:
charge_collision = get_slide_collision(0)
STATES.ATTACK:
pass
func dist_to_player():
return position.distance_to(player.position)
func _on_AnimatedSprite_animation_finished():
if anim_sprite.animation == "spawning":
spawn_done = true

82
enemies/Enemy.tscn Normal file
View file

@ -0,0 +1,82 @@
[gd_scene load_steps=13 format=2]
[ext_resource path="res://ASSETS/enemy_spritesheet.png" type="Texture" id=1]
[ext_resource path="res://enemies/Enemy.gd" type="Script" id=2]
[sub_resource type="AtlasTexture" id=8]
atlas = ExtResource( 1 )
region = Rect2( 0, 0, 30, 30 )
[sub_resource type="AtlasTexture" id=9]
atlas = ExtResource( 1 )
region = Rect2( 30, 0, 30, 30 )
[sub_resource type="AtlasTexture" id=10]
atlas = ExtResource( 1 )
region = Rect2( 60, 0, 30, 30 )
[sub_resource type="AtlasTexture" id=11]
atlas = ExtResource( 1 )
region = Rect2( 90, 0, 30, 30 )
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 10 ), SubResource( 9 ), SubResource( 8 ) ],
"loop": true,
"name": "roaming",
"speed": 30.0
}, {
"frames": [ SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ) ],
"loop": false,
"name": "spawning",
"speed": 4.0
} ]
[sub_resource type="CircleShape2D" id=2]
radius = 42.0
[sub_resource type="Gradient" id=3]
[sub_resource type="GradientTexture" id=4]
gradient = SubResource( 3 )
width = 100
[sub_resource type="Gradient" id=5]
offsets = PoolRealArray( 0 )
colors = PoolColorArray( 1, 0, 0, 1 )
[sub_resource type="GradientTexture" id=6]
gradient = SubResource( 5 )
width = 100
[node name="Enemy" type="KinematicBody2D"]
scale = Vector2( 0.5, 0.5 )
collision_mask = 5
script = ExtResource( 2 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
scale = Vector2( 2, 2 )
frames = SubResource( 1 )
animation = "spawning"
flip_h = true
[node name="RayCast2D" type="RayCast2D" parent="."]
enabled = true
cast_to = Vector2( 50, 0 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 2 )
[node name="DEBUG_Dir" type="Sprite" parent="."]
visible = false
scale = Vector2( 1, 4 )
texture = SubResource( 4 )
offset = Vector2( 50, 0 )
[node name="DEBUG_Vel" type="Sprite" parent="."]
visible = false
scale = Vector2( 0.48, 4 )
texture = SubResource( 6 )
offset = Vector2( 50, 0 )
[connection signal="animation_finished" from="AnimatedSprite" to="." method="_on_AnimatedSprite_animation_finished"]

View file

@ -8,9 +8,26 @@
config_version=4 config_version=4
_global_script_classes=[ {
"base": "KinematicBody2D",
"class": "Enemy",
"language": "GDScript",
"path": "res://enemies/Enemy.gd"
}, {
"base": "KinematicBody2D",
"class": "Giovanna",
"language": "GDScript",
"path": "res://Giovanna.gd"
} ]
_global_script_class_icons={
"Enemy": "",
"Giovanna": ""
}
[application] [application]
config/name="Platformer" config/name="Platformer"
run/main_scene="res://Level1.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[display] [display]
@ -70,6 +87,11 @@ jump={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":32,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":32,"unicode":0,"echo":false,"script":null)
] ]
} }
quit={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
[physics] [physics]