Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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 / Got XYZ cordinates, now I have to move it further away from its current location on: 2012-07-06 11:42:04
Hey

I'm currently programming with JavaScript(not Java) and Three.js but my problem is not related to which language I use but some XYZ cordinate math which isn't one of my strong points.


I am trying to draw a line from camera.position to mouse click and it works fine, I just cannot figure out how to move the end location further away.

1  
2  
3  
4  
5  
6  
   var geometry = new THREE.Geometry();
   //start position
  geometry.vertices.push( camera.position );
   //end position
  geometry.vertices.push( new THREE.Vector3( vector.x, vector.y, vector.z ) );  
   var line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0x0000FF, opacity: 1 } ) );


This piece of code does work but the line itself it extremely short, I have tried to multiply every value by 2 but that only works in some directions, if I move the camera to another direction the line is pointing the wrong direction and not towards my click, so I think my cordinate math is way off.

My end goal is to do raycast with the mouse click, sometimes the ray does hit something and sometimes it does not, so I'm trying to debug it by displaying a line.
2  Game Development / Newbie & Debugging Questions / Re: 2D Isometric-Diamond: Several question into one thread on: 2012-05-10 15:06:57
Thanks for the great answers.

We've made a choice to move to jMonkeyEngine 3 where I am currently studying theire SDK and documentation and my friend is learning how to use Blender.


Against, thanks for the help.
3  Game Development / Newbie & Debugging Questions / Re: 2D Isometric-Diamond: Several question into one thread on: 2012-05-08 13:46:40
It's best to move the player and then set mapX/YOffset to center the player again.


The player X and Y is the X and Y of the screen so if I change those the player would not be centered anymore, and the mapX and Y offset is just so the map is centeret on the screen.
4  Game Development / Newbie & Debugging Questions / Re: 2D Isometric-Diamond: Several question into one thread on: 2012-05-07 21:25:17

Thanks there is alot of good information Smiley

Could you tell me, is moving the offset of the map right or should I move the player instead?
5  Game Development / Newbie & Debugging Questions / 2D Isometric-Diamond: Several question into one thread on: 2012-05-07 19:01:42
Hello everyone, I'm new here Smiley


So I am currently working on a 2D Isometric-diamond Zombie survival game.

I have followed this guide for having a solid base: http://www.java-gaming.org/topics/basic-game/21919/view.html



My first problem is when I move my character my game renders white lines between the tiles like small render lags.

First problem kinda solved: I tried to increase increase the mapXOffset by deltaTime * 0.2 in each update and it removed all the white lines.
Though somehow I still think I'm doing it wrong by moving the mapXOffset instead of the player and now I have to somehow when I press the arrows keys they have to go to the update method hmm.


My plan is to keep the player in the center of the screen all the time, currently the player is the small black rectangle



The tiles graphic is both within a tilesheet.png

My tilemap array
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  
   //Tile map
  int[][] tileMap_array = new int[][] {
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},      
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},      
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1}      
   };



Rendering the map and player
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
      for (int i=0; i<tileMap_array.length; i++)
      {
         for (int j=(tileMap_array[i].length-1); j>=0; j--)
         {
            if (tileMap_array[i][j] == 1)
            {
               //Getting subimage of tilesheet              
              g.drawImage(tileMap_img.getSubimage(0, 32, 62, 32), ((j*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2)+((i*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2) - mapXOffset, ((i*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2)-((j*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2) + mapYOffset, null);
            }
            else
            {
               g.drawImage(tileMap_img.getSubimage(0, 0, 62, 32), ((j*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2)+((i*tileMap_img.getSubimage(0, 32, 62, 32).getWidth())/2) - mapXOffset, ((i*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2)-((j*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2) + mapYOffset, null);
            }              
         }
      }
     
      g.setColor(Color.black);
      g.fillRect(player.x, player.y, 10, 10);



When the player clicks an arrow key its not the player moving but the world around him.
1  
2  
   int mapXOffset;
   int mapYOffset;



So when the player clicks an arrow key I change the value of one of the map offsets
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
         @Override
         public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub
           if (e.getKeyCode() == 37)
            {
               //Left arrow
              mapXOffset -= 5;
            }            
            else if (e.getKeyCode() == 38)
            {
               //Up arrow
              mapYOffset += 5;
            }
            else if (e.getKeyCode() == 39)
            {
               //Right arrow
              mapXOffset += 5;
            }
            else if (e.getKeyCode() == 40)
            {
               //Down arrow
              mapYOffset -= 5;
            }            
         }


I have two guesses, either its doing the small white lines because I has to re-render the whole world each time or its because I'm doing the variable changing within the code above and not using the the deltatime within my update method
1  
2  
3  
   protected void update(int deltaTime)
   {
   }





My second question is: How could I go about making collisions? I plan to put in objects, even interactive objects like doors and so on.

My third question is: When the player is close to a staircase how could I simulate he is walking up on the staircase to the next floor inside a building?


And ofcourse if there is any tip/advice where I could do something better, please say so.



Thanks in advance.
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

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

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

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23
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!