JAVA下的桌球运动轨迹

编程入门 行业动态 更新时间:2024-10-09 09:13:00

JAVA下的<a href=https://www.elefans.com/category/jswz/34/1756611.html style=桌球运动轨迹"/>

JAVA下的桌球运动轨迹

       本项目基于对Java语言学习所做的小项目,通过不断刷新桌子的静态图,实现肉眼可见的母球运动轨迹。如果想更好实现游戏效果。

1.可以加入不同的初始速度变量来模拟不同力道下球的运动。

2.设定减速变量代表桌子的摩擦力。

3.加塞下的不同运动轨迹等需要制定相对应的轨迹函数,需要借助数学工具带入。

4.至于其他子球入洞的效果是需要判定该球到入的洞口的坐标,

   我本人感觉IJ做成该游戏具有一定复杂性,可以用unity相应的游戏平台更便捷。代码仅供参考,相应的图片和参数都需要自己调整,后续我会把完整项目放入网盘,供大家查阅。

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package com.hellojava.firstproject;import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;
import javax.swing.JFrame;public class ballGame extends JFrame {Image ball = Toolkit.getDefaultToolkit().getImage("images/ball(1)(1).png");Image desk = Toolkit.getDefaultToolkit().getImage("images/desk4(1).png");double x = 200.0;double y = 200.0;double degree = -1.0466666666666666;public ballGame() {}public void paint(Graphics g) {System.out.println("窗口被画了一次。");g.drawImage(this.desk, -20, -10, (ImageObserver)null);g.drawImage(this.ball, (int)this.x, (int)this.y, (ImageObserver)null);this.x += 10.0 * Math.cos(this.degree);this.y += 10.0 * Math.sin(this.degree);if (this.y > 405.0 || this.y < 80.0) {this.degree = -this.degree;}if (this.x > 720.0 || this.x < 55.0) {this.degree = 3.14 - this.degree;}}void launchFrame() {this.setSize(815, 480);this.setLocation(100, 100);this.setVisible(true);while(true) {this.repaint();try {Thread.sleep(40L);} catch (InterruptedException var2) {var2.printStackTrace();}}}public static void main(String[] args) {System.out.println("我的小游戏开始了!");ballGame game = new ballGame();game.launchFrame();}
}

更多推荐

JAVA下的桌球运动轨迹

本文发布于:2024-02-07 10:39:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756509.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:桌球   轨迹   JAVA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!