#Space game shooting asteroids

31 messages · Page 1 of 1 (latest)

slender mica
#

Any advice is welcome and appreciated.

#

I will continue my quest for a solution while I wait for input.🤓

slender mica
#

Update: I found a decent video. I built an enemy class. I am making progress on figuring out scope and available variables.
I haven't updated my GitHub but I will when I get to a good spot. I can upload earlier if necessary. I am doing it🤓

normal night
#

Have you tried chatgpt.

I guess you could make a bullet object. It would have the vector properties of

bullet = {
shot_type: "normal",
current_position: createVector(x,y),
shot_speed: createVector(vx, vy),
bullet_graphic_frame: 0,
shot_energy_damage : 1,

move() {
this.currrent_position.add( this.shot_speed)
}
// check if off screen
// check if collision
}

Note I added variable for animation and shot energy (which defaults to 1 but could be a future feature worth adding for powerups.)

oh this is javascript. chatgpt says in java it should be.

class Bullet {
String shot_type = "normal";
PVector current_position;
PVector shot_speed;
int bullet_graphic_frame = 0;
int shot_energy_damage = 1;

// Constructor
Bullet(float x, float y, float vx, float vy) {
current_position = new PVector(x, y);
shot_speed = new PVector(vx, vy);
}

void move() {
current_position.add(shot_speed);
}

// Add methods to check if off screen and if there is a collision.
// Implement the collision detection logic based on your requirements.
// You can use processing functions such as 'width', 'height', 'dist', etc.
// For example:
// boolean isOffScreen() {
// return (current_position.x < 0 || current_position.x > width || current_position.y < 0 || current_position.y > height);
// }
}

slender mica
#

Thanks for the input. I have the majority of it written.
I don't chatgpt. I am trying to understand it. My specific problem is the distance method for PVector. I am getting a nonsense(at least to me) I don't understand.

#

I am still working on it.

chilly acorn
#

Hi, what is your specific problem with the dist() method?

slender mica
#

I will ask again this weekend.

#

I am making progress I want to update the GitHub so you can see my work. Thank you for you interest in helping me.

slender mica
slender mica
#

Here is the link

#

I think my specific problem is in these methods.

#
 //Tests for a collision between bullet and an enemy
  boolean checkHit(Enemy enemies) {
    float dist = PVector.dist(this, enemies)-(this._length + enemies._length);
    println("enemy dist................." + dist);
    println(this._length - enemies._length);
    return(dist <= 0);
  }```
#
 void hitTarget(ArrayList<Bullet> bullets) {
    hit_target = false;

    for ( Bullet Bullet : bullets) {
      if (Bullet == this) {
        continue;
      }
      for (Enemy Enemy : enemies) {
        if (!hit_target && checkHit(Enemy)) {
          hit_target = true;
          println("bullet has hit a target");
        }
      }
    }
  }```
#

This is the output from my test statements java bullet has hit a target enemy dist.................-59.0 -41 I should note the values are always the same. They never change.

#

My thoughts...

#

The bullet knows it hits a target.

#

I tried to use the method that checks for collision between actors. (ship and asteroid) and it does not seem to work the same when using two different Lists.

#

I am unsure how to.....

#

compare the two ArrayLists to see if a collision has occured between an enemy and a bullet. I found a video that uses a nested enhanced loop.

#

I feel like I am close. hitTarget() seems to be working. The value is negative and it does say it hit the target. I am questioning my knowledge of PVector.dist() since the math seems off.

#

I also wonder about nesting an enhanced loop.

#

Advice is always welcome from you.🤓

chilly acorn
#

I will look at your code.

#

Btw negative values are correct because of the position of the vectors on the screen, if you need only positive values for checks, you can use the abs() method on the result, which gives an absolute (positive) number from the input.

slender mica
#

This has me a little frustrated. All adds to understanding so it is good in the end.

slender mica
#

I am currently working on a test sketch. Just the basics to try to understand where I need to change my thinking.