Files
Nockin_On_Hells_Door/script/Gameboy.cs
Dukantic b32f61c50e game
2024-10-25 20:35:40 +02:00

108 lines
1.7 KiB
C#

using Godot;
using Godot.Collections;
using System;
using System.Threading.Tasks;
public partial class Gameboy : CanvasLayer
{
[Export] CharacterBody2D player;
//[Export] Array<Texture2D> image_boss;
[Export] AnimationPlayer anim;
[Export] Control Cmenu;
[Export] Label scoreLabel;
bool menu = true;
int round = -1;
int actScore = 0;
int score = 0;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Visible = false;
anim.Play("RESET");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
/*
if (Input.IsActionJustPressed("game"))
{
start();
}
else if (Input.IsActionJustPressed("game"))
{
stop();
}
*/
}
async void start()
{
await ToSignal(GetTree().CreateTimer(0.5), "timeout");
Input.MouseMode = Input.MouseModeEnum.Visible;
player.Set("pausable", false);
this.Visible = true;
}
void stop()
{
Input.MouseMode = Input.MouseModeEnum.Hidden;
player.Set("pausable", true);
this.Visible = false;
}
void attack()
{
if(round == 8 || (int)Cmenu.Get("spell") -1 >= round)
{
round = (round + 1) % 9;
anim.Play(round.ToString());
actScore++;
updateScore();
}
else
{
actScore = 0;
anim.Play("RESET");
menu = true;
}
}
public void APressed()
{
if (menu)
{
menu = false;
round = 0;
anim.Play("start");
}
else
{
attack();
}
}
public void BPressed()
{
if (menu)
{
stop();
}
else
{
menu = true;
anim.Play("RESET");
}
}
void updateScore()
{
if (actScore >= score) score = actScore;
scoreLabel.Text = "High Score : " + score.ToString();
}
}