The Method starfield(variables) is not applicable for arguments
in
Programming Questions
•
10 months ago
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.
would greatly appreciate if somebody can send me on the right track to correct this.
- //Global Varibles
Enemy myEnemy; //Enemey object Oriented varible
Player myPlayer; //Player Object Oriented varible
starField mystarField;
//--Global Variable end--
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();
}
void draw(){ //our main program
background(0);
mystarField.drawstarfield();
myEnemy.drawEnemy();
myEnemy.moveEnemy();
myEnemy.wallCheck();
myPlayer.drawPlayer();
myPlayer.keyPressed();
}
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 = 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;
}
}
}
1