Merge commit '1425b74bd71ecc5ec9f5056487f210068cf499e9' into 240x320
This commit is contained in:
commit
5408d89cc3
@ -4,6 +4,7 @@ import com.annimon.jecp.Graphics;
|
|||||||
import com.annimon.jecp.Image;
|
import com.annimon.jecp.Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Draws background by separate layers.
|
||||||
* @author aNNiMON
|
* @author aNNiMON
|
||||||
*/
|
*/
|
||||||
public class Background {
|
public class Background {
|
||||||
|
@ -27,6 +27,7 @@ public class Enemy {
|
|||||||
|
|
||||||
public boolean isCollide(int sx, int sy) {
|
public boolean isCollide(int sx, int sy) {
|
||||||
if (inRange(sx, x, x + enemyWidth) && inRange(sy, y, y + enemyHeight)) {
|
if (inRange(sx, x, x + enemyWidth) && inRange(sy, y, y + enemyHeight)) {
|
||||||
|
// If bullet collide enemy - hide them.
|
||||||
visible = false;
|
visible = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.annimon.militaryhero;
|
|||||||
import com.annimon.jecp.Graphics;
|
import com.annimon.jecp.Graphics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Class for game states.
|
||||||
* @author aNNiMON
|
* @author aNNiMON
|
||||||
*/
|
*/
|
||||||
public class GameState {
|
public class GameState {
|
||||||
|
@ -4,6 +4,7 @@ import com.annimon.jecp.Image;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Simply image loader.
|
||||||
* @author aNNiMON
|
* @author aNNiMON
|
||||||
*/
|
*/
|
||||||
public class ImageLoader {
|
public class ImageLoader {
|
||||||
@ -14,6 +15,11 @@ public class ImageLoader {
|
|||||||
OBSTACLES = "obstacles.png",
|
OBSTACLES = "obstacles.png",
|
||||||
ENEMY = "enemy.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) {
|
public static Image load(String name) {
|
||||||
try {
|
try {
|
||||||
return Image.createImage("res/" + name);
|
return Image.createImage("res/" + name);
|
||||||
|
@ -4,13 +4,14 @@ import com.annimon.jecp.InputListener;
|
|||||||
import com.annimon.jecp.Keys;
|
import com.annimon.jecp.Keys;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Processing keys and pointer actions.
|
||||||
* @author aNNiMON
|
* @author aNNiMON
|
||||||
*/
|
*/
|
||||||
public abstract class InputProcessor implements InputListener {
|
public abstract class InputProcessor implements InputListener {
|
||||||
|
|
||||||
public static final int LEFT = 0, UP = 1, RIGHT = 2, DOWN = 3, FIRE = 4;
|
public static final int LEFT = 0, UP = 1, RIGHT = 2, DOWN = 3, FIRE = 4;
|
||||||
|
|
||||||
|
/** Stores dpad-keys pressed state */
|
||||||
private final boolean[] dpadState;
|
private final boolean[] dpadState;
|
||||||
|
|
||||||
public InputProcessor() {
|
public InputProcessor() {
|
||||||
|
@ -6,10 +6,12 @@ import com.annimon.jecp.Jecp;
|
|||||||
import com.annimon.jecp.Keys;
|
import com.annimon.jecp.Keys;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Main loop.
|
||||||
* @author aNNiMON
|
* @author aNNiMON
|
||||||
*/
|
*/
|
||||||
public class MainApp extends InputProcessor implements ApplicationListener {
|
public class MainApp extends InputProcessor implements ApplicationListener {
|
||||||
|
|
||||||
|
/** Coords for enemies */
|
||||||
private static final int[] COORD = {
|
private static final int[] COORD = {
|
||||||
3, 160, 24, 159, 50, 114, 72, 129, 115, 178,
|
3, 160, 24, 159, 50, 114, 72, 129, 115, 178,
|
||||||
43, 187, 182, 162, 172, 116, 148, 148, 228, 177,
|
43, 187, 182, 162, 172, 116, 148, 148, 228, 177,
|
||||||
@ -50,12 +52,14 @@ public class MainApp extends InputProcessor implements ApplicationListener {
|
|||||||
for (int i = 0; i < enemies.length; i++) {
|
for (int i = 0; i < enemies.length; i++) {
|
||||||
enemies[i].draw(g);
|
enemies[i].draw(g);
|
||||||
}
|
}
|
||||||
|
// We need to draw enemies BEFORE obstacles.
|
||||||
background.drawObstacles(g);
|
background.drawObstacles(g);
|
||||||
aim.draw(g);
|
aim.draw(g);
|
||||||
GameState.drawState(g, width, height);
|
GameState.drawState(g, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
|
// Processing aim movings.
|
||||||
if (isPressed(LEFT)) aim.move(-1, 0);
|
if (isPressed(LEFT)) aim.move(-1, 0);
|
||||||
else if (isPressed(RIGHT)) aim.move(1, 0);
|
else if (isPressed(RIGHT)) aim.move(1, 0);
|
||||||
if (isPressed(UP)) aim.move(0, -1);
|
if (isPressed(UP)) aim.move(0, -1);
|
||||||
@ -71,6 +75,7 @@ public class MainApp extends InputProcessor implements ApplicationListener {
|
|||||||
public void isFirePressed() {
|
public void isFirePressed() {
|
||||||
if (GameState.isEndGame()) return;
|
if (GameState.isEndGame()) return;
|
||||||
|
|
||||||
|
// Check collides with aim and recalculate remaining enemies.
|
||||||
final int x = aim.getAimX();
|
final int x = aim.getAimX();
|
||||||
final int y = aim.getAimY();
|
final int y = aim.getAimY();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
@ -23,18 +23,30 @@ public class SniperAim {
|
|||||||
y = (height - aimHeight) / 2;
|
y = (height - aimHeight) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move aim by relative coordinates.
|
||||||
|
* @param dx horizontal offset.
|
||||||
|
* @param dy vertical offset.
|
||||||
|
*/
|
||||||
public void move(int dx, int dy) {
|
public void move(int dx, int dy) {
|
||||||
x += dx;
|
x += dx;
|
||||||
y += dy;
|
y += dy;
|
||||||
|
|
||||||
|
// Check bounds horizontally.
|
||||||
final int aw2 = aimWidth / 2;
|
final int aw2 = aimWidth / 2;
|
||||||
if (x < -aw2) x = -aw2;
|
if (x < -aw2) x = -aw2;
|
||||||
else if (x + aw2 > width) x = width - aw2;
|
else if (x + aw2 > width) x = width - aw2;
|
||||||
|
// Check bounds vertically.
|
||||||
final int ah2 = aimHeight / 2;
|
final int ah2 = aimHeight / 2;
|
||||||
if (y < -ah2) y = -ah2;
|
if (y < -ah2) y = -ah2;
|
||||||
else if (y + ah2 > height) y = height - 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) {
|
public void set(int x, int y) {
|
||||||
this.x = x - aimWidth / 2;
|
this.x = x - aimWidth / 2;
|
||||||
this.y = y - aimHeight / 2;
|
this.y = y - aimHeight / 2;
|
||||||
@ -50,6 +62,7 @@ public class SniperAim {
|
|||||||
|
|
||||||
public void draw(Graphics g) {
|
public void draw(Graphics g) {
|
||||||
g.drawImage(aim, x, y);
|
g.drawImage(aim, x, y);
|
||||||
|
// Fill screen around aim image.
|
||||||
g.setColor(0xFF000000);
|
g.setColor(0xFF000000);
|
||||||
final int bottom = y + aimHeight;
|
final int bottom = y + aimHeight;
|
||||||
g.fillRect(0, 0, width, y);
|
g.fillRect(0, 0, width, y);
|
||||||
|
@ -13,5 +13,6 @@ public class Main extends Application {
|
|||||||
|
|
||||||
public Main() {
|
public Main() {
|
||||||
super(new MainApp(), 320, 240);
|
super(new MainApp(), 320, 240);
|
||||||
|
setTitle("Military Hero");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user