package pong;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable,KeyListener{
private static final long serialVersionUID = 1L;
public static int WIDTH = 240;
public static int HEIGHT = 120;
public static int SCALE = 5;
public BufferedImage layer = new BufferedImage (WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
public Player player;
public Game() {
this.setPreferredSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
this.addKeyListener(this);
player = new Player();
}
public static void main(String[] args) {
Game game = new Game();
JFrame frame = new JFrame("pong");
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(game);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
new Thread(game).start();
}
public void tick() {
}
public void render() {
BufferStrategy bs = this.getBufferStrategy();
if(bs == null) {
this.createBufferStrategy(3);
return;
}
Graphics g = layer.getGraphics();
player.render(g);
g = bs.getDrawGraphics();
g.drawImage(layer, 0, 0, WIDTH*SCALE,HEIGHT*SCALE,null);
bs.show();
}
@Override
public void run() {
while(true) {
tick();
render();
try {
Thread.sleep(1000/60);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void keyPressed(KeyEvent e) {
if(KeyEvent.KEY_PRESSED == KeyEvent.VK_RIGHT) {
Player.right = true ;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
antonysamuel07:
eu uso o editor de codigo eclips
Soluções para a tarefa
Respondido por
0
Resposta:
? pontos de graça?
Explicação:
Perguntas interessantes
Geografia,
6 meses atrás
Matemática,
6 meses atrás
Matemática,
8 meses atrás
Matemática,
11 meses atrás
Matemática,
11 meses atrás