Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Best way to track and display score?  (Read 650 times)
0 Members and 1 Guest are viewing this topic.
Offline Bassex96

Senior Duke


Medals: 4



« Posted 2013-04-21 03:29:09 »

I'm trying to add score to my brickbreaker game. When the brick is hit, I want the score to appear above the brick and fade upward. I've made a score class, but it is all kinds of jacked up. I'm going to scrap the whole class and start over..I've been trying to pass the spritebatch through classes to get to the score class and all that and it's just not working...

My bricks are drawn in my level class, my game logic is in GameScreen. I'm confused where to draw what and how to put it together..Any advice is very appreciated! I hope i've explained my problem correctly..
Offline alaslipknot
« Reply #1 - Posted 2013-04-21 17:44:55 »

i think the easy way to do it is :

1- create a variable that hold your score
2-check if the ball hit a brick
if it does
3-add "point" to your score integer
4-draw a string that contain your score int in the X & Y coordinate of the brick
   in the same time :
    -you create a variable that will be the transparency setting of your string
    and you do something like that
    - TranSetting -=1 ;
      if (tranSetting==0){
      tranSetting=0;          //just to stop decreasing
      }
5-when you hit a brick again, the tranSetting back to it's normal value and you redo everything from step #3


i dunno if i helped
good luck
 

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline Bassex96

Senior Duke


Medals: 4



« Reply #2 - Posted 2013-04-21 18:08:54 »

Thanks.  I meant organization-wise really. I've got it implemented already, but i'm not sure i'm doing it the best way. I'm fairly happy with it now though.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alaslipknot
« Reply #3 - Posted 2013-04-21 18:50:56 »

Thanks.  I meant organization-wise really. I've got it implemented already, but i'm not sure i'm doing it the best way. I'm fairly happy with it now though.

"A man who carries a cat by the tail learns something he can learn in no other way."
~Mark Twain~

it doesn't matter if you do it the best way for the first time, in fact, i believe it will "hurt" you specially if you are learning (copying) from other people, do it you way and then when it doesn't work, you should ask for help, i think it's the best way to learn   

good luck

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #4 - Posted 2013-04-21 20:09:32 »

In the context of gamedev, that is absolute blasphemy. You could make a game loop run perfectly your computer but not on soneone else's, but you would never notice. It's extremely important to get it right the first time, otherwise you will develop bad habits...
Offline Bassex96

Senior Duke


Medals: 4



« Reply #5 - Posted 2013-04-21 20:27:15 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
package com.psillicoder.brickbreaker;

import com.badlogic.gdx.math.Rectangle;

public class Score {
   private static final int distance = 50;
   private int x;
   private int y;
   private String text;
   private int intScore;
   private int iDistance = 0;
   private boolean bDestroyed = false;
   public Score(int score, int x, int y) {
      this.intScore = score;
      this.x = x;
      this.y = y;
      text = "+" + score;
   }

   
   public void update() {
      //for (int i=0;i<=distance;i++) {
      if (iDistance <= distance) {
         if (iDistance==50) {
            bDestroyed = true;
         }else
         {
         this.y++;
         this.iDistance++;
         }
     
      }
   }
   
   public boolean isDestroyed() {
      return bDestroyed;
   }
   
   public int getX() {
      return this.x;
   }
   
   public int getY() {
      return this.y;
   }
   
   
   
   public String getScore() {
      String stringScore = "+" + this.intScore;
      return stringScore;
   }
}


That is my code for showing the score when the brick is hit and moving it up the screen until it disappears. I'm going to add some alpha blending too.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (75 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!