Results 1 to 12 of 12
Thread: How to do a score board?
- 06-02-2010, 10:58 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
How to do a score board?
hey
I wanna make a score board.
for exempel: When you touch the cirkel you should get one point.
could any one please help me:)?
Java Code:import java.applet.*; import java.awt.*; import java.awt.geom.Ellipse2D; import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.*; public class TE extends Applet implements KeyListener { Image bild1; float x = 80.0f, xPlayer = 20.0f; float y = 20.0f, yPlayer = 60.0f; int horPlayer = 0, verPlayer = 0; float hor = 1.0f, ver = 0.5f; Random rnd = new Random(); public void init() { this.addKeyListener(this); } public void paint(Graphics g) { bild1=getImage(getCodeBase(),"prog3.GIF"); BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB); Graphics bufferedGraphics = image.getGraphics(); bufferedGraphics.setColor(Color.WHITE); bufferedGraphics.fillRect(0, 0, image.getWidth(), image.getHeight()); bufferedGraphics.setColor(Color.BLACK); bufferedGraphics.drawRect(10, 10, 150, 150); bufferedGraphics.setColor(Color.RED); int x = (int) this.x; int y = (int) this.y; bufferedGraphics.fillOval(x, y, 10, 10); bufferedGraphics.setColor(Color.BLUE); x = (int) this.xPlayer; y = (int) this.yPlayer; bufferedGraphics.fillOval(x, y, 10, 10); bufferedGraphics.dispose(); g.drawImage(image, 0, 0, null); try { Thread.sleep(15); } catch (InterruptedException e) { System.out.println("EERRRROOOOORRRR"); } uppdatera(); } public void uppdatera() { if (x + hor > 150.0 || x + hor < 10.0) hor = -hor; x += hor; if (y + ver > 150.0 || y + ver < 10.0) ver = -ver; y += ver; if (xPlayer + horPlayer > 150.0 || xPlayer + horPlayer < 10.0) horPlayer = 0; xPlayer += horPlayer; if (yPlayer + verPlayer > 150.0 || yPlayer + verPlayer < 10.0) verPlayer = 0; yPlayer += verPlayer; Shape circlePC = new Ellipse2D.Float(x, y, 10.0f, 10.0f); Shape circlePlayer = new Ellipse2D.Float(xPlayer, yPlayer, 10.0f, 10.0f); if (circlePC.intersects(circlePlayer.getBounds())) { hor = -hor; ver = -ver; do { circlePC = new Ellipse2D.Float(x, y, 10.0f, 10.0f); circlePlayer = new Ellipse2D.Float(xPlayer, yPlayer, 10.0f, 10.0f); x += hor; y += ver; } while (circlePC.intersects(circlePlayer.getBounds())); } repaint(); } private int mathrandom() { // TODO Auto-generated method stub return 0; } public void keyTyped(KeyEvent e) { //empty } public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT) horPlayer = -2; if (key == KeyEvent.VK_RIGHT) { horPlayer = 2; System.out.println("right"); } if (key == KeyEvent.VK_UP) verPlayer = -2; if (key == KeyEvent.VK_DOWN) verPlayer = 2; } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_LEFT && horPlayer != 0) horPlayer = 0; if (key == KeyEvent.VK_RIGHT && horPlayer != 0) horPlayer = 0; if (key == KeyEvent.VK_UP && verPlayer != 0) verPlayer = 0; if (key == KeyEvent.VK_DOWN && verPlayer != 0) verPlayer = 0; } }
- 06-02-2010, 03:52 PM #2
What does the program now do or not do? Please explain.
Add some debugging code using println() to show where in the code its executing and what the values are there.
- 06-02-2010, 04:53 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
The program does:
One cirkel moves randomly in a box and bounce on the walls.
the second cirkel can i move with the arrow keys.
If the second cirkel touch the first cirkel (the one that moves random), then the first cirkel will bounce the other direction.
- 06-02-2010, 04:56 PM #4
Does that explains what you want the program to do.
What does it do now? How do you want to change it? What does it not do?
- 06-02-2010, 05:08 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
This is what is does now:
One cirkel moves randomly in a box and bounce on the walls.
the second cirkel can i move with the arrow keys.
If the second cirkel touch the first cirkel (the one that moves random), then the first cirkel will bounce the other direction.
I wanna make a score board so you can get points if for exampel the blue cirkel touch the first cirkel, then you get one point and so on.
Do you understand?
- 06-02-2010, 05:13 PM #6
OK, How do you trying to detect if the circles touch? One test would be if the distance between the centers of the circles is < sum of their radius's.if for exampel the blue cirkel touch the first cirkel
- 06-02-2010, 05:20 PM #7
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
I mean it was en exempel.
If you can make up some easier way to get score plz help me.
Just so i get score somehow i don,t really care how.
I just wanna learn how to use score. It is my first time.
hmm, i can,t come up with some easy way.....to get score.
- 06-02-2010, 05:26 PM #8
You need to find where in the program it detects that the circles are touching.
Have you found that yet?
Use System.out.println() to output the results. Later you'll need to learn how to add an output field in the applet and display the results there.
- 06-02-2010, 05:30 PM #9
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
Here i suppose:
Java Code:public void uppdatera() { if (x + hor > 150.0 || x + hor < 10.0) hor = -hor; x += hor; if (y + ver > 150.0 || y + ver < 10.0) ver = -ver; y += ver; if (xPlayer + horPlayer > 150.0 || xPlayer + horPlayer < 10.0) horPlayer = 0; xPlayer += horPlayer; if (yPlayer + verPlayer > 150.0 || yPlayer + verPlayer < 10.0) verPlayer = 0; yPlayer += verPlayer; Shape circlePC = new Ellipse2D.Float(x, y, 10.0f, 10.0f); Shape circlePlayer = new Ellipse2D.Float(xPlayer, yPlayer, 10.0f, 10.0f); if (circlePC.intersects(circlePlayer.getBounds())) { hor = -hor; ver = -ver; do { circlePC = new Ellipse2D.Float(x, y, 10.0f, 10.0f); circlePlayer = new Ellipse2D.Float(xPlayer, yPlayer, 10.0f, 10.0f); x += hor; y += ver; } while (circlePC.intersects(circlePlayer.getBounds())); } repaint(); }
- 06-02-2010, 05:34 PM #10
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
I have tried something like
diffrent varibels on player_pos and boll_posJava Code:if( player_pos == boll_pos ) { playerscore += 200; }
But i coulden,t get it to work right.
- 06-02-2010, 10:06 PM #11
What are player_pos and boll_pos?
It looks like:
circlePC.intersects(circlePlayer.getBounds())
is the test to make.
- 06-03-2010, 10:10 AM #12
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
how can I draw a board in 2d array?
By java_fun2007 in forum New To JavaReplies: 8Last Post: 12-28-2011, 05:58 PM -
need help making a game board
By Don k in forum New To JavaReplies: 2Last Post: 04-30-2010, 12:09 AM -
game board design
By tomitu in forum New To JavaReplies: 12Last Post: 02-27-2010, 05:31 PM -
how to create board in java...
By zenith in forum New To JavaReplies: 5Last Post: 01-20-2010, 04:42 AM -
Programming a Board Game
By makanti in forum New To JavaReplies: 7Last Post: 03-10-2009, 02:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks