diff --git a/.idea/misc.xml b/.idea/misc.xml
index 1ce6e7f..d15472f 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/out/production/final/Ball.class b/out/production/final/Ball.class
deleted file mode 100644
index 6b6d60b..0000000
Binary files a/out/production/final/Ball.class and /dev/null differ
diff --git a/out/production/final/GameFrame.class b/out/production/final/GameFrame.class
index 1c47018..324fea9 100644
Binary files a/out/production/final/GameFrame.class and b/out/production/final/GameFrame.class differ
diff --git a/out/production/final/GamePanel.class b/out/production/final/GamePanel.class
index 044ca3c..f46390f 100644
Binary files a/out/production/final/GamePanel.class and b/out/production/final/GamePanel.class differ
diff --git a/out/production/final/GenericObject.class b/out/production/final/GenericObject.class
deleted file mode 100644
index 8d4a782..0000000
Binary files a/out/production/final/GenericObject.class and /dev/null differ
diff --git a/out/production/final/Main.class b/out/production/final/Main.class
index aa9ef20..7723e71 100644
Binary files a/out/production/final/Main.class and b/out/production/final/Main.class differ
diff --git a/out/production/final/Paddle.class b/out/production/final/Paddle.class
deleted file mode 100644
index 18d0f6d..0000000
Binary files a/out/production/final/Paddle.class and /dev/null differ
diff --git a/src/GamePanel.java b/src/GamePanel.java
index a525e47..c43b40d 100644
--- a/src/GamePanel.java
+++ b/src/GamePanel.java
@@ -9,21 +9,24 @@ Implements Runnable interface to use "threading" - let the game do two things at
*/
import java.awt.*;
import java.awt.event.*;
+import java.util.ArrayList;
import javax.swing.*;
public class GamePanel extends JPanel implements Runnable, KeyListener{
//dimensions of window
- public static final int GAME_WIDTH = 1920;
- public static final int GAME_HEIGHT = 1080;
+ public static final int GAME_WIDTH = 1536;
+ public static final int GAME_HEIGHT = 768;
public Thread gameThread;
public Image image;
public Graphics graphics;
public PlayerBall ball;
+ public static ArrayListmap = new ArrayList();
public GamePanel(){
+ map.add(new Tile(1000, 700));
ball = new PlayerBall(GAME_WIDTH/2, GAME_HEIGHT/2); //create a player controlled ball, set start location to middle of screen
this.setFocusable(true); //make everything in this class appear on the screen
this.addKeyListener(this); //start listening for keyboard input
@@ -54,6 +57,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
//call the draw methods in each class to update positions as things move
public void draw(Graphics g){
ball.draw(g);
+ for(Tile i: map){
+ i.draw(g);
+ }
}
//call the move methods in other classes to update positions
@@ -64,14 +70,21 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
//handles all collision detection and responds accordingly
public void checkCollision(){
-
+ ball.isGrounded = false;
+
+ for(Tile i: map){
+
+ }
//force player to remain on screen
if(ball.y<= 0){
ball.y = 0;
}
if(ball.y >= GAME_HEIGHT - PlayerBall.BALL_DIAMETER){
ball.y = GAME_HEIGHT-PlayerBall.BALL_DIAMETER;
+ ball.yVelocity = 0;
+ ball.isGrounded = true;
}
+
if(ball.x <= 0){
ball.x = 0;
}
diff --git a/src/PlayerBall.java b/src/PlayerBall.java
index 176b387..cbd6611 100644
--- a/src/PlayerBall.java
+++ b/src/PlayerBall.java
@@ -9,11 +9,17 @@ import java.awt.event.*;
public class PlayerBall extends Rectangle{
- public int yVelocity;
- public int xVelocity;
- public final int SPEED = 20; //movement speed of ball
+ public double yVelocity;
+ public double xVelocity;
+ public final double SPEED = 20; //movement speed of ball
+ public final double speedCap = 7; //Speed cap of ball
public static final int BALL_DIAMETER = 20; //size of ball
+ public boolean rightPressed = false;
+ public boolean leftPressed = false;
+ public boolean upPressed= false;
+ public boolean downPressed = false;
+ public boolean isGrounded = false;
//constructor creates ball at given location with given dimensions
public PlayerBall(int x, int y){
super(x, y, BALL_DIAMETER, BALL_DIAMETER);
@@ -24,22 +30,19 @@ public class PlayerBall extends Rectangle{
//if the keyboard input isn't any of the options (d, a, w, s), then nothing happens
public void keyPressed(KeyEvent e){
if(e.getKeyChar() == 'd'){
- setXDirection(SPEED);
+ rightPressed = true;
move();
}
-
if(e.getKeyChar() == 'a'){
- setXDirection(SPEED*-1);
+ leftPressed = true;
move();
}
-
if(e.getKeyChar() == 'w'){
- setYDirection(SPEED*-1);
+ upPressed = true;
move();
}
-
if(e.getKeyChar() == 's'){
- setYDirection(SPEED);
+ downPressed = true;
move();
}
}
@@ -48,22 +51,19 @@ public class PlayerBall extends Rectangle{
//Makes the ball stop moving in that direction
public void keyReleased(KeyEvent e){
if(e.getKeyChar() == 'd'){
- setXDirection(0);
+ rightPressed = false;
move();
}
-
if(e.getKeyChar() == 'a'){
- setXDirection(0);
+ leftPressed = false;
move();
}
-
if(e.getKeyChar() == 'w'){
- setYDirection(0);
+ upPressed = false;
move();
}
-
if(e.getKeyChar() == 's'){
- setYDirection(0);
+ downPressed = false;
move();
}
}
@@ -71,27 +71,37 @@ public class PlayerBall extends Rectangle{
//called from GamePanel whenever a mouse click is detected
//changes the current location of the ball to be wherever the mouse is located on the screen
public void mousePressed(MouseEvent e){
- x = e.getX();
- y = e.getY();
+ //x = e.getX();
+ // y = e.getY();
}
- //called whenever the movement of the ball changes in the y-direction (up/down)
- public void setYDirection(int yDirection){
- yVelocity = yDirection;
- }
- //called whenever the movement of the ball changes in the x-direction (left/right)
- public void setXDirection(int xDirection){
- xVelocity = xDirection;
- }
-
- //called frequently from both PlayerBall class and GamePanel class
- //updates the current location of the ball
public void move(){
- y = y + yVelocity;
- x = x + xVelocity;
+ y = y + (int)yVelocity;
+ x = x + (int)xVelocity;
+ if(rightPressed==true){
+ xVelocity+=1;
+ }
+ if(leftPressed==true){
+ xVelocity-=1;
+ }
+ if(upPressed&isGrounded){
+ yVelocity = -10;
+ }
+ xVelocity*=0.9;
+ yVelocity+=0.3;
+ capSpeed();
}
+ public void capSpeed(){
+ if(xVelocity>speedCap){
+ xVelocity = speedCap;
+ } else if(xVelocity<-1*speedCap) {
+ xVelocity = -1*speedCap;
+ }
+ }
+
+
//called frequently from the GamePanel class
//draws the current location of the ball to the screen
public void draw(Graphics g){
diff --git a/src/Tile.java b/src/Tile.java
new file mode 100644
index 0000000..06b7153
--- /dev/null
+++ b/src/Tile.java
@@ -0,0 +1,16 @@
+import java.awt.*;
+
+public class Tile {
+ public int x;
+ public int y;
+ public static final int length = 30;
+ public Tile(int x, int y){
+ this.x = x;
+ this.y = y;
+ }
+
+ public void draw(Graphics g){
+ g.setColor(Color.black);
+ g.fillRect(x, y, length, length);
+ }
+}