Hey guys I'm looking at my code and I'm trying to figure out how make all the enemies shot at the player right now I have to pass an argument or change something, right now I have the x and y of the bullet finding its location by putting myEnemyX and myEnemyY but the problem is i have 12 enemies and I'm not a 100% sure how do i pass the value for all 12 enemies
also for some reason when I'm working in java mode I added a dmg player so i can see when its taking dmg from the bullets but when i exported for web its not showing up any idea why is that?
Also for some reason when I play it in java mode and i press the space bar it shots just fine but when its online i have to either hold down the space bar or move left and right to shoot at the same time.
Hey guys working on my final, I'm not a great programer and I'm pushing the limits of what i know with this final but I'm trying to get this game to work and I'm having a problem with the logic with everything detecting each other here the sample of the game with the code i put it in open processing so you guys could take a look and give lend me a hand in trying to finish this.
Class_bullet idk how to make it so that all the ships shot right now i know that i might need an array but the way i have my game setup the
x = myEnemy.enemyX; // start with a random x location
y = myEnemy.enemyY; //start a little above the widnow
this is how I make one of my enemy shoot not all of them
and then i need both bullets to start shooting between the players and the enemies. Thanks in advance for a taking a look, like i said I'm trying to get this done but having a hard time, the example of the book does the math with radius to do the intersect but I'm using images.
Hello guys I'm working on exercise 10-10 and trying to convert its intersection Boolean to work with and image
now the math is checking for the radius between two circles but I'm working with a circle and an image
this is the example they have in the book
/ A function that returns true or false based if the catcher intersects a raindrop boolean intersect(Drop d) {
if (distance < r + d.r) { // Compare distance to sum of radii return true; } else { return false; } }
Now I'm trying to figure out what would be a better option to solve this with and image I thought I would solve it by trying to solve this problem with and image. I tryed going with the width of the image but i keep getting an error (Pimage float,float,float,float) is not compatible with (Pimage float,float,float) here my code for my class catcher
class Catcher{ //Global Variables //------------------\\ float catcherX; //x postion of player float catcherY; //y postion of player float cSpeed; //players speed PImage Catcher_1; //Glove or Bucket float catcherW; // catcher width //------------------\\
I'm trying to do the example from the book on algorithm in the intersection part for some reason when my balls intersect they are not being highlighted was wondering if somebody can tell me where I'm going wrong
void setup(){ size(1000,700); myCatcher = new Catcher(); ball1 = new Ball(64); ball2 = new Ball(32); smooth(); } void draw(){ background(0); myCatcher.display(); myCatcher.moveRight(); myCatcher.moveLeft(); myCatcher.moveUp(); myCatcher.moveDown(); ball1.move(); ball2.move(); if (ball1.intersect(ball2)){ ball1.hightlight(); ball2.hightlight(); } ball1.display(); ball2.display(); } void keyPressed(){ if (key == CODED) { if (keyCode == RIGHT && myCatcher.catcherX < width - 50){ myCatcher.moveRight(); }
if (keyCode == LEFT && myCatcher.catcherX > 0){ myCatcher.moveLeft(); } if (keyCode == UP && myCatcher.catcherY > 0){ myCatcher.moveUp(); } if (keyCode == DOWN && myCatcher.catcherY < height -50){ myCatcher.moveDown(); } } } class Ball{ float r; //radius float x,y; //location float xspeed,yspeed; //speed color c = color(100,50); // color
//constructor Ball(float tempR){ r = tempR; x = random(width); y = random(height); xspeed = random(-5,5); yspeed = random(-5,5); } void move(){ x += xspeed; //Inrements x y += yspeed; //Increments y
// check horizontal edges if(x > width || x < 0){ xspeed *= -1; } // check vertical edges if(y > height || y < 0){ yspeed *= -1; } } //highlight whenever balls are touching void hightlight(){ c = color(255,0,0); } //Draw Ball void display(){ stroke(255); fill(100,50); ellipse(x,y,r*2,r*2); c = color(100,50); } //A function that returns true or false based on whether two circle intersect //If distance is less than the sum of radii the circles touch boolean intersect(Ball b){ float distance = dist(x,y,b.x,b.y); //calculate distance if (distance < r + b.r){ //compare distance to sum of radius return true; } else{ return false; } } }
I have several enemy sprites I know how to switch their location and speed but not how to change the sprite if anybody could lend me a hand, I have about 12 enemies i wanna use where it says idk how to turn this into a varible
Enemy(float tempXpos, float tempYpos, float tempXspeed) {
Enemy_1 = loadImage("Enemy_1.png");
where i can change what I'm loading for an image passing it threw an argument.
void setup(){ //basic setup for enemy 3 test size(1000,680); //skect size smooth(); //does something i forgot myEnemy = new Enemy(200,400,5);// initializin enemy varible myEnemy1 = new Enemy(300,100,4); //initializing second varible of enemy }
I know my problem in this code is the way I'm trying too crate this background starfield it work fine when it was just functions and not in a class but now that I'm trying to make it a class getting all sort of issues
would greatly appreciate if somebody can send me on the right track to correct this.
void setup(){ //basic setup for enemy 3 test size(1000,680); //skect size smooth(); //does something i forgot myEnemy = new Enemy(); myPlayer = new Player(); mystarField = new starField(); }
Enemy() { Enemy_1 = loadImage("Enemy_1.png"); enemyX = 0; enemyY = 0; speed = 20; } void drawEnemy(){ image(Enemy_1,enemyX,enemyY); } void moveEnemy(){ // Change the x location by speed enemyX = enemyX + speed; } void wallCheck(){ if ((enemyX > width - 150) || (enemyX < 0)){ speed = speed * -1; } } } class Player{//Player Class with all the information for the player float playerX; //x postion of player float playerY; //y postion of player float pspeed; //players speed PImage Player_1; // space-ship-cointainer
Player(){ Player_1 = loadImage("Player_1.png"); playerX = 500; playerY = 600; pspeed = 5; } void drawPlayer(){ image(Player_1,playerX,playerY); } void keyPressed(){ if (key == CODED) { if (keyCode == RIGHT) { playerX = playerX + pspeed; } if (playerX > width - 50){ playerX = width - 50; } if (keyCode == LEFT) { playerX = playerX - pspeed; } if (playerX < 0){ playerX = 0; } } } } class starField{ //stars field to make it more like a space game float y = 50; //vertical location of each star float x = 10; //intial horizontal location of the first line float y1 = 50; //vertical location of each star float x1 = 50; //intial horizontal location of the first line float Cid = 5; //width of the ellipse float spacing = 45; //How far apart is each star float spacing1 = 10; //How far apart is each star float dia = 5; //height of each star float endStars = 985; float r; float g; float b; float a;
starField(){ float y = 50; //vertical location of each star float x = 10; //intial horizontal location of the first line float y1 = 50; //vertical location of each star float x1 = 50; //intial horizontal location of the first line float Cid = 5; //width of the ellipse float spacing = 45; //How far apart is each star float spacing1 = 10; //How far apart is each star float dia = 5; //height of each star } void displaystarfield(){ starField(10,15,1,1); starField(30,40,2,2); starField(10,80,1,1); starField(30,120,2,2); starField(10,160,1,1); starField(30,210,2,2); starField(10,280,1,1); starField(30,350,2,2); starField(10,420,1,1); starField(30,470,2,2); starField(10,520,1,1); starField(30,590,2,2); starField(10,640,1,1); }
void drawstarfield(float x, float y,float cid,float dia){ noStroke(); r = random(255); g = random(255); b = random(255); a = random(255); while (x <= endStars){ fill(r,g,b,a); ellipse(x,y,Cid,dia); x = x + spacing; } } }
Hi guys I'm trying to setup a class to make enemies for a space shooter game for my final for class and I decided to use images for the space ships, I know my mistake is located somewhere in displaying the enemy from an image if somebody could spot where my mistake is at I would greatly appreciate it.
Trying to add shooting to my little space game and hit detection looking at Chrisir simple shoot mechanic I don't know how to use classes yet and I'm trying to look at it and bring it down to its basic terms I was wondering if there was a more basic example too look at where i could try and break it down and understand it.
Hey guys I'm trying to work on a moving star field at the moment I want it to kinda move on the Y axis and repeat right now I have a simple while to repeat the my ellipses going to the right and have random blinking to give them that twinkle like stars was wondering how would I animated them to move up the Y axis and then repeat over to give it the feel of upward movement
//Global Varibles float y = 50; //vertical location of each star float x = 10; //intial horizontal location of the first line float y1 = 50; //vertical location of each star float x1 = 50; //intial horizontal location of the first line float Cid = 5; //width of the ellipse float spacing = 20; //How far apart is each star float spacing1 = 10; //How far apart is each star float dia = 5; //height of
each star
float endStars = 500;
//colorGroup variables that we are going to use random to play with
float r;
float g;
float b;
float a;
//Global Varibles
void setup(){
size(500,500);
smooth();
background(0);
ellipseMode(CENTER); // setting up the ellipse in center
}
void draw(){
starField(0,50,4,4);
}
void starField(float x, float y,float cid,float dia){
r = random(255);
g = random(255);
b = random(255);
a = random(255);
while (x <= endStars){
fill(r,g,b,a);
ellipse(x,y,Cid,dia);
x = x + spacing;
}
}
Hi guys I been working on creating a simple enemy AI for my space invader type game and running into several small issues, one is that I had to redo my functions over and over again to create different positions for the enemies and have them travel at different speed was wondering if there was a way I could make my functions simpler and second when i actually start putting enemies on screen well they kick each other out of the screen which was pretty funny but not the effect i was going for. Here my code so if anybody could give me a quick hand fairly new at this stuff and a little confuse
void setup(){ //basic setup for enemy 3 test
size(500,500); //skect size
smooth(); //does something i forgot
}
void draw(){ //our main program
background(0);
move(); // to move enemies
bounce(); // to make enemies move from left to right
drawEnemy(30,50,50,color(255,0
,0));
move1(); // to move enemies
bounce1(); // to make enemies move from left to right
drawEnemy1(60,70,60,color(0,25
5,0));
}
void move(){
// Change the x location by speed
enemyX = enemyX + speed;
}
void move1(){
// Change the x location by speed
enemyX1 = enemyX1 + speed;
}
void move2(){
// Change the x location by speed
enemyX2 = enemyX2 + speed;
}
void move3(){
// Change the x location by speed
enemyX3 = enemyX3 + speed;
}
void move4(){
// Change the x location by speed
enemyX4 = enemyX4 + speed;
}
void move5(){
// Change the x location by speed
enemyX5 = enemyX5 + speed1;
}
void move6(){
// Change the x location by speed
enemyX6 = enemyX6 + speed1;
}
void move7(){
// Change the x location by speed
enemyX7 = enemyX7 + speed1;
}
void move20(){
// Change the x location by speed
enemyX20 = enemyX20 + speed1;
}
void move8(){
// Change the x location by speed
enemyX8 = enemyX8 + speed1;
}
void move9(){
// Change the x location by speed
enemyX9 = enemyX9 + speed5;
}
void move10(){
// Change the x location by speed
enemyX10 = enemyX10 + speed2;
}
void move11(){
// Change the x location by speed
enemyX11 = enemyX11 + speed4;
}
void move12(){
// Change the x location by speed
enemyX12 = enemyX12 + speed2;
}
void move13(){
// Change the x location by speed
enemyX13 = enemyX13 + speed5;
}
void move14(){
// Change the x location by speed
enemyX14 = enemyX14 + speed3;
}
void move15(){
// Change the x location by speed
enemyX15 = enemyX15 + speed3;
}
void move16(){
// Change the x location by speed
enemyX16 = enemyX16 + speed3;
}
void move17(){
// Change the x location by speed
enemyX17 = enemyX17 + speed4;
}
void bounce(){
if ((enemyX > width) || (enemyX < 0)){
speed = speed * -1;
}
}
void bounce1(){
if ((enemyX1 > width) || (enemyX1 < 0)){
speed = speed * -1;
}
}
void bounce2() {
if ((enemyX2 > width) || (enemyX2 < 0)){
speed = speed * -1;
}
}
void bounce3() {
if ((enemyX3 > width) || (enemyX3 < 0)){
speed = speed * -1;
}
}
void bounce4() {
if ((enemyX4 > width) || (enemyX4 < 0)){
speed = speed * -1;
}
}
void bounce5() {
if ((enemyX5 > width) || (enemyX5 < 0)){
speed1 = speed1 * +1;
}
}
void bounce6() {
if ((enemyX6 > width) || (enemyX6 < 0)){
speed1 = speed1 * -1;
}
}
void bounce7() {
if ((enemyX7 > width) || (enemyX7 < 0)){
speed1 = speed1 * +1;
}
}
void bounce8() {
if ((enemyX8 > width) || (enemyX8 < 0)){
speed1 = speed1 * -1;
}
}
void bounce9() {
if ((enemyX9 > width) || (enemyX9 < 0)){
speed5 = speed5 * -1;
}
}
void bounce10() {
if ((enemyX10 > width) || (enemyX10 < 0)){
speed2 = speed2 * -1;
}
}
void bounce11() {
if ((enemyX11 > width) || (enemyX12 < 0)){
speed4 = speed4 * -1;
}
}
void bounce12() {
if ((enemyX12 > width) || (enemyX12 < 0)){
speed2 = speed2 * -1;
}
}
void bounce13() {
if ((enemyX13 > width) || (enemyX13 < 0)){
speed5 = speed5 * -1;
}
}
void bounce14() {
if ((enemyX14 > width) || (enemyX14 < 0)){
speed3 = speed3 * -1;
}
}
void bounce15() {
if ((enemyX15 > width) || (enemyX15 < 0)){
speed3 = speed3 * -1;
}
}
void bounce16() {
if ((enemyX16 > width) || (enemyX16 < 0)){
speed3 = speed3 * -1;
}
}
void bounce17() {
if ((enemyX17 > width) || (enemyX17 < 0)){
speed4 = speed4 * -1;
}
}
void bounce20() {
if ((enemyX20 > width) || (enemyX20 < 0)){
speed1 = speed1 * -1;
}
}
void drawEnemy(int x, int y, int thesize, color c) {
int offset = thesize / 4;
rectMode(CENTER);
ellipseMode(CENTER);
stroke(200);
fill(c);
rect(enemyX,y,thesize,thesize/
2);
fill(200);
ellipse(enemyX - offset,y - offset,offset,offset/2);
ellipse(enemyX + offset,y - offset,offset,offset/2);
ellipse(enemyX - offset,y + offset,offset,offset/2);
ellipse(enemyX + offset,y + offset,offset,offset/2);
}
void drawEnemy1(int x, int y, int thesize1, color c) {
int offset1 = thesize1 / 4;
rectMode(CENTER);
ellipseMode(CENTER);
stroke(200);
fill(c);
rect(enemyX1,enemyY1,thesize1,
thesize1/2);
fill(200);
ellipse(enemyX1 - offset1,enemyY1 - offset1,offset1,offset1/2);
ellipse(enemyX1 + offset1,enemyY1 - offset1,offset1,offset1/2);
ellipse(enemyX1 - offset1,enemyY1 + offset1,offset1,offset1/2);
ellipse(enemyX1 + offset1,enemyY1 + offset1,offset1,offset1/2);
}
hey guys I'm trying to make a simple movement with keyCode where I manipulate a square on the x and y plane but every time I press the key right it keep moving and never stop, I want it to just move for how long I hold the key down and once i release i want it to just stop in place and when i press another key change in direction here what I'm working with so far.
float x = 0; //x loc of square
float y = 0; //y loc of square
void setup();(
size(200,200)
}
void draw(){
fill(255);
rect(x,y,10,10);
if (key == CODED){
if (keyCode == RIGHT);
x = x + 1;
}
else {
x = x;
}
}
that how far I've gotten because the square just likes to run of the page. I would like some guidance in the right direction.