Your question is too much to be included in SO. However, I created a simple βengineβ to get started. This is a general purpose, therefore also suitable for your needs.
The main class with the game loop into which the game is loaded, the input is checked, sprites are moved, collisions are checked, the score is updated, etc.
public class Game extends Application { Random rnd = new Random(); Pane playfieldLayer; Pane scoreLayer; Image playerImage; Image enemyImage; List<Player> players = new ArrayList<>(); List<Enemy> enemies = new ArrayList<>(); Text collisionText = new Text(); boolean collision = false; Scene scene; @Override public void start(Stage primaryStage) { Group root = new Group();
The base class for sprites, which includes common methods such as moving, etc.
public abstract class SpriteBase { Image image; ImageView imageView; Pane layer; double x; double y; double r; double dx; double dy; double dr; double health; double damage; boolean removable = false; double w; double h; boolean canMove = true; public SpriteBase(Pane layer, Image image, double x, double y, double r, double dx, double dy, double dr, double health, double damage) { this.layer = layer; this.image = image; this.x = x; this.y = y; this.r = r; this.dx = dx; this.dy = dy; this.dr = dr; this.health = health; this.damage = damage; this.imageView = new ImageView(image); this.imageView.relocate(x, y); this.imageView.setRotate(r); this.w = image.getWidth();
Subclasses of a sprite class such as a player ...
public class Player extends SpriteBase { double playerShipMinX; double playerShipMaxX; double playerShipMinY; double playerShipMaxY; Input input; double speed; public Player(Pane layer, Image image, double x, double y, double r, double dx, double dy, double dr, double health, double damage, double speed, Input input) { super(layer, image, x, y, r, dx, dy, dr, health, damage); this.speed = speed; this.input = input; init(); } private void init() {
... and enemies
public class Enemy extends SpriteBase { public Enemy(Pane layer, Image image, double x, double y, double r, double dx, double dy, double dr, double health, double damage) { super(layer, image, x, y, r, dx, dy, dr, health, damage); } @Override public void checkRemovability() { if( Double.compare( getY(), Settings.SCENE_HEIGHT) > 0) { setRemovable(true); } } }
You also need an input mechanism to control the playerβs sprite.
public class Input { private BitSet keyboardBitSet = new BitSet();
And some global settings
public class Settings { public static double SCENE_WIDTH = 400; public static double SCENE_HEIGHT = 800; public static double PLAYER_SHIP_SPEED = 4.0; public static double PLAYER_SHIP_HEALTH = 100.0; public static double PLAYER_MISSILE_SPEED = 4.0; public static double PLAYER_MISSILE_HEALTH = 200.0; public static int ENEMY_SPAWN_RANDOMNESS = 100; }
You can use any image for sprites. I took mine from Wikipedia:
player.png

enemy.png

If you put all this in a game package, you can run Game.java. This will give you a controlled emoticon with zombie emoticons that scroll down. You must evade them. I left the images without transparency for you to notice that I am using simple rectangle collision detection. You will probably go for pixel-collision detection.
It looks like this:

I am not saying that this is a solution, it is just a solution. For example, you will need to limit the animation timer. Or you can set the movement in seconds instead of each frame, etc.
If you need more information, you can check out my blog where I found myself How to create a 2D-Shoot'em'up with JavaFX . There you will also find e. d. how to add animated sprites (I also found out what you sent from the link), scrollable background, cloud layer on top of other layers, etc. Hope this helps you.