void setup(){size(800,600);
}
void draw(){
fill(0,102,153,51); text("star!",100,100);
textSize(60);
fill(250,0,250);rect(101,101,200,200);
}
fill(0,0,0)填色
text("...") 文字
textSize(60) 文字大小
-------------

void setup(){
size(800,600);
}
void draw(){
background(255);
if(bulletFlying){
ellipse(bulletX,bulletY,50,50);fill(250,0,0);
bulletX+=3;
}//函式判斷
}
float bulletX=500,bulletY=100;
boolean bulletFlying=false;//函式判斷
void keyPressed(){
bulletFlying=true;//函式判斷
}
我們用函式判斷,bulletFlying一開始判斷為 false(0)
按下按鍵後 就變為true(1)
if函式 讓圓的位置 +3....
----------多顆子彈-------
for(int i=0;i<bulletN;i++)
{
if(bulletFlying[i])
{
ellipse(bulletX[i],bulletY[i],50,50);
bulletX[i]+=3;
}
}
}
float []bulletX=new float[100]; 第N顆子彈的X座標
float []bulletY=new float[100]; 第N顆子彈的Y座標
int bulletN=0;//第幾顆子彈
boolean []bulletFlying= new boolean[100];
void keyPressed(){
bulletFlying[bulletN]=true;
bulletX[bulletN]=100;
bulletY[bulletN]=100;
bulletN++;
}
------------------------------------------
PImage Bg,bullet;//圖片宣告
void setup()
{
size(800,600);
Bg= loadImage("disert.jpg");//將圖片拉入程式及可放入程式資料夾
bullet= loadImage("bullet.png");
imageMode(CENTER);
}
void draw()
{
image(Bg,width/2,height/2,width,height);
image(bullet,mouseX,mouseY,100,100);
}
-------------------------圖片+子彈移動-----------------

PImage Bg,bullet;
void setup()
{
size(800,600);
Bg= loadImage("disert.jpg");
bullet= loadImage("bullet.png");
imageMode(CENTER);
}
void draw()
{
image(Bg,width/2,height/2,width,height);
image(bullet,mouseX,mouseY,100,100);
for(int i=0;i<bulletN;i++)
{
if(bulletFlying[i]){
image(bullet,bulletX[i],bulletY[i],100,100);
bulletX[i]+=3;
}
}
}
float []bulletX= new float[100];
float []bulletY= new float[100];
boolean []bulletFlying = new boolean[100];
int bulletN=0;
void mousePressed()
{
bulletFlying[bulletN]=true;
bulletX[bulletN]=mouseX;
bulletY[bulletN]=mouseY;
bulletN++;
}
------------向上然後下墜--------
PImage Bg,bullet;
void setup()
{
size(800,600);
Bg= loadImage("disert.jpg");
bullet= loadImage("bullet.png");
imageMode(CENTER);
}
void draw()
{
image(Bg,width/2,height/2,width,height);
image(bullet,mouseX,mouseY,100,100);
for(int i=0;i<bulletN;i++)
{
if(bulletFlying[i]){
image(bullet,bulletX[i],bulletY[i],100,100);
bulletY[i]+=bulletVY[i];
bulletVY[i]+=0.98;
}
}
}
float []bulletX= new float[100];
float []bulletY= new float[100];
float []bulletVY= new float[100];
boolean []bulletFlying = new boolean[100];
int bulletN=0;
void mousePressed()
{
bulletFlying[bulletN]=true;
bulletX[bulletN]=mouseX;
bulletY[bulletN]=mouseY;
bulletVY[bulletN]=-20;
bulletN++;
}
沒有留言:
張貼留言