求前辈们指导,若可运行重赏
processing吧
全部回复
仅看楼主
level 1
以下是我的code,
就是运行后单次点击鼠标射击子弹,没问题。
但是连续按就会不断重置或者说使用同一个子弹不断从大炮中射出
有什么办法可以做出可以无限正常射出子弹,连续,
可能表达不是很清楚,前辈们可以直接run这个code,
能帮忙解决的,一定会回报,谢谢
/*
April 24
game
Hawke Jiang
*/
PVector mPos;//position of the mouse
PVector tPos;// the postiion of the turret
PVector pPos;// the positon of the player project
PVector tDir;//the firing direction of the turret, length 1
//PVector vel;
//PVector acc;
//PVector size1;
PVector pVel;//
PVector grav = new PVector(0,1);//gravty
void setup(){
size(600,600);
init();
// vel = PVector.random2D();
// vel.mult(5);
// acc = new PVector (0,1);
// size1 = new PVector(30,30);
}
void init(){
//PVector.initializations
mPos = new PVector();//zerioo until mousex and y exist
tPos = new PVector(width/8,height);//
pPos = new PVector(-1000, -1000);//projectile bank location
tDir = new PVector();//
pVel = new PVector ();
}
void mousePressed(){
//set the bullet position to the turret
pPos.set(tPos);
//set the initial velcit to the turret direction
pVel.set(tDir.div(2));
// vel = PVector.random2D();
// vel.mult(10);
}
void draw(){
//clear the last frame
background(200);
//check ksy so see if is new key input for turret
if (keyPressed){
if (key == 'a'&&tPos.x >9){//only accept the key command if it doesn't move
tPos.x -= 10;
}
else if (key == 'd'&&tPos.x < width - 9){
tPos.x += 10;
}
}
//update
//a***tes the projectile is it not in the bank
if (pPos.x!=-1000){
pVel.add(grav);
pPos.add(pVel);
}
mPos.set(mouseX,mouseY);
tDir = PVector.sub(mPos,tPos);
tDir.normalize();
tDir.mult(50);
//draw
fill(255);
// line(mPos.x, mPos.y,0,0);// line from the origin to the mouse position postion
// ellipse(mPos.x, mPos.y,10,10);
// line(tPos.x, tPos.y,0,0);// line from the origin to the mouse position postion
ellipse(tPos.x, tPos.y,40,40);
strokeWeight(5);
line(tPos.x + tDir.x, tPos.y + tDir.y, tPos.x, tPos.y);
fill(255,0,0);
ellipse(tPos.x + tDir.x, tPos.y + tDir.y,10,10);
//bullet
ellipse(pPos.x,pPos.y,10,10);
}
2017年04月25日 21点04分 1
level 1
就是怎么做才能不停开火,就不止一颗子弹
2017年04月25日 21点04分 2
level 3
先创建一个类,把子弹相关参数放到类里;建立一个子弹类的数组(数组里再添加一个判断子弹是否出屏幕的成员变量,当子弹出屏幕的时候应该停止更新,节省内存),每当鼠标点击时,将数组里的一个类初始化,index=(index%数组.length)+1,以此类推。若index回到零的时候,检测该对象是否在屏幕外,用上面提到的参数,如果该对象在屏幕外:初始化新对象 否则什么也不做 。 也就是说可以用数组的长度限制同时出现在屏幕上的子弹数
2017年04月26日 15点04分 4
1