-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from gal11002/GavinClone
Gavin clone
- Loading branch information
Showing
12 changed files
with
618 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,98 @@ | ||
package sprites; | ||
|
||
import java.awt.Color; | ||
import java.awt.Graphics2D; | ||
import java.awt.event.KeyEvent; | ||
|
||
import view.MapUI; | ||
|
||
public class PlayerSprite { | ||
private static final int WIDTH = 30; | ||
MapUI mapui; | ||
public int x, y = 0; | ||
public int row, col; | ||
int dx, dy = 0; | ||
public int changeInX = 0; | ||
public int changeInY = 0; | ||
Color color = new Color(0, 0, 0); | ||
boolean leftBeingPressed = false; | ||
boolean rightBeingPressed = false; | ||
boolean downBeingPressed = false; | ||
boolean upBeingPressed = false; | ||
|
||
public PlayerSprite(MapUI mapui) { | ||
this.mapui = mapui; | ||
} | ||
|
||
public void keyPressed(KeyEvent e) { | ||
if (e.getKeyCode() == KeyEvent.VK_LEFT) { | ||
dx = -1; | ||
leftBeingPressed = true; | ||
} | ||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) { | ||
dx = 1; | ||
rightBeingPressed = true; | ||
} | ||
if (e.getKeyCode() == KeyEvent.VK_UP) { | ||
dy = -1; | ||
upBeingPressed = true; | ||
} | ||
if (e.getKeyCode() == KeyEvent.VK_DOWN) { | ||
dy = 1; | ||
downBeingPressed = true; | ||
} | ||
} | ||
|
||
public void keyReleased(KeyEvent e) { | ||
if (e.getKeyCode() == KeyEvent.VK_LEFT) { | ||
leftBeingPressed = false; | ||
if (rightBeingPressed == false) | ||
dx = 0; | ||
} | ||
|
||
if (e.getKeyCode() == KeyEvent.VK_RIGHT) { | ||
rightBeingPressed = false; | ||
if (leftBeingPressed == false) | ||
dx = 0; | ||
} | ||
|
||
if (e.getKeyCode() == KeyEvent.VK_UP) { | ||
upBeingPressed = false; | ||
if (downBeingPressed == false) | ||
dy = 0; | ||
} | ||
|
||
if (e.getKeyCode() == KeyEvent.VK_DOWN) { | ||
downBeingPressed = false; | ||
if (upBeingPressed == false) | ||
dy = 0; | ||
} | ||
|
||
// This fixes some bugs with holding three keys down at once and letting go of two (Basically ensures that dx and dy match which keys are currently being held) | ||
if(leftBeingPressed) | ||
dx = -1; | ||
if(rightBeingPressed) | ||
dx = 1; | ||
if(downBeingPressed) | ||
dy = 1; | ||
if(upBeingPressed) | ||
dy = -1; | ||
|
||
} | ||
|
||
public void move() { | ||
if (x + dx >= 0 && x + dx <= mapui.getWidth() - WIDTH && y + dy >= 0 && y + dy <= mapui.getHeight() - WIDTH) { | ||
x = x + dx; | ||
changeInX = changeInX + dx; | ||
y = y + dy; | ||
changeInY = changeInY + dy; | ||
} | ||
|
||
} | ||
|
||
public void paint(Graphics2D g) { | ||
g.setColor(color); | ||
g.fillOval(x, y, WIDTH, WIDTH); | ||
} | ||
|
||
} |
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,33 @@ | ||
package tests; | ||
|
||
import javax.swing.JFrame; | ||
|
||
import model.Map; | ||
import model.Player; | ||
import view.MapUI; | ||
import controller.RPGame; | ||
|
||
public class MockGame { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
// This sets up the window for the game which is a 300 by 300 pixels JFrame | ||
Player player = new Player("TestPlayer", 0, null); | ||
Map map = new Map(30, 40); | ||
map.initializePlayer(player, 0, 0); | ||
JFrame frame = new JFrame("Merchant RPG"); | ||
MapUI mapui = new MapUI(map); | ||
frame.add(mapui); | ||
frame.setSize(RPGame.WIDTH, RPGame.HEIGHT); | ||
frame.setResizable(false); | ||
frame.setVisible(true); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setLocationRelativeTo(null); | ||
|
||
while (true) { | ||
mapui.move(); | ||
mapui.repaint(); | ||
Thread.sleep(10); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.