Tuesday, April 29, 2014

Using Magic

The bulk of the gameplay involves the player casting magic spells on opponents. The wand cannot move more than 1/3rd of the screen from the bottom. Additionally, the wand can be pointing to the northwest, north, or northeast. First, the player will select the spell to use:

void keyPressed()
{
  
  if (key == CODED)
  {
    if ((keyCode == LEFT) && (wandX < 35))
    {
      wandX += 35; 
      
    }
    else if ((keyCode == RIGHT) && (wandX > -35))
    {
      wandX -= 35; 
    }
    
  }
  else if (key == 'f')
    {
     type = 1; 
     userSound = minim.loadFile("FIRE.wav");
     magicEffect = color(255,0,0);
     magicEffect2 = color(255,100,0);
                playerResistanceM = 1;
          playerResistanceI = 1;
                          playerResistanceP = 1;

    }
   else if (key == 'i')
   {

    type = 2;
         userSound = minim.loadFile("ICE.wav");
         magicEffect = color(0,0,255);
         magicEffect2 = color(0,200,255);
                    playerResistanceM = 1;
          playerResistanceI = 0.5;
                          playerResistanceP = 1;


   }
   else if  (key == 'm')
   {
          userSound = minim.loadFile("MAGIC.wav");

     type = 3;
          magicEffect = color(155,0,155);
          magicEffect2 = color(255,0,0);
          playerResistanceM = 0.5;
          playerResistanceI = 1;
                playerResistanceP = 1;




   }
    else if (key == 'p')
    {
          userSound = minim.loadFile("ICE.wav");    //Right now, the poison file doesn't work, substituting ice sound.

      type = 4; 
      magicEffect = color(0,155,0);
      magicEffect2 = color(0,255,100);
      playerResistanceI = 1;
      playerResistanceM = 1;
      playerResistanceP = 0.5;



    }
    else if (key == 's')
    {
      type = 5;
           userSound = minim.loadFile("SWORD.wav");
      playerResistanceM = 1;
          playerResistanceI = 1;
                          playerResistanceP = 1;


      magicEffect = color(200);
    }
    else if (key == 'h')
    {
     type = 6; 
     userSound = minim.loadFile("HEAL.wav");
     magicEffect = color(255,255,0);
     magicEffect2 = color(255,255,100);
           playerResistanceM = 1;
          playerResistanceI = 1;
                          playerResistanceP = 1;

    }
    else if (key == 'c')
    {
     type = 7;
          userSound = minim.loadFile("RECHARGE.wav");

     magicEffect = color(0,255,155);
     magicEffect2 = color(0,255,255); 
           playerResistanceM = 1;
          playerResistanceI = 1;
                          playerResistanceP = 1;

      
    }
    {
    }
    
}

When the appropriate key is pressed, the user sound effect and spell color. If the player types 's' for the sword, the wand is redrawn to look like a sword. Likewise, the arrow keys move the wand direction.

When the player clicks (to use the wand), the program will check:



1. Player SP (to make sure the player has enough spell points)
2. What spell (to know what to use)



//Mouse Pressed

void mousePressed()
{  
  if (!cast)
  {
    if (type == 5)
    {
         cast = !cast;
         
        if (level == 1)
       {     
        if (goblin.swing())
        {
          goblin.impact(); 
        }
       }
       
       else if (level == 2)
       {
        if (snake.swing())
        {
          snake.impact(); 
        }
         
       }
       else if (level == 3)
       {
        if (wizard.swing())
        {
          wizard.impact(); 
        }
         
       }
      else if (level == 4)
       {
        if (dragon.swing())
        {
          dragon.impact(); 
        }
         
       }
    }
    else
    {
    
    if (!checkSP())
    {
      if (!low)
      {
          low = !low;
          if (attaText)
          {
            attaText = !attaText;
          }
          if (missText)
          {
           missText = !missText; 
          }
      }
    }
    else
    {
      if (low)
      {
        low = !low;
      }
   cast = !cast; 
   if (type == 1)
   {
        sp -= 10; 
   }
   else if (type == 2)
   {
        sp -= 10; 
   }
   else if (type == 3)
   {
        sp -= 20; 
   }
   else if (type == 4)
   {
        sp -= 5; 
   }
   else if (type == 6)
   {
     sp -= 15;
   }


If the wand is a catcher, it does nothing if clicked.

   else if (type == 7)
   {
    cast = !cast; 
   }
    }

  }
  }
}

Meanwhile, a boolean variable will check whether the mouse has been clicked. If so, it will cast the spell and reset the variable.If you are using a healing spell, the for loop is ignored and simply uses an ellipse emitting from the wand.

if (cast)
  {
     userSound.rewind();  //sound effect, see (Sound & music)
     userSound.play();
    if (type == 6)
    {
      if (hp < maxHP)
      {
      hp += 25;
      }
      if (hp > maxHP)
      {
       hp = maxHP; 
      }
      
      fill(magicEffect, 70);
      stroke(magicEffect,70);
      ellipse(castPosX,castPosY,150,150);
      cast = !cast;
    }
   else 
   {

   if (sparks <= 15) 
   {
     magic.add(new Magic(castPosX,castPosY,wandX));
   }

A for loop will then check to see if any of the magic effects hit the creature.  The design is adapted from Park Hyebin, Konkuk University. 

   for (int i = magic.size()-1; i >= 0; i--)        //Adapted from circle motion by Park Hyebin, Konkuk University - http://www.openprocessing.org/sketch/144900
    {

       Magic m = (Magic) magic.get(i);
       m.move(); 
       m.display();
       if ((level == 1) && (goblin.hit(m)))
       {
         goblin.impact();
         magic.remove(i);
         sparks++;
       }
       else if ((level == 2) && (snake.hit(m)))
       {
         snake.impact();
         magic.remove(i);
         sparks++;
       }
       else if ((level == 3) && (wizard.hit(m)))
       {
         wizard.impact();
         magic.remove(i);
         sparks++;
       }
     else if ((level == 4) && (dragon.hit(m)))
       {
         dragon.impact();
         magic.remove(i);
         sparks++;
       }
       if (m.finished())
       {
          magic.remove(i); 
          sparks++;
        }

If the creature is defeated, the for loop is ended (so the next creature can be created).

      if (defeated)
       {
        i = magic.size()-1;

        defeated = !defeated; 
       }


No comments:

Post a Comment