diff --git a/Project.xml b/Project.xml index d2cac59..eeffad6 100644 --- a/Project.xml +++ b/Project.xml @@ -112,6 +112,9 @@ + + + diff --git a/README.md b/README.md index 8b06cf5..832467c 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,9 @@ This game was made with love to Newgrounds and its community. Extra love to Tom ### Kade Engine - [KadeDeveloper](https://twitter.com/KadeDeveloper) - Maintainer and lead programmer - [The contributors](https://github.com/KadeDev/Kade-Engine/graphs/contributors) + + +### Shoutouts +- [GWebDev](https://github.com/GrowtopiaFli) - Video Code +- [Rozebud](https://github.com/ThatRozebudDude) - Ideas (that I stole) +- [Puyo](https://github.com/daniel11420) - Setting up appveyor and a lot of other help \ No newline at end of file diff --git a/assets/preload/videos/daWeirdVid/dontDelete.webm b/assets/preload/videos/daWeirdVid/dontDelete.webm new file mode 100644 index 0000000..c8865c7 Binary files /dev/null and b/assets/preload/videos/daWeirdVid/dontDelete.webm differ diff --git a/docs/_includes/header.html b/docs/_includes/header.html index b5765cd..9780191 100644 --- a/docs/_includes/header.html +++ b/docs/_includes/header.html @@ -26,7 +26,7 @@ hr {

Changelogs Building - Modcharts + Modchart Documentation Guides
 


diff --git a/docs/modchart.md b/docs/modchart.md index e1fae25..cdc02ea 100644 --- a/docs/modchart.md +++ b/docs/modchart.md @@ -1,531 +1,2 @@ -# Lua Modcharts - -In the 1.4.2 release of Kade Engine, we introduced Mod Charts. Mod Charts are a way of changing gameplay without hard coded values. This is achieved by using the Lua Scripting language to create script files that run during runtime. - -Song data is located in `assets/data//`, so the Lua file containing your scripts should be located at exactly `assets/data//modchart.lua`. (replace with the name of the song. for example, `assets/data/milf/` for milf) - -If the file doesn't exist, Lua code won't be ran. - -## Examples - -Full Example - -```lua -function start (song) - print("Song: " .. song .. " @ " .. bpm .. " downscroll: " .. downscroll) -end - - -function update (elapsed) -- example https://twitter.com/KadeDeveloper/status/1382178179184422918 - local currentBeat = (songPos / 1000)*(bpm/60) - for i=0,7 do - setActorX(_G['defaultStrum'..i..'X'] + 32 * math.sin((currentBeat + i*0.25) * math.pi), i) - setActorY(_G['defaultStrum'..i..'Y'] + 32 * math.cos((currentBeat + i*0.25) * math.pi), i) - end -end - -function beatHit (beat) - -- do nothing -end - -function stepHit (step) - -- do nothing -end - -function keyPressed (key) - -- do nothing -end - -print("Mod Chart script loaded :)") -``` - -Spinning Receptor Example - -```lua -function update (elapsed) - for i=0,7 do - setActorAngle(getActorAngle(i) + 15, i) - end -end -``` - -Spinning Hud Example - -```lua -function update (elapsed) - camHudAngle = camHudAngle + 0.005 -end -``` - -Spin at a specific part of the song - -```lua -function update (elapsed) - if curStep >= 352 and curStep < 400 then - local currentBeat = (songPos / 1000)*(bpm/60) - for i=0,7 do - setActorX(_G['defaultStrum'..i..'X'] + 32 * math.sin((currentBeat + i*0.25) * math.pi), i) - setActorY(_G['defaultStrum'..i..'Y'] + 32 * math.cos((currentBeat + i*0.25) * math.pi), i) - end - else - for i=0,7 do - setActorX(_G['defaultStrum'..i..'X'],i) - setActorY(_G['defaultStrum'..i..'Y'],i) - end - end -end -``` - -Showing/Hiding receptors/the hud - -```lua -function start (song) - showOnlyStrums = true -- remove all hud elements besides notes and strums - for i=0,3 do -- fade out the first 4 receptors (the ai receptors) - tweenFadeIn(i,0,0.6) - end -end -``` - -Looping through all of the rendered notes - -```lua -for i = 0, getRenderedNotes() do -- sets all of the rendered notes to 0 0 on the x and y axsis - setRenderedNotePos(0,0,i) -end -``` - -Centering BF's Side - -```lua -function setDefault(id) - _G['defaultStrum'..id..'X'] = getActorX(id) -end - --- put this somewhere in a function - -for i = 4, 7 do -- go to the center - tweenPosXAngle(i, _G['defaultStrum'..i..'X'] - 275,getActorAngle(i) + 360, 0.6, 'setDefault') -end -``` - -Jumping Arrows Example -```lua -function stepHit (step) - if step == 1 then - setActorAccelerationY(100, 4) - end - if step == 3 then - setActorAccelerationY(100, 5) - end - if step == 5 then - setActorAccelerationY(100, 6) - end - if step == 7 then - setActorAccelerationY(100, 7) - end - for i=4,7 do - if getActorY(i) >= 100 then - setActorY(100, i) - setActorVelocityY(-100, i) - end - end -end -``` - - -### Available Hooks - -Current calls to functions include, - -| Name | Arguments | Description | -| :-----: | :------------: | :----------------------------------------------------------: | -| start | Song Name | Gets called when the song starts | -| update | Elapsed frames | Gets called every frame (after the song starts) | -| stepHit | Current Step | Gets called when ever a step hits (steps are in between beats, aka 4 steps are in a beat) | -| beatHit | Current Beat | Gets called when ever a beat hits | -| keyPressed | Key Pressed | Gets called when a key just got pressed (up, down, left, right, accept) | - - - -### Global Variables - -Kade Engine provides a list of global variables to be used in the lua scripting interface. - -| G Name | Type | Description | -| :------------------: | :---: | :----------------------------------------------------------: | -| bpm | Float | The current BPM of the song | -| fpsCap | Int | The current FPS Cap (set by the player) | -| downscroll | Bool | Whether the player is in downscroll or not | -| cameraAngle | Float | The angle that the Main Camera should be rotated | -| camHudAngle | Float | The angle that the Hud should be rotated | -| followXOffset | Float | The x offset to be added when the camera moves between a character | -| followYOffset | Float | The y offset to be added when the camera moves between a character | -| showOnlyStrums | Bool | Whether to show the Hud and Strums or only the Strums | -| strumLine1Visible | Bool | Whether to show the first strum line or not | -| strumLine2Visible | Bool | Whether to show the secondstrum line or not | -| defaultStrum0-7X | Float | (0-7 is strum0,strum1,strum2,etc) get the default X coordinate for the strum | -| defaultStrum0-7Y | Float | (0-7 is strum0,strum1,strum2,etc) get the default Y coordinate for the strum | -| defaultStrum0-7Angle | Float | (0-7 is strum0,strum1,strum2,etc) get the default Angle for the strum | -| screenWidth | Int | The width of the current gamespace | -| screenHeight | Int | The height of the current gamespace | -| hudWidth | Int | The width of the hud | -| hudHeight | Int | The height of the hud | -| scrollSpeed | Int | The current scrollspeed | -| mustHit | Bool | If the current section is a must hit section | -| strumLineY | Float | The current Strum Line Y Position | - -## Functions - -Kade Engine exposes a lot of functions that let you modify elements in the game field. - - - -To get started every sprite has an id, and there are some id's that are accessible without creating one. - -These premade id's are the following: - -| Sprite Id | Value | -| :--------: | :--------------------------------------: | -| 0-7 | Represents Receptor 0-7 | -| boyfriend | Represents the Boyfriend Actor (player1) | -| dad | Represents the Dad Actor (player2) | -| girlfriend | Represents the Girlfriend Actor | - - - -### Sprites - -##### makeSprite(string SpritePath,string SpriteId,bool DrawBehind) - -Creates a sprite out of the specified image, returns the id you gave it. - -*Note: Sprite Path is normally the FILE NAME so if your file is named `Image` it'll go to assets/data/songName/Image.png so don't include the extension* - -### Hud/Camera - -##### setHudPosition(int x, int y) - -Sets the game hud's position in space. - -##### getHudX() - -Returns the hud's x position - -##### getHudY() - -Returns the hud's y position - -##### setCamPosition(int x, int y) - -Set's the current camera's position in space - -##### getCameraX() - -Returns the current camera's x position - -##### getCameraY() - -Returns the current camera's y position - -##### setCamZoom(float zoomAmount) - -Set's the current camera's zoom - -##### setHudZoom(float zoomAmount) - -Set's the hud's zoom - -### Strumline - -##### setStrumlineY(float y) - -Set's the y position of the strumLine - -### Actors - -##### getRenderedNotes() - -Returns the amount of rendered notes. - -##### getRenderedNoteX(int id) - -Returns the x position of the rendered note id - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteY(int id) - -Returns the y position of the rendered note id - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteScaleX(int id) - -Returns the scale x of the rendered note id - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteScaleY(int id) - -Returns the scale y of the rendered note id - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteType(int id) - -Returns the note data of an note (0-3, left, down, up, right) - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteHit(int id) - -Returns whether a rendered note must be hit by the player or not - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### isSustain(int id) - -Returns whether a rendered note is a sustain note or not (if they appear as the trail) - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### isParentSustain(int id) - -Returns whether a rendered note's parrent is a sustain note or not (if they appear as the trail) - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteParentX(int id) - -Returns the current parent x of the specified rendered note's id - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteParentY(int id) - -Returns the current parent y of the specified rendered note's id - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteCalcX(int id) - -Returns what the game would normally put the specified rendered note x. - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### anyNotes() - -Returns true if there are rendered notes, and returns false if there are none - -##### getRenderedNoteStrumtime(int id) - -Returns strum time of the rendered note. - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteAlpha(int id) - -Returns the alpha of the rendered note id - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteWidth(int id) - -Returns the width of the specified rendered note. - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### getRenderedNoteAngle(int id) - -Returns the angle of the specified rendered note. - -*Note: Rendered Notes id's are special in the way that they act. 0 = closest note to any receptor, last index = the farthest away from any receptor.* - -##### setRenderedNotePos(int x, int y, int id) - -Set's the position of the rendered note id - -*Note: Setting a Rendered Note's property will stop the note from updating it's alpha & x properties* - -##### setRenderedNoteAlpha(float alpha, int id) - -Set's the alpha of the rendered note id - -*Note: Setting a Rendered Note's property will stop the note from updating it's alpha & x properties* - -##### setRenderedNoteScale(float scale, int id) - -Set's the scale of the rendered note id - -*Note: Setting a Rendered Note's property will stop the note from updating it's alpha & x properties* - -##### setRenderedNoteScaleX(float scale, int id) **Currently broken** - -Set's the scale x of the rendered note id - -*Note: Setting a Rendered Note's property will stop the note from updating it's alpha & x properties* - -##### setRenderedNoteScaleY(float scale, int id) **Currently broken** - -Set's the scale y of the rendered note id - -*Note: Setting a Rendered Note's property will stop the note from updating it's alpha & x properties* - -##### getActorX(string/int id) - -Returns the x position for the sprite id - -##### getActorY(string/int id) - -Returns the y position for the sprite id - -##### getActorScaleX(string/int id) - -Returns the scale x for the sprite id - -##### getActorScaleY(string/int id) - -Returns the scale y for the sprite id - -##### getActorAlpha(string/int id) - -Returns the alpha for the sprite id - -##### getActorAngle(string/int id) - -Returns the angle for the sprite id - -##### setActorX(int x, string/int id) - -Set's the x position for the sprite id - -##### setActorAccelerationX(int x, string/int id) - -Sets the x acceleration for the sprite id - -##### setActorDragX(int x, string/int id) - -Sets the x drag for the sprite id - -##### setActorVelocityX(int x, string/int id) - -Sets the x velocity for the sprite id - -##### setActorY(int y, string/int id) - -Set's the y position for the sprite id - -##### setActorAccelerationY(int y, string/int id) - -Sets the y acceleration for the sprite id - -##### setActorDragY(int y, string/int id) - -Sets the y drag for the sprite id - -##### setActorVelocityY(int y, string/int id) - -Sets the y velocity for the sprite id - -##### setActorAlpha(float alpha, string/int id) - -Set's the alpha for the sprite id - -##### setActorAngle(int alpha, string/int id) - -Set's the angle for the sprite id - -##### setActorScale(float scale, string/int id) - -Set's the scale for the sprite id - -##### setActorScaleXY(float scaleX, float scaleY, string/int id) - -Set's the x and y scale for the sprite id - -##### setActorFlipX(bool flip, string/int id) - -Set's the x flip for the sprite id - -##### setActorFlipY(bool flip, string/int id) - -Set's the y flip for the sprite id - -##### getActorWidth(string/int id) - -Returns the width for the sprite id - -##### getActorHeight(string/int id) - -Returns the height for the sprite id - -##### changeBoyfriendCharacter(string id) - -Changes the Boyfriend sprite to another character - -##### changeDadCharacter(string id) - -Changes the Dad sprite to another character - -##### playActorAnimation(string/int id, string anim, bool force, bool reverse) - -Plays an animation on a sprite - -### Tweens - -*Note, On Complete functions are based by the function name (and they also well get called when the tween completes)* - -##### tweenPos(string/int id, int toX, int toY, float time, string onComplete) - -Smoothly tween into a x and y position - -##### tweenPosXAngle(string/int id, int toX, float toAngle, float time, string onComplete) - -Smoothly tween into a x position and angle - -##### tweenPosYAngle(string/int id, int toY, float toAngle, float time, string onComplete) - -Smoothly tween into a y position and angle - -##### tweenAngle(string/int id, float toAngle, float time, string onComplete) - -Smoothly tween into a angle - -##### tweenFadeIn(string/int id, float toAlpha, float time, string onComplete) - -Smoothly fade in to an alpha - -##### tweenFadeOut(string/int id, float toAlpha, float time, string onComplete) - -Smoothly fade out to an alpha - - - - - -### Window & Screen - -##### getWindowX() - -Returns the window's x position - -##### getWindowY() - -Returns the window's y position - -##### getScreenWidth() - -Returns the width of the screen - -##### getScreenHeight() - -Returns the height of the screen - -##### setWindowPos(int x, int y) - -Sets the window's position - -##### resizeWindow(int width, int height) - -Resizes the window +### RELOCATED +Relocated to [here](https://github.com/KadeDev/Kade-Engine/wiki/) \ No newline at end of file diff --git a/source/Caching.hx b/source/Caching.hx new file mode 100644 index 0000000..2c6fb50 --- /dev/null +++ b/source/Caching.hx @@ -0,0 +1,128 @@ +package; + +import haxe.Exception; +import flixel.tweens.FlxEase; +import flixel.tweens.FlxTween; +import sys.FileSystem; +import sys.io.File; +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond; +import flixel.addons.transition.FlxTransitionableState; +import flixel.addons.transition.TransitionData; +import flixel.graphics.FlxGraphic; +import flixel.graphics.frames.FlxAtlasFrames; +import flixel.math.FlxPoint; +import flixel.math.FlxRect; +import flixel.util.FlxColor; +import flixel.util.FlxTimer; +import flixel.text.FlxText; + +using StringTools; + +class Caching extends MusicBeatState +{ + var toBeDone = 0; + var done = 0; + + var text:FlxText; + var kadeLogo:FlxSprite; + + override function create() + { + FlxG.mouse.visible = false; + + FlxG.worldBounds.set(0,0); + + text = new FlxText(FlxG.width / 2, FlxG.height / 2 + 300,0,"Loading..."); + text.size = 34; + text.alignment = FlxTextAlign.CENTER; + text.alpha = 0; + + kadeLogo = new FlxSprite(FlxG.width / 2, FlxG.height / 2).loadGraphic(Paths.image('KadeEngineLogo')); + kadeLogo.x -= kadeLogo.width / 2; + kadeLogo.y -= kadeLogo.height / 2 + 100; + text.y -= kadeLogo.height / 2 - 125; + text.x -= 170; + kadeLogo.setGraphicSize(Std.int(kadeLogo.width * 0.6)); + + kadeLogo.alpha = 0; + + add(kadeLogo); + add(text); + + trace('starting caching..'); + + sys.thread.Thread.create(() -> { + cache(); + }); + + + super.create(); + } + + var calledDone = false; + + override function update(elapsed) + { + + if (toBeDone != 0 && done != toBeDone) + { + var alpha = HelperFunctions.truncateFloat(done / toBeDone * 100,2) / 100; + kadeLogo.alpha = alpha; + text.alpha = alpha; + text.text = "Loading... (" + done + "/" + toBeDone + ")"; + } + + super.update(elapsed); + } + + + function cache() + { + + var images = []; + var music = []; + + trace("caching images..."); + + for (i in FileSystem.readDirectory(FileSystem.absolutePath("assets/shared/images/characters"))) + { + if (!i.endsWith(".png")) + continue; + images.push(i); + } + + trace("caching music..."); + + for (i in FileSystem.readDirectory(FileSystem.absolutePath("assets/songs"))) + { + music.push(i); + } + + toBeDone = Lambda.count(images) + Lambda.count(music); + + trace("LOADING: " + toBeDone + " OBJECTS."); + + for (i in images) + { + var replaced = i.replace(".png",""); + FlxG.bitmap.add(Paths.image("characters/" + replaced,"shared")); + trace("cached " + replaced); + done++; + } + + for (i in music) + { + FlxG.sound.cache(Paths.inst(i)); + FlxG.sound.cache(Paths.voices(i)); + trace("cached " + i); + done++; + } + + trace("Finished caching..."); + + FlxG.switchState(new TitleState()); + } + +} \ No newline at end of file diff --git a/source/GameDimensions.hx b/source/GameDimensions.hx new file mode 100644 index 0000000..db4a62a --- /dev/null +++ b/source/GameDimensions.hx @@ -0,0 +1,7 @@ +package; + +class GameDimensions +{ + public static var width:Int = 1280; + public static var height:Int = 720; +} \ No newline at end of file diff --git a/source/GlobalVideo.hx b/source/GlobalVideo.hx new file mode 100644 index 0000000..2c4f707 --- /dev/null +++ b/source/GlobalVideo.hx @@ -0,0 +1,95 @@ +package; + +import openfl.Lib; + +class GlobalVideo +{ + private static var video:VideoHandler; + private static var webm:WebmHandler; + public static var isWebm:Bool = false; + public static var isAndroid:Bool = false; + public static var daAlpha1:Float = 0.2; + public static var daAlpha2:Float = 1; + + public static function setVid(vid:VideoHandler):Void + { + video = vid; + } + + public static function getVid():VideoHandler + { + return video; + } + + public static function setWebm(vid:WebmHandler):Void + { + webm = vid; + isWebm = true; + } + + public static function getWebm():WebmHandler + { + return webm; + } + + public static function get():Dynamic + { + if (isWebm) + { + return getWebm(); + } else { + return getVid(); + } + } + + public static function calc(ind:Int):Dynamic + { + var stageWidth:Int = Lib.current.stage.stageWidth; + var stageHeight:Int = Lib.current.stage.stageHeight; + + var width:Float = GameDimensions.width; + var height:Float = GameDimensions.height; + + //trace("AH: " + stageWidth); + //trace(width); + + var ratioX:Float = height / width; + var ratioY:Float = width / height; + var appliedWidth:Float = stageHeight * ratioY; + var appliedHeight:Float = stageWidth * ratioX; + //trace(appliedWidth); + var remainingX:Float = stageWidth - appliedWidth; + var remainingY:Float = stageHeight - appliedHeight; + remainingX = remainingX / 2; + remainingY = remainingY / 2; + + appliedWidth = Std.int(appliedWidth); + appliedHeight = Std.int(appliedHeight); + + if (appliedHeight > stageHeight) + { + remainingY = 0; + appliedHeight = stageHeight; + } + + if (appliedWidth > stageWidth) + { + remainingX = 0; + appliedWidth = stageWidth; + } + + switch(ind) + { + case 0: + return remainingX; + case 1: + return remainingY; + case 2: + return appliedWidth; + case 3: + return appliedHeight; + } + + return null; + } +} \ No newline at end of file diff --git a/source/Main.hx b/source/Main.hx index 48f0fc3..e04c2f5 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -1,5 +1,7 @@ package; + +import webm.WebmPlayer; import openfl.display.BlendMode; import openfl.text.TextFormat; import openfl.display.Application; @@ -49,6 +51,8 @@ class Main extends Sprite } } + public static var webmHandler:WebmHandler; + private function init(?E:Event):Void { if (hasEventListener(Event.ADDED_TO_STAGE)) @@ -73,10 +77,8 @@ class Main extends Sprite gameHeight = Math.ceil(stageHeight / zoom); } - #if !debug - initialState = TitleState; - #end - + initialState = Caching; + game = new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen); addChild(game); diff --git a/source/ModchartState.hx b/source/ModchartState.hx index 1203ea5..02da357 100644 --- a/source/ModchartState.hx +++ b/source/ModchartState.hx @@ -1,6 +1,7 @@ // this file is for modchart things, this is to declutter playstate.hx // Lua +import openfl.display3D.textures.VideoTexture; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxAtlasFrames; #if windows @@ -417,6 +418,33 @@ class ModchartState // hud/camera + + Lua_helper.add_callback(lua,"initBackgroundVideo", function(videoName:String) { + trace('playing assets/videos/' + videoName + '.webm'); + PlayState.instance.backgroundVideo("assets/videos/" + videoName + ".webm"); + }); + + Lua_helper.add_callback(lua,"pauseVideo", function() { + if (!GlobalVideo.get().paused) + GlobalVideo.get().pause(); + }); + + Lua_helper.add_callback(lua,"resumeVideo", function() { + if (GlobalVideo.get().paused) + GlobalVideo.get().pause(); + }); + + Lua_helper.add_callback(lua,"restartVideo", function() { + GlobalVideo.get().restart(); + }); + + Lua_helper.add_callback(lua,"setVideoSpritePos", function(x:Int,y:Int) { + PlayState.instance.videoSprite.setPosition(x,y); + }); + + Lua_helper.add_callback(lua,"setVideoSpriteScale", function(scale:Float) { + PlayState.instance.videoSprite.setGraphicSize(Std.int(PlayState.instance.videoSprite.width * scale)); + }); Lua_helper.add_callback(lua,"setHudAngle", function (x:Float) { PlayState.instance.camHUD.angle = x; diff --git a/source/PlayState.hx b/source/PlayState.hx index b5107eb..e795630 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1,5 +1,6 @@ package; +import webm.WebmPlayer; import flixel.input.keyboard.FlxKey; import haxe.Exception; import openfl.geom.Matrix; @@ -1344,6 +1345,9 @@ class PlayState extends MusicBeatState case 'Bopeebo' | 'Philly Nice' | 'Blammed' | 'Cocoa' | 'Eggnog': allowedToHeadbang = true; default: allowedToHeadbang = false; } + + if (useVideo) + GlobalVideo.get().resume(); #if windows // Updating Discord Rich Presence (with Time Left) @@ -1506,16 +1510,6 @@ class PlayState extends MusicBeatState switch (Math.abs(i)) { - case 0: - babyArrow.x += Note.swagWidth * 0; - babyArrow.animation.add('static', [0]); - babyArrow.animation.add('pressed', [4, 8], 12, false); - babyArrow.animation.add('confirm', [12, 16], 24, false); - case 1: - babyArrow.x += Note.swagWidth * 1; - babyArrow.animation.add('static', [1]); - babyArrow.animation.add('pressed', [5, 9], 12, false); - babyArrow.animation.add('confirm', [13, 17], 24, false); case 2: babyArrow.x += Note.swagWidth * 2; babyArrow.animation.add('static', [2]); @@ -1526,75 +1520,85 @@ class PlayState extends MusicBeatState babyArrow.animation.add('static', [3]); babyArrow.animation.add('pressed', [7, 11], 12, false); babyArrow.animation.add('confirm', [15, 19], 24, false); + case 1: + babyArrow.x += Note.swagWidth * 1; + babyArrow.animation.add('static', [1]); + babyArrow.animation.add('pressed', [5, 9], 12, false); + babyArrow.animation.add('confirm', [13, 17], 24, false); + case 0: + babyArrow.x += Note.swagWidth * 0; + babyArrow.animation.add('static', [0]); + babyArrow.animation.add('pressed', [4, 8], 12, false); + babyArrow.animation.add('confirm', [12, 16], 24, false); } - case 'normal': - babyArrow.frames = Paths.getSparrowAtlas('NOTE_assets'); - babyArrow.animation.addByPrefix('green', 'arrowUP'); - babyArrow.animation.addByPrefix('blue', 'arrowDOWN'); - babyArrow.animation.addByPrefix('purple', 'arrowLEFT'); - babyArrow.animation.addByPrefix('red', 'arrowRIGHT'); + case 'normal': + babyArrow.frames = Paths.getSparrowAtlas('NOTE_assets'); + babyArrow.animation.addByPrefix('green', 'arrowUP'); + babyArrow.animation.addByPrefix('blue', 'arrowDOWN'); + babyArrow.animation.addByPrefix('purple', 'arrowLEFT'); + babyArrow.animation.addByPrefix('red', 'arrowRIGHT'); + + babyArrow.antialiasing = true; + babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7)); + + switch (Math.abs(i)) + { + case 0: + babyArrow.x += Note.swagWidth * 0; + babyArrow.animation.addByPrefix('static', 'arrowLEFT'); + babyArrow.animation.addByPrefix('pressed', 'left press', 24, false); + babyArrow.animation.addByPrefix('confirm', 'left confirm', 24, false); + case 1: + babyArrow.x += Note.swagWidth * 1; + babyArrow.animation.addByPrefix('static', 'arrowDOWN'); + babyArrow.animation.addByPrefix('pressed', 'down press', 24, false); + babyArrow.animation.addByPrefix('confirm', 'down confirm', 24, false); + case 2: + babyArrow.x += Note.swagWidth * 2; + babyArrow.animation.addByPrefix('static', 'arrowUP'); + babyArrow.animation.addByPrefix('pressed', 'up press', 24, false); + babyArrow.animation.addByPrefix('confirm', 'up confirm', 24, false); + case 3: + babyArrow.x += Note.swagWidth * 3; + babyArrow.animation.addByPrefix('static', 'arrowRIGHT'); + babyArrow.animation.addByPrefix('pressed', 'right press', 24, false); + babyArrow.animation.addByPrefix('confirm', 'right confirm', 24, false); + } - babyArrow.antialiasing = true; - babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7)); + default: + babyArrow.frames = Paths.getSparrowAtlas('NOTE_assets'); + babyArrow.animation.addByPrefix('green', 'arrowUP'); + babyArrow.animation.addByPrefix('blue', 'arrowDOWN'); + babyArrow.animation.addByPrefix('purple', 'arrowLEFT'); + babyArrow.animation.addByPrefix('red', 'arrowRIGHT'); - switch (Math.abs(i)) - { - case 0: - babyArrow.x += Note.swagWidth * 0; - babyArrow.animation.addByPrefix('static', 'arrowLEFT'); - babyArrow.animation.addByPrefix('pressed', 'left press', 24, false); - babyArrow.animation.addByPrefix('confirm', 'left confirm', 24, false); - case 1: - babyArrow.x += Note.swagWidth * 1; - babyArrow.animation.addByPrefix('static', 'arrowDOWN'); - babyArrow.animation.addByPrefix('pressed', 'down press', 24, false); - babyArrow.animation.addByPrefix('confirm', 'down confirm', 24, false); - case 2: - babyArrow.x += Note.swagWidth * 2; - babyArrow.animation.addByPrefix('static', 'arrowUP'); - babyArrow.animation.addByPrefix('pressed', 'up press', 24, false); - babyArrow.animation.addByPrefix('confirm', 'up confirm', 24, false); - case 3: - babyArrow.x += Note.swagWidth * 3; - babyArrow.animation.addByPrefix('static', 'arrowRIGHT'); - babyArrow.animation.addByPrefix('pressed', 'right press', 24, false); - babyArrow.animation.addByPrefix('confirm', 'right confirm', 24, false); + babyArrow.antialiasing = true; + babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7)); + + switch (Math.abs(i)) + { + case 0: + babyArrow.x += Note.swagWidth * 0; + babyArrow.animation.addByPrefix('static', 'arrowLEFT'); + babyArrow.animation.addByPrefix('pressed', 'left press', 24, false); + babyArrow.animation.addByPrefix('confirm', 'left confirm', 24, false); + case 1: + babyArrow.x += Note.swagWidth * 1; + babyArrow.animation.addByPrefix('static', 'arrowDOWN'); + babyArrow.animation.addByPrefix('pressed', 'down press', 24, false); + babyArrow.animation.addByPrefix('confirm', 'down confirm', 24, false); + case 2: + babyArrow.x += Note.swagWidth * 2; + babyArrow.animation.addByPrefix('static', 'arrowUP'); + babyArrow.animation.addByPrefix('pressed', 'up press', 24, false); + babyArrow.animation.addByPrefix('confirm', 'up confirm', 24, false); + case 3: + babyArrow.x += Note.swagWidth * 3; + babyArrow.animation.addByPrefix('static', 'arrowRIGHT'); + babyArrow.animation.addByPrefix('pressed', 'right press', 24, false); + babyArrow.animation.addByPrefix('confirm', 'right confirm', 24, false); } - - default: - babyArrow.frames = Paths.getSparrowAtlas('NOTE_assets'); - babyArrow.animation.addByPrefix('green', 'arrowUP'); - babyArrow.animation.addByPrefix('blue', 'arrowDOWN'); - babyArrow.animation.addByPrefix('purple', 'arrowLEFT'); - babyArrow.animation.addByPrefix('red', 'arrowRIGHT'); - - babyArrow.antialiasing = true; - babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7)); - - switch (Math.abs(i)) - { - case 0: - babyArrow.x += Note.swagWidth * 0; - babyArrow.animation.addByPrefix('static', 'arrowLEFT'); - babyArrow.animation.addByPrefix('pressed', 'left press', 24, false); - babyArrow.animation.addByPrefix('confirm', 'left confirm', 24, false); - case 1: - babyArrow.x += Note.swagWidth * 1; - babyArrow.animation.addByPrefix('static', 'arrowDOWN'); - babyArrow.animation.addByPrefix('pressed', 'down press', 24, false); - babyArrow.animation.addByPrefix('confirm', 'down confirm', 24, false); - case 2: - babyArrow.x += Note.swagWidth * 2; - babyArrow.animation.addByPrefix('static', 'arrowUP'); - babyArrow.animation.addByPrefix('pressed', 'up press', 24, false); - babyArrow.animation.addByPrefix('confirm', 'up confirm', 24, false); - case 3: - babyArrow.x += Note.swagWidth * 3; - babyArrow.animation.addByPrefix('static', 'arrowRIGHT'); - babyArrow.animation.addByPrefix('pressed', 'right press', 24, false); - babyArrow.animation.addByPrefix('confirm', 'right confirm', 24, false); - } } babyArrow.updateHitbox(); @@ -1706,6 +1710,9 @@ class PlayState extends MusicBeatState public static var songRate = 1.5; + public var stopUpdate = false; + public var removedVideo = false; + override public function update(elapsed:Float) { #if !debug @@ -1715,6 +1722,18 @@ class PlayState extends MusicBeatState if (FlxG.save.data.botplay && FlxG.keys.justPressed.ONE) camHUD.visible = !camHUD.visible; + + if (useVideo && GlobalVideo.get() != null && !stopUpdate) + { + if (GlobalVideo.get().ended && !removedVideo) + { + remove(videoSprite); + removedVideo = true; + } + } + + + #if windows if (executeModchart && luaModchart != null && songStarted) { @@ -1838,6 +1857,12 @@ class PlayState extends MusicBeatState if (FlxG.keys.justPressed.SEVEN) { + if (useVideo) + { + GlobalVideo.get().stop(); + remove(videoSprite); + removedVideo = true; + } #if windows DiscordClient.changePresence("Chart Editor", null, null, true); #end @@ -1883,6 +1908,13 @@ class PlayState extends MusicBeatState #if debug if (FlxG.keys.justPressed.EIGHT) { + if (useVideo) + { + GlobalVideo.get().stop(); + remove(videoSprite); + removedVideo = true; + } + FlxG.switchState(new AnimationDebug(SONG.player2)); #if windows if (luaModchart != null) @@ -2433,6 +2465,12 @@ class PlayState extends MusicBeatState function endSong():Void { + if (useVideo) + { + GlobalVideo.get().stop(); + PlayState.instance.remove(PlayState.instance.videoSprite); + } + if (!loadRep) rep.SaveReplay(saveNotes); else @@ -3066,6 +3104,66 @@ class PlayState extends MusicBeatState }); } + public var fuckingVolume:Float = 1; + public var useVideo = false; + + public static var webmHandler:WebmHandler; + + public var playingDathing = false; + + public var videoSprite:FlxSprite; + + public function backgroundVideo(source:String) // for background videos + { + useVideo = true; + + var ourSource:String = "assets/videos/daWeirdVid/dontDelete.webm"; + WebmPlayer.SKIP_STEP_LIMIT = 90; + var str1:String = "WEBM SHIT"; + webmHandler = new WebmHandler(); + webmHandler.source(ourSource); + webmHandler.makePlayer(); + webmHandler.webm.name = str1; + + GlobalVideo.setWebm(webmHandler); + + GlobalVideo.get().source(source); + GlobalVideo.get().clearPause(); + if (GlobalVideo.isWebm) + { + GlobalVideo.get().updatePlayer(); + } + GlobalVideo.get().show(); + + if (GlobalVideo.isWebm) + { + GlobalVideo.get().restart(); + } else { + GlobalVideo.get().play(); + } + + var data = webmHandler.webm.bitmapData; + + videoSprite = new FlxSprite(-470,-30).loadGraphic(data); + + videoSprite.setGraphicSize(Std.int(videoSprite.width * 1.2)); + + remove(gf); + remove(boyfriend); + remove(dad); + add(videoSprite); + add(gf); + add(boyfriend); + add(dad); + + trace('poggers'); + + if (!songStarted) + webmHandler.pause(); + else + webmHandler.resume(); + } + function noteMiss(direction:Int = 1, daNote:Note):Void { if (!boyfriend.stunned) diff --git a/source/VideoHandler.hx b/source/VideoHandler.hx new file mode 100644 index 0000000..1b01699 --- /dev/null +++ b/source/VideoHandler.hx @@ -0,0 +1,195 @@ +//This was made by GWebDev lol btw this uses actuate +package; + +import motion.Actuate; +import openfl.display.Sprite; +import openfl.events.AsyncErrorEvent; +import openfl.events.MouseEvent; +import openfl.events.NetStatusEvent; +import openfl.media.Video; +import openfl.net.NetConnection; +import openfl.net.NetStream; +import flixel.FlxG; + +using StringTools; + +class VideoHandler +{ + public var netStream:NetStream; + public var video:Video; + public var isReady:Bool = false; + public var addOverlay:Bool = false; + public var vidPath:String = ""; + public var ignoreShit:Bool = false; + + public function new() + { + isReady = false; + } + + public function source(?vPath:String):Void + { + if (vPath != null && vPath.length > 0) + { + vidPath = vPath; + } + } + + public function init1():Void + { + isReady = false; + video = new Video(); + video.visible = false; + } + + public function init2():Void + { + #if web + var netConnection = new NetConnection (); + netConnection.connect (null); + + netStream = new NetStream (netConnection); + netStream.client = { onMetaData: client_onMetaData }; + netStream.addEventListener (AsyncErrorEvent.ASYNC_ERROR, netStream_onAsyncError); + + netConnection.addEventListener (NetStatusEvent.NET_STATUS, netConnection_onNetStatus); + netConnection.addEventListener (NetStatusEvent.NET_STATUS, onPlay); + netConnection.addEventListener (NetStatusEvent.NET_STATUS, onEnd); + #end + } + + public function client_onMetaData (metaData:Dynamic) { + + video.attachNetStream (netStream); + + video.width = FlxG.width; + video.height = FlxG.height; + + } + + + public function netStream_onAsyncError (event:AsyncErrorEvent):Void { + + trace ("Error loading video"); + + } + + + public function netConnection_onNetStatus (event:NetStatusEvent):Void { + trace (event.info.code); + } + + public function play():Void + { + #if web + ignoreShit = true; + netStream.close(); + init2(); + netStream.play(vidPath); + ignoreShit = false; + #end + trace(vidPath); + } + + public function stop():Void + { + netStream.close(); + onStop(); + } + + public function restart():Void + { + play(); + onRestart(); + } + + public function update(elapsed:Float):Void + { + video.x = GlobalVideo.calc(0); + video.y = GlobalVideo.calc(1); + video.width = GlobalVideo.calc(2); + video.height = GlobalVideo.calc(3); + } + + public var stopped:Bool = false; + public var restarted:Bool = false; + public var played:Bool = false; + public var ended:Bool = false; + public var paused:Bool = false; + + public function pause():Void + { + netStream.pause(); + paused = true; + } + + public function resume():Void + { + netStream.resume(); + paused = false; + } + + public function togglePause():Void + { + if (paused) + { + resume(); + } else { + pause(); + } + } + + public function clearPause():Void + { + paused = false; + } + + public function onStop():Void + { + if (!ignoreShit) + { + stopped = true; + } + } + + public function onRestart():Void + { + restarted = true; + } + + public function onPlay(event:NetStatusEvent):Void + { + if (event.info.code == "NetStream.Play.Start") + { + played = true; + } + } + + public function onEnd(event:NetStatusEvent):Void + { + if (event.info.code == "NetStream.Play.Complete") + { + ended = true; + } + } + + public function alpha():Void + { + video.alpha = GlobalVideo.daAlpha1; + } + + public function unalpha():Void + { + video.alpha = GlobalVideo.daAlpha2; + } + + public function hide():Void + { + video.visible = false; + } + + public function show():Void + { + video.visible = true; + } +} \ No newline at end of file diff --git a/source/WebmHandler.hx b/source/WebmHandler.hx new file mode 100644 index 0000000..77b9391 --- /dev/null +++ b/source/WebmHandler.hx @@ -0,0 +1,169 @@ +package; + +import flixel.FlxG; +import openfl.display.Sprite; +#if desktop +import webm.*; +#end + +class WebmHandler +{ + #if desktop + public var webm:WebmPlayer; + public var vidPath:String = ""; + public var io:WebmIo; + public var initialized:Bool = false; + + public function new() + { + } + + public function source(?vPath:String):Void + { + if (vPath != null && vPath.length > 0) + { + vidPath = vPath; + } + } + + public function makePlayer():Void + { + io = new WebmIoFile(vidPath); + webm = new WebmPlayer(); + webm.fuck(io, false); + webm.addEventListener(WebmEvent.PLAY, function(e) { + onPlay(); + }); + webm.addEventListener(WebmEvent.COMPLETE, function(e) { + onEnd(); + }); + webm.addEventListener(WebmEvent.STOP, function(e) { + onStop(); + }); + webm.addEventListener(WebmEvent.RESTART, function(e) { + onRestart(); + }); + webm.visible = false; + initialized = true; + } + + public function updatePlayer():Void + { + io = new WebmIoFile(vidPath); + webm.fuck(io, false); + } + + public function play():Void + { + if (initialized) + { + webm.play(); + } + } + + public function stop():Void + { + if (initialized) + { + webm.stop(); + } + } + + public function restart():Void + { + if (initialized) + { + webm.restart(); + } + } + + public function update(elapsed:Float) + { + webm.x = GlobalVideo.calc(0); + webm.y = GlobalVideo.calc(1); + webm.width = GlobalVideo.calc(2); + webm.height = GlobalVideo.calc(3); + } + + public var stopped:Bool = false; + public var restarted:Bool = false; + public var played:Bool = false; + public var ended:Bool = false; + public var paused:Bool = false; + + public function pause():Void + { + webm.changePlaying(false); + paused = true; + } + + public function resume():Void + { + webm.changePlaying(true); + paused = false; + } + + public function togglePause():Void + { + if (paused) + { + resume(); + } else { + pause(); + } + } + + public function clearPause():Void + { + paused = false; + webm.removePause(); + } + + public function onStop():Void + { + stopped = true; + } + + public function onRestart():Void + { + restarted = true; + } + + public function onPlay():Void + { + played = true; + } + + public function onEnd():Void + { + trace("IT ENDED!"); + ended = true; + } + + public function alpha():Void + { + webm.alpha = GlobalVideo.daAlpha1; + } + + public function unalpha():Void + { + webm.alpha = GlobalVideo.daAlpha2; + } + + public function hide():Void + { + webm.visible = false; + } + + public function show():Void + { + webm.visible = true; + } + #else + public var webm:Sprite; + public function new() + { + trace("THIS IS ANDROID! or some shit..."); + } + #end +} \ No newline at end of file