I'm a pretty new programmer working on a project involving classes. I want to create a Tigger-like creature that bounces (using gravity). I haven't gotten that far yet unfortunately. When I run the following code, I get a "expecting IDENT, found ','" error.
Code:int width=800;
int height=600;
float xpos=400;
float ypos=200;
float headwidth=60;
float headheight=100;
float nosewidth=40;
float noseheight=30;
float noseoffset=30;
float bodywidth=60;
float bodyheight=200;
float bodyoffset=150;
float direction=1;
float speed=4;
float levelofshake=5;
float bounciness=5;
float white=255;
float redness=255;
float greenness=140;
float blueness=0;
Creature tigger;
void setup() {
size(width,height);
smooth();
tigger=new Creature(xpos,ypos,direction,speed);
}
void draw() {
background(white);
tigger.display();
//tigger.bounce(bounciness);
//tigger.shake(levelofshake);
//tigger.talk();
}
class Creature {
Creature(tempXpos,tempYpos,tempDirection,tempSpeed) {
xpos=tempXpos;
ypos=tempYpos;
direction=tempDirection;
speed=tempSpeed;
}
}
void display() {
fill(redness,greenness,blueness);
ellipse(xpos-noseoffset,ypos,nosewidth,noseheight); //ellipse for the nose
ellipse(xpos,ypos,headwidth,headheight); //ellipse for the head
ellipse(xpos,ypos+bodyoffset,bodywidth,bodyheight); //ellipse for the body
}
I have some questions about this code that I can hopefully get answered here.
I'm wanting to have four customizable attributes of my creature, hence the xpos, ypos, direction and speed found when I initialized my object. I also don't want to have any hard-coded variables, so I put them all at the top of my code. I'll set them as global variables instead of variables within my classes, as I may use some in each of my classes. With this being the case, wouldn't all my attributes be easily customizable, not only the four I mentioned?
I have put my other three user-defined functions (bounce, shake and talk) into comments as I'll worry about those when the time comes. As for now, I just want my creature (so far just a head, nose and body [I'll improve them when the time comes]) to be displayed properly, yet my program isn't even running and I don't know why. No where in the appendix of Daniel Shiffman's book does it mention this area.
May I also know the basic things that are wrong with my code please? I'm only up to ch. 8 (on objects) in Shiffman's book, so I won't be able to fully understand coding from beyond that point. (When I try to make my creature talk, by importing an audio file from somewhere, I'll look ahead and read how to do it).
Thanks very much!