- 浏览: 131704 次
- 性别:
- 来自: 大连
文章分类
最新评论
-
datawarehouse:
datawarehouse 写道ngix 淘宝是基于这个开发了 ...
解密淘宝网的开源架构 -
datawarehouse:
ngix 淘宝是基于这个开发了一个自己的webserver吧。 ...
解密淘宝网的开源架构 -
eyelock:
我运行报错,,楼主能解答一下G,对swing不熟。
raphi ...
假期没事,写了个90行的俄罗斯方块,Java实现,史上最小巧 -
lostsky_11:
楼主写出例子了么?物理碰撞部分可能跟你说的差不多渲染部分可以搜 ...
Where is my water 游戏算法 -
xouou_53320:
都是牛人
假期没事,写了个90行的俄罗斯方块,Java实现,史上最小巧
每年过年都没事,都得写点小东西,今年是是男人就撑过20秒(20秒还是21秒来着,忘了) 可能有点小bug,再完善了.希望大家能支持,支持的就顶一下了
如果努努力也是可以压缩在100行以内的,90行的俄罗斯方块,100行的男人20秒
剩余问题
1.标题
2.开始没有splash
3.不能暂停
4.不能重新开始
5.速度慢
6.左右键有点冲突
7.结束统计
8.新的bomb出现时向飞机当前位置附近发射,现在是向中心附近发射
图片资源见附件.. 横向滚动飞机时,有个中间状态,半侧身,截图是在是不好截,暂时就一步到位,转过去了.. @_@
如果努努力也是可以压缩在100行以内的,90行的俄罗斯方块,100行的男人20秒
剩余问题
1.标题
2.开始没有splash
3.不能暂停
4.不能重新开始
5.速度慢
6.左右键有点冲突
7.结束统计
8.新的bomb出现时向飞机当前位置附近发射,现在是向中心附近发射
import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.image.BufferStrategy; import javax.swing.ImageIcon; import javax.swing.JFrame; /** * 转载请注明出处 http://mid.iteye.com 2012-01-24 * * @author http://mid.iteye.com * */ public class Fly21S extends JFrame implements Runnable, KeyListener { private int isPlaying = 0; private int bg[][] = new int[100][4];// x,y,color,speed private int bgMove[] = new int[100]; private Color[] colors = new Color[] { Color.BLUE, Color.CYAN, Color.GREEN, Color.ORANGE, Color.RED, Color.WHITE, Color.PINK, Color.YELLOW }; private int movePlanDir[] = new int[2]; // private long timeOffSet = new Date().getTime(); // private long paintBlank = 1; private Image bomb = new ImageIcon("D:\\Java\\eclipse\\workspace\\21sFly\\src\\bomb.gif").getImage(); private Image over = new ImageIcon("D:\\Java\\eclipse\\workspace\\21sFly\\src\\over.gif").getImage(); private Image[] planImages = new Image[] { new ImageIcon("D:\\Java\\eclipse\\workspace\\21sFly\\src\\plan1.gif").getImage(), new ImageIcon("D:\\Java\\eclipse\\workspace\\21sFly\\src\\plan3.gif").getImage(), new ImageIcon("D:\\Java\\eclipse\\workspace\\21sFly\\src\\plan5.gif").getImage(), new ImageIcon("D:\\Java\\eclipse\\workspace\\21sFly\\src\\crash.gif").getImage() }; private int[] planPos = new int[] { 150, 230 };// Plan's current position private double bombPos[][] = new double[50][4];// bomb's position,x direct, y direct. public Fly21S() { setSize(300, 300); setVisible(true); createBufferStrategy(2); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addKeyListener(this); this.setResizable(false); // init bg star for (int i = 0; i < bg.length; i++) { bg[i] = new int[] { getRandomLessThen(300), getRandomLessThen(300), getRandomLessThen(7), getRandomLessThen(2) + 1 }; bgMove[i] = 1; } // init bomb // up and down for (int i = 0; i < 25; i++) { int xPos = getRandomLessThen(300); int yPos = (int) (getPositiveOrNegative() == -1 ? -1 * getRandomLessThen(50) : (300 + getRandomLessThen(50))); int xDir = 150 - xPos + (getPositiveOrNegative() * getRandomLessThen(2)); int yDir = 150 - yPos + (getPositiveOrNegative() * getRandomLessThen(2)); bombPos[i] = new double[] { xPos, yPos, xDir, yDir };// } // left right for (int i = 0; i < 25; i++) { int xPos = (int) (getPositiveOrNegative() == -1 ? -1 * getRandomLessThen(50) : (300 + getRandomLessThen(50))); int yPos = getRandomLessThen(300); int xDir = 150 - xPos + (getPositiveOrNegative() * getRandomLessThen(2)); int yDir = 150 - yPos + (getPositiveOrNegative() * getRandomLessThen(2)); bombPos[25 + i] = new double[] { xPos, yPos, xDir, yDir };// } } private int getPositiveOrNegative() { return (Math.round(Math.random()) - 1) == 0 ? 1 : -1; } private int getRandomLessThen(int num) { return (int) Math.round(Math.random() * num); } public void paint(Graphics g) { BufferStrategy bs = this.getBufferStrategy(); if (bs == null) return; Graphics tg = bs.getDrawGraphics(); tg.fillRect(0, 20, 300, 300); // paint bg for (int i = 0; i < bg.length; i++) { tg.setColor(colors[bg[i][2]]); tg.drawLine(bg[i][0], bg[i][1], bg[i][0], bg[i][1]); } // paint bomb for (int i = 0; i < bombPos.length; i++) { tg.drawImage(bomb, (int) bombPos[i][0], (int) bombPos[i][1], null); } if (isPlaying == 0) { if (movePlanDir[0] == -1) tg.drawImage(planImages[0], planPos[0], planPos[1], null); else if (movePlanDir[0] == 1) tg.drawImage(planImages[2], planPos[0], planPos[1], null); else tg.drawImage(planImages[1], planPos[0], planPos[1], null); } else { tg.drawImage(planImages[3], planPos[0], planPos[1], null); tg.drawImage(over, 90, 60, null); // tg.drawChars(new char[] { 'H' }, 0, 1, 150, 150); } this.getBufferStrategy().show(); } public static void main(String[] args) { new Thread(new Fly21S()).start(); } public void run() { while (isPlaying == 0) try { for (int i = 0; i < bg.length; i++) { if (bgMove[i] % bg[i][3] == 0) { bg[i][1] = bg[i][1] + 1; if (bg[i][1] > 300) { bg[i][0] = (int) Math.round(Math.random() * 300); bg[i][1] = 0; bg[i][2] = (int) Math.round(Math.random() * 7); } bgMove[i] = 1; } else { bgMove[i]++; } } // move bomb for (int i = 0; i < bombPos.length; i++) { double speedXY = Math.sqrt(bombPos[i][2] * bombPos[i][2] + bombPos[i][3] * bombPos[i][3]); double xRate = bombPos[i][2] / speedXY; double yRate = bombPos[i][3] / speedXY; bombPos[i][0] = bombPos[i][0] + xRate * 1.3;// x to bombPos[i][1] = bombPos[i][1] + yRate * 1.3;// y to // new bomb if (bombPos[i][1] > 300 || bombPos[i][1] < 0) { int xPos = getRandomLessThen(300); int yPos = (int) (getPositiveOrNegative() == -1 ? -1 * getRandomLessThen(50) : (300 + getRandomLessThen(50))); int xDir = 150 - xPos + (getPositiveOrNegative() * getRandomLessThen(2)); int yDir = 150 - yPos + (getPositiveOrNegative() * getRandomLessThen(2)); bombPos[i] = new double[] { xPos, yPos, xDir, yDir };// } else if (bombPos[i][0] > 300 || bombPos[i][0] < 0) { int xPos = (int) (getPositiveOrNegative() == -1 ? -1 * getRandomLessThen(50) : (300 + getRandomLessThen(50))); int yPos = getRandomLessThen(300); int xDir = 150 - xPos + (getPositiveOrNegative() * getRandomLessThen(2)); int yDir = 150 - yPos + (getPositiveOrNegative() * getRandomLessThen(2)); bombPos[i] = new double[] { xPos, yPos, xDir, yDir };// } // check impact if (bombPos[i][0] > planPos[0] && bombPos[i][0] < planPos[0] + 10 && bombPos[i][1] > planPos[1] && bombPos[i][1] < planPos[1] + 10) { // crash isPlaying = 1; System.out.println("Crash~"); } } planPos[0] = planPos[0] + movePlanDir[0]; planPos[1] = planPos[1] + movePlanDir[1]; repaint(); Thread.sleep(33); } catch (InterruptedException e) { } } public void keyPressed(KeyEvent e) {// 38-上 40-下 37-左 39-右 // movePlanDir left right up down if ((e.getKeyCode() == 65 || e.getKeyCode() == 37)) {// left movePlanDir[0] = -1; } else if ((e.getKeyCode() == 68 || e.getKeyCode() == 39)) {// right movePlanDir[0] = 1; } else if ((e.getKeyCode() == 87 || e.getKeyCode() == 38)) {// up movePlanDir[1] = -1; } else if ((e.getKeyCode() == 83 || e.getKeyCode() == 40)) {// movePlanDir[1] = 1; } repaint(); } public void keyReleased(KeyEvent e) { if ((e.getKeyCode() == 65 || e.getKeyCode() == 37)) {// left movePlanDir[0] = 0; } else if ((e.getKeyCode() == 68 || e.getKeyCode() == 39)) {// right movePlanDir[0] = 0; } else if ((e.getKeyCode() == 87 || e.getKeyCode() == 38)) {// up movePlanDir[1] = 0; } else if ((e.getKeyCode() == 83 || e.getKeyCode() == 40)) {// movePlanDir[1] = 0; } repaint(); } public void keyTyped(KeyEvent e) { } }
图片资源见附件.. 横向滚动飞机时,有个中间状态,半侧身,截图是在是不好截,暂时就一步到位,转过去了.. @_@
发表评论
-
Where is my water 游戏算法
2012-01-23 19:56 2057过年把Where is my water完了一遍,对这个游戏的 ... -
假期没事,写了个90行的俄罗斯方块,Java实现,史上最小巧
2010-02-16 23:03 10970Bug已经Fix~~ 注释已经补充 import jav ... -
俄罗斯方块:C++中的常用错误原因~~
2008-07-20 20:45 1275很久没有用C++写程序了。。用起来很不顺手! 出了问题不知道怎 ... -
疯狂游戏系列之(一)疯狂俄罗斯策划
2008-07-18 20:38 1457闲来无事,做一个PSP上的俄罗斯方块游戏,大致原则是两个字 疯 ... -
PSP程序开发例子解析(十二)InputSystem
2008-07-14 20:50 1019InputSystem例子掩饰了如何在程序中输入文字 #i ... -
PSP程序开发例子解析(十一)HGEParticles
2008-07-14 20:50 1012HGEParticles这个例子很BT 模仿WindowsMe ... -
PSP程序开发例子解析(十)HGEDistortionMesh
2008-07-14 20:49 1640HGEDistortionMesh例子应用了HGE包中的内容 ... -
PSP程序开发例子解析(九)3DPrimer
2008-07-14 20:48 11923D例子显示一个Cube和一个人物 不断旋转 具体底部底层AP ... -
PSP程序开发例子解析(八)Animator
2008-07-14 20:48 920GameApp.cpp #include <std ... -
PSP程序开发例子解析(七)DisplayingChinese
2008-07-14 20:46 929显示中文 加载点阵文件 没啥说的 就是不清楚点阵文件是哪来的= ... -
PSP程序开发例子解析(六)TrueTypeFont
2008-07-14 20:45 1031按照Windows的ttf字体显示文字。。跑不起来 略 #i ... -
PSP程序开发例子解析(五)Shapes
2008-07-14 20:44 886绘制各种形状 无话可说 #include <st ... -
PSP程序开发例子解析(四)Splines
2008-07-14 20:38 925第四个例子讲述了曲线 ... -
PSP程序开发例子解析(三)ResourceManager
2008-07-14 20:38 929太晚了 明天再写 弄个res文件没找到 换了个工程 copy源 ... -
PSP程序开发例子解析(二)Images
2008-07-14 20:37 1115第二个例子程序演示了 ... -
PSP程序开发例子解析(一)HelloWorld
2008-07-14 20:31 2963今天晚上把PSP的开发环境搭建了起来 并且看了看PSP的Hel ... -
关于BMP图片格式(部分垃圾代码)
2007-11-17 19:05 1307java 代码 做了个刷投票的程序 识别随即码图片的地方 ...
相关推荐
一年级看图写话之过年了(五篇).docx
2011年过年是哪一天.doc
好看,背景音乐好听,是《绿色通道》,我自己感觉做的还挺不错的,起码写出了回家过年时每个人的心声
人教版小学美术一年级上册《第19课过年啦》word教案.doc
过年请假申请书精选.doc
人教 小学 一年级 美术 上册 过年啦PPT学习教案.pptx
从腊月二十三(或二十四日)小年节起,人们便开始“忙年”:扫房屋、洗头沐浴、准备年节器具等等,所有这些活动,有一个共同的主题,即“辞旧迎新”。 传统民俗:春节更是民众娱乐狂欢的节日。元日以后,各种丰富...
自动抢红包是一款面向广大微信、QQ用户的自动抢红包工具,只需挂在后台运行就可以实现自动进群抢红包,保证过年期间一个红包都不错过,数钱数到手软! 【实用功能】 全自动抢红包 开启自动抢红包功能后,手机将为...
20第二十课 过年啦 简案.DOC
20第二十课 ---过年啦.pptx
一年级作文大全过年.docx
2022年轻人过年新趋势洞察报告.pdf
2016年过年回家模板适用于新年春节主题设计应用。
网页动画素材 过年烟花(抖音资料)网页动画素材 过年烟花(抖音资料)网页动画素材 过年烟花(抖音资料)网页动画素材 过年烟花(抖音资料)网页动画素材 过年烟花(抖音资料)网页动画素材 过年烟花(抖音资料)...
import java.util.Calendar; import java.util.GregorianCalendar; import java.awt.*; import javax.swing.*; public class Ex extends JFrame{ public Ex() { super("倒计时"); setBackground(Color.WHITE); ...
过年的一件事作文.doc
二年级数学上册 过年综合练习一教案 青岛版 教案.doc
还有多少天过年 2024年春节计时器为您记录距离过年还有多少天 春节还有多少天 倒计时已为每位朋友开启,一起迎接2024年春节吧!
Android模仿支付宝过年咻一咻效果。