Cannot make a static reference...
in
Programming Questions
•
2 years ago
I am trying to make a battle senario like the ones in RPG's such as final fantasy or pokemon. I am currently in the early stages so i tried to run the code and see how it worked, because i thought it was working. but then i got the error message, :Cannot make a static refference to the non-static method Display() from the type RPG.player.
Please Help!
- int gamestate;//state that the game currently is
- final static int menu = 1;
- final static int battle = 2 ;
- int turn;//determines who moves: the player or the enemy
- final static int monsterturn = 4; // trolls turn
- final static int playerturn = 8;//player's turn
- int playerhealth = 1000;
- int monsterhealth = 666;
- int pattack;//player's attack
- int pdefense;//player's defense
- int pspeed;// player's speed
- int experience;//EXP
- int mattack, mdefense, mspeed;//speed, attack, defense
- //class for the player
- class Player{
- int px;
- int py;
- int prad;
- float levelbonus = random(0,5);
- Player(){
- pattack = 26;//attack (medium)
- pdefense = 40;//defense (high)
- pspeed = 15;//speed(kinda low)
- px = 650;
- py = 300;
- prad = 20;
- }
- void Display(){
- fill(0,255,42);
- ellipse(px,py,prad*2,prad*2);
- }
- void Attack(){
- if(mouseX>250&&mouseX<350&&mouseY>610&&mouseY<660 && mousePressed){
- monsterhealth = monsterhealth - pattack + mdefense;
- turn = monsterturn;
- }
- }
- }
- //monster's attacks.
- class Monster{
- int mx,my,mrad;
- float maction = random (0,100);//to calculate what the monster will do
- Monster(){
- mx = 100;//x coordinate
- my = 50;//y coordinate
- mrad = 21;//radius of circly
- mattack = 50;//attack powah
- mdefense = 20;//defense powah
- mspeed = 17;//speed powah
- }
- void Display(){
- fill(190,219,191);
- ellipse(mx,my,2*mrad,2*mrad);
- }
- void Action(){
- if(maction <=50){
- playerhealth = playerhealth - mattack + pdefense;
- turn = playerturn;
- }
- if(maction > 50){
- turn = playerturn;
- }
- }
- }
- void setup(){
- size(750,750);//325 is center.
- }
- void draw(){
- background(255);
- switch(gamestate){
- default://The menu is the default
- background (0);
- text("BLAH", 200,290);
- text("This is a story of a man who has yet to realize his purpose on the earth\nAs the evil forces of the Dark Lord Haldur march into the Realm of Aervidel\nAll hope seems lost",250,300);
- text("but one man, exiled from his home, leads a rebellion against these dark forces\nand little does he know that he will become the savior of Aervidel...", 300,350);
- fill(255);
- rect(275,400,100,100);
- if(mouseX>=275&&mouseX<=375&&mouseY<500&&mouseY>=400&&mousePressed){//start button
- gamestate = battle;
- }
- break;
- case battle:
- Player.Display();
- background (255);
- fill(255);
- rect(0,600,600,150);//UBI: USER BATTLE INTERFACE CONSOLE
- line(0,600,750,600);//makes the box for the health
- rect(250,610,100,50);//attack button
- rect(250,670,100,50);//defense button
- fill(0);
- text(playerhealth+"/1000", 625, 615);//player's health
- if(playerhealth = 0){
- noLoop();
- }
- switch (turn){
- case playerturn:
- Player.Attack();
- break;
- case monsterturn:
- break;
- }
- break;
- }
- }
1