Primitive type of float does not have field / simple interaction problem HELP PLEASE!
in
Programming Questions
•
11 months ago
Hello,
I am new to processing and I am currently banging my head against the wall with the situation I am currently in.
First problem:
Whenever I try and run this code:
- Planets[] planets = new Planets[15];
- SpaceMan spaceMan;
- float xo;
- float yo;
- float scaler = 2;
- float speed = 6;
- void setup() {
- size(600, 600);
- for (int i = 0; i< planets.length;i++) {
- planets[i] = new Planets();
- }
- spaceMan = new SpaceMan();
- xo = width/2;
- yo = height/2;
- }
- void draw() {
- background(0);
- translate(xo,yo);
- scale(scaler);
- translate(-xo,-yo);
- for (int i=0; i<planets.length; i++) {
- planets[i].display();
- planets[i].update();
- }
- pushMatrix();
- translate(xo,yo);
- spaceMan.person();
- spaceMan.control();
- popMatrix();
- }
- void keyPressed() {
- if(keyPressed == true) {
- if(keyCode == RIGHT){
- xo += speed;
- }
- else if(keyCode == LEFT){
- xo-=speed;
- }
- else if(keyCode == UP){
- yo-=speed;
- }
- else if(keyCode == DOWN){
- yo+=speed;
- }
- }
- }
- class Planets {
- color[] lollapalooza = {
- #FFFFFF, #002635, #013440, #AB1A25, #D97925, #EFE7BE
- };
- color[] pallete = lollapalooza;
- int i;
- float xpos;
- float ypos;
- float d;
- Planets() {
- fill(pallete[0]);
- xpos = random(d, width-d);
- ypos = random(d, height-d);
- d = random(25, 115);
- }
- void update() {
- fill(random(pallete.length));
- }
- void display() {
- ellipseMode(CENTER);
- fill(pallete[0]);
- noStroke();
- smooth();
- ellipse(xpos, ypos, d, d);
- }
- boolean hit (SpaceMan spaceMan) {
- if (xpos < xpos.spaceMan && ypos < ypos.spaceMan) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- class SpaceMan {
- float xpos;
- float ypos;
- float xo;
- float yo;
- float speedS;
- float d;
- SpaceMan() {
- xpos = xo;
- ypos = yo;
- d = 15;
- speedS = .00000001;
- }
- void control() {
- if (keyPressed == true) {
- if (keyCode == RIGHT) {
- xpos += speedS;
- }
- else if (keyCode == LEFT) {
- xpos -= speedS;
- }
- else if (keyCode == UP) {
- ypos -= speedS;
- }
- else if (keyCode == DOWN) {
- ypos += speedS;
- }
- }
- }
- void person() {
- fill(255, 255, 0);
- rect(xpos, ypos, d, d);
- }
- }
It gives me the error message of "The primitive type float does not have a field spaceMan" which doesn't make any sense since I have defined the field in another tab, so that's driving me crazy and I'm not sure what to do.
My second problem is with the boolean I want to make it so that when the boolean "hit" is activated that it will fill a planet with a random color from the palette. However, I have been greatly unsuccessful up until this point and ANY help would be extremely useful as well as greatly appreciated.
Thank you
1