Loading...
Logo
Processing Forum
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!
Copy code
  1. int gamestate;//state that the game currently is
  2. final static int menu = 1;
  3. final static int battle = 2 ; 
  4. int turn;//determines who moves: the player or the enemy
  5. final static int monsterturn = 4; // trolls turn
  6. final static int playerturn = 8;//player's turn
  7. int playerhealth = 1000;
  8. int monsterhealth = 666;
  9. int pattack;//player's attack
  10. int pdefense;//player's defense
  11. int pspeed;// player's speed
  12. int experience;//EXP
  13. int mattack, mdefense, mspeed;//speed, attack, defense

  14. //class for the player
  15. class Player{
  16.   int px;
  17.   int py;
  18.   int prad;
  19.   float levelbonus = random(0,5);
  20.    Player(){
  21.      pattack = 26;//attack (medium)
  22.      pdefense = 40;//defense (high)
  23.      pspeed = 15;//speed(kinda low)
  24.      px = 650;
  25.      py = 300;
  26.      prad = 20;
  27.    }
  28.    void Display(){
  29.      fill(0,255,42);
  30.      ellipse(px,py,prad*2,prad*2);
  31.    }
  32.    void Attack(){
  33.      if(mouseX>250&&mouseX<350&&mouseY>610&&mouseY<660 && mousePressed){
  34.        monsterhealth = monsterhealth - pattack + mdefense;
  35.        turn = monsterturn;

  36.      }  
  37.    }
  38.    
  39.    
  40. }
  41. //monster's attacks.
  42. class Monster{
  43.   int mx,my,mrad;
  44.   float maction = random (0,100);//to calculate what the monster will do 
  45.   
  46.   Monster(){
  47.     mx = 100;//x coordinate
  48.     my = 50;//y coordinate
  49.     mrad = 21;//radius of circly
  50.     mattack = 50;//attack powah
  51.     mdefense = 20;//defense powah
  52.     mspeed = 17;//speed powah
  53.   }
  54.   
  55.   void Display(){
  56.     fill(190,219,191);
  57.     ellipse(mx,my,2*mrad,2*mrad);
  58.   }
  59.   
  60.   void Action(){
  61.     if(maction <=50){
  62.       playerhealth = playerhealth - mattack + pdefense;
  63.       turn = playerturn;
  64.     } 
  65.     if(maction > 50){
  66.       turn = playerturn;
  67.     }
  68.   }
  69. }
  70.     
  71.     
  72.     


  73. void setup(){
  74.   size(750,750);//325 is center.
  75.   
  76. }
  77. void draw(){
  78.   background(255);
  79.   switch(gamestate){
  80.     
  81.     default://The menu is the default
  82.     background (0);
  83.     text("BLAH", 200,290);
  84.     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);
  85.     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);
  86.    
  87.     fill(255);
  88.     rect(275,400,100,100);
  89.     if(mouseX>=275&&mouseX<=375&&mouseY<500&&mouseY>=400&&mousePressed){//start button
  90.       gamestate = battle;
  91.     }
  92.     break;
  93.     
  94.     case battle:
  95.     Player.Display();
  96.     background (255);
  97.     fill(255);
  98.     rect(0,600,600,150);//UBI: USER BATTLE INTERFACE CONSOLE
  99.     line(0,600,750,600);//makes the box for the health
  100.     rect(250,610,100,50);//attack button
  101.     rect(250,670,100,50);//defense button
  102.     fill(0);
  103.     text(playerhealth+"/1000", 625, 615);//player's health
  104.     if(playerhealth = 0){
  105.       noLoop();
  106.     }
  107.     
  108.     
  109.     switch (turn){
  110.     case playerturn:
  111.     Player.Attack();
  112.     break;
  113.     case monsterturn:
  114.     
  115.     break;
  116.     
  117.       
  118.     }
  119.     break;
  120.   }
  121.  
  122.  
  123. }

Replies(1)

When you created a class, most of the time, you have to create an instance of it, using the new keyword.
Like Player player = new Player(); (add parameters to the constructor if you need). Then you call the methods like: player.Display(); This allows, for example, to have several distinct monsters.