Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
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
1  Game Development / Newbie & Debugging Questions / Re: Protecting database connection string on: 2013-10-17 14:07:01
Ah i was being an idiot, the question was in relation to a client->server application so yeah only the server needs to connect to the DB.
Thanks Smiley
2  Game Development / Newbie & Debugging Questions / Protecting database connection string on: 2013-10-17 13:44:51
When you connect using ODBC you have to provide credentials to connect to the DB. How do you protect from someone just reading the connection string once decompiled?
3  Game Development / Newbie & Debugging Questions / Re: Collision Detection with some Rectangles on: 2012-09-18 15:22:49
You could put all the Rectangles into an array of rectangles then you can go through them all in a for loop e.g.
1  
2  
3  
4  
5  
6  
for(int i = 0; i < rectangles.length(); i++){
       if(player.intersects(rectangles[i])){
         stopMovement();
         setOffWall(rect);
       }
}
4  Game Development / Newbie & Debugging Questions / Re: Java2D painting transparent overlay pause menu on: 2012-05-03 15:02:51
ohhhh okay i get you, think ill have the paused variable in the class thats calling those methods though e.g.

1  
2  
3  
4  
if(paused){
  player.update();
  map.updateTiles();
}
5  Game Development / Newbie & Debugging Questions / Re: Java2D painting transparent overlay pause menu on: 2012-05-03 14:47:50
okay i'm separating out the logic and rendering code completely into two different methods, should make life easier. I'm using an abstract super class for all my tiles so its an easy thing to add.

Can you link me your pseudo-code? cause it would be nice not to have to write timers everywhere Smiley
6  Game Development / Newbie & Debugging Questions / Re: Java2D painting transparent overlay pause menu on: 2012-05-03 14:39:02
Not using delta as i'm using a fixed time step loop i believe, don't really understand it. Its the only part of this clone i havent written i got it from a tutorial on here i plan to try and understand it one day Tongue

- http://www.java-gaming.org/topics/game-loops/24220/view.html
7  Game Development / Newbie & Debugging Questions / Re: Java2D painting transparent overlay pause menu on: 2012-05-03 14:22:33
aghh ok, i see. It was only getImage() being called in like the player draw method which went and counted to a next animation frame but i guess i could put it in a update method instead, thanks very much Cheesy
8  Game Development / Newbie & Debugging Questions / Java2D painting transparent overlay pause menu on: 2012-05-03 13:26:24
I'm making a pacman clone and i'm trying to make a pause menu which is just painted on top of the game with transparency to look cool, problem is it paints over and over again making the menu opaque.

To stop this i can continue to paint the normal game underneath the overlay but if i do this it makes things animate as i call player.drawImage(g2d) which then goes and makes the player move onto next animation frame even though the game is paused, so i really don't want to run the drawing code for the normal game at all.

I tried 'screen shoting' the game when i pause it making a copy of the buffer and storing in a buffered image drawing that and then the transparent menu to avoid calling the draw methods for tiles and player but this didn't seem to work very well, i think it was the way i copied the image via bufferedimage.getRaster(), i also tried just doing pauseBuffer = buffer type of copying but this didn't seem to work. Anyone know anyway i can make this work without having to add loads of checks in individual classes draw code to check if the game is paused?
9  Game Development / Game Mechanics / Re: Stopping from a jump on: 2012-03-27 12:55:05
if(){

}else if(){

}

-.-
10  Game Development / Game Play & Game Design / Re: 2D Tile Map + Camera on: 2012-02-28 10:28:05
Create an object that extends the rectangle class to make life easier, when the player moves move the rectangle as well(int the opposite direction). I personally have a small area the player can move in without moving the map, but if he goes to the edge of it the map will start to move. Then when it comes to drawing stuff to the screen just add the x cord of what your trying to draw and that of the map together. I know it sounds bad to move the entire world around the player and not the other way round but its not actually as bad as you would think. Smiley
e.g.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
     public void paint(Graphics g){
       player.drawEntity(g2d);
     }

   public void drawEntity(Graphics2D g2d){
      g2d.drawImage(image, getScreenX(), getScreenY(), null);
   }

   public int getScreenX(){
      return new Integer(getX() + Map.getX()); // map being my object that inherits from the rectangle class
  }
   
   public int getScreenY(){
      return new Integer(getY() + Map.getY());
   }


This is good as when you playing around with stuff like player, power ups, baddies all their x,y cords are relative to the map, so a cords of (300,300) could draw a player on the screen at (50, 50). So you could just set player spawn in code using local cords
e.g. player.setSpawn(10, 10); // spawn player top left of map
11  Game Development / Newbie & Debugging Questions / Re: Optimisations for large number of moving object collisions, input please! on: 2012-02-27 17:22:06
Why not work out the tile each player and enemies are on, and then check if that tile is solid and if so then react?

1  
2  
int tileX = player.getX()/tile.getWidth()
int tileY = player.getY()/tile.getHeight()

To make it more accurate check four points around the player or even more e.g. top right point
1  
2  
int tileX = player.getX()+player.getWidth()/tile.getWidth()
int tileY = player.getY()/tile.getHeight()

and do the same with baddies, think it might take less loops than your code as..
If you have a map size of 300x300 and 100 baddies
100 solid tiles
100x100x100 = 1x10^6
where if only 4 loops are needed to check the corners of each baddie/player
4x100 = 400... and some extra math



12  Game Development / Newbie & Debugging Questions / Re: New to Java Games! on: 2012-02-15 21:08:12
True, thanks. I might split my input into a separate in the future now Smiley
13  Game Development / Newbie & Debugging Questions / Re: New to Java Games! on: 2012-02-15 20:06:00
My code doesnt show it very well but i kind of use a hybrid between the two,
1  
player.setDX(-player.getRunSpeed());

I call my velocity variable dx and dy because im special like that, so in this method-
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   private void checkForInput(){    // this is only part of the method
     if(keyPress[2]){
         if(!(player.isJumping())){
            player.dy = -player.getJumpSpeed();
            player.setJumping(true);
         }
      }
     
      if(keyPress[3]){
         if(player.isJumping()){
            if(!(player.isDoubleJumping())){
               player.dy = -(player.getJumpSpeed());
               player.setDoubleJumping(true);
            }
         }
      }

The player isnt actually moved it just changes his velocity. I do it this way becuase then its easier to implement stuff like gravity exct..
He moves when the player.moveX() and player.moveY() methods are called, (there seperate for collision detection purposes)
14  Game Development / Newbie & Debugging Questions / Re: New to Java Games! on: 2012-02-15 19:33:52
Yea i agree with you, that array is just me being lazy. Bad idea to use that if your working in a group.  Tongue principle is the same though
15  Game Development / Newbie & Debugging Questions / Re: Problems serializing objects and sending over network on: 2012-02-15 19:31:35
Augh thanks, seems to be working now. Just buggy but thats the rest of my code i think Smiley
16  Game Development / Newbie & Debugging Questions / Re: New to Java Games! on: 2012-02-15 19:17:17
Look up object 'serilization' for save games, and signing applets to store files on the clients computer if its going to run as an applet. Ive heard signing is annoying to do at first but it gets easier once you've done it once.

For the key input I use several boolean variables and if a key is pressed it changes that variable to true, and released it changes it to false. Then somewhere in the gameloop I have a method that just goes through those boolean variables and if one is true then do stuff. For example,
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public void keyPressed(KeyEvent e) {
int k = e.getKeyCode();
switch(k){
      case KeyEvent.VK_A:
         game.keyPress[0] = true;
         break;
... // check other keys
// then elsewhere in a method called from the gameloop
  private void checkForInput(){
      if(keyPress[0]){
         player.setDX(-player.getRunSpeed());
      }else{
         player.setDX(0);
      }
// so on, so on


This seems to get me nice smooth movement Smiley

17  Game Development / Newbie & Debugging Questions / [FIXED] Problems serializing objects and sending over network on: 2012-02-15 18:59:57
I don't really know what im doing wrong, just trying to send an object called 'packet' from server to client using TCP.
This is how its serialized and sent server side
1  
2  
3  
4  
5  
6  
 bos = new ByteArrayOutputStream();
 objectOut = new ObjectOutputStream(bos);
 objectOut.writeObject(packet);
 String objectBytes = bos.toString();
               
 ps.println(objectBytes); // ps is a printstream, ps = new PrintStream(skt.getOutputStream());

Here is the client side code
1  
2  
3  
4  
5  
6  
7  
8  
 String data = br.readLine();

 byte[] objectData = data.getBytes();
 // Deserialize from a byte array
bis = new ByteArrayInputStream(objectData);
 in = new ObjectInputStream(bis);
 packet = (Packet) in.readObject();
 in.close();


This is sending strings, i tried doing it by just sending a the length of the byte array, then the byte array and reciving it like that client side but just couldnt get it working. Ive had several errors probably most commen is this 'java.io.StreamCorruptedException: invalid stream header', but i also get a 'java.io.EOFException' error. Am i go going about this completely the wrong way?
18  Game Development / Game Mechanics / Re: One of Those Collision Threads on: 2012-02-08 00:20:10
Only way i could get it to work is to make two collison methods to check X and then Y collision separately,  if x returned true the player moved x and if y = true then player.moveY..

The meathods create a temporary variable which represents where the player will be, for the x method for example
int newX = player.getX() + player.getVelY()
work out where he is on the grid by divison to work out the tile he is on. Work out a tile for each corner of the player e.g. the top left point, on 64x64 tiles
tileTopLeftPointX = newX/64;
tileTopRightPointY = player.getY()/64; // as this is just checking x collision player.getY() is just as it is

Then if this new tile is solid that means if the player moves he will be colliding with something so return the meathod false so the player doesnt move.
To stop the player from having a gap between him and the wall hes walking into if he has a high x velocity try to find the minmum x velocity the player could have moved and not intersect with the tile, if this is found then set the player velocty X to this value so he will squish against the wall, you can change how accurate you want it to be e.g.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
if(tiles[i][p].isSolid()){          // where i, p are integers worked out previously of the tile the top left player point is currently on
           if(tiles[i][p].getBounds().contains(topLeftX, topLeftY)){
               while(!(nDX > -0.2 && nDX < 0.2)){ // so if velocity is between here stop the loop becuase it is negligable
                 if(nDX > 0){
                     nDX -= 0.02;    //you could change the 0.02 smaller or larger to make it more or less accurate
                 }else if(nDX < 0){
                     nDX += 0.02;
                  }
                  topLeftX = (int) (player.getX() + nDX); // store where the player would be to see if he can now move
                 if(!(tiles[i][p].getBounds().contains(topLeftX, topLeftY))){ // if he can move set his velocity and return true to move x
                    player.setDX(nDX);
                     return true;
                  }
               }
               return false; // the while loop broke meaning he is close to the wall
           }else if // check the other points around the player for collision as say the bottom right of the player rect may be one a diffrent tile


19  Game Development / Newbie & Debugging Questions / Re: Is it my code or java2D thats being slow? on: 2012-02-07 22:48:52
Yea all the water tiles access 3 static images in a loader class that are loaded from the start and each cycle through pretty randomly, with the picture changing around every 300ms.

Water tiles are drawn first then player is drawn translucent ontop of the tile, as play is smaller i thought be better to do this way round(less pixels to shade).
So the tiles are drawn fully opaque, but the images that are drawn are basicly 64x64 of randomly bluey coloured pixels, i think this might be whats slowing it down
20  Game Development / Newbie & Debugging Questions / Re: Is it my code or java2D thats being slow? on: 2012-02-07 16:40:42
Yeaa i could, thinking of using doing my A level computing project using JOGL though. Because i could see an examiner who doesn't know what hes talking about thinking "hes using a library! That means he practically didn't do anything himself!"
21  Game Development / Newbie & Debugging Questions / Re: Is it my code or java2D thats being slow? on: 2012-02-07 16:34:46
aghh thanks :/ Sad this means im going to have to go lurk the Jogl forum now and buy a new book, gah. Thanks though  Grin
22  Game Development / Newbie & Debugging Questions / Re: Is it my code or java2D thats being slow? on: 2012-02-07 15:54:28
I havent done any anti-aliasing so that cant be it, also when i disable the water affecting the player sprite so the player is just drawn normal over the water it is still slow :/
23  Game Development / Newbie & Debugging Questions / Is it my code or java2D thats being slow? on: 2012-02-07 15:47:53
I have a 2D platformer game which runs at set at 60 fps, i only update tiles that are one the screen around the player, so about 12x8 tiles which are 64x64 in size. It runs fine but when i animate the tile by giving them an image they grab from another class, every time the update they tick to see if its time to update their animation if so, they grab a different image but this makes the game lag, the water animation has 3 slides each one is just blue with some different noise.

I also draw the player pixel by pixel and depending on the tiles hes standing on change the RGBA of each pixel to make it cool, e.g. i add transparency when in water so it looks like it.
tl;dr it only really slows down when >60% of the screen are water tiles but i have no idea how else i would implement them :S

24  Game Development / Newbie & Debugging Questions / Re: Java how to make menu, restart button and .jar file on: 2011-12-19 19:27:53
This might work for a menu, have a boolean variable you could use your player.alive if you have something like that, instanciate it equal to false so it will be false when you open the game so like        
public Boolean alive = false;
then in the game around the loop just put the functions that involve game logic like collision detection in a if statement for example

public void name_of_your_game_loop(){
     if(!(player.alive)){
       collCheck();
       moveStuff();
       someotherlogic();
    }
   repaint();
}
and build meathods that will repaint a menu with buttons when player is dead, then to get input just use KeyListener, to get keyinput for a key press. Or look up MouseListener which you can use to see if mouse has been clicked get the mouses xy position and check if that intersects with any of your buttons
25  Game Development / Networking & Multiplayer / Re: Telling the diffrence between two clients connected, from the same ip on: 2011-12-19 19:19:41
I dont really understand what you mean, probably because i have no idea what RMI is, i kinda see what you mean. At the moment my server does just get a connection then starts a new thread with the socket passed in as argument gets the streams and it does I/O from that with logic in another thread and the I/O threads and logic threads just change static data in my other class which also displays some info.

It doesnt crash, it binds a diffrent port auto i think

you can try the game here
http://81.96.53.133/egg/WeaponHat.htm
Its fine aslong as you dont refresh the page or open two copys of it..
I like the idea of giving each client a random name and attaching it onto every packet, but okay the wrong listener on teh server gets data from a client its not supposed to be listening to, should i ignor it completely or try and pass it to the other thread or something :S
26  Game Development / Networking & Multiplayer / Re: Telling the diffrence between two clients connected, from the same ip on: 2011-12-19 19:04:13
Any ideas what i can do diffrently then? To stop the server recving wrong data from clients, like if im running the client which is applet based and then open a new tab and open it up in that aswell and run it really messes the game up as im guessing servers reading data from client in new tab for client in first tab
27  Game Development / Networking & Multiplayer / Telling the diffrence between two clients connected, from the same ip on: 2011-12-19 18:55:25
I cant find away to do this, for example make it so when someone connects i want to make sure they dont open two connections to the same client so i made it so if two clients have two ip then dont accept the new client, but this means you have to be in diffrent houses to play the game. If say 20 people in an office or school all connected to the game under the same IP address how can i tell the clients apart?
28  Game Development / Newbie & Debugging Questions / Re: Solved - Bouncing an enemy on: 2011-12-14 22:11:33
Instread of the whole new direction thing just if x<whatever then make dx=-dx to move in the opposite direction
29  Game Development / Newbie & Debugging Questions / Re: TCP applet, disconnecting clients on: 2011-12-14 21:19:34
Thanks found it Socket.setSoTimeout(int) Cheesy
30  Game Development / Newbie & Debugging Questions / Re: Map Editor performance question on: 2011-12-14 20:04:18
The way i would do it would be to draw all the tiles relative to a rectangle and just move that rectangle about

To make it only draw stuff on screen I find a point on the screen and then find the points potition in tiles, then i take some away from it
upperX = pointXInTiles - 14
upperY = pointYInTiles - 14

Now your for loops dont have to run through every tile for example

20 being the width of the screen in tiles
   for (int i = upperViewY; i < (20 + upperViewY); i++) {
      for (int p = upperViewX; p < (20 + upperViewX); p++) {
                  //Do stuff like paint
              }
         }
Pages: [1] 2
 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!