rpw029
YaBB Newbies
Offline
Posts: 42
"cannot find class names [...]"
Dec 27th , 2009, 4:15pm
I've been playing around with the code for a small game in processing, and when I add in a chunk of code that I need I get the error bar saying "cannot find a class or type named "Panda"" Here is my code: PImage titlepage; PImage title2; PImage failimg; PImage winimg; PImage fullbackground; PImage fullbackground3; PImage panda; PImage duck; PImage strawberry; PImage onigri; PImage trap; PFont Herculanum; float page = 1; //title page float Jspeed = 0.9; //jump float backgroundx = 0; //bg speed float speed = 2; float a; float shake; //for movement boolean jump = false; boolean run = false; boolean loselife = false; boolean incscore = false; int score = 0; int timer = 100; int lives = 3; Panda p1; Onigri o1; Duck d1; Trap t1; void setup(){ size (600, 400); titlepage = loadImage("titlepage.png"); title2 = loadImage("title2.png"); fullbackground = loadImage("fullbackground.png"); //fullbackground2 = loadImage("fullbackground2.png"); panda = loadImage("panda.png"); strawberry = loadImage("strawberry.png"); onigri = loadImage("onigri.png"); duck = loadImage("duck.png"); trap = loadImage("trap.png"); winimg = loadImage("winimg.png"); failimg = loadImage("failimg.png"); Herculanum = loadFont ("Herculanum.vlw"); textFont (Herculanum); smooth(); p1 = new Panda("panda.png"); o1 = new Onigri(300, 150, 0.7, "onigri.png"); d1 = new Duck(500, 120, 1, "duck.png"); t1 = new Trap(625, 150, 0.5, "trap.png"); } void draw(){ if (page == 1){ image (titlepage, 0, 0); lives = 3; backgroundx = 0; speed = 1.5; o1.speed = 0.7; d1.speed = 0.7; t1.speed = 0.7; }else if (page == 1.5){ image (title2, 0, 0); backgroundx = 0; lives = 3; }else if (page == 2){ backgroundx = backgroundx - speed; backgroundx = constrain(backgroundx, width-fullbackground.width, 0); image (fullbackground, backgroundx, 0); p1.show(); o1.show(); d1.show(); t1.show(); p1.move(); o1.move(); d1.move(); t1.move(); fill(0); textSize(24); text ("LIVES: " + lives, 450, 40); text ("SCORE: " + score, 50, 40); text ("TIME: " + timer, 250, 40); //calculating collisions if ((p1.x + p1.w) > o1.x && p1.x < (o1.x + o1.w) && (p1.y + p1.h) > o1.y && p1.y < (o1.y + o1.h)){ //collect onigri incscore = true; score += 10; } if ((p1.x + p1.w) > d1.x && p1.x < (d1.x + d1.w) && (p1.y + p1.h) > d1.y && p1.y < (d1.y + d1.h)){ //collect duck incscore = true; score += 30; } if ((p1.x + p1.w) > t1.x && p1.x < (t1.x + t1.w) && (p1.y + p1.h) > t1.y && p1.y < (t1.y + t1.h)){ //collect trap incscore = false; lives -= 1; } } else if (page == 4){ image (failimg, 0, 0); } } if (run == true){ shake = cos(a)/60; a += 0.5; rotate(shake); } run = true; if (run = true){ timer -= 1; image (panda, x, y, 150, 150); } else { if (timer < 100){ run = true; jump = false; } } } else if (page == 3){ image (winimg, 0, 0); fill (255); jump = false; run = false; } else if (page == 4){ image (failimg, 0, 0); jump = false; run = false; } if (jump == true){ y += Jspeed; Jspeed += 0.1; run = false; if (y > 260){ jump = false; run = true; y = 260; } } if ((page == 2)&&(backgroundx == width-fullbackground.width+10)){ page = 3; } else if ((page == 2)&&(lives == 0)){ page = 4; } } void keyPressed(){ if (key == ' '){ if (page == 1){ page = 1.5; } else if (page == 2){ jump = true; Jspeed = -3; } else if (page == 2.5){ jump = true; Jspeed = -3; } else if (page == 3){ page = 1; p1.restart(); o1.restart(200.0, 337.0); d1.restart(500.0, 300.0); t1.restart(700.0, 350.0); } else if (page == 4){ page = 1; p1.restart(); o1.restart(200.0, 337.0); d1.restart(500.0, 300.0); t1.restart(700.0, 350.0); } } } void mousePressed(){ if (page == 1.5){ if ((mouseX > 200)&&(mouseX < 400)&&(mouseY > 150)&&(mouseY < 250)){ page = 2; } if ((mouseX > 200)&&(mouseX < 400)&&(mouseY > 275)&&(mouseY < 350)){ page = 3.5; } } } class Panda{ float x = 50; float y = 300; float w; float h; float velocityX = 0.0; float velocityY = 0.0; float acceleration = 0.0; PImage Panda; Panda (String pandain){ panda = loadImage (pandain); w = panda.width / 4; h = panda.height / 4; } void restart(){ x = 50; y = 300; velocityX = 0.0; velocityY = 0.0; acceleration = 0.0; } void show(){ image (panda, x, y, w, h); } void move(){ if ((keyPressed == true)&&(key == ' ')&&(y > 100)){ velocityY = -3.5; acceleration = 1; } x = x + velocityX; x = constrain (x, 0, 598); y = y + velocityY; y = constrain (y, 0, 300); velocityY = velocityY + acceleration; } } I also have the code for the other classes, it just didn't fit into this text box. But my code works just fine until I add in: if (run == true){ shake = cos(a)/60; a += 0.5; rotate(shake); } run = true; if (run = true){ timer -= 1; image (panda, x, y, 150, 150); } else { if (timer < 100){ run = true; jump = false; } } } else if (page == 3){ image (winimg, 0, 0); fill (255); jump = false; run = false; } else if (page == 4){ image (failimg, 0, 0); jump = false; run = false; } if (jump == true){ y += Jspeed; Jspeed += 0.1; run = false; if (y > 260){ jump = false; run = true; y = 260; } } if ((page == 2)&&(backgroundx == width-fullbackground.width+10)){ page = 3; } else if ((page == 2)&&(lives == 0)){ page = 4; } }