Skip to content

Commit

Permalink
init state and shits!!!!!!!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCatYT committed Feb 24, 2024
1 parent 368a689 commit dce6708
Show file tree
Hide file tree
Showing 14 changed files with 376 additions and 135 deletions.
6 changes: 5 additions & 1 deletion assets/shared/images/gfDanceTitle.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
"versiontext":"Friday Night Funkin': Vs. Foxa 3.0",
"friday":"FNF",
"night":"Vs",
"funkin":"Foxa"
"funkin":"Foxa",
"ngtext":"newgrounds",
"noAssociate":true,
"logoHover":true,
"showThanks":true
}
74 changes: 23 additions & 51 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Main extends Sprite
width: 1280, // WINDOW width
height: 720, // WINDOW height
zoom: -1.0, // game state bounds
initialState: () -> new TitleState(), // initial game state
initialState: () -> new StartingState(), // initial game state
framerate: 60, // default framerate
skipSplash: true, // if the default flixel splash screen should be skipped
startFullscreen: false // if the game should start at fullscreen mode
Expand All @@ -61,8 +61,7 @@ class Main extends Sprite
Lib.current.addChild(new Main());
}

public function new()
{
public function new() {
super();

// Credits to MAJigsaw77 (he's the og author for this code)
Expand All @@ -75,35 +74,24 @@ class Main extends Sprite

instance = this;

if (stage != null)
{
init();
}
else
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
if (stage != null) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(?E:Event):Void
{
private function init(?E:Event):Void {
if (hasEventListener(Event.ADDED_TO_STAGE))
{
removeEventListener(Event.ADDED_TO_STAGE, init);
}

setupGame();

var timer = new haxe.Timer(1);
timer.run = function()
{
timer.run = () -> {
coloring();
if (fpsVar.textColor == 0) fpsVar.textColor = -4775566;
} // needs to be done because textcolor beco
}

private function setupGame():Void
{
private function setupGame():Void {
final stageWidth:Int = Lib.current.stage.stageWidth;
final stageHeight:Int = Lib.current.stage.stageHeight;

Expand All @@ -130,38 +118,26 @@ class Main extends Sprite
addChild(fpsVar);
Lib.current.stage.align = "tl";
Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE;
if(fpsVar != null)
fpsVar.visible = ClientPrefs.data.showFPS;
if (fpsVar != null) fpsVar.visible = ClientPrefs.data.showFPS;
#end

#if linux
var icon = Image.fromFile("icon.png");
Lib.current.stage.window.setIcon(icon);
#end

#if html5
FlxG.autoPause = false;
FlxG.mouse.visible = false;
#end
#if html5 FlxG.autoPause = FlxG.mouse.visible = false; #end

#if (CRASH_HANDLER && !hl)
Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onCrash);
#end
#if (CRASH_HANDLER && hl)
hl.Api.setErrorHandler(onCrash);
#end

#if desktop
DiscordClient.start();
#end
#if (CRASH_HANDLER && !hl) Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onCrash); #end
#if (CRASH_HANDLER && hl) hl.Api.setErrorHandler(onCrash); #end
#if desktop DiscordClient.start(); #end

// shader coords fix
FlxG.signals.gameResized.add(function (w, h) {
FlxG.signals.gameResized.add((w, h) -> {
if (FlxG.cameras != null) {
for (cam in FlxG.cameras.list) {
@:privateAccess
if (cam != null && cam.filters != null)
resetSpriteCache(cam.flashSprite);
if (cam != null && cam.filters != null) resetSpriteCache(cam.flashSprite);
}
}

Expand Down Expand Up @@ -189,27 +165,23 @@ class Main extends Sprite
var currentColor = 0;

// Event Handlers
public function coloring():Void
{
// Hippity, Hoppity, your code is now my property (from KadeEngine)
if (ClientPrefs.data.fpsRainbow)
{
public function coloring():Void {
// Hippity, Hoppity, your code is now my property (from Kade Engine)
if (ClientPrefs.data.fpsRainbow) {
fpsVar.isRainbow = true;
if (currentColor >= array.length) currentColor = 0;
currentColor = Math.round(FlxMath.lerp(0, array.length, skippedFrames / ClientPrefs.data.framerate));
(cast(Lib.current.getChildAt(0), Main)).changeFPSColor(array[currentColor]);
currentColor++;
skippedFrames++;
if (skippedFrames > ClientPrefs.data.framerate)
skippedFrames = 0;
}
else
if (skippedFrames > ClientPrefs.data.framerate) skippedFrames = 0;
} else {
fpsVar.isRainbow = false;
fpsVar.textColor = FlxColor.fromRGB(255, 255, 255);
}
}

public function changeFPSColor(color:FlxColor)
{
fpsVar.textColor = color;
}
public function changeFPSColor(color:FlxColor) fpsVar.textColor = color;

static function resetSpriteCache(sprite:Sprite):Void {
@:privateAccess {
Expand Down
14 changes: 7 additions & 7 deletions source/backend/ClientPrefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import flixel.util.FlxSave;
import flixel.input.keyboard.FlxKey;
import flixel.input.gamepad.FlxGamepadInputID;

import states.TitleState;
import states.StartingState;

// Add a variable here and it will get automatically saved
@:structInit class SaveVariables {
Expand Down Expand Up @@ -256,15 +256,15 @@ class ClientPrefs {
}

public static function reloadVolumeKeys() {
TitleState.muteKeys = keyBinds.get('volume_mute').copy();
TitleState.volumeDownKeys = keyBinds.get('volume_down').copy();
TitleState.volumeUpKeys = keyBinds.get('volume_up').copy();
StartingState.muteKeys = keyBinds.get('volume_mute').copy();
StartingState.volumeDownKeys = keyBinds.get('volume_down').copy();
StartingState.volumeUpKeys = keyBinds.get('volume_up').copy();
toggleVolumeKeys(true);
}
public static function toggleVolumeKeys(?turnOn:Bool = true)
{
FlxG.sound.muteKeys = turnOn ? TitleState.muteKeys : [];
FlxG.sound.volumeDownKeys = turnOn ? TitleState.volumeDownKeys : [];
FlxG.sound.volumeUpKeys = turnOn ? TitleState.volumeUpKeys : [];
FlxG.sound.muteKeys = turnOn ? StartingState.muteKeys : [];
FlxG.sound.volumeDownKeys = turnOn ? StartingState.volumeDownKeys : [];
FlxG.sound.volumeUpKeys = turnOn ? StartingState.volumeUpKeys : [];
}
}
59 changes: 54 additions & 5 deletions source/backend/CoolUtil.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package backend;

import flixel.FlxBasic;
import flixel.FlxObject;
//import flixel.util.FlxSave;

//import flixel.math.FlxPoint;
Expand All @@ -10,6 +11,12 @@ import lime.utils.Assets as LimeAssets;

using StringTools;

enum SlideCalcMethod
{
SIN;
COS;
}

class CoolUtil
{
public static function makeOutlinedGraphic(Width:Int, Height:Int, Color:Int, LineThickness:Int, OutlineColor:Int){
Expand Down Expand Up @@ -87,6 +94,9 @@ class CoolUtil
return daList;
}

inline public static function removeFromString(remove:String = "", string:String = "")
return string.replace(remove, "");

public static function removeDuplicates(string:Array<String>):Array<String> {
var tempArray:Array<String> = new Array<String>();
var lastSeen:String = null;
Expand Down Expand Up @@ -120,17 +130,56 @@ class CoolUtil
return endResult;
}

inline public static function dominantColor(sprite:flixel.FlxSprite):Int
/**
* Pablooooooo
* @param amplitude
* @param calcMethod
* @param slowness
* @param delayIndex
* @param offset
* @return Float
*/
public static function slideEffect(amplitude:Float, calcMethod:SlideCalcMethod, slowness:Float = 1, delayIndex:Float = 0, ?offset:Float):Float
{
if (slowness < 0) slowness = 1;
var slider:Float = (FlxG.sound.music.time / 1000) * (Conductor.bpm / 60);

var slideValue:Float;

switch (calcMethod) {
case SIN: slideValue = offset + amplitude * Math.sin(((slider + delayIndex) / slowness) * Math.PI);
case COS: slideValue = offset + amplitude * Math.cos(((slider + delayIndex) / slowness) * Math.PI);
}

return slideValue;
}

inline public static function GCD(a, b)
return b == 0 ? FlxMath.absInt(a) : GCD(b, a % b);

inline public static function closest2Multiple(num:Float)
return Math.floor(num/2)*2;

public static function addZeros(v:String, length:Int, end:Bool = false) {
var r = v;
while(r.length < length)
r = end ? r + '0': '0$r';
return r;
}

public static function objectCenter(object:FlxObject, target:FlxObject, axis:FlxAxes = XY) {
if (axis == XY || axis == X) object.x = target.x + target.width / 2 - object.width / 2;
if (axis == XY || axis == Y) object.y = target.y + target.height / 2 - object.height / 2;
}

inline public static function dominantColor(sprite:flixel.FlxSprite):Int {
final countByColor:Map<Int, Int> = [];
for(col in 0...sprite.frameWidth) {
for(row in 0...sprite.frameHeight) {
final colorOfThisPixel:Int = sprite.pixels.getPixel32(col, row);
if(colorOfThisPixel != 0) {
if(countByColor.exists(colorOfThisPixel))
countByColor[colorOfThisPixel] = countByColor[colorOfThisPixel] + 1;
else if(countByColor[colorOfThisPixel] != 13520687 - (2*13520687))
countByColor[colorOfThisPixel] = 1;
if(countByColor.exists(colorOfThisPixel)) countByColor[colorOfThisPixel] = countByColor[colorOfThisPixel] + 1;
else if(countByColor[colorOfThisPixel] != 13520687 - (2*13520687)) countByColor[colorOfThisPixel] = 1;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions source/cutscenes/DialogueBoxPsych.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import objects.TypedAlphabet;
import cutscenes.DialogueCharacter;
import psychlua.LuaUtils;

// Gonna try to kind of make it compatible to Forever Engine,
// love u Shubs no homo :flushedh4:
typedef DialogueFile =
{
var dialogue:Array<DialogueLine>;
Expand Down
6 changes: 6 additions & 0 deletions source/import.hx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ import objects.Alphabet;
import objects.BGSprite;
import states.PlayState;
import states.LoadingState;
import states.StartingState;
import states.FreeplayState;
import states.SaveFileState;
import states.CreditsState;
import states.MainMenuState;
import states.CharacterSelectionState;

// Flixel
#if (flixel >= "5.3.0")
Expand Down
2 changes: 2 additions & 0 deletions source/openfl/display/FPS.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class FPS extends TextField
public var memoryMegas:Float = 0;
public var memoryTotal:Float = 0;

public var isRainbow:Bool= false;

public var borderSize:Int = 1;

// border code by @raltyro and @sayofthelor, taken from psike engine mcuz i
Expand Down
Loading

0 comments on commit dce6708

Please sign in to comment.