
-----------------------------------
FigNeutron
Fri Jun 12, 2015 10:07 pm

Ready to Program Java Pong Game moving paddles help
-----------------------------------
Hi, im trying to get my paddle to move up and down, and wondered if someone can tell me why its only moving once and then stops, i will paste my code for my main game class and my paddle class.

I am very new to java, this being my first non hsa console game, all help is greatly appreciated


import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import usefulstuff.*;
import java.util.*;


public class Pong
{
    public static void main (String

and the paddle class...


package usefulstuff;
/**
 * paddle Class (Grade 11)
 *
 * @author Patrick 
 * @version 1
 */
import java.awt.*;
import javax.swing.*;
import hsa.Console;

public class paddle
{
    // INSTANCE VARIABLES
    private int h; // height of the mine
    private int x; //x coordinate of the upper left corner of the line
    private int y; //y coordinate of the upper left corner of the mine
private Color color; //color of paddle
    /**
     * Constructor for objects of class ImageShape
     */
    public paddle ()
    {
        //declare all initital values
        h = 100;
        x = 100;
        y = 100;
        color = Color.white;
    }



    /**
    * Draws the ImageShape
    *
    * @param g   the Graphics context to draw on
    */
    public void draw (Console c)
    {
        c.setColor (color);
        c.fillRect (x,y,10,50);

        
    }
 public void draw (Graphics g)
    {
        g.setColor (color);
        g.fillRect (x,y,10,80);

        
        
    }

    /**
     * Sets the height of a ImageShape
     *
     * @param  newh   new height of the ImageShape
     */
    public void setHeight (int newh)
    {
        h = newh;
    }


    /**
     * Sets the color of a mine
     *
     * @param  newh   new color of the paddle
     */
    public void setColor (Color newc)
    {
        color = newc;
    }
    
    /**
     * Sets the color of a mine
     *
     * @param  newh   new color of the paddle
     */
    public Color getColor ()
    {
        return color;
    }
    
    
    // public boolean contains (int ptx, int pty)
    // {
    // //if point is withi the square surrounding pacman- return true
    // //if (x< otx < x+h) AND (y < pty < y + h)
    // if (x < ptx < x + h && y 
    // 
    
    
    
    
    
    
    
    
    
    
    
    
    
    


    /**
    * Returns the height of the ImageShape
    *
    * @return  the height
    */
    public int getHeight ()
    {
        return h;
    }


    /**
    *Returns the X of the paddle
    *
    *@return  x coord of the upper left corner of the mine
    */
    public int getX ()
    {
        return h;
    }


    /**
    *Returns the y of the mine
    *
    *@return  the y coordinate of the upper left corner
    */
    public int getY ()
    {
        return h;
    }
    
     /**
    *Returns the center X of the mine
    *
    *@return  the center X
    */
    public int getCenterX ()
    {
        return x+h/2;
    }

     /**
    // *Returns the center Y of the mine
    // *
    // *@return  the center Y
    // */
    // public int getCenterX ()
    // {
    //     return x+h/2;
    // }

    /**
     * Sets the (x,y) coordinates of upper left corner of the ImageShape
     *
     * @param  newx   new x coordinate
     * @param  newy   new y coordinate
     */
    public void setPosition (int newx, int newy)
    {
        x = newx;
        y = newy;

    }






} // ImageShape class


the problem is that the paddle only moves up or down once, and then becomes unresponsive, the 3 states are for my loading, menu, and game screens.
Again, thanks alot. this has been really bugging me, and sorry for any mistakes in advance, first time poster.

-----------------------------------
Zren
Fri Jun 12, 2015 11:25 pm

RE:Ready to Program Java Pong Game moving paddles help
-----------------------------------
What's wrong with this picture?

http://i.imgur.com/ctvNSnU.png

-----------------------------------
FigNeutron
Fri Jun 12, 2015 11:28 pm

RE:Ready to Program Java Pong Game moving paddles help
-----------------------------------
OMG ahahhaha, thanks for that, i cant believe i kept missing that, and to whoever arranged my code to picture format, is there a link explaining how to do that?

-----------------------------------
Zren
Fri Jun 12, 2015 11:31 pm

RE:Ready to Program Java Pong Game moving paddles help
-----------------------------------
You wrap code like so:


class Hello {}

[/code]

-----------------------------------
FigNeutron
Fri Jun 12, 2015 11:33 pm

RE:Ready to Program Java Pong Game moving paddles help
-----------------------------------
Ok, i fixed the above^^ picture in my code, but that did not solve the problem, the rectangle moves up 10 once, but then wont respond, and again sorry, im a real noob

--ok, thanks for letting me know about the wrapping

-----------------------------------
FigNeutron
Fri Jun 12, 2015 11:40 pm

RE:Ready to Program Java Pong Game moving paddles help
-----------------------------------
oh....just realized i have key char instead of code...

-- so now it can move up or down (lol) but still only once, i know this is a waste of all your time, but id appreciate if someone could show me why this is, and thanks for the help so far!

-----------------------------------
FigNeutron
Sun Jun 14, 2015 4:22 pm

RE:Ready to Program Java Pong Game moving paddles help
-----------------------------------
i figured it out guys, had to set position variables and add or subtract from them, thanks anyways
