童年的欢乐,虽然游戏很简单,但已经实现了基本的移动,发炮,碰撞,声音等效果,如下图:
请尊重别人的劳动成果 转载请务必注明出处 - http://www.zuidaima.com/share/1550463409654784.htm
相关代码如下:
package zuidaima.Game; import java.applet.AudioClip; import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JApplet; class Cannonball { static int y = 560, score = 0; int temp = 240; ClassLoader classLoader = this.getClass().getClassLoader(); public void paint(Graphics g, int x2) { int t = 0; if (y == 560) { temp = x2; } g.setColor(Color.red); g.fillOval(temp + 20, y, 10, 10); if (y < 560) y--; g.setColor(Color.LIGHT_GRAY); g.fillOval(temp + 20, y + 10, 10, 10); if (((temp + 20) % 40 == 0 && y == 70 && HoneyBee.a[0][(temp + 20) / 40 - 1] == 1) || ((temp + 20) % 40 == 0 && y == 110 && HoneyBee.a[1][(temp + 20) / 40 - 1] == 1) || ((temp + 20) % 40 == 0 && y == 150 && HoneyBee.a[2][(temp + 20) / 40 - 1] == 1)) { AudioClip au = JApplet.newAudioClip(classLoader .getResource("112.wav")); au.play(); g.setColor(Color.LIGHT_GRAY); g.fillRect(temp + 20, y, 20, 30); if (y == 70) { t = 0; } else if (y == 110) { t = 1; } else if (y == 150) { t = 2; } HoneyBee.a[t][(temp + 20) / 40 - 1] = 0; score += 100; y = 560; } if (y == 0) { y = 560; } } } public class HoneyBee extends Frame { static int x1 = 200; static int[][] a = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, }; ClassLoader classLoader = this.getClass().getClassLoader(); public HoneyBee() { AudioClip au = JApplet.newAudioClip(classLoader .getResource("start.wav")); au.play(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } }); addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int keycode = e.getKeyCode(); if (keycode == KeyEvent.VK_LEFT) { x1 = x1 - 10; } else if (keycode == KeyEvent.VK_RIGHT) { x1 = x1 + 10; } else if (keycode == KeyEvent.VK_SPACE) { if (Cannonball.y == 560) { AudioClip au = JApplet.newAudioClip(classLoader .getResource("BONG.wav")); au.play(); Cannonball.y = 559; } else { } } repaint(); } }); } public void paint(Graphics g) { int num; g.setColor(Color.BLUE); g.drawString("分数:" + Cannonball.score, 20, 50); g.fillOval(x1, 560, 50, 30); g.setColor(Color.BLACK); num = 0; for (int i = 0; i < 11; i++) { if (a[0][i] == 1) g.fillOval(num = num + 40, 70, 10, 10); else num = num + 40; } num = 0; for (int i = 0; i < 11; i++) { if (a[1][i] == 1) g.fillOval(num = num + 40, 110, 10, 10); else num = num + 40; } num = 0; for (int i = 0; i < 11; i++) { if (a[2][i] == 1) g.fillOval(num = num + 40, 150, 10, 10); else num = num + 40; } } public static void main(String[] args) { HoneyBee th = new HoneyBee(); th.setBackground(Color.LIGHT_GRAY); th.setSize(500, 600); th.setTitle("小蜜蜂游戏"); th.setVisible(true); Graphics g = th.getGraphics(); Cannonball cb = new Cannonball(); while (true) { try { Thread.sleep(4); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } cb.paint(g, x1); } } }
相关推荐
小蜜蜂游戏 块的应用以及动画的应用 小蜜蜂游戏 块的应用以及动画的应用 小蜜蜂游戏 块的应用以及动画的应用
很不错的小蜜蜂游戏源码 很不错的小蜜蜂游戏源码 很不错的小蜜蜂游戏源码 很不错的小蜜蜂游戏源码 很不错的小蜜蜂游戏源码 很不错的小蜜蜂游戏源码
我用Java写的小蜜蜂游戏,图形界面,解压后在myEclipse里直接import运行即可。
“小蜜蜂”这个游戏相信我们小时候都玩过,这次用python写了这个小游戏,可以运行,功能完好,可以随意调整敌机以及我方发射子弹的速度和数量。
nes模拟器和小蜜蜂小游戏nes模拟器和小蜜蜂小游戏nes模拟器和小蜜蜂小游戏
一个小游戏,源代码,小蜜蜂和飞机。帮助学习vc
模仿小蜜蜂游戏的J2ME手机版源代码,内含的导出包可以直接导入手机运行.
经典射击游戏素材-小蜜蜂.rar 大全
模仿红白机上面的小蜜蜂游戏,初学者可以看看
我用Java编写的小蜜蜂游戏,包括了游戏功能和图形界面,解压后在myEclipse里直接import运行即可。 注意这个游戏不是Android游戏,不能在Android手机里运行,请不要混淆哦。
改良JS版小蜜蜂游戏,完善了一边移动一边发子弹的不足,代码完整,结构清晰,注释详细,适合初学者学习!
一个经典小游戏,是从Qt的代码移植到Delphi7的。 支持键盘和鼠标操作,可以调节速度,调节主窗口的透明度,适合在办公室玩。
这是一个用java代码编写的一个简单的打字的游戏。感性趣的可以拿去看看。
自己的课程设计+试验报告 QQ820487892
小蜜蜂是一款由深圳市盟小蜜科技有限公司研发的社交电商APP。~小蜜蜂是slogan是让省钱变得更简单
c#写的小游戏,适合对开发有兴趣的同学,游戏是小蜜蜂
lwjgl的一个小蜜蜂游戏源码,使用lwjgl 2.9.1的库,中文英文注释,方便学习。
采用LIBGDX1.6.1编写的模仿街机小蜜蜂的游戏,其中涉及到BOX2D等内容
这是我用原生js写的一个游戏,目前还没有什么bug。
实用J2ME开发的经典手机小游戏 与星球大战相似 对小蜜蜂进行射击 直到通关 有生命值限制