completely rewritten with godot 4 beta

This commit is contained in:
2022-11-25 00:31:57 +01:00
parent 42d11b7fb3
commit 2e97d1fec7
38 changed files with 375 additions and 632 deletions

View File

@@ -1,19 +0,0 @@
using Godot;
using System;
public class main : Node2D
{
public override void _Ready()
{
}
public override void _Process(float delta)
{
if (Input.IsActionJustReleased("fullscreen"))
{
OS.WindowFullscreen = !OS.WindowFullscreen;
}
}
}

View File

@@ -1,45 +1,26 @@
using Godot;
using System;
public class player : KinematicBody2D
public partial class player : CharacterBody2D
{
[Export]
public int speed = 400;
[Export]
public int speed = 400;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
public override void _PhysicsProcess(float delta)
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _PhysicsProcess(double delta)
{
MoveAndCollide(new Vector2
(
Input.GetActionStrength("move_right")
- Input.GetActionStrength("move_left"),
Input.GetActionStrength("move_down")
Input.GetActionStrength("move_right")
- Input.GetActionStrength("move_left"),
Input.GetActionStrength("move_down")
- Input.GetActionStrength("move_up")
).LimitLength(1)
* speed * delta
).LimitLength(1)
* speed * (float)delta
);
}
public override void _Process(float delta)
{
//debug the grid
int currentCellID = 1;
var tilemap = GetNode<TileMap>("/root/Main/World/Foreground");
Vector2 coordinates = tilemap.WorldToMap(Position);
if (Input.IsActionJustReleased("debug"))
{
GD.Print("All Number 1 tiles: " + tilemap.GetUsedCellsById(1));
GD.Print("Player coordinate: " + coordinates);
}
if (Input.IsKeyPressed((int)KeyList.F1))
{
tilemap.SetCell((int)coordinates.x, (int)coordinates.y, -1);
}
if (Input.IsKeyPressed((int)KeyList.F2))
{
if(tilemap.GetCell((int)coordinates.x, (int)coordinates.y) == -1)
{
tilemap.SetCell((int)coordinates.x, (int)coordinates.y, currentCellID); //place offset coordinates += offset = build coordinates
}
}
}
}

View File

@@ -1,27 +0,0 @@
using Godot;
using System;
using System.Linq;
public class tilemap_foreground : TileMap
{
public override void _Process(float delta)
{
ReplaceStaticTiles(1, "debug_tile_one");
}
public void ReplaceStaticTiles(int CellID, string sceneName)
{
Vector2[] allCells = GetUsedCellsById(CellID).OfType<Vector2>().ToArray();
for(int i = 0; i < allCells.Length; i++)
{
GD.Print(allCells[i]);
SetCell((int)allCells[i].x, (int)allCells[i].y, -1);
var scene = GD.Load<PackedScene>("res://scenes/interactable_tiles/" + sceneName + ".tscn");
var instance = scene.Instance();
AddChild(instance);
var node = GetNode<Node2D>(instance.GetPath());
node.Position = allCells[i] * CellSize; //node has to be Node2D and can't be centered
GD.Print(node);
}
}
}