Skip to content

Commit

Permalink
brain, hurts, should, be, asleep
Browse files Browse the repository at this point in the history
* Added blank controls instance for unmaintained arrow fields.
* Gave ArrowField a controls and settings instance.
* Made the strums group a sprite group.
* Renamed setFieldPosition to setPosition.
* Made some proper downscroll support.
* Tried to fix up arrow field positioning system.
  • Loading branch information
rodney528 committed Dec 11, 2024
1 parent 7f99b1b commit f7f40ed
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 38 deletions.
5 changes: 5 additions & 0 deletions engine/source/backend/Controls.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Controls implements IFlxDestroyable {
*/
public static var p2(default, null):Controls = new Controls();

/**
* Used for arrow field's when it's not maintained by a player.
*/
public static var blank(default, null):Controls = new Controls();

// UI //
/**
* When you press left to move through ui elements
Expand Down
22 changes: 13 additions & 9 deletions engine/source/backend/system/Settings.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum abstract FpsType(String) from String to String {
/**
* The main settings for the engine.
*/
@:structInit class MainSettings {
class MainSettings {
#if MOD_SUPPORT
/**
* If true, this is like enabling soloOnlyMode in Modding.
Expand Down Expand Up @@ -105,12 +105,14 @@ enum abstract FpsType(String) from String to String {
* If true, logs with the `Warning` level won't show up.
*/
public var ignoreLogWarnings:Bool = true;

@:allow(backend.system.Settings) function new() {}
}

/**
* The settings for each player.
*/
@:structInit class PlayerSettings {
class PlayerSettings {
/**
* If true, the strums will be at the bottom of the screen instead of the top.
*/
Expand All @@ -123,7 +125,7 @@ enum abstract FpsType(String) from String to String {
/**
* Basically, do you wish for the characters to repeat their sing anim every time they hit a sustain note?
*/
public var beatLoop:Bool = true;
public var stepJitter:Bool = true;
/**
* If true, press shit all you fucking want asshole.
*/
Expand Down Expand Up @@ -158,6 +160,8 @@ enum abstract FpsType(String) from String to String {
* If true, missing a note or sustain piece will make you miss that entire note. Otherwise you can miss each note piece.
*/
public var missFullSustain:Bool = true;

@:allow(backend.system.Settings) function new() {}
}

/**
Expand All @@ -167,33 +171,33 @@ class Settings {
/**
* The current settings.
*/
public static var setup(default, set):MainSettings = {}
public static var setup(default, set):MainSettings = new MainSettings();
inline static function set_setup(value:MainSettings):MainSettings
return setup = value;
/**
* Default settings.
*/
public static var defaults(default, null):MainSettings = {}
public static var defaults(default, null):MainSettings = new MainSettings();

/**
* Player 1's settings!
*/
public static var setupP1(default, set):PlayerSettings = {}
public static var setupP1(default, set):PlayerSettings = new PlayerSettings();
inline static function set_setupP1(value:PlayerSettings):PlayerSettings
return setupP1 = value;
/**
* Default player 1 settings.
*/
public static var defaultsP1(default, null):PlayerSettings = {}
public static var defaultsP1(default, null):PlayerSettings = new PlayerSettings();

/**
* Player 2's settings!
*/
public static var setupP2(default, set):PlayerSettings = {}
public static var setupP2(default, set):PlayerSettings = new PlayerSettings();
inline static function set_setupP2(value:PlayerSettings):PlayerSettings
return setupP2 = value;
/**
* Default player settings.
*/
public static var defaultsP2(default, null):PlayerSettings = {}
public static var defaultsP2(default, null):PlayerSettings = new PlayerSettings();
}
82 changes: 64 additions & 18 deletions engine/source/objects/gameplay/ArrowField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,17 @@ class ArrowField extends BeatGroup {
* If true, this field is maintained by a player.
*/
public var isPlayer(get, never):Bool;
inline function get_isPlayer():Bool {
inline function get_isPlayer():Bool
return status != null && (status == !PlayConfig.enemyPlay || PlayConfig.enableP2) && !PlayConfig.botplay;
}

public var controls(get, never):Null<Controls>;
inline function get_controls():Null<Controls>
if (status == null) return Controls.blank;
else return status == PlayConfig.enemyPlay ? Controls.p2 : Controls.p1;
public var settings(get, never):Null<PlayerSettings>;
inline function get_settings():Null<PlayerSettings>
if (status == null) return Settings.setupP1;
else return status == PlayConfig.enemyPlay ? Settings.setupP2 : Settings.setupP1;

// signals
/**
Expand Down Expand Up @@ -110,7 +118,7 @@ class ArrowField extends BeatGroup {
/**
* The strums of the field.
*/
public var strums(default, null):BeatTypedGroup<Strum> = new BeatTypedGroup<Strum>();
public var strums(default, null):BeatTypedSpriteGroup<Strum> = new BeatTypedSpriteGroup<Strum>();
/**
* The notes of the field.
*/
Expand All @@ -121,6 +129,7 @@ class ArrowField extends BeatGroup {
public var sustains(default, null):BeatTypedGroup<BeatTypedGroup<Sustain>> = new BeatTypedGroup<BeatTypedGroup<Sustain>>();

public var noteKillRange:Float = 350;
public var strumSpacing:Float = -45;

/**
* The amount of strums in the field.
Expand All @@ -130,13 +139,18 @@ class ArrowField extends BeatGroup {
inline function set_strumCount(value:Int):Int
return strumCount = 4;//Std.int(FlxMath.bound(value, 1, 9));

override public function new(mania:Int = 4, ?singers:Array<Character>) {
override public function new(?singers:Array<Character>, mania:Int = 4) {
strumCount = mania;
super();

for (i in 0...strumCount)
strums.add(new Strum(this, i));
setFieldPosition(FlxG.width / 2, FlxG.height / 2);

strums.group.memberAdded.add((_:Strum) -> strums.members.sort((a:Strum, b:Strum) -> return FlxSort.byValues(FlxSort.ASCENDING, a.id, b.id)));
strums.group.memberRemoved.add((_:Strum) -> strums.members.sort((a:Strum, b:Strum) -> return FlxSort.byValues(FlxSort.ASCENDING, a.id, b.id)));

resetInternalPositions();
setPosition(FlxG.width / 2, FlxG.height / 2);

if (singers != null)
assignedActors = singers;
Expand All @@ -147,8 +161,6 @@ class ArrowField extends BeatGroup {
}

inline function _input():Void {
var isP2:Bool = status == PlayConfig.enemyPlay;
var controls:Controls = isP2 ? Controls.p2 : Controls.p1;
for (i => strum in strums.members)
input(
i,
Expand All @@ -174,7 +186,7 @@ class ArrowField extends BeatGroup {
controls.noteRightReleased
]
[i],
isP2 ? Settings.setupP2 : Settings.setupP1
settings
);
}

Expand Down Expand Up @@ -238,6 +250,7 @@ class ArrowField extends BeatGroup {
}

override function update(elapsed:Float):Void {
// Hopefully the on update method is temporary until I can find a better way. As on input was giving some issues.
if (isPlayer)
_input();

Expand Down Expand Up @@ -330,18 +343,51 @@ class ArrowField extends BeatGroup {
}
}

/**
* Set's the position of the strums.
* @param x The x position.
* @param y The y position.
*/
public function setFieldPosition(x:Float = 0, y:Float = 0):Void {
public var totalWidth(default, null):Float;
public function resetInternalPositions():Void {
inline function helper(a:Strum, b:Strum):Void
if (a != null && b != null)
b.x = a.x + a.width + strumSpacing;

for (i => strum in strums.members) {
strum.setPosition(x - (Note.baseWidth / 2), y);
strum.x += Note.baseWidth * i;
strum.x -= (Note.baseWidth * ((strumCount - 1) / 2));
// if (SaveManager.getOption('strumShift')) strum.x -= Note.baseWidth / 2.4;
strum.y = -strum.height / 2;
helper(strum, strums.members[i + 1]);
}

totalWidth = 0; // reset width
for (i => strum in strums.members)
totalWidth += strum.width;

totalWidth += strumSpacing * (strumCount - 1);
for (strum in strums)
strum.x -= totalWidth / 2;
}

/**
* The center x position of the field.
*/
@:isVar public var x(get, set):Float = 0;
inline function get_x():Float
return strums.x;
inline function set_x(value:Float):Float
return strums.x = value;
/**
* The center y position of the field.
*/
@:isVar public var y(get, set):Float = 0;
inline function get_y():Float
return strums.y;
inline function set_y(value:Float):Float
return strums.y = value;

/**
* Set's the center position of the strum group.
* @param x The center x position.
* @param y The center y position.
*/
inline public function setPosition(x:Float = 0, y:Float = 0):Void {
this.x = x;
this.y = y;
}

/**
Expand Down
7 changes: 1 addition & 6 deletions engine/source/objects/gameplay/Note.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class Note extends FlxSprite {
public var tail(default, null):BeatTypedGroup<Sustain> = new BeatTypedGroup<Sustain>();

// Note specific variables.
/**
* The base overall note width.
*/
public static var baseWidth(default, null):Float = 160 * 0.7;

/**
* The strum lane index.
*/
Expand Down Expand Up @@ -118,7 +113,7 @@ class Note extends FlxSprite {
strum ??= setStrum;

var distance:{position:Float, time:Float} = {position: 0, time: 0}
var scrollAngle:Float = 270;
var scrollAngle:Float = setField.settings.downscroll ? 90 : 270;

var angleDir:Float = Math.PI / 180;
angleDir = scrollAngle * angleDir;
Expand Down
10 changes: 6 additions & 4 deletions engine/source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,11 @@ class PlayState extends BeatState {
];
// TODO: @Zyflx said to tweak the y position, do it after HUD visuals are finalized.
for (i => field in fields) {
var fieldWidth:Float = Note.baseWidth * 4;
// TODO: Get ArrowField positioning working!
field.setFieldPosition((FlxG.width / 2) - (fieldWidth / 2) + (fieldWidth * i) - (fieldWidth * ((order.length - 1) / 2)), (FlxG.height / 2) - (FlxG.height / 2.2));
field.y = (FlxG.height / 2) - ((FlxG.height / 2.6) * (Settings.setupP1.downscroll ? -1 : 1));
field.x = (FlxG.width / 2) - (field.strums.width / 2);
field.x += field.strums.width * i;
field.x -= (field.strums.width * ((fields.length - 1) / 2));
field.visible = true;
}
}
Expand All @@ -458,8 +460,8 @@ class PlayState extends BeatState {
ArrowField.player = arrowFieldMapping.get(chartData.fieldSettings.player);

// position system doesn't work yet, so for now there being put on screen like this
enemyField.setFieldPosition((FlxG.width / 2) - (FlxG.width / 4), (FlxG.height / 2) - (FlxG.height / 2.2));
playerField.setFieldPosition((FlxG.width / 2) + (FlxG.width / 4), (FlxG.height / 2) - (FlxG.height / 2.2));
enemyField.setPosition((FlxG.width / 2) - (FlxG.width / 4), (FlxG.height / 2) - ((FlxG.height / 2.6) * (Settings.setupP2.downscroll ? -1 : 1)));
playerField.setPosition((FlxG.width / 2) + (FlxG.width / 4), (FlxG.height / 2) - ((FlxG.height / 2.6) * (Settings.setupP1.downscroll ? -1 : 1)));
enemyField.visible = playerField.visible = true;

countdownAssets = {
Expand Down
2 changes: 1 addition & 1 deletion setup/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Main {
static var optionalCheck:Map<String, Bool> = new Map<String, Bool>();
static var questDesc:Map<String, String> = new Map<String, String>();

static var dashes:String = '-------------------------------------------------------------------------------';
inline static var dashes:String = '-------------------------------------------------------------------------------';

public static function main():Void {
// arguments
Expand Down

0 comments on commit f7f40ed

Please sign in to comment.