Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ www-test/


## NetBeans:

/nbproject/private/
/android/nbproject/private/
/core/nbproject/private/
Expand Down Expand Up @@ -144,7 +145,7 @@ nbactions.xml
nb-configuration.xml

# VS Code
/.vscode
.vscode/

## OS-Specific:
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
api "org.mini2Dx:universal-tween-engine:$universalTweenVersion"

implementation "org.luaj:luaj-jse:3.0.1"
implementation 'org.jetbrains:annotations:15.0'

if(enableGraalNative == 'true') {
implementation "io.github.berstanio:gdx-svmhelper-annotations:$graalHelperVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TitleScreen extends FunkinScreen {
@Override
public void show() {
super.show();
tickleFight = Funkin.playSound("shared/sounds/tickleFight.ogg");
tickleFight = new FunkinSound("shared/sounds/tickleFight.ogg");
Funkin.playMusic("preload/music/freakyMenu/freakyMenu.ogg", 0.5f);
}

Expand Down
56 changes: 53 additions & 3 deletions core/src/main/java/me/stringfromjava/funkin/tween/FunkinTween.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
package me.stringfromjava.funkin.tween;

import me.stringfromjava.funkin.tween.settings.FunkinTweenSettings;

import java.lang.reflect.Field;
import java.util.ArrayList;

/**
* Core manager class for creating new tweens.
* Core class for creating new tweens to add nice and smooth animations to visual objects.
* <p>
* Note that this doesn't have to be used on sprites, it can be used on just about anything!
*/
public final class FunkinTween {
public class FunkinTween {

/**
* The global tween manager for the entire game.
*/
public static FunkinTweenManager globalManager = new FunkinTweenManager();

/**
* The object to tween.
*/
protected Object object;

/**
* The settings used for how the tween is handled and calculated (aka how it looks and animates).
*/
protected FunkinTweenSettings tweenSettings;

private final ArrayList<Field> cachedFields;

/**
* @param object The object to tween values.
* @param settings The settings that configure and determine how the tween should animate and last for.
*/
public FunkinTween(Object object, FunkinTweenSettings settings) {
this.tweenSettings = settings;
this.cachedFields = new ArrayList<>();

Field[] allFields = object.getClass().getFields();
var neededFields = settings.getGoalFields();

// Due to how costly it is using Java reflect, we cache the fields we need
// before we actually do the real tweening functionality. This is so it
// doesn't cause lag while multiple tweens are being active.
for (Field field : allFields) {
String fName = field.getName();

if (!field.trySetAccessible() && !neededFields.contains(fName)) {
continue;
}

cachedFields.add(field);
}
}

private FunkinTween() {
public FunkinTweenSettings getTweenSettings() {
return tweenSettings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.stringfromjava.funkin.tween;

import java.util.ArrayList;

/**
* Core manager class for handling all {@link FunkinTween}s that are currently active.
*/
public final class FunkinTweenManager {

/**
* A list where all current active tweens are stored.
*/
public final ArrayList<FunkinTween> activeTweens = new ArrayList<>();

public void update(float delta) {
// TODO: Iterate through every active tween and update them!
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package me.stringfromjava.funkin.tween.settings;

import me.stringfromjava.funkin.tween.FunkinTween;

/**
* Class where all easer functions are stored, mostly used for tweening.
*/
public final class FunkinTweenEase {

// Easing constants for specific functions.
private static final float PI2 = (float) Math.PI / 2;
private static final float EL = (float) ((float) 2 * Math.PI / .45);
private static final float B1 = (float) ((float) 1 / 2.75);
private static final float B2 = (float) ((float) 2 / 2.75);
private static final float B3 = (float) ((float) 1.5 / 2.75);
private static final float B4 = (float) ((float) 2.5 / 2.75);
private static final float B5 = (float) ((float) 2.25 / 2.75);
private static final float B6 = (float) ((float) 2.625 / 2.75);
private static final float ELASTIC_AMPLITUDE = 1;
private static final float ELASTIC_PERIOD = 0.4f;

private FunkinTweenEase() {
}

public static float linear(float t) {
return t;
}

public static float quadIn(float t) {
return t * t;
}

public static float quadOut(float t) {
return -t * (t - 2);
}

public static float quadInOut(float t) {
return t <= .5 ? t * t * 2 : 1 - (--t) * t * 2;
}

public static float cubeIn(float t) {
return t * t * t;
}

public static float cubeOut(float t) {
return 1 + (--t) * t * t;
}

public static float cubeInOut(float t) {
return t <= .5 ? t * t * t * 4 : 1 + (--t) * t * t * 4;
}

public static float quartIn(float t) {
return t * t * t * t;
}

public static float quartOut(float t) {
return 1 - (t -= 1) * t * t * t;
}

public static float quartInOut(float t) {
return t <= .5 ? t * t * t * t * 8 : (float) ((1 - (t = t * 2 - 2) * t * t * t) / 2 + .5);
}

public static float quintIn(float t) {
return t * t * t * t * t;
}

public static float quintOut(float t) {
return (t = t - 1) * t * t * t * t + 1;
}

public static float quintInOut(float t) {
return ((t *= 2) < 1) ? (t * t * t * t * t) / 2 : ((t -= 2) * t * t * t * t + 2) / 2;
}

public static float smoothStepIn(float t) {
return 2 * smoothStepInOut(t / 2);
}

public static float smoothStepOut(float t) {
return 2 * smoothStepInOut((float) (t / 2 + 0.5)) - 1;
}

public static float smoothStepInOut(float t) {
return t * t * (t * -2 + 3);
}

public static float smootherStepIn(float t) {
return 2 * smootherStepInOut(t / 2);
}

public static float smootherStepOut(float t) {
return 2 * smootherStepInOut((float) (t / 2 + 0.5)) - 1;
}

public static float smootherStepInOut(float t) {
return t * t * t * (t * (t * 6 - 15) + 10);
}

public static float sineIn(float t) {
return (float) (-Math.cos(PI2 * t) + 1);
}

public static float sineOut(float t) {
return (float) Math.sin(PI2 * t);
}

public static float sineInOut(float t) {
return (float) (-Math.cos(Math.PI * t) / 2 + .5);
}

public static float bounceIn(float t) {
return 1 - bounceOut(1 - t);
}

public static float bounceOut(float t) {
if (t < B1)
return (float) (7.5625 * t * t);
if (t < B2)
return (float) (7.5625 * (t - B3) * (t - B3) + .75);
if (t < B4)
return (float) (7.5625 * (t - B5) * (t - B5) + .9375);
return (float) (7.5625 * (t - B6) * (t - B6) + .984375);
}

public static float bounceInOut(float t) {
return t < 0.5
? (1 - bounceOut(1 - 2 * t)) / 2
: (1 + bounceOut(2 * t - 1)) / 2;
}

public static float circIn(float t) {
return (float) -(Math.sqrt(1 - t * t) - 1);
}

public static float circOut(float t) {
return (float) Math.sqrt(1 - (t - 1) * (t - 1));
}

public static float circInOut(float t) {
return (float) (t <= .5 ? (Math.sqrt(1 - t * t * 4) - 1) / -2 : (Math.sqrt(1 - (t * 2 - 2) * (t * 2 - 2)) + 1) / 2);
}

public static float expoIn(float t) {
return (float) Math.pow(2, 10 * (t - 1));
}

public static float expoOut(float t) {
return (float) (-Math.pow(2, -10 * t) + 1);
}

public static float expoInOut(float t) {
return (float) (t < .5 ? Math.pow(2, 10 * (t * 2 - 1)) / 2 : (-Math.pow(2, -10 * (t * 2 - 1)) + 2) / 2);
}

public static float backIn(float t) {
return (float) (t * t * (2.70158 * t - 1.70158));
}

public static float backOut(float t) {
return (float) (1 - (--t) * (t) * (-2.70158 * t - 1.70158));
}

public static float backInOut(float t) {
t *= 2;
if (t < 1)
return (float) (t * t * (2.70158 * t - 1.70158) / 2);
t--;
return (float) ((1 - (--t) * (t) * (-2.70158 * t - 1.70158)) / 2 + .5);
}

public static float elasticIn(float t) {
return (float) -(ELASTIC_AMPLITUDE * Math.pow(2,
10 * (t -= 1)) * Math.sin((t - (ELASTIC_PERIOD / (2 * Math.PI) * Math.asin(1 / ELASTIC_AMPLITUDE))) * (2 * Math.PI) / ELASTIC_PERIOD));
}

public static float elasticOut(float t) {
return (float) (ELASTIC_AMPLITUDE * Math.pow(2,
-10 * t) * Math.sin((t - (ELASTIC_PERIOD / (2 * Math.PI) * Math.asin(1 / ELASTIC_AMPLITUDE))) * (2 * Math.PI) / ELASTIC_PERIOD)
+ 1);
}

public static float elasticInOut(float t) {
if (t < 0.5) {
return (float) (-0.5 * (Math.pow(2, 10 * (t -= 0.5f)) * Math.sin((t - (ELASTIC_PERIOD / 4)) * (2 * Math.PI) / ELASTIC_PERIOD)));
}
return (float) (Math.pow(2, -10 * (t -= 0.5f)) * Math.sin((t - (ELASTIC_PERIOD / 4)) * (2 * Math.PI) / ELASTIC_PERIOD) * 0.5 + 1);
}

@FunctionalInterface
public interface FunkinTweenEaseFunction {
float compute(float t);
}

@FunctionalInterface
public interface FunkinTweenEaseStartCallback {
void run(FunkinTween tween);
}

@FunctionalInterface
public interface FunkinTweenEaseUpdateCallback {
void run(FunkinTween tween);
}

@FunctionalInterface
public interface FunkinTweenEaseCompleteCallback {
void run(FunkinTween tween);
}
}
Loading