-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added music player, automatic frame initialization, and more!
- Loading branch information
suncloudsmoon
committed
Aug 9, 2020
1 parent
236ed69
commit 2816ad1
Showing
14 changed files
with
628 additions
and
97 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package tilegame2d; | ||
|
||
import javax.swing.ImageIcon; | ||
import javax.swing.JFrame; | ||
|
||
/** | ||
* Contains methods that automatically creates and sets values for JFrame. | ||
* | ||
* @author Ganesha Ajjampura | ||
* | ||
*/ | ||
public class SimpleFrame { | ||
|
||
public JFrame frame; | ||
|
||
/** | ||
* Initializes the frame with default values. | ||
* | ||
* @param title A String value specifying the title of the JFrame object. | ||
* @param icon A ImageIcon object containing the image for the JFrame icon. | ||
* @param width An integer value specifying the width of the JFrame object. | ||
* @param height An integer value specifying the height of the JFrame object. | ||
*/ | ||
public void initializeFrame(String title, ImageIcon icon, int width, int height) { | ||
frame = new JFrame(); | ||
frame.setTitle(title); | ||
frame.setSize(width, height); | ||
frame.setIconImage(icon.getImage()); | ||
frame.setResizable(false); | ||
frame.setVisible(true); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
} | ||
|
||
/** | ||
* Initializes the frame with default values and the animation class added. | ||
* | ||
* @param sg A object containing the child class of SimpleGraphics. | ||
* @param title A String value specifying the title of the JFrame object. | ||
* @param icon A ImageIcon object containing the image for the JFrame icon. | ||
* @param width An integer value specifying the width of the JFrame object. | ||
* @param height An integer value specifying the height of the JFrame object. | ||
*/ | ||
public void initializeFrameForAnimation(SimpleGraphics sg, String title, ImageIcon icon, int width, int height) { | ||
frame = new JFrame(); | ||
sg.screen(); | ||
frame.add(sg); | ||
frame.setTitle(title); | ||
frame.setSize(width, height); | ||
frame.setLocationRelativeTo(null); | ||
frame.setIconImage(icon.getImage()); | ||
frame.setResizable(false); | ||
frame.setVisible(true); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package tilegame2d; | ||
|
||
import java.awt.event.ActionEvent; | ||
|
||
import javax.swing.AbstractAction; | ||
import javax.swing.Action; | ||
import javax.swing.JComponent; | ||
import javax.swing.JFrame; | ||
import javax.swing.JRootPane; | ||
import javax.swing.KeyStroke; | ||
|
||
/** | ||
* Contains methods that simply the process of key bindings. | ||
* | ||
* @author Ganesha Ajjampura | ||
* | ||
*/ | ||
public abstract class SimpleGameKeys { | ||
|
||
private Action goUp; | ||
private Action goDown; | ||
private Action goLeft; | ||
private Action goRight; | ||
|
||
public abstract void moveUp(); | ||
|
||
public abstract void moveDown(); | ||
|
||
public abstract void moveLeft(); | ||
|
||
public abstract void moveRight(); | ||
|
||
/** | ||
* Configures W A S D keys to an input and action map with key bindings. | ||
* | ||
* @param frame A JFrame object specifying the main frame used by the game. | ||
*/ | ||
public void configureWasdKeyBindings(JFrame frame) { | ||
goUp = new goUp(); | ||
goDown = new goDown(); | ||
goLeft = new goLeft(); | ||
goRight = new goRight(); | ||
|
||
JRootPane rootOfAll = frame.getRootPane(); | ||
|
||
// Move Up | ||
rootOfAll.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("W"), "goUp"); | ||
rootOfAll.getActionMap().put("goUp", goUp); | ||
|
||
// Move Down | ||
rootOfAll.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("S"), "goDown"); | ||
rootOfAll.getActionMap().put("goDown", goDown); | ||
|
||
// Move Left | ||
rootOfAll.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("A"), "goLeft"); | ||
rootOfAll.getActionMap().put("goLeft", goLeft); | ||
|
||
// Move Right | ||
rootOfAll.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("D"), "goRight"); | ||
rootOfAll.getActionMap().put("goRight", goRight); | ||
} | ||
|
||
private class goUp extends AbstractAction { | ||
|
||
private static final long serialVersionUID = -5327395479500958279L; | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
moveUp(); | ||
|
||
} | ||
|
||
} | ||
|
||
private class goDown extends AbstractAction { | ||
|
||
private static final long serialVersionUID = -2867139883452440832L; | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
moveDown(); | ||
|
||
} | ||
|
||
} | ||
|
||
private class goLeft extends AbstractAction { | ||
|
||
private static final long serialVersionUID = -3638859233582503618L; | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
moveLeft(); | ||
|
||
} | ||
|
||
} | ||
|
||
private class goRight extends AbstractAction { | ||
|
||
private static final long serialVersionUID = 7041504566770698300L; | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
moveRight(); | ||
|
||
} | ||
|
||
} | ||
} |
Oops, something went wrong.