If you think the Android project Hungry-Mouse 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
//Name: Rewards.java
//Purpose: all the attributes and functions of the rewards like collision and rewards collected
//www.java2s.compackage com.hungry.mouse.main;
import java.util.ArrayList;
import android.graphics.Rect;//hold 4 integer coordinates for rectangle
publicclass Rewards {
//local variables
privateint power, centerX, speedX, centerY;
privateint movementSpeed;
private Background bg = GameScreen.getBg1();
private Mouse Mouse = GameScreen.getMouse();
public Rect r = new Rect(0, 0, 0, 0);
publicboolean collected=false;
//Behavioral Method, update coordinates and intersects
publicvoid update() {
centerX += speedX;
speedX = bg.getSpeedX() * 5 + movementSpeed;
r.set(centerX - 25, centerY - 25, centerX + 25, centerY + 35);
if (Rect.intersects(r, Mouse.yellowRed)) {
checkCollision();
}
}
//check if mouse and reward had collision
privatevoid checkCollision() {
if (Rect.intersects(r, Mouse.rect)|| Rect.intersects(r, Mouse.rect2) || Rect.intersects(r, Mouse.rect3) || Rect.intersects(r, Mouse.rect4)) {
Mouse.addCollectedCheeses(1);
this.collected=true;
this.setCenterX(-100);
if (Settings.soundEnabled)
Assets.collect.play(1);
}
}
//when background moves, the enemy must move to the same direction
public Background getBg() {
return bg;
}
publicvoid setBg(Background bg) {
this.bg = bg;
}
//getters//
publicboolean getColleceted(){
return collected;
}
publicint getCenterX() {
return centerX;
}
publicint getCenterY() {
return centerY;
}
//setters//
publicvoid setCenterX(int centerX) {
this.centerX = centerX;
}
publicvoid setCenterY(int centerY) {
this.centerY = centerY;
}
}