<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #shooting - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23shooting</link>
      <pubDate>Sun, 08 Aug 2021 19:14:54 +0000</pubDate>
         <description>Tagged with #shooting - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23shooting/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to make the invader can shoot by theirself?</title>
      <link>https://forum.processing.org/two/discussion/22113/how-to-make-the-invader-can-shoot-by-theirself</link>
      <pubDate>Thu, 20 Apr 2017 20:41:56 +0000</pubDate>
      <dc:creator>LeegeeRicky</dc:creator>
      <guid isPermaLink="false">22113@/two/discussions</guid>
      <description><![CDATA[<p>Hi there, I'm making a game where something comes across the screen, from one side to the other. What I'd like to do is that the invader can shoot the bullet itself at a random moment by using 1D array not the arraylist, and I'm really stuck with it... Here is what i got so far:</p>

<pre><code>    //Main class
    int AlienRow = 4;
    int AlienCol = 8;
    int AfirstNullBullet = 0;
    Alien[][] alien = new Alien[AlienCol][AlienRow];
    BulletAlien[] bulletAlien = new BulletAlien[5];

    void setup()
    {
      size(700, 600);
      gameStart();
      setAlien();
    }

    void draw()
    {
      background(255);
    }

    void setAlien()
    {
      /* Set up the position of the image and how many rows and cols */
      for (int i = 0; i &lt; AlienCol; i++) 
      {
        for (int j = 0; j &lt; AlienRow; j++) 
        {
          alien[i][j] = new Alien(30 * (2*(i+1)), 30 * (1*(j+1)));
        }
      }//end for loop
    }

    void displayBullets() 
    {
      for (int a = 0; a &lt; bulletAlien.length; a++)
      {
        if (bulletAlien[a] != null)
        {
          bulletAlien[a].Adisplay();
          bulletAlien[a].Amove();

          if (bulletAlien[a].ay &lt; height || bulletAlien[a].ay &gt; 0)
          {
            bulletAlien[a] = null;
          } else
          {
            AfirstNullBullet = a;
        }
      }
    }

    //Alien class
    class Alien
    {
      float x, y;
      float ximg = 0;
      float speed = 2;

      Boolean moveLeft = false;

      Alien(float x, float y)
      {
        this.x = x;
        this.y = y;
      }

      void display()
      {
        eclipse(x, y, 40, 40);
      }

      void move() 
      { 
        if (!moveLeft)
        {
          x += speed;
        }
        if (moveLeft)
        {
          x -= speed;
        }
        if (x &lt;= 0)
        {
          moveLeft = false;
          y += 90;
        }
        if (x &gt;= width - 30)
        {
          moveLeft = true;
          y += 90;
        }
        if (y &gt;= 550)//When the alien go out of the button the game wiil end
        {
          gameEnd = true;
        }
      }

      void update() 
      {
        display();
        move();
      }

      void Alienshoot() 
      {
        if (int (random(100)) &gt; 0) 
        {
          bulletAlien[AfirstNullBullet] = new BulletAlien(x, y, 20);
        }
      }
    }

    //Bullet class
    class BulletAlien 
    {
      float ax, ay;
      float aspeed;

      BulletAlien(float ax, float ay, float aspeed) 
      {
        this.ax = ax;
        this.ay = ay;
        this.aspeed = aspeed;
      }

      void Adisplay()
      {
        fill(255, 255, 255);
        rect(ax, ay, 4, 15);
      }

      void Amove()
      {
        ay -= aspeed;
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Need help with code. (cannon)</title>
      <link>https://forum.processing.org/two/discussion/20552/need-help-with-code-cannon</link>
      <pubDate>Mon, 30 Jan 2017 14:18:51 +0000</pubDate>
      <dc:creator>sk_14295</dc:creator>
      <guid isPermaLink="false">20552@/two/discussions</guid>
      <description><![CDATA[<p>I have somehow managed to get this game started..but the angle of aim does not match the angle of the gun.
Can someone please fix the codes? I really don't have time...i need to get it done by midnight..will someone please help me with my project.</p>

<p>float cannonX, cannonY; 
float cannonLength = 40; // How long the cannon on the tank extends
float cannonAngle = PI*3/4;
float cannonAngleStep = 0.005; // step to change cannonAngle
float cannonPower = 0;</p>

<p>float gravity = 0; // Strength of gravity
float gravitySpeed = 0.00981;
float time; // calculate time for the gravity component
float wind = 0; // Strength of wind
float explodePositionX; 
float explodePositionY;
boolean explode = false;
float explosionStrength = 1;</p>

<p>float bulletSpeedX = 0;
float bulletSpeedY = 0;
float bulletX = 0;
float bulletY = 0;
Boolean renderBullet = false;</p>

<p>float chargeAngle = PI*3/4.;
Boolean charging = false;</p>

<p>boolean objectInMotion = false;
float targetDistance = 50; // distance from left boundary the target is positioned
boolean targetHit = false;
int score = 0;
int total = 0;</p>

<p>float[] groundLevel; // Y coordinate of the ground for each X coordinate
float x,y; // position of the projectile
float r = 10; // radius of the projectile
float speed =20.0; // speed of projectile</p>

<p>void setup (){
size (1000,600);
cannonX = width-20;
cannonY = height/2;</p>

<p>// Initialize the ground level
// Implement random surface of the ground
groundLevel = new float[width];
for(float i = 0; i &lt; width; i++) {
groundLevel[(int)i] = height/3;
}</p>

<p>// Load font</p>

<p>}</p>

<p>void draw(){
background(200);
drawGround();
drawTarget();
drawCannon();
aimCannon();
shootCannon();
drawProjectile();
drawScore(); 
}</p>

<p>void drawGround(){
// See the groundLevel[] variable to know where to draw the ground
// Ground should be drawn in a dark gray
stroke(118,57,40); // set dark brown
for(int x = 0; x &lt; width; x++) {
line (x,height, x,height-groundLevel[x]); // draw in loop a vertikal line at lokation x
}
}</p>

<p>void drawTarget(){
ellipseMode(RADIUS);
for (int i = 10; i &gt;0; i--){
if (i&lt;4) {
fill(0);
stroke(255);
}
else{
fill(255);
stroke(0);
}
ellipse(targetDistance,height/2, 10<em>i, height/2/11</em>i);</p>

<p>}
stroke(2555,0,0);
line(targetDistance,height/11/2, targetDistance,height-height/11/2); 
}</p>

<p>void drawCannon(){
stroke(85,107,47); // set darkolivegreen color to draw the cannon
fill(85,107,47);
smooth();
strokeWeight(8);
// invert the sign of the angle in order to point the cannon upwards (and not downwards)
line(cannonX, cannonY, cannonX+cannonLength<em>cos(-cannonAngle), cannonY+cannonLength</em>sin(-cannonAngle));
strokeWeight(1); // reset to default widht
arc(cannonX, cannonY, cannonLength*3/4, cannonLength/2, -PI-PI/6, PI/6);
}</p>

<p>void aimCannon(){
fill(100);
ellipse(mouseX, mouseY,1, 1);
}</p>

<p>void shootCannon(){
if(mousePressed){
charging = true;</p>

<p>//increase power
cannonPower++;</p>

<p>//draw power charge
strokeWeight(2);
stroke(255,0,0);
line(cannonX,cannonY,cannonX + cos(cannonAngle - chargeAngle) * cannonPower,cannonY + sin(cannonAngle-chargeAngle)<em>cannonPower);
line(cannonX,cannonY,cannonX + cos(cannonAngle + chargeAngle) * cannonPower,cannonY + sin(cannonAngle+chargeAngle)</em>cannonPower);
// invert the sign of the angle in order to point the cannon upwards (and not downwards)
}else{
if(charging){</p>

<p>//find the correct speed from angle &amp; power
bulletSpeedX = cos(cannonAngle) * cannonPower;
bulletSpeedY = sin(cannonAngle) * cannonPower;</p>

<p>//set the start position of the bullet at the position of the user
bulletX = cannonX;
bulletY = cannonY;</p>

<p>//tell the program to render the bullet
renderBullet = true;</p>

<p>charging = false;
cannonPower = 0;
} 
}</p>

<p>if(renderBullet){
//apply gravity
gravity += gravity;
bulletSpeedY += gravity; 
//apply speed
bulletX += bulletSpeedX;
bulletY += bulletSpeedY;</p>

<p>//render the bullet
fill(255,0,0);
ellipse(bulletX,bulletY,5,5);</p>

<p>//check if we still need to render the bullet 
if(bulletY &gt; 600) renderBullet = false;
}</p>

<p>}</p>

<p>void drawProjectile(){
// Implementation
// drawExplosion(); 
}</p>

<p>void drawScore(){
// Display score 
// Implementation
}</p>

<p>// Draw esplosion, if collision with target is detected
void drawExplosion() {
if(explode){
noStroke();
fill(255, explosionStrength*2, 0); 
ellipse(explodePositionX, explodePositionY, explosionStrength, explosionStrength);
explosionStrength+=5;
// delay(2);
if (explosionStrength&gt;100){
explode=false; 
explosionStrength=1;
}
} 
}</p>
]]></description>
   </item>
   <item>
      <title>Shooting</title>
      <link>https://forum.processing.org/two/discussion/16848/shooting</link>
      <pubDate>Fri, 27 May 2016 13:39:20 +0000</pubDate>
      <dc:creator>martango</dc:creator>
      <guid isPermaLink="false">16848@/two/discussions</guid>
      <description><![CDATA[<p>i'm using images for bullets and my ship has to shoot aliens when i pressed space bar. how  can i make it  as simple as i can ?</p>

<p>i did something like that but this is one time bullet. It has to continuously shoot.</p>

<pre><code>  noCursor();
  background(0);

  image(s1, mouseX,650);
  image(p1, 20, 30);

  if (keyPressed) {
    if (keyPressed == true &amp;&amp; key ==' ') {
      image(n1, mouseX, bo);
    }
  }
  bo = bo -10;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to limit number of bullets in shooting game?</title>
      <link>https://forum.processing.org/two/discussion/11750/how-to-limit-number-of-bullets-in-shooting-game</link>
      <pubDate>Sat, 18 Jul 2015 13:51:52 +0000</pubDate>
      <dc:creator>kkesih</dc:creator>
      <guid isPermaLink="false">11750@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I'm just learning processing and trying to create a very simple shooting game. I need to know how to fire bullets from the location of a mouse click to random positions, and limit the number of bullets to 10. What is the best way to approach this?</p>
]]></description>
   </item>
   <item>
      <title>Objects</title>
      <link>https://forum.processing.org/two/discussion/11735/objects</link>
      <pubDate>Fri, 17 Jul 2015 04:52:08 +0000</pubDate>
      <dc:creator>juanClot</dc:creator>
      <guid isPermaLink="false">11735@/two/discussions</guid>
      <description><![CDATA[<p>If i have an array of object from this</p>

<pre><code>class Shot {
  PVector loc;
  PVector vel;  
  int r,g,b; 
  Shot (PVector loc, PVector direction, int r, int g, int b) {
    this.loc=new PVector ();
    vel=new PVector();
    this.loc = loc.get();
    vel= direction.get();
    vel.normalize();
    vel.mult(9);
    this.r=r;
    this.g=g;
    this.b=b;
  }
  void displayShot() {    
    loc.add(vel);
    noStroke();
    fill(r,g,b);
    ellipse(loc.x, loc.y, 4, 4);    
  }  
}
</code></pre>

<p>and i want to shoot them by ckicking. How could i make it work without shooting too many of those(by to many i mean one each draw). because my game works perfect but it shoots a lot, its nice but THERE ARE TO MANY GOING OUT.</p>
]]></description>
   </item>
   </channel>
</rss>