midori-school/levels/ui/gameplay.gd

152 lines
5.4 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-01-27 23:38:20 +01:00
var bhud = load("res://levels/bottomhud.tscn").instantiate()
2024-01-30 04:05:17 +01:00
var thud = load("res://levels/ui/tophud.tscn").instantiate()
2024-06-09 00:09:54 +02:00
var pmenu = load("res://levels/ui/pause.tscn").instantiate()
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-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:
level = load(Global.places[Global.dplace[0]][Global.dplace[1]][Global.dplace[2]][0]).instantiate()
2024-01-27 21:10:58 +01:00
#player = load(Global.pchars[Global.dcpchar]).instantiate()
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:
level = load(Global.places[Global.cplace[0]][Global.cplace[1]][Global.cplace[2]][0]).instantiate()
2024-01-27 21:10:58 +01:00
# player = load(Global.pchars[Global.cpchar]).instantiate()
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)
get_tree().root.add_child.call_deferred(level)
2024-01-27 23:38:20 +01:00
get_tree().root.add_child.call_deferred(bhud)
2024-01-30 04:05:17 +01:00
get_tree().root.add_child.call_deferred(thud)
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-07-14 23:55:40 +02:00
bgsound.bus = &"Music"
bgsound.mix_target = 1
sfx1.mix_target = 1
sfx1.bus = &"SFX1"
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-01-20 14:58:29 +01:00
var velocity = Vector2.ZERO
2024-07-16 02:22:33 +02:00
if Global.live > 4 && Global.live < 9:
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-08-16 22:54:37 +02:00
gamepadtest.new(event)
2024-06-11 23:36:12 +02:00
if Input.is_action_just_pressed("Pause") && Global.cdialog == []:
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-03-06 18:49:01 +01:00
if Global.dparty[0][0] != null:
2024-01-27 21:10:58 +01:00
Global.dcpchar = 0
else:
2024-03-06 18:49:01 +01:00
if Global.party[0][0] != null:
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-03-06 18:49:01 +01:00
if Global.dparty[1][0] != null:
2024-01-27 21:10:58 +01:00
Global.dcpchar = 1
else:
2024-03-06 18:49:01 +01:00
if Global.party[1][0] != null:
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-03-06 18:49:01 +01:00
if Global.dparty[2][0] != null:
2024-01-27 21:10:58 +01:00
Global.dcpchar = 2
else:
2024-03-06 18:49:01 +01:00
if Global.party[2][0] != null:
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-03-06 18:49:01 +01:00
if Global.dparty[3][0] != null:
2024-01-27 21:10:58 +01:00
Global.dcpchar = 3
else:
2024-03-06 18:49:01 +01:00
if Global.party[3][0] != null:
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-06-09 00:09:54 +02:00
if Global.live != 1 && ishud:
2024-01-30 04:05:17 +01:00
get_tree().root.remove_child(thud)
ishud = false
2024-06-09 00:09:54 +02:00
elif Global.live == 1 && !ishud:
2024-01-30 04:05:17 +01:00
get_tree().root.add_child.call_deferred(thud)
ishud = true
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]]
else:
for i in 4:
if Global.party[i][0] != null:
for j in 7:
Global.mstats[Global.party[i][0]][j] = Global.basestats[Global.party[i][0]][j] * Global.level[Global.dparty[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-06-15 23:11:43 +02:00
get_tree().root.add_child.call_deferred(pmenu)
ispaused = true
Global.live = 4
elif Global.live == 4 && ispaused:
get_tree().root.remove_child(pmenu)
2024-06-11 23:36:12 +02:00
get_tree().root.add_child.call_deferred(bhud)
2024-06-15 23:11:43 +02:00
ispaused = false
2024-06-17 23:08:25 +02:00
pmenu = load("res://levels/ui/pause.tscn").instantiate()
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:
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:
get_tree().change_scene_to_file("res://backgounds/result.tscn")
elif Global.live == 8:
get_tree().change_scene_to_file("res://levels/ui/Cutscenes.tscn")
elif Global.live == 6:
if Global.debug:
Global.live = 0
get_tree().change_scene_to_file("res://levels/ui/scene.tscn")
else:
Global.live = 0
get_tree().change_scene_to_file("res://title.tscn")