Having issue with setting up a class
in
Programming Questions
•
10 months ago
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.
- //Global Varibles
Enemy myEnemy; //Enemey object Oriented varible
//--Global Variable end--
void setup(){ //basic setup for enemy 3 test
size(1000,680); //skect size
smooth(); //does something i forgot
}
void draw(){ //our main program
background(0);
myEnemy.drawEnemy();
myEnemy.moveEnemy();
myEnemy.wallCheck();
}
class Enemy{
PImage Enemy_1;
PImage Enemy_2;
PImage Enemy_3;
PImage Enemy_4;
PImage Enemy_5;
PImage Enemy_6;
PImage Enemy_7;
PImage Enemy_8;
PImage Enemy_9;
PImage Enemy_10;
PImage Enemy_11;
PImage Enemy_12;
PImage Enemy_13;
float enemyX;
float enemyY;
float speed;
Enemy() {
Enemy_1 = loadImage("Enemy_1.png");
enemyX = 0;
enemyY = 0;
speed = 1;
}
void drawEnemy(){
image(Enemy_1,enemyX,enemyY);
}
void moveEnemy(){
// Change the x location by speed
enemyX = enemyX + speed;
}
void wallCheck(){
if ((enemyX > width) || (enemyX < 0)){
speed = speed * -1;
}
}
}
1