midori-school/levels/ui/gameplay.gd

227 lines
8 KiB
GDScript3
Raw Normal View History

2024-01-20 11:38:12 +01:00
extends Node2D
2024-08-16 22:54:37 +02:00
const gamepadtest = preload("res://gamepad.gd")
2024-01-20 11:38:12 +01:00
var level
var player
var music
var bgsound := AudioStreamPlayer.new()
2024-01-20 13:21:28 +01:00
var sfx1 := AudioStreamPlayer.new()
2024-01-20 11:38:12 +01:00
var musictrack
2024-11-04 00:29:58 +01:00
var bhud = load("res://levels/bottomhud.tscn").instance()
var thud = load("res://levels/ui/tophud.tscn").instance()
var pmenu = load("res://levels/ui/pause.tscn").instance()
2024-11-14 23:25:32 +01:00
var mgamepad = load("res://levels/ui/missinggamepad.tscn").instance()
2024-12-02 02:07:54 +01:00
var tcontrol = load("res://levels/ui/touchcontrols.tscn").instance()
2024-11-14 23:25:32 +01:00
var ismgamepad = false
2024-06-09 00:09:54 +02:00
var ispaused = false
2024-01-30 04:05:17 +01:00
var ishud = true
2024-01-20 11:38:12 +01:00
# Called when the node enters the scene tree for the first time.
func _ready():
2024-11-18 20:58:50 +01:00
if Global.dificulty == 1:
if Global.difdamage != 0:
print("Script Kiddie")
Global.difdamage = Global.dparty/0
2024-12-02 20:49:07 +01:00
elif Global.dificulty == 2 || Global.dificulty == 0:
2024-11-18 20:58:50 +01:00
if Global.difdamage == 0 || Global.difdamage == 1:
Global.difdamage = 1
else:
print("Script Kiddie")
Global.difdamage = Global.dparty/0
elif Global.dificulty == 3:
2024-11-19 21:07:39 +01:00
if Global.difdamage == 0 || Global.difdamage == 3:
Global.difdamage = 3
2024-11-18 20:58:50 +01:00
else:
print("Script Kiddie")
Global.difdamage = Global.dparty/0
elif Global.dificulty == 4:
2024-11-19 21:07:39 +01:00
if Global.difdamage == 0 || Global.difdamage == 6:
Global.difdamage = 6
2024-11-18 20:58:50 +01:00
else:
print("Script Kiddie")
Global.difdamage = Global.dparty/0
2024-11-14 23:25:32 +01:00
Input.connect("joy_connection_changed",self,"_on_joy_connection_changed")
2024-05-15 23:53:24 +02:00
_statrebase()
2024-01-20 11:38:12 +01:00
add_child(bgsound)
2024-01-20 13:21:28 +01:00
add_child(sfx1)
2024-01-20 11:38:12 +01:00
if Global.debug:
2024-11-04 00:29:58 +01:00
level = load(Global.places[Global.dplace[0]][Global.dplace[1]][Global.dplace[2]][0]).instance()
#player = load(Global.pchars[Global.dcpchar]).instance()
2024-01-27 21:10:58 +01:00
musictrack = Global.musictracks[Global.places[Global.dplace[0]][Global.dplace[1]][Global.dplace[2]][1]]
2024-05-16 00:51:17 +02:00
Global.isboss = Global.places[Global.dplace[0]][Global.dplace[1]][Global.dplace[2]][2]
2024-01-20 11:38:12 +01:00
else:
2024-11-04 00:29:58 +01:00
level = load(Global.places[Global.cplace[0]][Global.cplace[1]][Global.cplace[2]][0]).instance()
# player = load(Global.pchars[Global.cpchar]).instance()
2024-01-27 21:10:58 +01:00
musictrack = Global.musictracks[Global.places[Global.cplace[0]][Global.cplace[1]][Global.cplace[2]][1]]
2024-05-16 00:51:17 +02:00
Global.isboss = Global.places[Global.cplace[0]][Global.cplace[1]][Global.cplace[2]][2]
2024-01-27 21:10:58 +01:00
#if Global.cspawnarea[0] != null && Global.cspawnarea[0] != null:
# player.position.x = Global.cspawnarea[0]
# player.position.y = Global.cspawnarea[1]
#elif Global.debug:
# player.position.x = Global.places[Global.dplace[0]][Global.dplace[1]][Global.dplace[2]][1]
# player.position.y = Global.places[Global.dplace[0]][Global.dplace[1]][Global.dplace[2]][2]
#else:
# player.position.x = Global.places[Global.cplace[0]][Global.cplace[1]][Global.cplace[2]][1]
# player.position.y = Global.places[Global.cplace[0]][Global.cplace[1]][Global.cplace[2]][2]
2024-01-20 11:38:12 +01:00
music = load(musictrack)
2024-11-04 00:29:58 +01:00
call_deferred("_level")
call_deferred("_bhud")
call_deferred("_thud")
2024-12-02 02:07:54 +01:00
call_deferred("_tcontrol")
2024-01-27 21:10:58 +01:00
#get_tree().root.add_child.call_deferred(player)
2024-01-20 11:38:12 +01:00
bgsound.stream = music
2024-11-04 00:29:58 +01:00
bgsound.bus = "Music"
2024-07-14 23:55:40 +02:00
bgsound.mix_target = 1
sfx1.mix_target = 1
2024-11-04 00:29:58 +01:00
sfx1.bus = "SFX1"
2024-09-26 22:06:33 +02:00
Global.wait = Time.get_ticks_msec()
2024-05-16 00:51:17 +02:00
if !Global.isboss:
2024-01-27 23:38:20 +01:00
bgsound.play(0)
2024-01-20 13:21:28 +01:00
2024-01-20 11:38:12 +01:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
2024-12-02 20:49:07 +01:00
if Global.live != 1 && ishud:
get_tree().root.remove_child(thud)
get_tree().root.remove_child(tcontrol)
ishud = false
elif Global.live == 1 && !ishud:
call_deferred("_thud")
call_deferred("_tcontrol")
ishud = true
2024-12-02 02:45:44 +01:00
if Global.isresume:
Global.isresume = false
_pausemenu()
2024-01-20 14:58:29 +01:00
var velocity = Vector2.ZERO
2024-09-06 02:16:49 +02:00
if (Global.live > 4 && Global.live < 9) || Global.live == 2:
2024-06-15 23:11:43 +02:00
_exit()
#velocity = (Vector2.RIGHT.rotated(rotation) * -100 * Global.xm * delta)-Vector2.UP.rotated(rotation) * -100 * Global.ym * delta
func _input(event):
2024-12-02 02:45:44 +01:00
if ismgamepad && (event is InputEventJoypadButton || Input.is_key_pressed(KEY_ENTER) || Input.is_action_just_pressed("mclick")):
2024-11-14 23:25:32 +01:00
ismgamepad = false
get_tree().root.remove_child(mgamepad)
Global.live = 1
2024-08-16 22:54:37 +02:00
gamepadtest.new(event)
2024-12-02 20:49:07 +01:00
if Input.is_action_just_pressed("Pause") && (Global.live == 1 || Global.live == 4):
2024-06-15 23:11:43 +02:00
_pausemenu()
#Global.exitgame = true
2024-05-07 00:57:20 +02:00
if Global.live == 1 && Input.is_action_pressed("schar") && Input.is_action_just_pressed("ui_up"):
2024-01-27 21:10:58 +01:00
if Global.debug:
2024-09-06 02:16:49 +02:00
if Global.dparty[0][0] != null && Global.dstats[Global.dparty[0][0]][0] > 0:
2024-01-27 21:10:58 +01:00
Global.dcpchar = 0
else:
2024-09-06 02:16:49 +02:00
if Global.party[0][0] != null && Global.cstats[Global.party[0][0]][0] > 0:
2024-01-27 21:10:58 +01:00
Global.cpchar = 0
2024-05-07 00:57:20 +02:00
elif Global.live == 1 && Input.is_action_pressed("schar") && Input.is_action_just_pressed("ui_right"):
2024-01-27 21:10:58 +01:00
if Global.debug:
2024-09-06 02:16:49 +02:00
if Global.dparty[1][0] != null && Global.dstats[Global.dparty[1][0]][0] > 0:
2024-01-27 21:10:58 +01:00
Global.dcpchar = 1
else:
2024-09-06 02:16:49 +02:00
if Global.party[1][0] != null && Global.cstats[Global.party[1][0]][0] > 0:
2024-01-27 21:10:58 +01:00
Global.cpchar = 1
2024-05-07 00:57:20 +02:00
elif Global.live == 1 && Input.is_action_pressed("schar") && Input.is_action_just_pressed("ui_down"):
2024-01-27 21:10:58 +01:00
if Global.debug:
2024-09-06 02:16:49 +02:00
if Global.dparty[2][0] != null && Global.dstats[Global.dparty[2][0]][0] > 0:
2024-01-27 21:10:58 +01:00
Global.dcpchar = 2
else:
2024-09-06 02:16:49 +02:00
if Global.party[2][0] != null && Global.cstats[Global.party[2][0]][0] > 0:
2024-01-27 21:10:58 +01:00
Global.cpchar = 2
2024-05-07 00:57:20 +02:00
elif Global.live == 1 && Input.is_action_pressed("schar") && Input.is_action_just_pressed("ui_left"):
2024-01-27 21:10:58 +01:00
if Global.debug:
2024-09-06 02:16:49 +02:00
if Global.dparty[3][0] != null && Global.dstats[Global.dparty[3][0]][0] > 0:
2024-01-27 21:10:58 +01:00
Global.dcpchar = 3
else:
2024-09-06 02:16:49 +02:00
if Global.party[3][0] != null && Global.cstats[Global.party[3][0]][0] > 0:
2024-01-27 21:10:58 +01:00
Global.cpchar = 3
2024-01-27 23:38:20 +01:00
if Global.bossready:
Global.bossready = false
sfx1.stream = load(Global.sfxtracks[1])
sfx1.play(0)
bgsound.play(0)
2024-05-15 23:53:24 +02:00
func _statrebase():
if Global.debug:
for i in 4:
if Global.dparty[i][0] != null:
for j in 7:
Global.mstats[Global.dparty[i][0]][j] = Global.basestats[Global.dparty[i][0]][j] * Global.dlevel[Global.dparty[i][0]]
2024-09-06 02:16:49 +02:00
Global.cstats[Global.dparty[i][0]][j] = Global.basestats[Global.dparty[i][0]][j] * Global.dlevel[Global.dparty[i][0]]
2024-05-15 23:53:24 +02:00
else:
for i in 4:
if Global.party[i][0] != null:
for j in 7:
2024-09-06 02:16:49 +02:00
Global.mstats[Global.party[i][0]][j] = Global.basestats[Global.party[i][0]][j] * Global.level[Global.party[i][0]]
Global.cstats[Global.party[i][0]][j] = Global.basestats[Global.party[i][0]][j] * Global.level[Global.party[i][0]]
2024-06-11 23:36:12 +02:00
func _pausemenu():
2024-06-15 23:11:43 +02:00
if Global.live == 1 && !ispaused:
2024-06-11 23:36:12 +02:00
get_tree().root.remove_child(bhud)
2024-11-04 00:29:58 +01:00
call_deferred("_pmenu")
2024-06-15 23:11:43 +02:00
ispaused = true
Global.live = 4
elif Global.live == 4 && ispaused:
get_tree().root.remove_child(pmenu)
2024-11-04 00:29:58 +01:00
call_deferred("_bhud")
2024-06-15 23:11:43 +02:00
ispaused = false
2024-11-04 00:29:58 +01:00
pmenu = load("res://levels/ui/pause.tscn").instance()
2024-06-15 23:11:43 +02:00
Global.live = 1
2024-06-11 23:36:12 +02:00
func _exit():
2024-08-05 00:33:57 +02:00
Global.cdialog = []
2024-06-15 23:11:43 +02:00
Global.exitgame = false
2024-06-11 23:36:12 +02:00
ishud = false
Global.bossready = false
Global.cboss = [null, null, null]
2024-07-05 18:53:41 +02:00
#if Global.live == 4:
2024-12-02 02:07:54 +01:00
get_tree().root.remove_child(tcontrol)
2024-07-05 18:53:41 +02:00
get_tree().root.remove_child(pmenu)
#else:
# get_tree().root.remove_child(thud)
# get_tree().root.remove_child(bhud)
2024-06-15 23:11:43 +02:00
#get_tree().root.remove_child(player)
2024-06-11 23:36:12 +02:00
get_tree().root.remove_child(level)
2024-07-16 02:22:33 +02:00
if Global.live == 7:
2024-11-04 00:29:58 +01:00
get_tree().change_scene("res://backgounds/result.tscn")
2024-07-16 02:22:33 +02:00
elif Global.live == 8:
2024-11-04 00:29:58 +01:00
get_tree().change_scene("res://levels/ui/Cutscenes.tscn")
2024-09-06 02:16:49 +02:00
elif Global.live == 5:
2024-09-26 22:06:33 +02:00
Global.result = [0, 0, 0, 0, 0]
2024-09-06 02:16:49 +02:00
_statrebase()
2024-11-04 00:29:58 +01:00
get_tree().change_scene("res://backgounds/warp.tscn")
2024-09-06 02:16:49 +02:00
elif Global.live == 2:
2024-09-26 22:06:33 +02:00
Global.result = [0, 0, 0, 0, 0]
2024-09-06 02:16:49 +02:00
_statrebase()
get_tree().root.remove_child(thud)
2024-11-04 00:29:58 +01:00
get_tree().change_scene("res://backgounds/gameover.tscn")
2024-07-16 02:22:33 +02:00
elif Global.live == 6:
2024-09-26 22:06:33 +02:00
Global.result = [0, 0, 0, 0, 0]
2024-07-16 02:22:33 +02:00
if Global.debug:
Global.live = 0
2024-11-04 00:29:58 +01:00
get_tree().change_scene("res://levels/ui/scene.tscn")
2024-07-16 02:22:33 +02:00
else:
Global.live = 0
2024-11-04 00:29:58 +01:00
get_tree().change_scene("res://title.tscn")
2024-11-14 23:25:32 +01:00
func _on_joy_connection_changed(device_id, connected):
if !ismgamepad && !connected && Global.gamepad != 0 && Global.live == 1:
ismgamepad = true
Global.live = 4
call_deferred("_mgamepad")
2024-11-04 00:29:58 +01:00
func _level():
get_tree().root.add_child(level)
func _thud():
get_tree().root.add_child(thud)
func _bhud():
get_tree().root.add_child(bhud)
func _pmenu():
get_tree().root.add_child(pmenu)
2024-11-14 23:25:32 +01:00
func _mgamepad():
get_tree().root.add_child(mgamepad)
2024-12-02 02:07:54 +01:00
func _tcontrol():
get_tree().root.add_child(tcontrol)