Back to project page candy-drop.
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.
package com.gregfmartin.facetapper.entities; //from w w w . j a v a 2s. c o m import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; /** * Base class for all Candy that's used in the game * * @author Gregory Martin */ abstract public class CandyBase extends Actor { /** * Base falling speed for the entity. This is used as the base operand for calculating the actual * falling speed for an object of CandyBase type. */ static final protected float BASE_FALLING_SPEED = 1.5F; /** * Base rotation speed for the entity. This is used as a base operand for calculating the actual * rotation speed for an object of CandyBase type. */ static final protected float BASE_ROTATION_SPEED_LOWER = 1.2F; /** * Base rotation speed for the entity. This is mainly used as a reference point for the largest possible * rotation speed the entity could have. */ static final protected float BASE_ROTATION_SPEED_UPPER = 14.0F; /** * Base image scale for the entity. This is mainly used as a reference point for the largest possible * scale the image could be. */ static final protected float BASE_SCALE_UPPER = 0.6F; /** * Base image scale for the entity. This is mainly used as a reference point for the smallest possible * scale the image could be. */ static final protected float BASE_SCALE_LOWER = 0.4F; protected int mScore; protected float mFallingSpeed; protected float mRotationSpeed; protected float mScale; protected TextureRegion mTexture; protected boolean mAlive; protected InputListener mInputListener; protected Sound mTapSound; protected CandyBase() {} protected CandyBase(int score, float fallingSpeed, float rotationSpeed, float scale) { mScore = clipScore(score); mFallingSpeed = clipFallingSpeed(fallingSpeed); mRotationSpeed = clipRotationSpeed(rotationSpeed); mScale = clipScalar(scale); mAlive = true; mTapSound = Gdx.audio.newSound(Gdx.files.internal("se/beep.ogg")); mInputListener = new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { return handleTouchDown(event, x, y, pointer, button); } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { handleTouchUp(event, x, y, pointer, button); } }; addListener(mInputListener); generateTexture(); } public int getScorePerHit() { return mScore; } public float getFallingSpeed() { return mFallingSpeed; } public float getRotationSpeed() { return mRotationSpeed; } public float getScalar() { return mScale; } public TextureRegion getTexture() { return mTexture; } public boolean isAlive() { return mAlive; } public void setScorePerHit(int score) { mScore = score; } public void setFallingSpeed(float fallingSpeed) { mFallingSpeed = fallingSpeed; } public void setRotationSpeed(float rotationSpeed) { mRotationSpeed = rotationSpeed; } public void setScalar(float scale) { mScale = scale; } public void setAlive(boolean alive) { mAlive = alive; } public void augmentFallingSpeed(float augment) { mFallingSpeed += augment; } public void augmentRotationSpeed(float augment) { mRotationSpeed += augment; } public void augmentScale(float augment) { mScale += augment; } abstract public void generateTexture(); abstract public int clipScore(int score); abstract public float clipFallingSpeed(float fallingSpeed); abstract public float clipRotationSpeed(float rotationSpeed); abstract public float clipScalar(float scalar); abstract public boolean handleTouchDown(InputEvent event, float x, float y, int pointer, int button); abstract public void handleTouchUp(InputEvent event, float x, float y, int pointer, int button); @Override public void draw(SpriteBatch batch, float parentAlpha) { super.draw(batch, parentAlpha); batch.draw(mTexture, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation(), false); } }