NGSEClubOrganization / Pong

This is our first project: Pong (recreated with JPanels and javax.swing!)
2 stars 1 forks source link

ehh... gameball.java is missing some method #1

Open andrewshi98 opened 10 years ago

andrewshi98 commented 10 years ago

import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Graphics2D.; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.; import java.awt.event.*;

import javax.swing.JFrame; import javax.swing.Timer;

public class GameBall {

private int x, y, mvX, mvY, size;

public GameBall(int parx, int pary, int parmvX, int parmvY, int parSize) {
    x = parx;
    y = pary;
    mvX = parmvX;
    mvY = parmvY;
    size = parSize;
}

public void move() {
    x += mvX;
    y += mvY;
}

//Sets
public void setX(int parX) {x = parX;}
public void setY(int parY) {x = parY;} 
public void setmvX(int parmvX) { mvX = parmvX;}
public void setmvY(int parmvY) { mvY = parmvY;}
public void setSize(int parSize) {size = parSize;}

//Gets
public Rectangle2D sigh(){return new Rectangle2D.Double(x, y, size, size);}
public int getSize() {return size;}
public int getCenterY() {return y;}
public int getX() {return x;}
public int getY() {return y;}
public int getmvX() {return mvX;}
public int getmvY() {return mvY;}    

}

//Should be like that

andrewshi98 commented 10 years ago

for pong.java, just change g2.fill(gameBall.geteEllipse()); to: g2.fill(gameBall.sigh());

andrewshi98 commented 10 years ago

By the way:

change (bCent >= p1Y && bCent < p1Y + ((1/3) * pSizeY)) to (bCent >= p1Y - pSizeY && bCent < p1Y + ((1/3) * pSizeY))

p2 ALSO

rybla commented 10 years ago

Ah thank you! I will implement that

rybla commented 10 years ago

Why should I make gameBall a Rectangle2D though? I think that making it that will make it a draw a rectangle and not a circle (for the gameBall)

rybla commented 10 years ago

And also, I am going to make an edit on the logic of the paddle reflection, for it seems that it changes the y-direction of the ball when it shouldn't. Ill point out the change in my next commit

andrewshi98 commented 10 years ago

Ehhhh.... for the shape of the gameball, i make it as a rectangle because i forgot the name of the method to create a circle.....

AlexBlumer commented 10 years ago

A circle is an Ellipse2D with the length and width being the same.

rybla commented 10 years ago

I made an update, but it doesnt work at all yet. I will work on it more later, but I wanted to throw out my collider testing. Maybe you guys can tweak it so that it work right, it should pretty easily

rybla commented 10 years ago

Its in the TestPong (test for a collider method to collisions rather than boundaries)

andrewshi98 commented 10 years ago

you didn't put break; after every case

rybla commented 10 years ago

Switches and cases have special syntax

rybla commented 10 years ago

Oh wait i see what you mean

rybla commented 10 years ago

i will fix that

rybla commented 10 years ago

Also guys, try to put your new repositories in the Pong / NGSE_Pong repository so we can have all the pong stuff in one place.

rybla commented 10 years ago

Pong now works! Just a few slightly buggy things to fix in my code. I will check your guys's out tomorrow in apcompsci