Add comments
This commit is contained in:
parent
79ada53ec0
commit
1425b74bd7
@ -4,6 +4,7 @@ import com.annimon.jecp.Graphics;
|
||||
import com.annimon.jecp.Image;
|
||||
|
||||
/**
|
||||
* Draws background by separate layers.
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class Background {
|
||||
|
@ -27,6 +27,7 @@ public class Enemy {
|
||||
|
||||
public boolean isCollide(int sx, int sy) {
|
||||
if (inRange(sx, x, x + enemyWidth) && inRange(sy, y, y + enemyHeight)) {
|
||||
// If bullet collide enemy - hide them.
|
||||
visible = false;
|
||||
return true;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.annimon.militaryhero;
|
||||
import com.annimon.jecp.Graphics;
|
||||
|
||||
/**
|
||||
* Class for game states.
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class GameState {
|
||||
|
@ -4,6 +4,7 @@ import com.annimon.jecp.Image;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Simply image loader.
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class ImageLoader {
|
||||
@ -14,6 +15,11 @@ public class ImageLoader {
|
||||
OBSTACLES = "obstacles.png",
|
||||
ENEMY = "enemy.png";
|
||||
|
||||
/**
|
||||
* Load image without checking file existing.
|
||||
* @param name image name with extension.
|
||||
* @return Image object or null.
|
||||
*/
|
||||
public static Image load(String name) {
|
||||
try {
|
||||
return Image.createImage("res/" + name);
|
||||
|
@ -4,13 +4,14 @@ import com.annimon.jecp.InputListener;
|
||||
import com.annimon.jecp.Keys;
|
||||
|
||||
/**
|
||||
*
|
||||
* Processing keys and pointer actions.
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public abstract class InputProcessor implements InputListener {
|
||||
|
||||
public static final int LEFT = 0, UP = 1, RIGHT = 2, DOWN = 3, FIRE = 4;
|
||||
|
||||
/** Stores dpad-keys pressed state */
|
||||
private final boolean[] dpadState;
|
||||
|
||||
public InputProcessor() {
|
||||
|
@ -6,10 +6,12 @@ import com.annimon.jecp.Jecp;
|
||||
import com.annimon.jecp.Keys;
|
||||
|
||||
/**
|
||||
* Main loop.
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class MainApp extends InputProcessor implements ApplicationListener {
|
||||
|
||||
/** Coords for enemies */
|
||||
private static final int[] COORD = {
|
||||
6, 321, 49, 318, 100, 228, 145, 259, 230, 356,
|
||||
86, 375, 365, 325, 344, 232, 296, 296, 457, 355,
|
||||
@ -50,12 +52,14 @@ public class MainApp extends InputProcessor implements ApplicationListener {
|
||||
for (int i = 0; i < enemies.length; i++) {
|
||||
enemies[i].draw(g);
|
||||
}
|
||||
// We need to draw enemies BEFORE obstacles.
|
||||
background.drawObstacles(g);
|
||||
aim.draw(g);
|
||||
GameState.drawState(g, width, height);
|
||||
}
|
||||
|
||||
public void onUpdate() {
|
||||
// Processing aim movings.
|
||||
if (isPressed(LEFT)) aim.move(-1, 0);
|
||||
else if (isPressed(RIGHT)) aim.move(1, 0);
|
||||
if (isPressed(UP)) aim.move(0, -1);
|
||||
@ -71,6 +75,7 @@ public class MainApp extends InputProcessor implements ApplicationListener {
|
||||
public void isFirePressed() {
|
||||
if (GameState.isEndGame()) return;
|
||||
|
||||
// Check collides with aim and recalculate remaining enemies.
|
||||
final int x = aim.getAimX();
|
||||
final int y = aim.getAimY();
|
||||
int counter = 0;
|
||||
|
@ -23,18 +23,30 @@ public class SniperAim {
|
||||
y = (height - aimHeight) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move aim by relative coordinates.
|
||||
* @param dx horizontal offset.
|
||||
* @param dy vertical offset.
|
||||
*/
|
||||
public void move(int dx, int dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
|
||||
// Check bounds horizontally.
|
||||
final int aw2 = aimWidth / 2;
|
||||
if (x < -aw2) x = -aw2;
|
||||
else if (x + aw2 > width) x = width - aw2;
|
||||
// Check bounds vertically.
|
||||
final int ah2 = aimHeight / 2;
|
||||
if (y < -ah2) y = -ah2;
|
||||
else if (y + ah2 > height) y = height - ah2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set aim to absolute coordinates.
|
||||
* @param x new horizontal position.
|
||||
* @param y new vertical position.
|
||||
*/
|
||||
public void set(int x, int y) {
|
||||
this.x = x - aimWidth / 2;
|
||||
this.y = y - aimHeight / 2;
|
||||
@ -50,6 +62,7 @@ public class SniperAim {
|
||||
|
||||
public void draw(Graphics g) {
|
||||
g.drawImage(aim, x, y);
|
||||
// Fill screen around aim image.
|
||||
g.setColor(0xFF000000);
|
||||
final int bottom = y + aimHeight;
|
||||
g.fillRect(0, 0, width, y);
|
||||
|
Loading…
Reference in New Issue
Block a user