Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Easy way to click an image on: 2013-04-25 14:37:47
Hi there,

I am not good in java at all, but I am trying to programm in my spare time. I know to do some actions but I have no idea to do any mouse events. Does anyone have a good tutorial for this? Because I want to click an image to go to the next screen. For the menu, so the buttons can work. I got now all the buttons in the menu, but if you can't press them it's really useless.

I have also a screen to show you the buttons.


Already thanks!
-RoseSlayer
2  Game Development / Newbie & Debugging Questions / Re: Rendering Health-System like Zelda or MineCraft? on: 2013-03-29 13:29:56
@matheus23,

I will try the code out, but already thanks for helping me out!

-RoseSlayer
3  Game Development / Newbie & Debugging Questions / Re: Rendering Health-System like Zelda or MineCraft? on: 2013-03-29 13:24:51
@opiop65,
I want to save as much space in my spritesheet as possible, so not the greatest option.

@Cero,
I'm using eclipse with java jdk1.7_0 (maybe jdk1.6_0) only so nothing else then that.

-RoseSlayer
4  Game Development / Newbie & Debugging Questions / Rendering Health-System like Zelda or MineCraft? on: 2013-03-29 13:16:16
Hello there,

Currently I'm working on a small RPG game, but in a RPG game you need health. So I started to begin with coding the health system. The only part that´s still missing is the part of rendering them. The part that I already finished is that you have total 12 hp (in half heart so 6 hp total) and the damage system.

Idea
My idea was to make "half" hearts, this aren't really half hearts but just the same heart image with other color.
If you have as example 7 hp (3,5 hearts total) But how can you code the rendering of this idea?

I don't want the full code, give me some hints/tips how I can do this. I still need too learn alot.
-RoseSlayer
5  Game Development / Game Mechanics / Re: Easy lightning (and chunk system) on: 2013-02-14 20:56:09
It looks like you are just drawing a semi transparent black square over the tiles.

It does look that way! Stop doing that, though. You can tint the sprite in Slick2d using
1  
Color.grey.bind();

and in LibGDX using
1  
spriteBatch.setColor(Color.grey);



This maybe sounds really stupid to you, but how to install Slick2d properly? I used: http://code.google.com/p/gate541/wiki/SlickAndEclipse but it doesn't seems to work, still gives an error at importing Slick2D..

Thanks
-RoseSlayer
6  Game Development / Game Mechanics / Re: Easy lightning (and chunk system) on: 2013-02-12 21:41:49
It looks like you are just drawing a semi transparent black square over the tiles.

If this is not with java2d you can just give it a color value of like .5f, .5f, .5f Basically, scaling down rgb.

If it is with java2d then there are many hacks with AlphaComposites you can use to get fast lighting.

I actually found a way to almost colorize a sprite like opengl without losing acceleration.

Thanks for your reaction, I'm fearly new to programming but I know the basics etc. but however could your give me some more information about the .5f? how I use it as a code etc.

Thanks!
-RoseSlayer
7  Game Development / Game Mechanics / Re: Easy lightning (and chunk system) on: 2013-02-12 16:59:20
But lightning is cool. And it emits light. xD

Haha! that's true.. I don't know why I had called it lightning but lighting is a better word for it (probably because I'm horrible at my English).. Thanks but for my lightning question I solved it almost all. Is there only a way to set the "mask" of the rectangle as example you got a character and you can color it in with 1 color, how is this possible? also here's a small picture:

The question: It's a rec... Is there anyway how the rectangle can "fit" the sprite?
Cause this looks awfull..

Already thanks!
-RoseSlayer
(P.S: It's darker because it's the back layer!)
8  Game Development / Game Mechanics / Re: Easy lightning (and chunk system) on: 2013-02-11 21:45:03
Terraria sprites where for testing porpuse Cheesy glad you like it! But I was already going to make it 14x14 because that is better for liquids either you can't do 13:2 so it isn't the greatest random number that I had choosen. and for the power, that is a great option. I'm going to add that aswell. I think I am going to create an extra class for the lightning aswell. For the chunk system it's great to make it all over again because it's random generated so the new chunck will also be random generated etc. so repeating it might be an excellent idea.
9  Game Development / Game Mechanics / Easy lightning (and chunk system) on: 2013-02-11 16:54:28
Hello there,

I'm currently working on a game that's using squares and it is in 2D. However I want to make it a bit more realistic and maybe larger... So I got some small questions how I can make some smooth lightning that isn't really flat and maps that aren't at maximum 200*200(blocks not pixels, 1 block = 13pixels.)

Lightning System
For the lightning system I tried to do something with variables and just a simple lightning from above. I made the lightning with the fillRec functie and the Color functie the color is basicly (0,0,0,lightning) and in the level tick I made the lightning system like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
               try { //Lightning effect in the air and contact on ground.
                 if(y != 0) {
                     if(block[x][y].id == Tile.air && block[x][y - 1].id == Tile.air || block[x][y].id != Tile.air && block[x][y - 1].id == Tile.air) {
                        block[x][y].lightning = block[x][y - 1].lightning;
                     }
                  }
               } catch(Exception e) { }
               
               try { //Lightning effect spreading on blocks that aren't air.
                 if(y != 0) {
                     if(block[x][y].id != Tile.air && block[x][y - 1].id != Tile.air && block[x][y - 1].lightning != 250 || block[x][y].id == Tile.air && block[x][y - 1].id != Tile.air && block[x][y - 1].lightning != 250) {
                        block[x][y].lightning = block[x][y - 1].lightning + 50;
                     }
                  }
               } catch(Exception e) { }
               



As you can see, I basicly made it the if there's a block above the block and that block isn't equal to the id Tile.air that the lightning += 50. At my first opinion this was a great and easy idea to make a small but working lightning system. It now looks like this:

Some small things I saw and that were that the lightning on not fully squared blocks isn't the best and the lightning isn't really good when there's a platform like this image:


And hints of tips are welcome, I know lightning doesn't spread from top to bottom only but from left and right either.

Chunk System
Is there a good way to make your small chunks loop? like this small prototype map is 50*50 blocks and if you're on block x 30 that it makes a new chunk/level on that place with a looping map not that there's a mountain on that spot and 1 block left of it there are plains..

thanks for reading it already.
-RoseSlayer
10  Game Development / Game Mechanics / Re: Tips for making underground caves, buildings? on: 2013-02-02 19:42:12
Oke I will search for them, thanks alot mate!
I just love Voxels as a word I guess. but whatever

-RoseSlayer
11  Game Development / Game Mechanics / Tips for making underground caves, buildings? on: 2013-02-02 19:34:29
Hello all!

I'm currently developing a voxel-based 2D game. I'm using int random for generating the world but for generating smooth caves I think that random amount of blocks -> air isn't the best option so I'm not asking any source code or whatever (because I am trying to learn) but what might be the best option for generating smooth caves or random buildings. I hope it will be quickle responded because tonight I have alot of time making the generating code. I'm currently making the world by Tiles/Blocks that are 13pixels in height as in width. The best and smoothest option is always the best!

-Roseslayer
12  Game Development / Newbie & Debugging Questions / Re: [unsolved] Recalling an int, gives an "empty" spot. on: 2013-01-01 12:33:47
There is a few solutions you can do.

1) You can store an array of ints if you need the previous values for multiple entries.

2) I think an easier solution might be to have a boolean within the Screen.class like
 boolean upgrade 
. You can iterate through the loop and whatever
 Screen 
needs the upgrade will be automatically updated, then set that variable to false afterward.

3) If it needs to be updated to a certain point. You can store
 int upgrade 
in the Screen.class instead. This way you'll be able to tell a tower exactly how far you want it to upgrade. If the tower isn't at the number upgrade in the Screen.class, then it is time to upgrade it.

[EDIT]
Solved it,

Screen.room.block[blockY][blockX] = Screen.room.block[y]
  • ;
that needs to be
{blockY=y; blockX=x;}
13  Game Development / Newbie & Debugging Questions / Re: [unsolved] Recalling an int, gives an "empty" spot. on: 2012-12-31 16:13:15
I'm not sure I entirely understand your question, but can't you just make a variable that stores it?

for example StoredX and StoredY? and then use those?

I thought to do that the same, so i made blockX and blockY as store places. only when the store gets his first x and y, the blockX and blockY (that are 0 at start) are changing to x and Y (2 and 3 as example so blockX = 2 and blockY =3, but the other values 0,0 are gone and so are the groundID and the airID of that block.
if i change the blockY on start to 3 and blockX to 3 then at (2,2) there's an "empty" spot, do you understand this better? cause I don't know how I can explain it good.

-Roseslayer
thanks already!
14  Game Development / Newbie & Debugging Questions / [Solved] Recalling an int, gives an "empty" spot. on: 2012-12-31 15:23:11
Hello all,
It's me again and I got a small question: Does anyone know the best way to recalling an int that was made with a "for" line? I'm currently using a code where I am doing this:
1  
Screen.room.block[blockY][blockX] = Screen.room.block[y][x];

The only problem is, the previous blockY and blockX are "empty" when you press your LMB. the airID and the groundID are 0 when I press my LMB. I need to "recall" the ints for another script, because when I upgrade a tower it needs to know where to upgrade. My code can be a little bit odd. I'm fairly new to programming.
my whole code:
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  
      if(mouseButton == 1) { 
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = true;
                  Screen.room.block[blockY][blockX] = Screen.room.block[y][x];
                         if(Screen.room.block[y][x].airID >= 2 && Screen.room.block[y][x].airID <= 7){upgradeScreen = Screen.room.block[y][x].airID -1; upgradeStore = true;}else{upgradeStore = false; upgradeScreen =0;}
               } else {
                  Screen.room.block[y][x].rangeVisible = false;
               }
            }
         }
         if(upgradeStore == true){
            for(int i=0;i<upgradeButton.length;i++) {
               if(upgradeButton[i].contains(Screen.mse)) {
                  if(upgradeButtonID[i] != Value.airAir) {
                     if(upgradeButtonID[i] == Value.airUpgrade) {
                        if(Screen.money >= upgradePrice){
                           if(Screen.room.block[blockY][blockX].airID != 4 ){
                              Screen.room.block[blockY][blockX].airID += 1;
                              Screen.money -= upgradePrice;
                              upgradeScreen += 1;
                           }
                        }
                     }
                     if(upgradeButtonID[i] == Value.airSell){
                         Screen.room.block[blockY][blockX].sell();
                        Screen.money += sellPrice;
                     }
                  }
               }
            }
         }


Screen before pressing LMB

Screen after pressing LMB


-Roseslayer
Already thanks!
15  Game Development / Newbie & Debugging Questions / Re: [unsolved] Selecting a boolean multiple times. on: 2012-12-30 16:02:49
[EDIT]
The only parts I don't understand are oneOnly.length();
and oneOnly[mousex][mousey] = true;

You mean, the only parts which give errors are these lines Wink
Okey, sorry for picking around on you Cheesy

I'm sure the first one is supposed to be
oneOnly.length
and the second one: You need to get the mouse position in your window somehow.
There are several ways to do this with java2D. I guess you should google that, because that was answered often.
The first one I already knew, cause he didnt made a void, but still posted it without a reason, sometimes I'm kinda useless and ctomni231, I'm going to try that. cause the problem of my code is the else statement with the if
1  
}else if(!Screen.room.block[y][x].contains(Screen.mse)){
this giving me alot of problems but I am trying your idea, I will send how it went.

[edit]
I did it alot more easier, and fixed it. I'm a little bit brainless that I didn't thaught of this:
1  
                      if(Screen.room.block[y][x].airID >= 2 && Screen.room.block[y][x].airID <= 7){UpgradeScreen = Screen.room.block[y][x].airID -1; upgradeStore = true;}else{upgradeStore = false; UpgradeScreen =0;}


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  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
   public void click(int mouseButton) {
      if(mouseButton == 3) {
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(!Screen.room.block[y][x].contains(Screen.mse)){
                      Screen.room.block[y][x].rangeVisible = false;
                      upgradeStore = false;
                   }
            }
         }
      }
      if(mouseButton == 1) {  
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(Screen.room.block[y][x].contains(Screen.mse)){
                     Screen.room.block[y][x].rangeVisible = true;
                          if(Screen.room.block[y][x].airID >= 2 && Screen.room.block[y][x].airID <= 7){UpgradeScreen = Screen.room.block[y][x].airID -1; upgradeStore = true;}else{upgradeStore = false; UpgradeScreen =0;}
               }else{
                     Screen.room.block[y][x].rangeVisible = false;
               }
            }
         }
         for(int i=0;i<button.length;i++) {
            if(button[i].contains(Screen.mse)) {
               if(store == true){
                  if(buttonID[i] != Value.airAir) {
                     if(buttonID[i] == Value.airTrashCan) {
                        holdsItem = false;
                     } else {
                        heldID = buttonID[i];
                        realID = i;
                        holdsItem = true;
                     }
                  }
               }
            }
               
            if(holdsItem) {
                  if(Screen.money >= buttonPrice[realID]) {
                     for(int y = 0; y<Screen.room.block.length;y++) {
                        for(int x = 0; x<Screen.room.block[0].length;x++) {
                           if(Screen.room.block[y][x].contains(Screen.mse)){
                              if(Screen.room.block[y][x].groundID != Value.groundGrass | Screen.room.block[y][x].airID != Value.airAir) {holdsItem = false;}
                              if(Screen.room.block[y][x].groundID == Value.groundGrass && Screen.room.block[y][x].airID == Value.airAir) {
                                 Screen.room.block[y][x].airID =  heldID;
                                 Screen.money -= buttonPrice[realID];
                                 holdsItem = false;
                                 upgradeStore = true;
                                 if(Screen.room.block[y][x].airID >= 2 && Screen.room.block[y][x].airID <= 7)//2-7 towers in Value.
                                {UpgradeScreen = Screen.room.block[y][x].airID -1;
                                 }
                              }
                           }
                        }
                     }
                  }
            }
         }
      }
      System.out.println("Store=" + store);
      System.out.println("UpgradeStore=" + upgradeStore);
      System.out.println("UpgradeScreen=" + UpgradeScreen);
   }


Thanks for helping me all, really thanks for that!

-Roseslayer
Thanks
16  Game Development / Newbie & Debugging Questions / Re: [unsolved] Selecting a boolean multiple times. on: 2012-12-29 20:08:21
I know where to put this code, but I fully want to understand this code, because I want to know what I am doing in my own programm right?

[EDIT]
The only parts I don't understand are oneOnly.length();
and oneOnly[mousex][mousey] = true;
17  Game Development / Newbie & Debugging Questions / Re: [unsolved] Selecting a boolean multiple times. on: 2012-12-29 19:58:03
Ctomni, sorry for my late reaction, but can you explain your script? If you know what I mean, cause I'm kinda new to java and I don't really know what you're trying to do there.

-Roseslayer
Thanks
18  Game Development / Newbie & Debugging Questions / Re: Selecting a tower. on: 2012-12-28 15:24:46
Anyone know how to fix  the main problem? you cant go in upgradeStore cause it will always be 0 and store will always be true if you arent pressing. someone know what I am doing wrong here?

-Roseslayer
Thanks already
19  Game Development / Newbie & Debugging Questions / Re: Selecting a tower. on: 2012-12-28 13:18:02
All true, but still my problem isn't fixed the CPU is only faster, thanks for that but still I need help at my "main" problem.

-Roseslayer
Thanks
20  Game Development / Newbie & Debugging Questions / Re: Selecting a tower. on: 2012-12-28 01:08:42
How you mean use the else-if statement? This will not change a thing to
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
                if(Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = true;
                  store = false;
                  if(Screen.room.block[y][x].airID == 2) {UpgradeScreen = 1;}//airTowerLaser1.
                 if(Screen.room.block[y][x].airID == 3) {UpgradeScreen = 2;}//airTowerLaser2.
                 if(Screen.room.block[y][x].airID == 4) {UpgradeScreen = 3;}//airTowerLaser3.
                 if(Screen.room.block[y][x].airID == 5) {UpgradeScreen = 4;}//airTowerArcher1.
                 if(Screen.room.block[y][x].airID == 6) {UpgradeScreen = 5;}//airTowerArcher2.
                 if(Screen.room.block[y][x].airID == 7) {UpgradeScreen = 6;}//airTowerArcher3.
              }else if(!Screen.room.block[y][x].contains(Screen.mse)){
                  UpgradeScreen = 0;
                  Screen.room.block[y][x].rangeVisible = false;
                  if(store == false) {store = true;}
               }

Or am I using it wrong at some point

-Roseslayer
Thanks
21  Game Development / Newbie & Debugging Questions / Re: Selecting a tower. on: 2012-12-28 00:49:47
the store boolean is only for to show if the store is on, I'll post some pictures about it,

Store true;


Store false && UpgradeScreen= 1;


Store draw script:
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  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
   public void draw (Graphics g) {
      ImageIcon b = new ImageIcon("res/HUD.png");
      image = b.getImage();
      g.drawImage(image, 0, 0, null);
     
      if(store == false){
         //Makes Buttons
        for(int i=0;i<button.length;i++) {
            //Sell
           if(button[i].contains(Screen.mse)) {
               g.setColor(new Color(255,255,255,120));
               g.fillRect(500,  443+6, 52, 52);
            }
            g.drawImage(Screen.tileset_res[0], 500,  443+6, 52, 52, null);
            g.drawImage(Screen.tileset_air[Value.airSell], 500,  443+6, 52, 52, null);
            //Upgrade
           if(button[i].contains(Screen.mse)) {
               g.setColor(new Color(255,255,255,120));
               g.fillRect(440,  443+6, 52, 52);
            }
            g.drawImage(Screen.tileset_res[0], 440,  443+6, 52, 52, null);
            g.drawImage(Screen.tileset_air[Value.airUpgrade], 440 ,  443+6, 52, 52, null);
         }
         //Showing the tower stats.
        g.setFont(new Font("Courier New", Font.BOLD, 18));
         g.setColor(new Color(41,41,41));
         g.drawRect(198, 443, 154, 64);
         g.drawRect(199, 444, 152, 62);
         g.setColor(new Color(98,98,98,120));
         g.fillRect(200, 445, 151, 61);
         g.setColor(new Color(41,41,41));
         g.drawString(" TOWER STATS", 200, 458);
         g.setFont(new Font("Courier New", Font.BOLD, 14));
         if (UpgradeScreen== 1) {
            g.drawString(" Damage:       20", 200, 470);
            g.drawString(" Range:        180", 200, 480);
            g.drawString(" Rate Of Fire: 100", 200, 490);
            g.drawString(" Sell Price:   10", 200, 500);
         }  
         if (UpgradeScreen== 2) {
            g.drawString(" Damage:       35", 200, 470);
            g.drawString(" Range:        140", 200, 480);
            g.drawString(" Rate Of Fire: 150", 200, 490);
            g.drawString(" Sell Price:   30", 200, 500);
         }
         if (UpgradeScreen== 3) {
            g.drawString(" Damage:       60", 200, 470);
            g.drawString(" Range:        100", 200, 480);
            g.drawString(" Rate Of Fire: 175", 200, 490);
            g.drawString(" Sell Price:   60", 200, 500);
         }
         if (UpgradeScreen== 4) {
            g.drawString(" Damage:       10", 200, 470);
            g.drawString(" Range:        150", 200, 480);
            g.drawString(" Rate Of Fire: 300", 200, 490);
            g.drawString(" Sell Price:   20", 200, 500);
         }  
         if (UpgradeScreen== 5) {
            g.drawString(" Damage:       15", 200, 470);
            g.drawString(" Range:        175", 200, 480);
            g.drawString(" Rate Of Fire: 350", 200, 490);
            g.drawString(" Sell Price:   45", 200, 500);
         }
         if (UpgradeScreen== 6) {
            g.drawString(" Damage:       30", 200, 470);
            g.drawString(" Range:        200", 200, 480);
            g.drawString(" Rate Of Fire: 450", 200, 490);
            g.drawString(" Sell Price:   90", 200, 500);
         }
      }
      if(store == true) {
         for(int i=0;i<button.length;i++) {
            if(button[i].contains(Screen.mse)) {
               g.setColor(new Color(255,255,255,120));
               g.fillRect(button[i].x, button[i].y, button[i].width, button[i].height);
            }
           
            g.drawImage(Screen.tileset_res[0], button[i].x, button[i].y, button[i].width, button[i].height, null);
            if(buttonID[i] != Value.airAir)g.drawImage(Screen.tileset_air[buttonID[i]], button[i].x + itemIn, button[i].y + itemIn, button[i].width - (itemIn*2), button[i].height - (itemIn*2), null);
            if(buttonPrice[i] > 0) {
               g.setFont(new Font("Courier New", Font.BOLD, 14));
               g.setColor(new Color(41,41,41));
               g.drawString("€" +buttonPrice[i] + ",-",  button[i].x + itemIn, button[i].y + itemIn + 62);
            }
         }
      }
     
      g.drawImage(Screen.tileset_res[1], buttonHealth.x, buttonHealth.y, buttonHealth.width, buttonHealth.height, null);
      g.drawImage(Screen.tileset_res[2], buttonCoins.x, buttonCoins.y, buttonCoins.width, buttonCoins.height, null);
      g.drawImage(Screen.tileset_res[3], buttonKilled.x, buttonKilled.y, buttonKilled.width, buttonKilled.height, null);
      g.setFont(new Font("Courier New", Font.BOLD, 14));
      g.setColor(new Color(236, 0, 0));
      g.drawString("" + Screen.health +"/" + Screen.maxHealth, buttonHealth.x + buttonHealth.width + iconSpace, buttonHealth.y + iconTextY);
      g.setColor(new Color(255, 205, 6));
      g.drawString("" + Screen.money, buttonCoins.x + buttonCoins.width + iconSpace, buttonCoins.y + iconTextY);
      g.setColor(new Color(190, 189, 187));
      g.drawString("" + Screen.killed, buttonKilled.x + buttonKilled.width + iconSpace, buttonKilled.y + iconTextY);
      g.setColor(new Color(255, 255, 255));
     
      if(holdsItem) {
         g.drawImage(Screen.tileset_air[heldID], Screen.mse.x - ((button[0].width - (itemIn*2) )/2) + itemIn, Screen.mse.y - ((button[0].width - (itemIn*2) )/2) + itemIn, button[0].width - (itemIn*2), button[0].height - (itemIn*2), null);
      }
   }
22  Game Development / Newbie & Debugging Questions / Re: Selecting a tower. on: 2012-12-27 23:10:48
Thx for your post and I worked it out in the new code. it goes now with Screen.room.block[y][ x]*(as example 3 and 4). Only 1 problem either when i remove the // by the store (//store = true;) then the store will always be true, without my script works good only at 1 point it doesn't work good, a big point: you can press evrywhere on the map and the latest "UpgradeScreen" shows up.

[EDIT]
I changed the code, I debugged few things with System.out.println(""); and it's running very good! only this part isn't running very good:

1  
2  
3  
4  
5  
}else{
           UpgradeScreen = 0;
           Screen.room.block[y][x].rangeVisible = false;
           if(store == false) {store = true;}
}

It's making my other code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
      if(mouseButton == 3) {
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(!Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = false;
               }
            }
         }
         if(holdsItem == true) {holdsItem = false;}
         if(store == false) {store = true;}
      }

not working anymore, I can tell this because without the Store = true; in the first code it's working good only you will always see the Upgrademenu that's why it needs to be false, and same with UpgradeScreen =0; then you will never see the good stats. Anyone got 1 idea for this? Am I missing some point here? please tell me

Whole Code:
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  
54  
55  
56  
57  
58  
59  
60  
public void click(int mouseButton) {
      if(mouseButton == 1) {  
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = true;
                  store = false;
                  if(Screen.room.block[y][x].airID == 2) {UpgradeScreen = 1;}//airTowerLaser1.
                 if(Screen.room.block[y][x].airID == 3) {UpgradeScreen = 2;}//airTowerLaser2.
                 if(Screen.room.block[y][x].airID == 4) {UpgradeScreen = 3;}//airTowerLaser3.
                 if(Screen.room.block[y][x].airID == 5) {UpgradeScreen = 4;}//airTowerArcher1.
                 if(Screen.room.block[y][x].airID == 6) {UpgradeScreen = 5;}//airTowerArcher2.
                 if(Screen.room.block[y][x].airID == 7) {UpgradeScreen = 6;}//airTowerArcher3.
              }else{
                  UpgradeScreen = 0;
                  Screen.room.block[y][x].rangeVisible = false;
                  //if(store == false) {store = true;}
              }
            }
         }
         for(int i=0;i<button.length;i++) {
            if(button[i].contains(Screen.mse)) {
               if(store == true){
                  if(buttonID[i] != Value.airAir) {
                     if(buttonID[i] == Value.airTrashCan) {
                        holdsItem = false;
                     } else {
                        heldID = buttonID[i];
                        realID = i;
                        holdsItem = true;
                     }
                  }
               }
            }
           
            if(holdsItem) {
               if(Screen.money >= buttonPrice[realID]) {
                  for(int y = 0; y<Screen.room.block.length;y++) {
                     for(int x = 0; x<Screen.room.block[0].length;x++) {
                        if(Screen.room.block[y][x].contains(Screen.mse)){
                           if(Screen.room.block[y][x].groundID == Value.groundRoad){holdsItem = false;}
                           if(Screen.room.block[y][x].groundID != Value.groundRoad && Screen.room.block[y][x].airID == Value.airAir) {
                              Screen.room.block[y][x].airID =  heldID;
                              Screen.money -= buttonPrice[realID];
                              holdsItem = false;
                              Screen.store.store = false;
                              if(Screen.room.block[y][x].airID == 2) {UpgradeScreen = 1;}//airTowerLaser1.
                             if(Screen.room.block[y][x].airID == 3) {UpgradeScreen = 2;}//airTowerLaser2.
                             if(Screen.room.block[y][x].airID == 4) {UpgradeScreen = 3;}//airTowerLaser3.
                             if(Screen.room.block[y][x].airID == 5) {UpgradeScreen = 4;}//airTowerArcher1.
                             if(Screen.room.block[y][x].airID == 6) {UpgradeScreen = 5;}//airTowerArcher2.
                             if(Screen.room.block[y][x].airID == 7) {UpgradeScreen = 6;}//airTowerArcher3.
                          }
                        }
                     }
                  }
               }
            }
         }
      }


-Roseslayer
Thanks already.
23  Game Development / Newbie & Debugging Questions / [solved] Selecting a boolean multiple times. on: 2012-12-27 22:27:14
Hello all,

This is my first post on the forum. I'm coming here for learning more Java, cause I'm kinda new to this. Currently I'm making myself a towerdefence game. It all worked out very good so far. Until I needed to make the upgrade/sell system of towers by pressing on them. At this moment I got all the towers stationed in the class Block. So my question is really much how can I select only 1 tower if there are 10 (as example) on the map and only upgrading/ selling that one. Anyone got a good tutorial/ explenation for letting this work, that would be great

[edit]
Ok, I solved some things. only the problem is, when i remove the // by the store (//store = true;) then the store will always be true, without my script works good only at 1 point it doesn't work good, a big point: you can press evrywhere on the map and the latest "UpgradeScreen" shows up.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
            for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(Screen.room.block[y][x].contains(Screen.mse)){
                  store = false;
                  if(Screen.room.block[y][x].airID == Value.airTowerLaser1) {UpgradeScreen = 1;}
                  if(Screen.room.block[y][x].airID == Value.airTowerLaser2) {UpgradeScreen = 2;}
                  if(Screen.room.block[y][x].airID == Value.airTowerLaser3) {UpgradeScreen = 3;}
               } else {
                  //store = true; It will never turn on again. Disabled for testing
              }
            }
         }
   }

-Roseslayer, my English can be really bad.
Thanks.
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (94 views)
2013-05-17 21:29:12

alaslipknot (102 views)
2013-05-16 21:24:48

gouessej (132 views)
2013-05-16 00:53:38

gouessej (127 views)
2013-05-16 00:17:58

theagentd (138 views)
2013-05-15 15:01:13

theagentd (126 views)
2013-05-15 15:00:54

StreetDoggy (168 views)
2013-05-14 15:56:26

kutucuk (189 views)
2013-05-12 17:10:36

kutucuk (192 views)
2013-05-12 15:36:09

UnluckyDevil (199 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 1.141 seconds with 21 queries.