generated from Joalor64GH/HaxeFlixel-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09df9e4
commit b5d7e00
Showing
4 changed files
with
63 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,70 @@ | ||
package; | ||
|
||
import flixel.sound.FlxSound; | ||
import flixel.text.FlxText; | ||
import flixel.FlxState; | ||
import flixel.FlxG; | ||
|
||
class PlayState extends FlxState | ||
class PlayState extends BeatState | ||
{ | ||
var curSong:String = ''; | ||
|
||
var strumYPos:Float = 100; | ||
var noteSize:Float = 20; | ||
var music:FlxSound; | ||
var notes:Array<Note>; | ||
var currentNoteIndex:Int = 0; | ||
|
||
override public function create() | ||
{ | ||
super.create(); | ||
|
||
var text:FlxText = new FlxText(0, 0, 0, "Hello World", 64); | ||
var text:FlxText = new FlxText(0, 0, 0, "use space at the moment\nidk", 64); | ||
text.screenCenter(); | ||
add(text); | ||
|
||
for (i in 0...4) | ||
{ | ||
drawNote(400 + i * noteSize, strumYPos, noteSize); | ||
} | ||
var strumline:FlxSprite = new FlxSprite(0, FlxG.height - 20).makeGraphic(FlxG.width, 5, FlxColor.WHITE); | ||
add(strumline); | ||
|
||
music = FlxG.sound.load(Paths.music('synth'), 1); // just for testing | ||
music.play(true); | ||
|
||
notes = [ | ||
new Note(0, 1000), | ||
new Note(1000, 2000) | ||
]; | ||
|
||
for (note in notes) | ||
add(note); | ||
} | ||
|
||
override public function update(elapsed:Float) | ||
{ | ||
super.update(elapsed); | ||
} | ||
|
||
function drawNote(x:Float, y:Float, size:Float) | ||
{ | ||
var note:Note = new Note(x, y); | ||
add(note); | ||
if (currentNoteIndex < notes.length && music.position >= notes[currentNoteIndex].time) | ||
{ | ||
notes[currentNoteIndex].trigger(); | ||
currentNoteIndex++; | ||
} | ||
|
||
for (note in notes) | ||
{ | ||
note.y += 100 * elapsed; | ||
if (note.y > FlxG.height) | ||
{ | ||
note.kill(); | ||
trace('missed!'); | ||
} | ||
} | ||
|
||
if (FlxG.keys.justPressed.SPACE) | ||
{ | ||
if (currentNoteIndex < notes.length && notes[currentNoteIndex].visible) | ||
{ | ||
notes[currentNoteIndex].kill(); | ||
trace('note hit!'); | ||
} | ||
else | ||
trace('missed!'); | ||
} | ||
} | ||
} |