Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualburnt_casadilla

Posted 11 August 2012 - 02:42 PM

[source lang="java"] class Ball { int x; int y; int width; int height; public Ball(int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; } } Ball ball1 = new Ball(100, 100, 20, 20); Ball ball2 = new Ball(200, 200, 20, 20); Ball ball3 = new Ball(50, 50, 20, 20); Ball ball4 = new Ball(25, 25, 20, 20); 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); } public void init() { this.setSize(WIDTH, HEIGHT); } public void start() { Thread th = new Thread(this); th.start();//start main game } 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) { g.setColor(Color.black); g.fillOval(xpos - radius, ypos - radius, 2 * radius, 2 * radius); g.setColor(Color.blue); g.fillOval((int)ball1.x, (int)ball1.y, (int)ball1.width, (int)ball1.height); g.setColor(Color.red); g.fillOval((int)ball2.x, (int)ball2.y, (int)ball2.width, (int)ball2.height); g.setColor(Color.green); g.fillOval((int)ball3.x, (int)ball3.y, (int)ball3.width, (int)ball3.height); g.setColor(Color.magenta); g.fillOval((int)ball4.x, (int)ball4.y, (int)ball4.width, (int)ball4.height); } }[/source]

got number 1 i think

#1burnt_casadilla

Posted 11 August 2012 - 02:42 PM

[source lang="java"] class Ball { int x; int y; int width; int height; public Ball(int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; } } Ball ball1 = new Ball(100, 100, 20, 20); Ball ball2 = new Ball(200, 200, 20, 20); Ball ball3 = new Ball(50, 50, 20, 20); Ball ball4 = new Ball(25, 25, 20, 20); 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); } public void init() { this.setSize(WIDTH, HEIGHT); } public void start() { Thread th = new Thread(this); th.start();//start main game } 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) { g.setColor(Color.black); g.fillOval(xpos - radius, ypos - radius, 2 * radius, 2 * radius); g.setColor(Color.blue); g.fillOval((int)ball1.x, (int)ball1.y, (int)ball1.width, (int)ball1.height); g.setColor(Color.red); g.fillOval((int)ball2.x, (int)ball2.y, (int)ball2.width, (int)ball2.height); g.setColor(Color.green); g.fillOval((int)ball3.x, (int)ball3.y, (int)ball3.width, (int)ball3.height); g.setColor(Color.magenta); g.fillOval((int)ball4.x, (int)ball4.y, (int)ball4.width, (int)ball4.height); } }got number 1 i thinnk[/source]

PARTNERS