Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (515)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
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] 2 3 4
1  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-11-07 21:30:56
Nope, the aliens just move until they hit they bottom.

All i want is for them to move periodically, why does something so simple in concept turn out to be complicated? :/

Concept would be:
1. Move Down
2. Wait Duration Of Delay
3. Move Down

loop until game ends :S
2  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-11-06 18:29:37
Using SKIP_TICKS doesnt work :s, if i pass next_game_tick it works but they move down the screen too fast.
3  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-11-06 16:10:16
Thanks for the help Smiley
Really Appreciated Smiley
4  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-11-05 22:22:03
Err... I'm not too sure :S
This is my game loop 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  
      
   // constants for the game loop, fps etc
   final int TICKS_PER_SECOND = 30;
   final int SKIP_TICKS = 1000 / TICKS_PER_SECOND;

   // longs to control the interpolation
   long next_game_tick = System.currentTimeMillis();
   
   long sleep_time = 0;

   // Boolean to say game is running
   boolean game_is_running = true;


   // game loop class
    private class Logic extends Thread
    {
       // constructor for game loop
       public Logic()
       {
          // start the thread
           start();
         }
       // what to do when the thread starts
         public void run()
         {
            // the loop itself
            while( game_is_running )
           {
               // run the update method
              update();
              //  repaint the screen
              invalidate();
           
              // interpolation code
              next_game_tick += SKIP_TICKS;
              sleep_time = next_game_tick - System.currentTimeMillis();
             
              if( sleep_time >= 0 )
              {
                 try
                 {   // stop the thread for a short period of time so that it isn't always running
                    Thread.sleep(sleep_time);
                 }
                 catch(InterruptedException e)
                 {
                    e.printStackTrace();
                 }
              }
              else
              {
                 // Running behind
              }
           }
         }
    }
5  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-11-04 16:13:11
My gameloop dosnt have an elapsed time, how will i do about getting that :/
6  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-11-03 16:19:22
SHC do you just pass getCurrentTime() to the update() eg. update(getCurrentTime);?
7  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-11-02 15:53:12
i havent put it in yet, im still trying to work out how to pass the elapsed time variable, im not sure whether system.currentTimeMilliseconds() will work or not
8  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-11-01 15:01:08
It does Smiley Thanks a lot Smiley
9  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-10-30 20:40:17
Is there a better way for me to handle the movement of the rows of aliens down the screen in a way so that i change the period between each movement?
10  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-10-30 20:12:42
If there is only one timer will it cause an issue creating multiple timertasks?
oh and in the timertask's run method, i will want to change the speed every 5 levels, so could i use
1  
2  
3  
4  
if( level.getLevel() % 5 )
{
 this.cancel();
}


then have a variable that is changed in the period parameter
11  Game Development / Newbie & Debugging Questions / Re: Multidimensional Array Movement on: 2013-10-30 20:01:48
That works wonders, now however, if the level changes i want the period variable to decrease so that there is less time between each movement, is there anyway to do that?
12  Game Development / Newbie & Debugging Questions / Multidimensional Array Movement on: 2013-10-29 12:16:40
I'm making a space invaders-esk game and i have 3 rows of 11 aliens. I've down this by creating a multi-dimensional array of aliens As this is supposed to be an invasion the aliens need to move down the screen every so often, currently i'm using this:
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  
 // update the game
    public void update()
    {      
       // schedule the aliens to move down
       alienTimer.schedule(new TimerTask(){

         public void run()
         {
             // move the aliens row by row
             moveAliens();
         }
         
       }, 1000, 2000);
     
    }

    // move the aliens row by row
    private void moveAliens()
    {
       for(int i = (aliens.length -1); i > -1; i--)
       {
          for(int j = 10; j > -1; j--)
          {
             if(aliens[i][j] == null)
             {
                // Do nothing alien doesn't exist
             }
             else
             {
                // move the alien down
                aliens[i][j].moveDown();
             }
          }
       }
    }

// Alien Move Down method
// move the alien
   public void moveDown()
   {
      getPosition().y += 5;
   }


but when i run the game the after the second delay all the aliens just move down the screen without stopping for the 2 second period. I've also tried scheduleAtFixedRate, but it had the same result.

Anyone have any ideas, and whilst your here, how could i go about having different rows move in opposite directions left and right, eg row 1 would move left, hit the screen bounce then move right, row 2 would move right, it the screen bounce, then move left.

Thanks for any help
13  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-23 18:43:51
Doesnt matter. I dungoofed. I was initalising a timer that wasnt being used
14  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-23 18:40:49
No, all my rockets are on the one thread, and that thread is basically the game loop
15  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-23 18:37:04
If i try and reuse the rockets, everything is good, up until i get a different error. TooManyThreads. How exactly did i manage to get this o.O? How do I go about approaching it? I google it and it doesnt help me much, just some people posting on forums asking how many threads is too many
16  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-23 18:13:34
That doesn't appear to work either, I am receiving the same problem.
17  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-22 20:37:44
Everything seems to be working okay-ish.

Multiple rockets will fire, but if i move the ship, therefore moving the starting x position of the rocket im getting the array out of bounds exception. Here is my porjectile, player rocket, array list, and methods that i use that when firing a rocket.

ArrayList
http://pastebin.java-gaming.org/b4d17773178

Projectile
http://pastebin.java-gaming.org/4d17781387c

PlayerRocket ( extends projectile )
http://pastebin.java-gaming.org/d1771983c73

The Methods
http://pastebin.java-gaming.org/177180c4371

My error is
1  
         elements[size++] = e;


in the
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   // Add the object to the array
   public void add(PlayerRocket e)
   {
      if(getSize() >= DEFAULT_CAPACITY)
      {
         // Do nothing can't have more than 16 on screen at once
      }
      else
      {
         // add the object at specific point
         elements[size++] = e;
      }
   }

of the projectile.

and it is telling me
1  
size = 2


18  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-22 20:15:23
Yeah, for the cloning I'm thinking of two solutions to it.
To clone it everytime i remove an element, or to create another array with each of the positions of the objects to be removed, then clone the arraylist, iterate through the array with the positions, then remove the objects from the temporary one, and then set the original list the same as the temp one.

Now i just need to try and find away to clone it :/
19  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-22 20:03:39
Yeah but its the library im most comfortable with, also gives me a market.

Here would this "list" help me at all?
http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/collection/List.html

 I think it might, if i can create a way to clone it then i could possibly clone the arraylist to another arraylist, remove the object from the temporary arraylist and then at the end set the permanent one the same as the tmp one?
20  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-22 19:55:07
Yeah, they've left out some classes that make things easier. I'll use the unsortedreadablelist. Does sorting matter? and I'll also check the enumeration for the for each, can i not simply use a basic for loop for this?
21  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-22 19:44:09
Jeremy in your StaticSet.java you use ArrayList and Iterator. Neither of these are available to me whereas the NoSuchElement is.
Could I possibly use my own ArrayList as a substitute for the ArrayList<>. However the iterator part i@m not too sure on.
22  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-22 19:23:33
I've created my own ArrayList class. With the JDK I'm now allowed to use type so it's specific for my PlayerRocket:
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  
package {...}data;

import {...}PlayerRocket;

public class ArrayList {
   
   // Constants
   private final int DEFAULT_CAPACITY = 16;
   
   // Store the objects into an array
   public PlayerRocket[] elements;
   
   // Integer
   private int size = 0;
   
   // Methods
   // Constructor
   public ArrayList()
   {
      // set the default capacity of the array
      elements = new PlayerRocket[DEFAULT_CAPACITY];
     
   }
   // Add the object to the array
   public void add(PlayerRocket e)
   {
      if(getSize() >= DEFAULT_CAPACITY)
      {
         // Do nothing can't have more than 16 on screen at once
      }
      else
      {
         // add the object at specific point
         elements[size++] = e;
      }
   }
   
   
   // Remove the object at a certain location
    public void remove(int i) {
       // Check to see if it will cause an error
           if (i < 0 || i > elements.length) {
               throw new ArrayIndexOutOfBoundsException();
           } else {
              // now set it to null
               elements[i] = null;
               // create a temporary list of objects
               PlayerRocket[] tmp = new PlayerRocket[--size];
               int foo = 0;
               // iterate through the elements list and add any non-null to tmp
               for(int j = 0; j < elements.length; j++) {
                   if(elements[j] != null) {
                       tmp[foo] = elements[j];
                       foo++;
                   }
               }
               // make elements equal to the tmp
               elements = tmp;
           }
       }

   
   // Getters and Setters
   public int getSize() {
      return size;
   }
   public void setSize(int size) {
      this.size = size;
   }
   
   public PlayerRocket[] getContents()
   {
      return elements;
   }
   
   public PlayerRocket getElement(int i)
   {
      return elements[i];
   }

}


And if i removed whilst iterating, i get an ArrayOutOdBoundsException.

Also I cannot use the LinkedList. It isnt available to me
23  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-21 21:15:09
I found a much better way :O
Blackberry has an Arrays class, if i extend that or even just use it on its own then I'm sorted
24  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-21 21:12:49
Looks like I have two options now.
I can either make my own one, or try and use this one : http://www.blackberry.com/developers/docs/4.3.0api/net/rim/device/api/collection/util/UnsortedReadableList.html

honestly, I think my best idea would be to create my own one. That way i have complete control over it.
25  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-21 20:51:01
out of interest, can you do the following without it complaining:

1  
java.util.ArrayList<String> test = new java.util.ArrayList<String>();



Nope it complains. I'll try and create my own class.

@Phibedy, why can't I just remove from the array list?
26  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-21 20:35:35
It was a lot of use! Thank you, gives me the theory to it.

Err... Yeah blame RIM. I'm working with the BlackBerry JDE 4.5.0 and when i try and import it, it wont let me, which means I can't use it Sad
So now i need to try and create a clone of it, which I'm skeptical of, because I'm not sure what the <> part of the ArrayList means.
27  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-21 20:30:32
Turns out I can't use ArrayList<>. it isnt included in the libraries that get delivered to the device im working for.

How can I go about creating a clone of this class?
28  Game Development / Newbie & Debugging Questions / Re: Using ArrayList<> adding and removing objects on: 2013-10-21 20:26:39
Thanks for the help so far, I think I can get to answer from here, what I'm looking for is once the active boolean equals false, then the rocket needs to be removed from the list, but I'm sure I can simply do an if check in the loop, my only problem is, i'll need it to iterate through this every time i call the repaint method will this slow down my game?
Because the rocket shouldnt be rendered if it isnt active, that way i want to remove it from the screen and list.
29  Game Development / Newbie & Debugging Questions / [Solved] Using ArrayList<> adding and removing objects on: 2013-10-21 19:20:19
Ok, so I'm planning on using ArrayList<> to add a PlayerRocket every time a rocket is fired.

I know that I can add them by using the add(Object o) method of the ArrayList<>.

Now what my problem is, is that my PlayerRocket has a boolean which says whether the rocket is active or not, and when that equals false, i need to remove that specific rocket from the arraylist. When i read the documentation, it says that using the method remove(Object o) removes the first one of that object off the list, how can i remove specific ones.

OR

is there an alternative, maybe where i can create my own ArrayList<> type class because i will need to iterate through the list as well?

Any help much appreciated
30  Game Development / Newbie & Debugging Questions / Re: What is the best practice for updating a game? on: 2013-09-25 16:56:15
A launcher is out of the question as it is to be deployed on a mobile device, however for desktop games I certainly see the usage of it.

The patches doesnt sound like a bad idea, but it would mean needing to code networking into the game or even just the titlescreen to check whether a new patch needs to be downloaded, and then it would download it, however i have a feeling that i'm left with just the full installation.

With that in mind, i'll just need to try my best to keep file sizes down, because when its on a mobile, i dont think someone is prepared to what however long it takes for their carrier internet service to download a GB worth of game files

Thanks everyone
Pages: [1] 2 3 4
 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (30 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (39 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (25 views)
2014-10-26 10:14:04

theagentd (31 views)
2014-10-25 15:46:29

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

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

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

lcass (43 views)
2014-10-15 16:18:58
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!