midori-school/sprites/common/player/player.gd

192 lines
6.5 KiB
GDScript3
Raw Normal View History

2024-11-04 00:29:58 +01:00
extends KinematicBody2D
2024-01-27 21:10:58 +01:00
2024-11-04 00:29:58 +01:00
var velocity
2024-01-27 21:10:58 +01:00
const SPEED = 300.0
2024-08-16 22:54:37 +02:00
var xm = 0
var ym = 0
2024-01-27 21:10:58 +01:00
const JUMP_VELOCITY = -400.0
var angle = 2
var sprite
var anim
2024-03-17 19:20:27 +01:00
var speed
2024-01-27 21:10:58 +01:00
var csprite
2024-06-17 23:08:25 +02:00
var attack
var crit
2024-01-29 01:52:01 +01:00
var bpress = false
2024-01-27 21:10:58 +01:00
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
2024-01-30 04:05:17 +01:00
var weakness
2024-06-17 23:08:25 +02:00
var speciality
2024-10-22 22:28:55 +02:00
var rboost = 1
2024-01-27 21:10:58 +01:00
func _ready():
2024-01-29 01:52:01 +01:00
add_to_group("players")
2024-01-27 21:10:58 +01:00
anim = $AnimationPlayer
2024-11-04 00:29:58 +01:00
sprite = $Sprite
2024-03-17 19:20:27 +01:00
#_charswitch()
_charinit()
2024-01-27 21:10:58 +01:00
func _physics_process(delta):
2024-09-06 02:16:49 +02:00
if Global.debug:
if Global.dplace != [1, 11, 19]:
if Global.dstats[Global.dparty[Global.dcpchar][0]][0] <= 0 && Global.live == 1:
if Global.dparty[0][0] != null && Global.dstats[Global.dparty[0][0]][0] > 0:
Global.dcpchar = 0
_charswitch()
elif Global.dparty[1][0] != null && Global.dstats[Global.dparty[1][0]][0] > 0:
Global.dcpchar = 1
_charswitch()
elif Global.dparty[2][0] != null && Global.dstats[Global.dparty[2][0]][0] > 0:
Global.dcpchar = 2
_charswitch()
elif Global.dparty[3][0] != null && Global.dstats[Global.dparty[3][0]][0] > 0:
Global.dcpchar = 3
_charswitch()
else:
Global.live = 2
else:
if Global.cplace != [1, 11, 19]:
if Global.cstats[Global.party[Global.cpchar][0]][0] <= 0 && Global.live == 1:
if Global.party[0][0] != null && Global.cstats[Global.party[0][0]][0] > 0:
Global.cpchar = 0
_charswitch()
elif Global.party[1][0] != null && Global.cstats[Global.party[1][0]][0] > 0:
Global.cpchar = 1
_charswitch()
elif Global.party[2][0] != null && Global.cstats[Global.party[2][0]][0] > 0:
Global.cpchar = 2
_charswitch()
elif Global.party[3][0] != null && Global.cstats[Global.party[3][0]][0] > 0:
Global.cpchar = 3
_charswitch()
else:
Global.live = 2
2024-01-27 21:10:58 +01:00
# Add the gravity.
#var velocity = Vector2.ZERO
2024-08-16 22:54:37 +02:00
#if Global.live == 1 || (xm == 0 && ym == 0):
2024-08-05 00:33:57 +02:00
if speed != null:
2024-10-22 22:28:55 +02:00
velocity = (Vector2.RIGHT.rotated(rotation) * speed * xm * delta * rboost)-Vector2.UP.rotated(rotation) * speed * ym * delta * rboost
2024-08-05 00:33:57 +02:00
#origmpos = get_viewport().get_mouse_position()
#if Input.get_joy_axis(0,JOY_AXIS_LEFT_Y) != 0:
# velocity = Vector2.UP.rotated(rotation) * -400 * Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)
Global.playerx = position.x
Global.playery = position.y
2024-08-16 22:54:37 +02:00
if ym > 0.3:
2024-08-05 00:33:57 +02:00
angle = 2
2024-08-16 22:54:37 +02:00
elif ym < -0.3:
2024-08-05 00:33:57 +02:00
angle = 0
2024-08-16 22:54:37 +02:00
elif xm > 0.3:
2024-08-05 00:33:57 +02:00
angle = 1
2024-08-16 22:54:37 +02:00
elif xm < -0.3:
2024-08-05 00:33:57 +02:00
angle = 3
if velocity.y != 0 || velocity.x != 0:
if angle == 0:
anim.play("nwalk")
elif angle == 1:
anim.play("ewalk")
elif angle == 3:
anim.play("wwalk")
else:
anim.play("swalk")
2024-01-27 21:10:58 +01:00
else:
2024-08-05 00:33:57 +02:00
if angle == 0:
anim.play("nidle")
elif angle == 1:
anim.play("eidle")
elif angle == 3:
anim.play("widle")
else:
anim.play("sidle")
2024-11-04 00:29:58 +01:00
position += velocity
velocity = move_and_slide(velocity)
#move_and_slide(position)
2024-01-29 01:52:01 +01:00
func _input(event):
2024-08-16 22:54:37 +02:00
xm = 0
ym = 0
2024-01-29 01:52:01 +01:00
if Global.live == 1:
2024-08-16 22:54:37 +02:00
if Global.live == 1 && !Input.is_action_pressed("schar"):
2024-11-04 00:29:58 +01:00
if Input.get_joy_axis(0,JOY_ANALOG_LX) > 0.2 || Input.get_joy_axis(0,JOY_ANALOG_LY) > 0.2 || Input.get_joy_axis(0,JOY_ANALOG_LX) < -0.2 || Input.get_joy_axis(0,JOY_ANALOG_LY) < -0.2:
xm = Input.get_joy_axis(0,JOY_ANALOG_LX)
ym = Input.get_joy_axis(0,JOY_ANALOG_LY)
2024-08-16 22:54:37 +02:00
else:
if Input.is_action_pressed("ui_left"):
xm = -1
if Input.is_action_pressed("ui_right"):
xm = 1
if Input.is_action_pressed("ui_up"):
ym = -1
if Input.is_action_pressed("ui_down"):
ym = 1
2024-10-22 22:28:55 +02:00
if Input.is_action_pressed("run"):
rboost = 4
elif Global.gamepad > 0:
2024-11-04 00:29:58 +01:00
rboost = (Input.get_joy_axis(0,JOY_ANALOG_R2) + 1)*2
2024-10-22 22:28:55 +02:00
else:
rboost = 1
2024-06-15 23:11:43 +02:00
if Input.is_action_pressed("schar") && (Input.is_action_just_released("ui_up") || Input.is_action_just_released("ui_down") || Input.is_action_just_released("ui_left") || Input.is_action_just_released("ui_right")):
2024-03-17 19:20:27 +01:00
_charswitch()
2024-10-22 22:28:55 +02:00
if Input.is_action_just_pressed("shoot") && !bpress && Global.live == 1:
2024-01-29 01:52:01 +01:00
bpress = true
var bullet
if Global.debug:
2024-03-06 18:49:01 +01:00
bullet = load(Global.pbbullets[Global.dparty[Global.dcpchar][0]])
2024-01-29 01:52:01 +01:00
else:
2024-03-06 18:49:01 +01:00
bullet = load(Global.pbbullets[Global.party[Global.cpchar][0]])
2024-11-04 00:29:58 +01:00
var new_pbullet = bullet.instance()
2024-01-29 03:42:38 +01:00
new_pbullet.btype = "players"
2024-06-17 23:08:25 +02:00
new_pbullet.attack = attack
new_pbullet.crit = crit
new_pbullet.speciality = speciality
2024-11-04 00:29:58 +01:00
new_pbullet.velocity = Vector2(0, -speed).rotated(deg2rad(angle * 90))
var rposition = Vector2(0, -96).rotated(deg2rad(angle * 90))
2024-01-29 01:52:01 +01:00
if angle == 2:
2024-01-29 03:42:38 +01:00
new_pbullet.position = Vector2(position.x + rposition.x, position.y + rposition.y + 98)
2024-01-29 01:52:01 +01:00
else:
2024-01-29 03:42:38 +01:00
new_pbullet.position = Vector2(position.x + rposition.x, position.y + rposition.y)
if new_pbullet.position.x > 0 && new_pbullet.position.y > 0 && new_pbullet.position.x < 1280 && new_pbullet.position.y < 720:
get_parent().add_child(new_pbullet)
2024-10-22 22:28:55 +02:00
elif Input.is_action_just_released("shoot") && bpress:
2024-01-29 01:52:01 +01:00
bpress = false
2024-01-30 04:05:17 +01:00
2024-03-17 19:20:27 +01:00
func _charinit():
if Global.debug:
2024-05-19 21:12:02 +02:00
speed = Global.mstats[Global.dparty[Global.dcpchar][0]][6]
2024-06-17 23:08:25 +02:00
attack = Global.mstats[Global.dparty[Global.dcpchar][0]][2]
crit = Global.mstats[Global.dparty[Global.dcpchar][0]][3]
2024-03-17 19:20:27 +01:00
#print(Global.dparty[Global.dcpchar][0])
#print(speed)
else:
2024-05-19 21:12:02 +02:00
speed = Global.mstats[Global.party[Global.cpchar][0]][6]
2024-06-17 23:08:25 +02:00
attack = Global.mstats[Global.party[Global.cpchar][0]][2]
crit = Global.mstats[Global.party[Global.cpchar][0]][3]
2024-03-17 19:20:27 +01:00
#print(Global.dparty[Global.cpchar][0])
#print(speed)
_charswitch()
2024-01-30 04:05:17 +01:00
func _charswitch():
if Global.debug:
2024-05-19 21:12:02 +02:00
if csprite != null && speed!=Global.mstats[Global.dparty[csprite][0]][6]:
2024-03-17 19:20:27 +01:00
print("Script Kiddie")
2024-05-19 21:12:02 +02:00
speed = Global.dparty/0
2024-03-17 19:20:27 +01:00
else:
2024-05-19 21:12:02 +02:00
speed = Global.mstats[Global.dparty[Global.dcpchar][0]][6]
2024-01-30 04:05:17 +01:00
if Global.dcpchar != csprite:
csprite = Global.dcpchar
2024-03-06 18:49:01 +01:00
sprite.texture = load(Global.pchars[Global.dparty[Global.dcpchar][0]][Global.dparty[Global.dcpchar][1]])
weakness = Global.specialities[Global.pcspecialities[Global.dparty[Global.dcpchar][0]]]
2024-06-17 23:08:25 +02:00
speciality = Global.pcspecialities[Global.dparty[Global.dcpchar][0]]
2024-03-17 19:20:27 +01:00
print(Global.dparty[Global.dcpchar][0])
print(speed)
2024-01-30 04:05:17 +01:00
else:
2024-07-24 01:46:32 +02:00
if csprite != null && speed!=Global.mstats[Global.party[csprite][0]][6]:
2024-03-17 19:20:27 +01:00
print("Script Kiddie")
2024-05-19 21:12:02 +02:00
speed = Global.party/0
2024-03-17 19:20:27 +01:00
else:
2024-07-24 01:46:32 +02:00
speed = Global.mstats[Global.party[Global.cpchar][0]][6]
2024-01-30 04:05:17 +01:00
if Global.cpchar != csprite:
csprite = Global.cpchar
2024-03-06 18:49:01 +01:00
sprite.texture = load(Global.pchars[Global.party[Global.cpchar][0]][Global.party[Global.cpchar][1]])
weakness = Global.specialities[Global.pcspecialities[Global.party[Global.cpchar][0]]]
2024-06-17 23:08:25 +02:00
speciality = Global.pcspecialities[Global.party[Global.cpchar][0]]