mirror of
https://github.com/creyD/ludum_dare_46.git
synced 2026-06-13 22:12:23 +02:00
setup for ai
This commit is contained in:
94
src/Boss/Boss_template.gd
Normal file
94
src/Boss/Boss_template.gd
Normal file
@@ -0,0 +1,94 @@
|
||||
extends KinematicBody2D
|
||||
class_name Boss
|
||||
"""
|
||||
This is an example player controller script created by Paul
|
||||
"""
|
||||
var velocity := Vector2.ZERO
|
||||
# This is how you export variables with ranges to the editor window
|
||||
export(bool) var debug := false
|
||||
export(int, 0, 500) var ACCELERATION := 450
|
||||
# Reference for the current player
|
||||
|
||||
onready var player_stats := $Stats
|
||||
onready var debug_label := $DebugLabel
|
||||
#onready var animation_player := $AnimationPlayer
|
||||
#var animation_tree := $AnimationTree
|
||||
#onready var animation_state = animation_tree.get("parameters/playback")
|
||||
|
||||
enum moveState{
|
||||
MOVE,
|
||||
HIT
|
||||
}
|
||||
|
||||
var movementState = moveState.MOVE
|
||||
|
||||
var damage_per_second := 0.0
|
||||
var totaldamage := 0.0
|
||||
|
||||
func _debug_update():
|
||||
debug_label.text = str(player_stats.health) + "/" + str(player_stats.max_health) + " HP\n"
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
totaldamage+=damage_per_second*delta
|
||||
player_stats.speed+=10*delta
|
||||
while(totaldamage>1):
|
||||
totaldamage-=1
|
||||
player_stats.health-=1
|
||||
while(totaldamage<-1):
|
||||
totaldamage+=1
|
||||
player_stats.health+=1
|
||||
_debug_update()
|
||||
if debug == true:
|
||||
match movementState:
|
||||
moveState.MOVE:
|
||||
movement_move(delta)
|
||||
moveState.HIT:
|
||||
movement_hit()
|
||||
|
||||
move()
|
||||
|
||||
# IMPORTANT: If you are using move_and_slide don't multiply by delta
|
||||
# Godots physics system does that internally
|
||||
# In move_and_collide(...) you have to multiply by delta.
|
||||
func move():
|
||||
move_and_slide(velocity)
|
||||
|
||||
func movement_move(delta):
|
||||
var input_vector = Vector2.ZERO
|
||||
# This is a clever way to handle directional input
|
||||
# Input.get_action_strength(...) returns a value between 0 and 1 depending
|
||||
# on how strong the controller direction is pressed
|
||||
# For keyboards it always returns 1 if pressed and 0 if not
|
||||
# The actions are custom and defined in the project settings
|
||||
input_vector.x = Input.get_action_strength("right") - Input.get_action_strength("left")
|
||||
input_vector.y = Input.get_action_strength("down") - Input.get_action_strength("up")
|
||||
input_vector = input_vector.normalized()
|
||||
|
||||
if input_vector == Vector2.ZERO:
|
||||
#animation_state.travel("idle")
|
||||
velocity = Vector2.ZERO
|
||||
else:
|
||||
velocity = velocity.move_toward(player_stats.speed * input_vector, ACCELERATION * delta)
|
||||
if Input.is_action_just_pressed("roll"):
|
||||
pass
|
||||
elif Input.is_action_just_pressed("attack"):
|
||||
pass
|
||||
|
||||
func movement_hit():
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
func hit_finished():
|
||||
movementState = moveState.MOVE
|
||||
|
||||
func _on_Stats_no_health():
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_Hurtbox_area_entered(area):
|
||||
player_stats.health-=area.damage
|
||||
damage_per_second = damage_per_second + area.damage
|
||||
|
||||
|
||||
func _on_Hurtbox_area_exited(area):
|
||||
damage_per_second = damage_per_second - area.damage
|
||||
67
src/Boss/Boss_template.tscn
Normal file
67
src/Boss/Boss_template.tscn
Normal file
@@ -0,0 +1,67 @@
|
||||
[gd_scene load_steps=9 format=2]
|
||||
|
||||
[ext_resource path="res://Overlap/HurtHit_Box/Hurtbox.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://Overlap/HurtHit_Box/Hitbox.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://Overlap/Stats/Stats.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://Boss/Boss_template.gd" type="Script" id=4]
|
||||
[ext_resource path="res://testSprites/white_boss_dog.png" type="Texture" id=5]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=1]
|
||||
radius = 18.0
|
||||
height = 18.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=2]
|
||||
radius = 18.0
|
||||
height = 18.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=3]
|
||||
radius = 8.0
|
||||
height = 15.0
|
||||
|
||||
[node name="Boss_template" type="KinematicBody2D"]
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
position = Vector2( 3.13451, -20.1418 )
|
||||
scale = Vector2( 2, 2 )
|
||||
texture = ExtResource( 5 )
|
||||
hframes = 60
|
||||
|
||||
[node name="Stats" parent="." instance=ExtResource( 3 )]
|
||||
|
||||
[node name="Hitbox" parent="." instance=ExtResource( 2 )]
|
||||
collision_layer = 0
|
||||
|
||||
[node name="CollisionShape2D" parent="Hitbox" index="0"]
|
||||
position = Vector2( 0, -15 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="Hurtbox" parent="." instance=ExtResource( 1 )]
|
||||
collision_layer = 4
|
||||
collision_mask = 0
|
||||
|
||||
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
|
||||
position = Vector2( 0, -15 )
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2( -1.52588e-05, 0 )
|
||||
rotation = 1.5708
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="DebugLabel" type="Label" parent="."]
|
||||
margin_left = -42.2456
|
||||
margin_top = -65.04
|
||||
margin_right = 42.7544
|
||||
margin_bottom = -48.04
|
||||
text = "Obermufti"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"]
|
||||
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
|
||||
[connection signal="area_exited" from="Hurtbox" to="." method="_on_Hurtbox_area_exited"]
|
||||
|
||||
[editable path="Hitbox"]
|
||||
|
||||
[editable path="Hurtbox"]
|
||||
Reference in New Issue
Block a user