CollisionScript.java -- Nears Incompletion

Discussion in 'JavaScript' started by Dhingcha, Aug 16, 2008.

Thread Status:
Not open for further replies.
  1. #1
    Hey, you guys. [sarcasm]Well, I just have to say, "What a great idea to stick 'Java Programming' in such an easy-to-find, manageable location!"[/sarcasm]

    Enough said. I'm currently working on an applet source for my newest series of noob-friendly tutorials. Too early in the morning--too tired.

    Here's the crap I jotted down in a minute or two. See if you guys can improve the semantics or pragmatics (however, I seem to have my prag's down-pat). It's supposed to be like one of those boring bouncing "RCA" logos bouncing from wall to wall on your television screen when you've been sitting idle too long without a good DVD. It needs to go slower and implement the directional enumerators to dictate which direction the sprite should move in terms of diagonal directions. There still needs to be wall collision detector and change the enumerator value accordingly.

    /* Author:  Brandon Zimmerman
     * E-mail:  b-zimmerman@live.com
     * Created: 06/07/08; 2:47 AM
     * 
     * (c) 2008 Circa Software Studios
     */
    
    import java.awt.*;
    import java.applet.*;
    
    public class BounceEffect extends Applet {    
        enum Direction {
            NW,SW,NE,SE
        }
        public void paint(Graphics g) {
            Direction directionOfSprite = Direction.SE;
            byte xPos = 5;
            byte yPos = 5;
            g.setColor(Color.BLACK);
            g.fillRect(0,0,300,250);
            for (;;) {
                g.setColor(Color.BLACK);
                g.drawRect(xPos,yPos,2,2);
                g.setColor(Color.GREEN);
                if (directionOfSprite == Direction.SE)
                    g.drawRect(++xPos,++yPos,2,2);
                else if (directionOfSprite == Direction.NE)
                    g.drawRect(++xPos,--yPos,2,2);
                else if (directionOfSprite == Direction.SW)
                    g.drawRect(--xPos,++yPos,2,2);
                else
                    g.drawRect(--xPos,--yPos,2,2);
            }
        }    
    }
    Code (markup):
    Thanks for your help you guys. If you want to simply post the source, that would do just nicely.
     
    Dhingcha, Aug 16, 2008 IP
Thread Status:
Not open for further replies.