Android Open Source - candy-drop Pulse






From Project

Back to project page candy-drop.

License

The source code is released under:

Copyright (c) 2014, Gregory Martin All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project candy-drop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gregfmartin.facetapper.entities;
/*from  ww  w  . j  av  a  2 s .c  om*/
/**
 * A sinusoidal wave that will trigger an action on amplitude. The wave does not operate on peak-to-peak
 * measurements. Amplitude and Frequency are not explicitly defined by the Pulse. These are left to the framework
 * to inject. The distance of the wave is fixed at 2*PI (or 360 degrees) and will loop. A Pulse also contains a
 * threshold that can be used for cases when the Frequency will not permit the measured value to reach peak
 * Amplitude.
 *
 * @author Gregory Martin
 */
public class Pulse {
    private float mAmplitude;
    private float mFrequency;
    private float mThreshold;
    private float mThresholdPercentage;
    private float mCurrentWavePoint;
    private float mCurrentWavePointValue;
    private float mWaveScope;

    public Pulse() {}

    public Pulse(float amplitude, float frequency, float thresholdPercentage, float scope) {
        mAmplitude = (float)Math.ceil(amplitude);
        mFrequency = (float)Math.ceil(frequency);
        mThreshold = 0.0F;
        mThresholdPercentage = thresholdPercentage;
        mWaveScope = scope;

        calculateThreshold();
    }

    private void calculateThreshold() {
        mThreshold = mAmplitude * mThresholdPercentage;
    }

    public void update() {
        // Move to the next measurable point in the wave
        mCurrentWavePoint = (float)Math.floor((mCurrentWavePoint + mFrequency) % mWaveScope);

        // Calculate the value on the current point in the sine wave
        mCurrentWavePointValue = (float)Math.floor(mAmplitude * (float)Math.sin(Math.toRadians(mFrequency * mCurrentWavePoint)));
    }

    public boolean isCurrentPointWithinThreshold() {
        if(mCurrentWavePointValue >= mThreshold) {
            return true;
        } else {
            return false;
        }
    }
}




Java Source Code List

com.gregfmartin.facetapper.GameCore.java
com.gregfmartin.facetapper.Main.java
com.gregfmartin.facetapper.entities.CandyBase.java
com.gregfmartin.facetapper.entities.CandyDrop.java
com.gregfmartin.facetapper.entities.Pulse.java
com.gregfmartin.facetapper.entities.Screen.java
com.gregfmartin.facetapper.entities.SplashImage.java
com.gregfmartin.facetapper.entities.Sucker.java
com.gregfmartin.facetapper.screens.ArenaScreen.java
com.gregfmartin.facetapper.screens.AssociationScreen.java
com.gregfmartin.facetapper.screens.SplashScreen.java
com.gregfmartin.facetapper.screens.TitleScreen.java
com.gregfmartin.facetapper.utils.Colour.java
com.gregfmartin.facetapper.utils.CoreUtil.java
com.gregfmartin.facetapper.utils.DevSettings.java
com.gregfmartin.facetapper.utils.Gl20Utils.java
com.gregfmartin.facetapper.utils.MathEngine.java
com.gregfmartin.facetapper.utils.StagePrep.java