yeah right now it just creates an oval at 150, 150 and it does nothing lol. but the dot is movable through the sides of the screen. now im trying to make an array to store different dots and then draw the dots to the screen. its not going to well
[source lang="java"] final int NUM_BALLS = 4; Ball b[]; public void update(Graphics g)//doublebuffer dont touch!! { if(dbImage == null) { dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } dbg.setColor(getBackground()); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); dbg.setColor(getForeground()); paint(dbg); g.drawImage(dbImage, 0, 0, this); } class AnimationThread implements Runnable { JApplet c; public AnimationThread(game game) { this.c = c; } public void run() { c.repaint(); } } class Ball extends Ellipse2D.Float { public Ball(int x, int y, int width, int height, Color mycolor) { } public Ball() { // TODO Auto-generated constructor stub } int x; int y; int width; int height; Color mycolor; public void paint(Graphics g) { g.setColor(mycolor); g.fillOval(x, y, width, height); } } public void Ball(int x, int y, int width, int height, Color mycolor) { b = new Ball[NUM_BALLS]; b[0] = new Ball(10, 10, 15, 15, Color.yellow); b[1] = new Ball(30, 30, 15, 15, Color.red); b[2] = new Ball(50, 50, 15, 15, Color.blue); b[3] = new Ball(70, 70, 15, 15, Color.red); } public void init() { this.setSize(WIDTH, HEIGHT); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3); executor.scheduleAtFixedRate(new AnimationThread(this), 0L, 20L, TimeUnit.MILLISECONDS); } public void start() { Thread th = new Thread(this); th.start();//start main game } public void stop() { } public void destroy() { } public boolean keyDown (Event e, int key) { if(key == Event.LEFT) { xspeed = -5; yspeed = 0; } if(key == Event.RIGHT) { xspeed = 5; yspeed = 0; } if(key == Event.UP) { yspeed = -5; xspeed = 0; } if(key == Event.DOWN) { yspeed = 5; xspeed = 0; } return true; } public void run() { while(true) { repaint(); if (xpos < 1) { xpos = 399; } if (xpos > 399) { xpos = 1; } if (ypos < 1) { ypos = 399; } if (ypos > 399) { ypos = 1; } ypos += yspeed; xpos += xspeed; try { Thread.sleep(20); } catch(InterruptedException ex){} } } public void paint(Graphics g) { Ball ball = new Ball(); g.setColor(Color.black); g.fillOval(xpos - radius, ypos - radius, 2 * radius, 2 * radius); for(int i = 0; i<NUM_BALLS; i++) { b[i].paint(g); } }}[/source]
the problem is in my ball class, i already know that
[source lang="java"] class Ball extends Ellipse2D.Float { int x; int y; int width; int height; Color mycolor; public void paint(Graphics g) { g.setColor(mycolor); g.fillOval(x, y, width, height); } } public void Ball(int x, int y, int width, int height, Color mycolor) { b = new Ball[NUM_BALLS]; b[0] = new Ball(10, 10, 15, 15, Color.yellow); b[1] = new Ball(30, 30, 15, 15, Color.red); b[2] = new Ball(50, 50, 15, 15, Color.blue); b[3] = new Ball(70, 70, 15, 15, Color.red); }[/source]
i know i have to make a constructor for the Ball class somewhere but idk where
Show differencesHistory of post edits
#2burnt_casadilla
Posted 11 August 2012 - 11:04 AM
yeah right now it just creates an oval at 150, 150 and it does nothing lol. but the dot is movable through the sides of the screen. now im trying to make an array to store different dots and then draw the dots to the screen. its not going to well
[source lang="java"] final int NUM_BALLS = 4; Ball b[]; public void update(Graphics g)//doublebuffer dont touch!! { if(dbImage == null) { dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } dbg.setColor(getBackground()); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); dbg.setColor(getForeground()); paint(dbg); g.drawImage(dbImage, 0, 0, this); } class AnimationThread implements Runnable { JApplet c; public AnimationThread(game game) { this.c = c; } public void run() { c.repaint(); } } class Ball extends Ellipse2D.Float { public Ball(int x, int y, int width, int height, Color mycolor) { } public Ball() { // TODO Auto-generated constructor stub } int x; int y; int width; int height; Color mycolor; public void paint(Graphics g) { g.setColor(mycolor); g.fillOval(x, y, width, height); } } public void Ball(int x, int y, int width, int height, Color mycolor) { b = new Ball[NUM_BALLS]; b[0] = new Ball(10, 10, 15, 15, Color.yellow); b[1] = new Ball(30, 30, 15, 15, Color.red); b[2] = new Ball(50, 50, 15, 15, Color.blue); b[3] = new Ball(70, 70, 15, 15, Color.red); } public void init() { this.setSize(WIDTH, HEIGHT); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3); executor.scheduleAtFixedRate(new AnimationThread(this), 0L, 20L, TimeUnit.MILLISECONDS); } public void start() { Thread th = new Thread(this); th.start();//start main game } public void stop() { } public void destroy() { } public boolean keyDown (Event e, int key) { if(key == Event.LEFT) { xspeed = -5; yspeed = 0; } if(key == Event.RIGHT) { xspeed = 5; yspeed = 0; } if(key == Event.UP) { yspeed = -5; xspeed = 0; } if(key == Event.DOWN) { yspeed = 5; xspeed = 0; } return true; } public void run() { while(true) { repaint(); if (xpos < 1) { xpos = 399; } if (xpos > 399) { xpos = 1; } if (ypos < 1) { ypos = 399; } if (ypos > 399) { ypos = 1; } ypos += yspeed; xpos += xspeed; try { Thread.sleep(20); } catch(InterruptedException ex){} } } public void paint(Graphics g) { Ball ball = new Ball(); g.setColor(Color.black); g.fillOval(xpos - radius, ypos - radius, 2 * radius, 2 * radius); for(int i = 0; i<NUM_BALLS; i++) { b[i].paint(g); } }}[/source]
the problem is in my ball class, i already know that
[source lang="java"] final int NUM_BALLS = 4; Ball b[]; public void update(Graphics g)//doublebuffer dont touch!! { if(dbImage == null) { dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } dbg.setColor(getBackground()); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); dbg.setColor(getForeground()); paint(dbg); g.drawImage(dbImage, 0, 0, this); } class AnimationThread implements Runnable { JApplet c; public AnimationThread(game game) { this.c = c; } public void run() { c.repaint(); } } class Ball extends Ellipse2D.Float { public Ball(int x, int y, int width, int height, Color mycolor) { } public Ball() { // TODO Auto-generated constructor stub } int x; int y; int width; int height; Color mycolor; public void paint(Graphics g) { g.setColor(mycolor); g.fillOval(x, y, width, height); } } public void Ball(int x, int y, int width, int height, Color mycolor) { b = new Ball[NUM_BALLS]; b[0] = new Ball(10, 10, 15, 15, Color.yellow); b[1] = new Ball(30, 30, 15, 15, Color.red); b[2] = new Ball(50, 50, 15, 15, Color.blue); b[3] = new Ball(70, 70, 15, 15, Color.red); } public void init() { this.setSize(WIDTH, HEIGHT); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3); executor.scheduleAtFixedRate(new AnimationThread(this), 0L, 20L, TimeUnit.MILLISECONDS); } public void start() { Thread th = new Thread(this); th.start();//start main game } public void stop() { } public void destroy() { } public boolean keyDown (Event e, int key) { if(key == Event.LEFT) { xspeed = -5; yspeed = 0; } if(key == Event.RIGHT) { xspeed = 5; yspeed = 0; } if(key == Event.UP) { yspeed = -5; xspeed = 0; } if(key == Event.DOWN) { yspeed = 5; xspeed = 0; } return true; } public void run() { while(true) { repaint(); if (xpos < 1) { xpos = 399; } if (xpos > 399) { xpos = 1; } if (ypos < 1) { ypos = 399; } if (ypos > 399) { ypos = 1; } ypos += yspeed; xpos += xspeed; try { Thread.sleep(20); } catch(InterruptedException ex){} } } public void paint(Graphics g) { Ball ball = new Ball(); g.setColor(Color.black); g.fillOval(xpos - radius, ypos - radius, 2 * radius, 2 * radius); for(int i = 0; i<NUM_BALLS; i++) { b[i].paint(g); } }}[/source]
the problem is in my ball class, i already know that
#1burnt_casadilla
Posted 11 August 2012 - 11:03 AM
yeah right now it just creates an oval at 150, 150 and it does nothing lol. but the dot is movable through the sides of the screen. now im trying to make an array to store different dots and then draw the dots to the screen. its not going to well
[source lang="java"] final int NUM_BALLS = 4; Ball b[]; public void update(Graphics g)//doublebuffer dont touch!! { if(dbImage == null) { dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } dbg.setColor(getBackground()); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); dbg.setColor(getForeground()); paint(dbg); g.drawImage(dbImage, 0, 0, this); } class AnimationThread implements Runnable { JApplet c; public AnimationThread(game game) { this.c = c; } public void run() { c.repaint(); } } class Ball extends Ellipse2D.Float { public Ball(int x, int y, int width, int height, Color mycolor) { } public Ball() { // TODO Auto-generated constructor stub } int x; int y; int width; int height; Color mycolor; public void paint(Graphics g) { g.setColor(mycolor); g.fillOval(x, y, width, height); } } public void Ball(int x, int y, int width, int height, Color mycolor) { b = new Ball[NUM_BALLS]; b[0] = new Ball(10, 10, 15, 15, Color.yellow); b[1] = new Ball(30, 30, 15, 15, Color.red); b[2] = new Ball(50, 50, 15, 15, Color.blue); b[3] = new Ball(70, 70, 15, 15, Color.red); } public void init() { this.setSize(WIDTH, HEIGHT); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3); executor.scheduleAtFixedRate(new AnimationThread(this), 0L, 20L, TimeUnit.MILLISECONDS); } public void start() { Thread th = new Thread(this); th.start();//start main game } public void stop() { } public void destroy() { } public boolean keyDown (Event e, int key) { if(key == Event.LEFT) { xspeed = -5; yspeed = 0; } if(key == Event.RIGHT) { xspeed = 5; yspeed = 0; } if(key == Event.UP) { yspeed = -5; xspeed = 0; } if(key == Event.DOWN) { yspeed = 5; xspeed = 0; } return true; } public void run() { while(true) { repaint(); if (xpos < 1) { xpos = 399; } if (xpos > 399) { xpos = 1; } if (ypos < 1) { ypos = 399; } if (ypos > 399) { ypos = 1; } ypos += yspeed; xpos += xspeed; try { Thread.sleep(20); } catch(InterruptedException ex){} } } public void paint(Graphics g) { Ball ball = new Ball(); g.setColor(Color.black); g.fillOval(xpos - radius, ypos - radius, 2 * radius, 2 * radius); for(int i = 0; i<NUM_BALLS; i++) { b[i].paint(g); } }}[/source]
[source lang="java"] final int NUM_BALLS = 4; Ball b[]; public void update(Graphics g)//doublebuffer dont touch!! { if(dbImage == null) { dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } dbg.setColor(getBackground()); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); dbg.setColor(getForeground()); paint(dbg); g.drawImage(dbImage, 0, 0, this); } class AnimationThread implements Runnable { JApplet c; public AnimationThread(game game) { this.c = c; } public void run() { c.repaint(); } } class Ball extends Ellipse2D.Float { public Ball(int x, int y, int width, int height, Color mycolor) { } public Ball() { // TODO Auto-generated constructor stub } int x; int y; int width; int height; Color mycolor; public void paint(Graphics g) { g.setColor(mycolor); g.fillOval(x, y, width, height); } } public void Ball(int x, int y, int width, int height, Color mycolor) { b = new Ball[NUM_BALLS]; b[0] = new Ball(10, 10, 15, 15, Color.yellow); b[1] = new Ball(30, 30, 15, 15, Color.red); b[2] = new Ball(50, 50, 15, 15, Color.blue); b[3] = new Ball(70, 70, 15, 15, Color.red); } public void init() { this.setSize(WIDTH, HEIGHT); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3); executor.scheduleAtFixedRate(new AnimationThread(this), 0L, 20L, TimeUnit.MILLISECONDS); } public void start() { Thread th = new Thread(this); th.start();//start main game } public void stop() { } public void destroy() { } public boolean keyDown (Event e, int key) { if(key == Event.LEFT) { xspeed = -5; yspeed = 0; } if(key == Event.RIGHT) { xspeed = 5; yspeed = 0; } if(key == Event.UP) { yspeed = -5; xspeed = 0; } if(key == Event.DOWN) { yspeed = 5; xspeed = 0; } return true; } public void run() { while(true) { repaint(); if (xpos < 1) { xpos = 399; } if (xpos > 399) { xpos = 1; } if (ypos < 1) { ypos = 399; } if (ypos > 399) { ypos = 1; } ypos += yspeed; xpos += xspeed; try { Thread.sleep(20); } catch(InterruptedException ex){} } } public void paint(Graphics g) { Ball ball = new Ball(); g.setColor(Color.black); g.fillOval(xpos - radius, ypos - radius, 2 * radius, 2 * radius); for(int i = 0; i<NUM_BALLS; i++) { b[i].paint(g); } }}[/source]