examples/levelSelect/LevelSelect

From FANG

Jump to: navigation, search

01 package examples.levelSelect;
02 //start auto-imports
03 import javax.swing.*;
04 //end auto-imports
05 
06 import fang.*;
07 import java.awt.geom.*;
08 
09 /**
10  * This class selects the level to
11  * move to.
12  @author Alex Park
13  @author modified by Jam when the
14  * FANG Engine was updated
15  */
16 public class LevelSelect
17          extends Game
18 {
19    /**Sprite to click to go to level 1*/
20    private StringSprite level1;
21    /**Sprite to click to go to level 2*/
22    private StringSprite level2;
23 
24    /**
25     @see fang.GameLevel#startLevel()
26     */
27    public void setup()
28    {
29       makeSprites();
30       addSprites();
31    }
32 
33    /**
34     *Adds sprites to the screen 
35     */
36    public void addSprites()
37    {
38       addSprite(level1);
39       addSprite(level2);
40    }
41 
42    /**
43     * Makes the sprites
44     */
45    public void makeSprites()
46    {
47       level1 = new StringSprite("Click to go to Level 1");
48       level1.setLocation(0.50.25);
49       level1.setScale(0.85);
50       level1.centerJustify();
51 
52       level2 = new StringSprite("Click to go to Level 2");
53       level2.setLocation(0.50.75);
54       level2.setScale(0.85);
55       level2.centerJustify();
56    }
57    /**
58     @see fang.GameLevel#advanceFrame(double)
59     */
60    public void advance(double timeAdvanced)
61    {
62       handleClick();
63    }
64 
65    /**
66     * Sets the variable levelNumber to a value
67     * when the screen is clicked
68     */
69    public void handleClick()
70    {
71       Location2D mouse = getClick2D();
72       if (mouse != null)
73       {
74          if(mouse.y >= && mouse.y <= 0.5)
75          {
76             addGame(new Level1("You are in Level 1\nClick to go back"));
77             finishGame();
78          }
79          else if(mouse.y <= && mouse.y >= 0.5)
80          {
81             addGame(new Level1("You are in Level 2\nClick to go back"));
82             finishGame();
83          }
84       }
85    }
86 }


Download/View examples/levelSelect/LevelSelect.java




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games