Skip to content

Commit

Permalink
player => kicker, #13
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Mar 12, 2024
1 parent 2d694f3 commit 7e822ad
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion js/model/SoccerBallPhase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SoccerBallPhase extends EnumerationValue {
// The phase in which a soccer ball has not yet been displayed on the field
public static readonly INACTIVE = new SoccerBallPhase();

// The phase in which a soccer is displayed in front of the player, but has not yet been kicked
// The phase in which a soccer is displayed in front of the kicker, but has not yet been kicked
public static readonly READY = new SoccerBallPhase();

// The phase after a soccer ball has been kicked, but before it has landed
Expand Down
2 changes: 1 addition & 1 deletion js/model/SoccerModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* SoccerModel is the base class for the soccer simulation. It manages the scene models and keyboard input properties.
* It also handles the state and behavior of the soccer balls, including their interactions with the soccer field and
* players.
* soccer players (kickers).
*
* @author Marla Schulz (PhET Interactive Simulations)
*/
Expand Down
26 changes: 13 additions & 13 deletions js/model/SoccerSceneModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export default class SoccerSceneModel<T extends SoccerBall = SoccerBall> extends
}
else {

// If the soccer player that kicked that ball was still in line when the ball lands, they can leave the line now.
// If the kicker that kicked that ball was still in line when the ball lands, they can leave the line now.
if ( soccerBall.kickerProperty.value === this.getFrontKicker() ) {
this.advanceLine();
}
Expand Down Expand Up @@ -510,25 +510,25 @@ export default class SoccerSceneModel<T extends SoccerBall = SoccerBall> extends
this.timeProperty.value += dt;
this.getActiveSoccerBalls().forEach( soccerBall => soccerBall.step( dt ) );

const frontPlayer = this.getFrontKicker();
const frontKicker = this.getFrontKicker();

if ( frontPlayer ) {
if ( frontKicker ) {

if ( this.numberOfQueuedKicksProperty.value > 0 &&
this.timeProperty.value >= this.timeWhenLastBallWasKickedProperty.value + TIME_BETWEEN_RAPID_KICKS ) {

this.advanceLine();

if ( frontPlayer.kickerPhaseProperty.value === KickerPhase.READY ) {
frontPlayer.kickerPhaseProperty.value = KickerPhase.POISED;
frontPlayer.timestampWhenPoisedBeganProperty.value = this.timeProperty.value;
if ( frontKicker.kickerPhaseProperty.value === KickerPhase.READY ) {
frontKicker.kickerPhaseProperty.value = KickerPhase.POISED;
frontKicker.timestampWhenPoisedBeganProperty.value = this.timeProperty.value;
}
}

// How long has the front player been poised?
if ( frontPlayer.kickerPhaseProperty.value === KickerPhase.POISED ) {
assert && assert( typeof frontPlayer.timestampWhenPoisedBeganProperty.value === 'number', 'timestampWhenPoisedBegan should be a number' );
const elapsedTime = this.timeProperty.value - frontPlayer.timestampWhenPoisedBeganProperty.value!;
// How long has the front kicker been poised?
if ( frontKicker.kickerPhaseProperty.value === KickerPhase.POISED ) {
assert && assert( typeof frontKicker.timestampWhenPoisedBeganProperty.value === 'number', 'timestampWhenPoisedBegan should be a number' );
const elapsedTime = this.timeProperty.value - frontKicker.timestampWhenPoisedBeganProperty.value!;
if ( elapsedTime > 0.075 ) {

const soccerBall = this.soccerBalls.find( soccerBall =>
Expand All @@ -538,7 +538,7 @@ export default class SoccerSceneModel<T extends SoccerBall = SoccerBall> extends

// In fuzzing, sometimes there are no soccer balls available
if ( soccerBall ) {
this.kickBall( frontPlayer, soccerBall, true );
this.kickBall( frontKicker, soccerBall, true );
this.numberOfQueuedKicksProperty.value--;
}
}
Expand Down Expand Up @@ -568,12 +568,12 @@ export default class SoccerSceneModel<T extends SoccerBall = SoccerBall> extends
}
}

// When a ball lands, or when the next player is supposed to kick (before the ball lands), move the line forward
// When a ball lands, or when the next kicker is supposed to kick (before the ball lands), move the line forward
// and queue up the next ball as well
private advanceLine(): void {

// Allow kicking another ball while one is already in the air.
// if the previous ball was still in the air, we need to move the line forward so the next player can kick
// If the previous ball was still in the air, we need to move the line forward so the next kicker can kick.
const kickers = this.kickers.filter( kicker => kicker.kickerPhaseProperty.value === KickerPhase.KICKING );
if ( kickers.length > 0 ) {
let nextIndex = this.activeKickIndexProperty.value + 1;
Expand Down
22 changes: 11 additions & 11 deletions js/view/KickerNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023-2024, University of Colorado Boulder

/**
* Shows a cartoon representation of a soccer player which will kick a ball.
* Shows a cartoon representation of a soccer player (aka kicker) which will kick a ball.
*
* @author Chris Klusendorf (PhET Interactive Simulations)
* @author Sam Reid (PhET Interactive Simulations)
Expand Down Expand Up @@ -29,7 +29,7 @@ const SCALE = 0.645;
export default class KickerNode extends Node {
public readonly kicker: Kicker;

public constructor( kicker: Kicker, playerImageSets: KickerImageSet[], modelViewTransform: ModelViewTransform2, providedOptions?: KickerNodeOptions ) {
public constructor( kicker: Kicker, kickerImageSets: KickerImageSet[], modelViewTransform: ModelViewTransform2, providedOptions?: KickerNodeOptions ) {
super( {

// Avoid a flickering on firefox where the image temporarily disappears (even in built mode)
Expand All @@ -41,26 +41,26 @@ export default class KickerNode extends Node {
this.kicker = kicker;

// Load in standing images for all locales
const standingPortrayalImageUSA = new Image( playerImageSets[ 0 ].standing );
const standingPortrayalImageAfrica = new Image( playerImageSets[ 1 ].standing );
const standingPortrayalImageAfricaModest = new Image( playerImageSets[ 2 ].standing );
const standingPortrayalImageUSA = new Image( kickerImageSets[ 0 ].standing );
const standingPortrayalImageAfrica = new Image( kickerImageSets[ 1 ].standing );
const standingPortrayalImageAfricaModest = new Image( kickerImageSets[ 2 ].standing );

this.addChild( standingPortrayalImageUSA );
this.addChild( standingPortrayalImageAfrica );
this.addChild( standingPortrayalImageAfricaModest );

// Load in poisedToKick images for all locales
const poisedToKickPortrayalImageUSA = new Image( playerImageSets[ 0 ].poisedToKick );
const poisedToKickPortrayalAfrica = new Image( playerImageSets[ 1 ].poisedToKick );
const poisedToKickPortrayalAfricaModest = new Image( playerImageSets[ 2 ].poisedToKick );
const poisedToKickPortrayalImageUSA = new Image( kickerImageSets[ 0 ].poisedToKick );
const poisedToKickPortrayalAfrica = new Image( kickerImageSets[ 1 ].poisedToKick );
const poisedToKickPortrayalAfricaModest = new Image( kickerImageSets[ 2 ].poisedToKick );

this.addChild( poisedToKickPortrayalImageUSA );
this.addChild( poisedToKickPortrayalAfrica );
this.addChild( poisedToKickPortrayalAfricaModest );

const kickingPortrayalImageUSA = new Image( playerImageSets[ 0 ].kicking );
const kickingPortrayalAfrica = new Image( playerImageSets[ 1 ].kicking );
const kickingPortrayalAfricaModest = new Image( playerImageSets[ 2 ].kicking );
const kickingPortrayalImageUSA = new Image( kickerImageSets[ 0 ].kicking );
const kickingPortrayalAfrica = new Image( kickerImageSets[ 1 ].kicking );
const kickingPortrayalAfricaModest = new Image( kickerImageSets[ 2 ].kicking );
this.addChild( kickingPortrayalImageUSA );
this.addChild( kickingPortrayalAfrica );
this.addChild( kickingPortrayalAfricaModest );
Expand Down
2 changes: 1 addition & 1 deletion js/view/SoccerSceneView.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023-2024, University of Colorado Boulder

/**
* Depicts a single scene in which soccer balls can be kicked. This includes the soccer balls, soccer players,
* Depicts a single scene in which soccer balls can be kicked. This includes the soccer balls, soccer players (kickers),
* and drag indicator arrow. The scene is rendered in two layers to ensure the correct z-ordering.
*
* @author Sam Reid (PhET Interactive Simulations)
Expand Down

0 comments on commit 7e822ad

Please sign in to comment.