- Napasai Sutthichutipong 6010545811
- Dechabhol Kotheeranurak 6010546664
Deadshot is 2D shooting game for 2 players on 1 computer. Players will fight each other by using their own weapons, the last remaining player is the winner of the game. Player can select characters and maps. This game will use projectile motion formula to calculate the path of bullet under the action of gravity. The main factor of the curve path is initial velocity of bullet and angle of reach.
- Players can select characters and maps
- Calculate projectile motion curve
- Javafx
- Threads
- Swing
- To study multi-threading
- To study Swing
System.out.println(w + " x " + h);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
// reference
// https://stackoverflow.com/questions/25761438/understanding-bufferedimage-getrgb-output-values
int pixel = image.getRGB(i, j);
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
if (red == 255 && green == 255 && blue == 255) {
addObject(new Block(i * 32, j * 32, 0, ObjectId.Block));
}
if (red == 255 && green == 106 && blue == 0) {
addObject(new Block(i * 32, j * 32, 1, ObjectId.Block1));
}
if (red == 64 && green == 64 && blue == 64) {
addObject(new Block(i * 32, j * 32, 3, ObjectId.Block2));
}
if (red == 255 && green == 0 && blue == 0) {
addObject(new Block(i * 32, j * 32, 2, ObjectId.BlockLava));
}
}
}
Block differrentiate by pixel's color.
x -= initV * Math.cos(Math.toRadians(angle))* timePos * 4;
realY = ((initV * Math.sin(Math.toRadians(angle))*time) + 0.5*-9.81*time*time);
realY2 = ((initV * Math.sin(Math.toRadians(angle))*time1) + 0.5*-9.81*time1*time1);
diff = realY2 - realY;
y -= diff * 10;
This code represent calculation of projectile motion using projectile motion formula and real gravity. First we calculate the position of each y then subtract it to compute delta y then multiply to estimated ratio. For x position we can ig nore it because horizontal speed is constant due to g = 0.