From 4cacc481ab6db09421525fc924600f2187178bf1 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 22 Jan 2022 20:17:36 -0700 Subject: [PATCH] add handloose --- projects/handloose/.gitignore | 1 + projects/handloose/.vscode/extensions.json | 5 + projects/handloose/.vscode/launch.json | 21 +++ projects/handloose/.vscode/settings.json | 13 ++ projects/handloose/.vscode/tasks.json | 13 ++ projects/handloose/Project.xml | 82 +++++++++ .../handloose/assets/data/data-goes-here.txt | 0 .../assets/images/images-go-here.txt | 0 .../assets/music/music-goes-here.txt | 0 .../assets/sounds/sounds-go-here.txt | 0 projects/handloose/hxformat.json | 15 ++ projects/handloose/source/AssetPaths.hx | 4 + projects/handloose/source/Main.hx | 13 ++ projects/handloose/source/TypingState.hx | 172 ++++++++++++++++++ 14 files changed, 339 insertions(+) create mode 100644 projects/handloose/.gitignore create mode 100644 projects/handloose/.vscode/extensions.json create mode 100644 projects/handloose/.vscode/launch.json create mode 100644 projects/handloose/.vscode/settings.json create mode 100644 projects/handloose/.vscode/tasks.json create mode 100644 projects/handloose/Project.xml create mode 100644 projects/handloose/assets/data/data-goes-here.txt create mode 100644 projects/handloose/assets/images/images-go-here.txt create mode 100644 projects/handloose/assets/music/music-goes-here.txt create mode 100644 projects/handloose/assets/sounds/sounds-go-here.txt create mode 100644 projects/handloose/hxformat.json create mode 100644 projects/handloose/source/AssetPaths.hx create mode 100644 projects/handloose/source/Main.hx create mode 100644 projects/handloose/source/TypingState.hx diff --git a/projects/handloose/.gitignore b/projects/handloose/.gitignore new file mode 100644 index 00000000..1f5d6409 --- /dev/null +++ b/projects/handloose/.gitignore @@ -0,0 +1 @@ +export \ No newline at end of file diff --git a/projects/handloose/.vscode/extensions.json b/projects/handloose/.vscode/extensions.json new file mode 100644 index 00000000..419972a4 --- /dev/null +++ b/projects/handloose/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "openfl.lime-vscode-extension" + ] +} diff --git a/projects/handloose/.vscode/launch.json b/projects/handloose/.vscode/launch.json new file mode 100644 index 00000000..5e9a7a19 --- /dev/null +++ b/projects/handloose/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Build + Debug", + "type": "lime", + "request": "launch" + }, + { + "name": "Debug", + "type": "lime", + "request": "launch", + "preLaunchTask": null + }, + { + "name": "Macro", + "type": "haxe-eval", + "request": "launch" + } + ] +} diff --git a/projects/handloose/.vscode/settings.json b/projects/handloose/.vscode/settings.json new file mode 100644 index 00000000..4c1a0e92 --- /dev/null +++ b/projects/handloose/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "search.exclude": { + "export/**/*.hx": true + }, + "[haxe]": { + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.codeActionsOnSave": { + "source.sortImports": true + } + }, + "haxe.enableExtendedIndentation": true +} \ No newline at end of file diff --git a/projects/handloose/.vscode/tasks.json b/projects/handloose/.vscode/tasks.json new file mode 100644 index 00000000..16a77646 --- /dev/null +++ b/projects/handloose/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "lime", + "command": "test", + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/projects/handloose/Project.xml b/projects/handloose/Project.xml new file mode 100644 index 00000000..09cef035 --- /dev/null +++ b/projects/handloose/Project.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/projects/handloose/assets/data/data-goes-here.txt b/projects/handloose/assets/data/data-goes-here.txt new file mode 100644 index 00000000..e69de29b diff --git a/projects/handloose/assets/images/images-go-here.txt b/projects/handloose/assets/images/images-go-here.txt new file mode 100644 index 00000000..e69de29b diff --git a/projects/handloose/assets/music/music-goes-here.txt b/projects/handloose/assets/music/music-goes-here.txt new file mode 100644 index 00000000..e69de29b diff --git a/projects/handloose/assets/sounds/sounds-go-here.txt b/projects/handloose/assets/sounds/sounds-go-here.txt new file mode 100644 index 00000000..e69de29b diff --git a/projects/handloose/hxformat.json b/projects/handloose/hxformat.json new file mode 100644 index 00000000..66cb3869 --- /dev/null +++ b/projects/handloose/hxformat.json @@ -0,0 +1,15 @@ +{ + "lineEnds": { + "leftCurly": "both", + "rightCurly": "both", + "objectLiteralCurly": { + "leftCurly": "after" + } + }, + "sameLine": { + "ifElse": "next", + "doWhile": "next", + "tryBody": "next", + "tryCatch": "next" + } +} diff --git a/projects/handloose/source/AssetPaths.hx b/projects/handloose/source/AssetPaths.hx new file mode 100644 index 00000000..db7ef444 --- /dev/null +++ b/projects/handloose/source/AssetPaths.hx @@ -0,0 +1,4 @@ +package; + +@:build(flixel.system.FlxAssets.buildFileReferences("assets", true)) +class AssetPaths {} diff --git a/projects/handloose/source/Main.hx b/projects/handloose/source/Main.hx new file mode 100644 index 00000000..1e58528d --- /dev/null +++ b/projects/handloose/source/Main.hx @@ -0,0 +1,13 @@ +package; + +import flixel.FlxGame; +import openfl.display.Sprite; + +class Main extends Sprite +{ + public function new() + { + super(); + addChild(new FlxGame(0, 0, TypingState, 1, 60, 60, true)); + } +} diff --git a/projects/handloose/source/TypingState.hx b/projects/handloose/source/TypingState.hx new file mode 100644 index 00000000..372a4cdd --- /dev/null +++ b/projects/handloose/source/TypingState.hx @@ -0,0 +1,172 @@ +package; + +import flixel.FlxG; +import flixel.FlxState; +import flixel.FlxSprite; +import flixel.util.FlxColor; +import flixel.input.gamepad.FlxGamepad; +import flixel.text.FlxText; + +using flixel.util.FlxSpriteUtil; + +enum ButtonBehavior +{ + Cycle(behaviors:Array); + Tab; + Control; + Backspace; + Shift; + Space; + Letter(char:String); +} + +// In DDR order: +enum ArrowDir +{ + Left; + Down; + Up; + Right; +} + +class TypingState extends FlxState +{ + var buttonIDs:Map; + var buttonBehaviors:Map; + + override public function create() + { + super.create(); + + // for now, hard-coded for the wii pad only + buttonIDs = [ + 16 => "-", 12 => "+", 7 => "B", 17 => "Up", 6 => "A", 19 => "Left", 20 => "Right", 9 => "Y", 18 => "Down", 8 => "X" + ]; + + buttonBehaviors = [ + "-" => Tab, + "+" => Control, + "B" => Cycle([ + Letter("m"), Letter("f"), Letter("w"), Letter("y"), Letter("p"), Letter("v"), Letter("b"), Letter("g"), Letter("k"), Letter("j"), Letter("q"), + Letter("x"), Letter("z")]), + "A" => Cycle([ + Letter("g"), Letter("k"), Letter("j"), Letter("q"), Letter("x"), Letter("z"), Letter("m"), Letter("f"), Letter("w"), Letter("y"), Letter("p"), + Letter("v"), Letter("b")]), + "Left" => Cycle([ + Letter("s"), + Letter("h"), + Letter("r"), + Letter("d"), + Letter("l"), + Letter("u"), + Letter("c"), + ]), + "Up" => Cycle([Letter("e"), Letter("t"), Letter("a"), Letter("o"), Letter("i"), Letter("n")]), + "Down" => Cycle([Letter("o"), Letter("i"), Letter("n"), Letter("e"), Letter("t"), Letter("a")]), + "Y" => Backspace, + "Right" => Shift, + "X" => Space + ]; + + var background = new FlxSprite(); + background.makeGraphic(1280, 720, FlxColor.BLACK); + // background.x = 0; + // background.y = 0; + + FlxSpriteUtil.beginDraw(FlxColor.WHITE); + + var spacing = 20; + var shapeSize = 100; + var x = spacing; + var y = 720 - shapeSize - spacing; + + // Split the screen into text area and dance area: + var splitX = 1280 / 2 + shapeSize; + background.drawLine(splitX, 0, splitX, 720); + // Split the left side into upper/lower: + background.drawLine(0, 720 - shapeSize - spacing * 2, splitX, 720 - shapeSize - spacing * 2); + + var bSprite = makeCircleSprite("B", x, y); + x += shapeSize + spacing; + var leftSprite = makeTriangleSprite(Left, "", x, y); + x += shapeSize + spacing; + var downSprite = makeTriangleSprite(Down, "", x, y); + x += shapeSize + spacing; + var upSprite = makeTriangleSprite(Up, "", x, y); + x += shapeSize + spacing; + var rightSprite = makeTriangleSprite(Right, "", x, y); + x += shapeSize + spacing; + var aSprite = makeCircleSprite("A", x, y); + + add(background); + add(bSprite); + add(leftSprite); + add(downSprite); + add(upSprite); + add(rightSprite); + add(aSprite); + } + + function makeTriangleSprite(dir:ArrowDir, text:String, x:Int, y:Int):FlxSprite + { + var spr = new FlxSprite(); + spr.makeGraphic(100, 100, FlxColor.TRANSPARENT, true); + FlxSpriteUtil.beginDraw(FlxColor.WHITE); + spr.drawTriangle(0, 0, 100); + + spr.angle = switch (dir) + { + case Left: + -90; + case Down: + 180; + case Up: + 0; + case Right: + 90; + }; + var text = new FlxText(text, 24); + text.angle = -spr.angle; + text.color = FlxColor.BLACK; + spr.stamp(text, 50 - Math.floor(text.width / 2), 50 - Math.floor(text.height / 2)); + + spr.x = x; + spr.y = y; + return spr; + } + + function makeCircleSprite(text:String, x:Int, y:Int):FlxSprite + { + var spr = new FlxSprite(); + spr.makeGraphic(100, 100, FlxColor.TRANSPARENT, true); + FlxSpriteUtil.beginDraw(FlxColor.WHITE); + spr.drawCircle(); + var text = new FlxText(text, 24); + text.color = FlxColor.BLACK; + spr.stamp(text, 50 - Math.floor(text.width / 2), 50 - Math.floor(text.height / 2)); + spr.x = x; + spr.y = y; + return spr; + } + + override public function update(elapsed:Float) + { + super.update(elapsed); + + // Important: can be null if there's no active gamepad yet! + var gamepad:FlxGamepad = FlxG.gamepads.lastActive; + if (gamepad != null) + { + updateGamepadInput(gamepad); + } + } + + function updateGamepadInput(gamepad:FlxGamepad):Void + { + var id = gamepad.firstJustPressedRawID(); + if (id != -1) + { + var whichButton = buttonIDs[id]; + } + } +}