Java台球游戏2
2016-08-27 22:23
148 查看
效果:测试窗口物体沿着任意角度飞行。
/**
* 测试窗口物体沿着任意角度飞行。
* 最后,实现一个小的台球游戏。
* @author Administrator
*
*/
public class GameFrame02 extends Frame {
Image img = GameUtil.getImage(“images/sun.jpg”);
class PaintThread extends Thread {
}
/**
* 测试窗口物体沿着任意角度飞行。
* 最后,实现一个小的台球游戏。
* @author Administrator
*
*/
public class GameFrame02 extends Frame {
Image img = GameUtil.getImage(“images/sun.jpg”);
/** * 加载窗口 */ public void launchFrame(){ setSize(500, 500); setLocation(100, 100); setVisible(true); new PaintThread().start(); //启动重画线程 addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); } private double x=100,y=100; private double degree=3.14/3; //[0,2pi] private double speed = 10; public void paint(Graphics g) { g.drawImage(img, (int)x, (int)y, null); if(speed>0){ speed -=0.05; }else{ speed = 0; } x += speed*Math.cos(degree); y += speed*Math.sin(degree); if(y>500-30||y<30){ degree = -degree; } if(x<0||x>500-30){ degree = Math.PI-degree; } } /** * 定义一个重画窗口的线程类,是一个内部类 * @author Administrator */
class PaintThread extends Thread {
public void run(){ while(true){ repaint(); try { Thread.sleep(40); //1s = 1000ms } catch (InterruptedException e) { e.printStackTrace(); } } } } public static void main(String[] args){ GameFrame02 gf=new GameFrame02(); gf.launchFrame(); }
}
相关文章推荐
- GUI_台球游戏核心功能开发JAVA077-082
- java台球游戏04
- Java扫雷游戏一例
- [JAVA] 俄罗斯方块游戏
- Java游戏编程---Java 线程
- JAVA GAME2D 游戏设计的答辨讲稿
- 游戏代码部分-------game包------GameFrame.java
- 游戏代码部分-------game包------ActionHandler.java
- Java游戏编程---第一章 2D图形和动画
- java游戏编程(1-2)线程池
- Java 游戏开发Notes
- [JAVA] 俄罗斯方块游戏
- Java游戏直棋(二)
- java 游戏API--
- 新来的,发个自己写的JAVA开窗户游戏
- 新Java技术工具亮相游戏开发商大会
- 用Java编写扫雷游戏--算法思考
- JAVA游戏直棋(一)
- Java游戏编程---人机交互和用户接口
- 游戏代码部分-------game包------GameApp.java