Skip to content

Commit

Permalink
Merge pull request #10 from forerunnergames/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
knightofiam authored Apr 21, 2021
2 parents 257ec55 + e41c9d8 commit 65bdc3e
Show file tree
Hide file tree
Showing 18 changed files with 1,079 additions and 742 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
godot_export_templates_download_url: https://downloads.tuxfamily.org/godotengine/${{env.GODOT_MONO_URL_VERSION}}/mono/Godot_v${{env.GODOT_MONO_FILE_VERSION}}_mono_export_templates.tpz
relative_project_path: ./
archive_export_output: true
create_release: false
create_release: true
base_version: 0.0.1
- name: upload executables
uses: actions/upload-artifact@v2
with:
name: executables
path: ~/.local/share/godot/dist/*.zip
path: ~/.local/share/godot/dist/*.zip
51 changes: 41 additions & 10 deletions Cliffs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,39 @@ public class Cliffs : Area2D
private Vector2 _cliffsPosition;
private CollisionShape2D _cliffsCollider;
private bool _isPlayerIntersectingCliffs;
private bool _isPlayerFullyIntersectingCliffs;
private AudioStreamPlayer _audio;
private AudioStreamPlayer _music;
private TileMap _iceTileMap;
private Vector2 _topLeft;
private Vector2 _bottomRight;
private Vector2 _topRight;
private Vector2 _bottomLeft;

public override void _Ready()
{
_audio = GetNode <AudioStreamPlayer> ("../AudioStreamPlayer");
_audio.Stream = ResourceLoader.Load <AudioStream> ("res://ambience_summer.wav");
_music = GetNode <AudioStreamPlayer> ("../AudioStreamPlayer2");
_music.Stream = ResourceLoader.Load <AudioStream> ("res://music2_trimmed.wav");
LoopAudio (_audio.Stream);
LoopAudio (_music.Stream);
_cliffsCollider = GetNode <CollisionShape2D> ("CollisionShape2D");
_cliffsPosition = _cliffsCollider.GlobalPosition;
_iceTileMap = GetNode <TileMap> ("Ice");

// TODO Remove.
for (var i = 1; i < 11; ++i)
{
if (Name != "Upper Cliffs") return;
GetNode <AnimatedSprite> ("Waterfall/waterfall " + i).Play();
}

// TODO Remove.
for (var i = 1; i < 4; ++i)
{
if (Name != "Upper Cliffs") return;
GetNode <AnimatedSprite> ("Waterfall/waterfall mist " + i).Play();
}
}

// ReSharper disable once UnusedMember.Global
Expand All @@ -40,13 +63,15 @@ public void _on_cliffs_area_exited (Area2D area)

_playerArea = area;
_isPlayerIntersectingCliffs = false;
GetNode <Player> ("../Player").IsInCliffs = false;
}

public override void _Process (float delta)
{
Update();
Sounds();

if (_playerArea == null) return;
if (!_isPlayerIntersectingCliffs) return;

_playerExtents = GetExtents (_playerArea);
_cliffsExtents = GetExtents (this);
Expand All @@ -58,27 +83,33 @@ public override void _Process (float delta)
_cliffsRect.Position = _cliffsPosition - _cliffsExtents;
_cliffsRect.Size = _cliffsExtents * 2;

_isPlayerFullyIntersectingCliffs = _isPlayerIntersectingCliffs && _cliffsRect.Encloses (_playerRect);
GetNode <Player> ("../Player").IsInCliffs = _isPlayerIntersectingCliffs && _cliffsRect.Encloses (_playerRect);

var player = GetNode <KinematicBody2D> ("../Player");
player.Set ("IsIntersectingCliffs", _isPlayerIntersectingCliffs);
player.Set ("IsFullyIntersectingCliffs", _isPlayerFullyIntersectingCliffs);
_topLeft = _playerArea.GlobalPosition - _playerExtents;
_bottomRight = _playerArea.GlobalPosition + _playerExtents;
_topRight.x = _playerArea.GlobalPosition.x + _playerExtents.x;
_topRight.y = _playerArea.GlobalPosition.y - _playerExtents.y;
_bottomLeft.x = _playerArea.GlobalPosition.x - _playerExtents.x;
_bottomLeft.y = _playerArea.GlobalPosition.y + _playerExtents.y;

Sounds();
GetNode <Player> ("../Player").IsTouchingCliffIce = IsIntersectingAnyTile (_topLeft, _iceTileMap) ||
IsIntersectingAnyTile (_bottomRight, _iceTileMap) ||
IsIntersectingAnyTile (_topRight, _iceTileMap) ||
IsIntersectingAnyTile (_bottomLeft, _iceTileMap);
}

private void Sounds()
{
if (_audio.Playing) return;

_audio.Play();
if (!_audio.Playing) _audio.Play();
if (!_music.Playing) _music.Play();
}

private static Vector2 GetExtents (Area2D area)
{
var collisionShape = area.GetNode <CollisionShape2D> ("CollisionShape2D");
var collisionRect = collisionShape.Shape as RectangleShape2D;

// ReSharper disable once InvertIf
if (collisionRect == null)
{
OnWrongCollisionShape (area, collisionShape.Shape);
Expand Down
22 changes: 22 additions & 0 deletions IStateMachine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

public interface IStateMachine <T> where T : Enum
{
public delegate void TransitionAction();
public delegate bool TransitionTrigger();
public bool Is (T state);
public void OnTransitionTo (T to, TransitionAction action);
public void OnTransitionFrom (T from, TransitionAction action);
public void OnTransition (T from, T to, TransitionAction action);
public void AddTrigger (T from, T to, TransitionTrigger trigger);
public void Update();
public void To (T to);
public void ToIf (T to, bool condition);
public void Push (T to);
public void PushIf (T to, bool condition);
public void Pop();
public void PopIf (bool condition);
public void PopIf (T state);
public void PopIf (T state, bool condition);
public void Reset();
}
27 changes: 27 additions & 0 deletions Log.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using Godot;

public static class Log
{
public static Level CurrentLevel { get; set; } = Level.Info;

public enum Level
{
Off,
Warn,
Info,
Debug,
All
}

public static bool All (string message) => CurrentLevel > Level.Debug && Print (message, Level.All);
public static bool Debug (string message) => CurrentLevel > Level.Info && Print (message, Level.Debug);
public static bool Info (string message) => CurrentLevel > Level.Warn && Print (message, Level.Info);
public static bool Warn (string message) => CurrentLevel > Level.Off && Print (message, Level.Warn);

private static bool Print (string message, Level level)
{
GD.Print ($"{level}: {DateTime.Now:HH:mm:ss:ffff} ", message);
return true;
}
}
Loading

0 comments on commit 65bdc3e

Please sign in to comment.