Proyecto
Proyecto
/*
*/
package futpong;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
this.pong = pong;
spawn();
}
int speed = 5;
if (this.motionY < 0) {
this.y = 0;
this.motionY = random.nextInt(4);
if (motionY == 0) {
motionY = 1;
} else {
this.motionY = -random.nextInt(4);
if (motionY == 0) {
motionY = -1;
if (checkCollision(paddle1) == 1) {
this.motionY = -2 + random.nextInt(4);
if (motionY == 0) {
motionY = 1;
amountOfHits++;
} else if (checkCollision(paddle2) == 1) {
this.motionY = -2 + random.nextInt(4);
if (motionY == 0) {
motionY = 1;
amountOfHits++;
if (checkCollision(paddle1) == 2) {
paddle2.score++;
spawn();
} else if (checkCollision(paddle2) == 2) {
paddle1.score++;
spawn();
this.amountOfHits = 0;
this.motionY = -2 + random.nextInt(4);
if (motionY == 0) {
motionY = 1;
if (random.nextBoolean()) {
motionX = 1;
} else {
motionX = -1;
if (this.x < paddle.x + paddle.width && this.x + width > paddle.x && this.y < paddle.y + paddle.height
&& this.y + height > paddle.y) {
return 1; //golpe
return 2; //puntaje
g.setColor(Color.WHITE);
g.fillOval(x, y, width, height);
Paddle
/*
*/
package futpong;
import java.awt.Color;
import java.awt.Graphics;
this.paddleNumber = paddleNumber;
if (paddleNumber == 1) {
this.x = 0;
}
if (paddleNumber == 2) {
g.setColor(Color.WHITE);
if (up) {
if (y - speed > 0) {
y -= speed;
} else {
y = 0;
} else {
y += speed;
} else {
y = futpong.pong.height - height;
}
}
Renderer
/*
*/
package futpong;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
//
// public Renderer() {
// this.setSize(150, 200);
// }
public void paint(Graphics2D grafico) {
//
//
//
//
//
// setOpaque(false);
// super.paintComponent(grafico);
@Override
super.paintComponent(g);
futpong.pong.render((Graphics2D) g);
if (image != null) {
}
}
Futpong
/*
*/
package futpong;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.Timer;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Dimension;
public int gameStatus = 0, scoreLimit = 3, playerWon; //0 = Menu, 1 = Pausa, 2 = Juegando papu, 3 =
Game Over :(, 4 = portada q no cogio chch
System.out.println("Inicio");
// imagen.setVisible(true);
@Override
int id = e.getKeyCode();
if (id == KeyEvent.VK_W) {
w = true;
up = true;
down = true;
if (selectingDifficulty) {
if (botDifficulty < 2) {
botDifficulty++;
} else {
botDifficulty = 0;
} else if (gameStatus == 0) {
scoreLimit++;
if (selectingDifficulty) {
if (botDifficulty > 0) {
botDifficulty--;
} else {
botDifficulty = 2;
scoreLimit--;
gameStatus = 0;
bot = true;
selectingDifficulty = true;
if (gameStatus == 0 || gameStatus == 3) {
if (!selectingDifficulty) {
bot = false;
} else {
selectingDifficulty = false;
start();
} else if (gameStatus == 1) {
gameStatus = 2;
} else if (gameStatus == 2) {
gameStatus = 1;
@Override
int id = e.getKeyCode();
if (id == KeyEvent.VK_W) {
w = false;
s = false;
up = false;
@Override
public futpong() {
jframe.setVisible(true);
jframe.add(renderer);
jframe.addKeyListener(this);
timer.start();
}
public void start() {
gameStatus = 2;
playerWon = 1;
gameStatus = 3;
gameStatus = 3;
playerWon = 2;
if (w) {
player1.move(true);
if (s) {
player1.move(false);
if (!bot) {
if (up) {
player2.move(true);
}
if (down) {
player2.move(false);
} else {
if (botCooldown > 0) {
botCooldown--;
if (botCooldown == 0) {
botMoves = 0;
player2.move(false);
botMoves++;
player2.move(true);
botMoves++;
if (botDifficulty == 0) {
botCooldown = 20;
if (botDifficulty == 1) {
botCooldown = 15;
}
if (botDifficulty == 2) {
botCooldown = 10;
ball.update(player1, player2);
@Override
if (gameStatus == 2) {
update();
renderer.repaint();
g.setColor(Color.GREEN);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// if (gameStatus == 0) {
// jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Alfonso\\Desktop\\FutPong.jpg"));
// }
if (gameStatus == 0) {
g.setColor(Color.WHITE);
// setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
// NOI18N
if (!selectingDifficulty) {
// jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Alfonso\\Desktop\\FutPong.jpg"));
g.drawString("<< Score Limit: " + scoreLimit + " >>", width / 2 - 150, height / 2 + 75);
if (selectingDifficulty) {
g.drawString("<< Bot Difficulty: " + string + " >>", width / 2 - 180, height / 2 - 25);
g.drawString("Press Space to Play", width / 2 - 150, height / 2 + 25);
if (gameStatus == 1) {
g.setColor(Color.BLACK);
if (gameStatus == 1 || gameStatus == 2) {
g.setColor(Color.WHITE);
g.setStroke(new BasicStroke(5f));
g.setStroke(new BasicStroke(5f));
g.setStroke(new BasicStroke(5f));
player1.render(g);
player2.render(g);
ball.render(g);
if (gameStatus == 3) {
g.setColor(Color.WHITE);
} else {