网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
10月05日漏签0天
processing吧 关注:7,140贴子:9,815
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 4回复贴,共1页
<<返回processing吧
>0< 加载中...

大神求助

  • 只看楼主
  • 收藏

  • 回复
  • 冯宇宙
  • 初级粉丝
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
求助 求把这个程序改写一下,我想让右边的靶子可以上下来回移动


  • 冯宇宙
  • 初级粉丝
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
/* Game playing is often either strategic or active. For any "shooting"
game, several things must be maintained. The x and y positions of any
objects being shot or drawn must be saved (and updated) for each iteration
of the main draw loop. To make a bullet move, store the initial x,y value
of the bullet. Update this for each new screen displayed (or every 10th
screen displayed) - based on desired display speed - see sample below.
Arrays are used to store these changing x and y values. Often many bullets
are active on the screen at a given moment. Keep the x,y values in two
arrays (of floats).s
float [] bulletX = new float [10]; // creates an array of 10 x values
float [] bulletY = new float [10]; // creates an array of 10 y values
You can use a keypress to trigger a "shot". The shot operation simply
establishes the first position of the bullet. After it has been positioned
its new position is updated independently of the gun or shooter.
*/
int max=10; // max number of bullets
int siz=8; // size of the bullets
int speed=20;
PImage pic;
PImage bullet;
PImage target;
PImage targetDead;
float [] targets = new float [3];
float [] bulletX = new float [max];
float [] bulletY = new float [max];
int [] show = {0,0,0};
float [] [] bullets = new float [max][2];
void setup() {
size(1000, 400); // sets the screen size
pic = loadImage ("pistol.gif");
target = loadImage ("pigeonGood.gif");
targetDead = loadImage ("pigeonDead2.gif");
textSize (32);
smooth(); // makes the graphics smooth
// setup targets
targets [0] = random (0,130); // y axis value for targets
targets [1] = random (140,270);
targets [2] = random (280,380);
for (int i=0; i<max; i++) {
bulletX[i]=-1; // -1 indicates a non-active bullet
}
frameRate (30); // 15 frames per second in display
}
void draw() {
background (0);
for (int i=0; i<max; i++) { // update the bullets already shot
if (bulletX[i] < width && bulletX[i] != -1) {
bulletX[i]+=speed; // move bullet 8 pixels right
ellipse (bulletX[i], bulletY[i], siz, siz); // draw updated bullet
if (bulletX [i] > 920 ) { // within blowup range on the x
if (bulletY[i] > targets[0] && bulletY[i] < targets[0] +50) {
show[0]=1;
}
if (bulletY[i] > targets[1] && bulletY[i] < targets[1] +50) {
// blow up!!!
targets [1] = 600;
}
if (bulletY[i] > targets[2] && bulletY[i] < targets[2] +50) {
// blow up!!!
targets [2] = 600;
}
}
if (targets[0]==600 && targets [1]==600 && targets [2]==600) {
exit();
}
} else {
bulletX[i]=-1;
}
}
image (pic,mouseX, mouseY,150,120);
if (show[0] == 0 ) {
image (target,900,targets[0],50,50);
} else {
image (targetDead,900,targets[0],50,50);
show[0]++;
}
if (show[0] > 10) {
targets[0] = 600;
}
image (target,900,targets[1],50,50);
image (target,900,targets[2],50,50);
// look in the keypressed area for shooting initialization code
if (mouseX > (width - 10)) {
exit(); // move the mouse to right edge to quit
}
}
/* Your task: 1. Using your knowledge of PImages, position some kind
of ship or image (it could be a hand with a pointed finger) on the
screen. Using a gif will allow you to use an irregular shape and
have one colour transparent.
2. (simple task)Place three small targets at the right edge of the screen.
When the x,y value of one of your bullets intersects the target, cause
target to explode (show an expolsion picture and don't draw the target
any more. You can include an exposion sound if you'd like).
3. (harder) Place random targets that are falling from the top of the screen.
You will need x,y arrays for these as well. Your gun will blow up
if one of the falling items hits you (the x,y's intersect). The targets
will blow up and disappear if you hit the target with a bullet.
You may choose to keep score when you hit a target successfully.
Bullet speed can be made faster by increasing the speed variable
To make things really complicated, you can have levels...
*/
void keyPressed() { // an event triggered to the system when a key is hit
if (key == CODED) { // a coded key is special like an --> key
if (keyCode == UP) {
// do something
}
}
if (key == 's') { //shoot
if (mouseX < width / 4) { // only let shots be made from left side
for (int i=0; i < max; i++) {
if (bulletX[i]==-1) {
bulletX [i] = mouseX+130; // use the mouse as a gun
bulletY [i] = mouseY+23;
ellipse (bulletX[i], bulletY[i], siz, siz);
break; // leave loop once you find a -1 in the array
}
}
}
}
}
//void blowUp (float x, float y) {
//}


2026-10-05 07:27:58
广告
不感兴趣
开通SVIP免广告
  • 冯宇宙
  • 初级粉丝
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
pic = loadImage ("pistol.gif"); 这个是枪
target = loadImage ("pigeonGood.gif"); 这个是好的靶子
targetDead = loadImage ("pigeonDead2.gif"); 这个是被打中的


  • 梦耶萧萧
  • 初级粉丝
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我会,我梦耶萧萧,加我Q


  • 梦耶萧萧
  • 初级粉丝
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我会,我梦耶萧萧,加我Q


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 4回复贴,共1页
<<返回processing吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示