Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  Equations or other problems  (Read 1159 times)
0 Members and 1 Guest are viewing this topic.
Offline deadteck

Senior Newbie





« Posted 2012-04-21 02:56:42 »

I'm following this tutorial http://www.youtube.com/watch?v=RGKI_2A5q0M&feature=BFa&list=PL656DADE0DA25ADBB and I copied all his code properly (i think) and my screen seems to move around randomly, if it isnt too bad could anybody help me Smiley
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  
package com.game.Fearless.input;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class InputHandler implements MouseListener, FocusListener, KeyListener, MouseMotionListener {

   
   public boolean[] key = new boolean[68836];
   @Override
   public void mouseDragged(MouseEvent e) {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void mouseMoved(MouseEvent e) {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void mouseClicked(MouseEvent e) {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void mouseEntered(MouseEvent e) {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void mouseExited(MouseEvent e) {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void mousePressed(MouseEvent e) {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void mouseReleased(MouseEvent e) {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void keyPressed(KeyEvent e) {
      int keyCode = e.getKeyCode();
      if (keyCode > 0 && keyCode < key.length) {
         key[keyCode] = true;
      }
   }

   @Override
   public void keyReleased(KeyEvent e) {
      int keyCode = e.getKeyCode();
      if (keyCode > 0 && keyCode < key.length) {
         key[keyCode] = false;
      }
   }

   @Override
   public void keyTyped(KeyEvent e) {
     
   }

   @Override
   public void focusGained(FocusEvent e) {
      for (int i = 0; i < key.length; i++){
         key[i] = false;
      }
   }

   @Override
   public void focusLost(FocusEvent e) {
     
   }

}
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  
104  
105  
106  
107  
108  
package com.game.Fearless.input;

public class Controller {
   
   public double x, z, xa, za, rotation, rotationa;
   
   public void tick(boolean forward, boolean left, boolean back, boolean right, boolean turnLeft, boolean turnRight) {
//previous code
//      double rotationSpeed = 1;
//      double rotationa = 0.5;
//      double walkSpeed =0.00025;
//      double xMove = 0;
//      double zMove = 0;
//      double angle = 0;
//      
//      if (forward) {
//         if (back == false) {
//            zMove++;
//            z += za;
//            x += xa;
//         }
//      }
//      if (left) {
//         if (right == false) {
//            xMove--;
//            x -= xa;
//            z += za;
//         }
//      }
//      if (back) {
//         if (forward == false) {
//            zMove--;
//            z -= za;
//            x -= xa;
//         }
//      }
//      if (right) {
//         if (left == false) {
//            xMove++;
//            x += xa;
//            z += za;
//         }
//      }
//      if (turnLeft) {
//         if (turnRight == false) {
//            angle += rotationa;
//         }
//         rotation -= angle * rotationSpeed;        
//      }
//      if (turnRight) {
//         if (turnLeft == false) {
//            angle += rotationa;
//         }
//         rotation += angle * rotationSpeed;
//      }
//            
//      xa += (xMove * Math.cos(rotation) + zMove * Math.sin(rotation)) * walkSpeed;
//      za += (xMove * Math.cos(rotation) - zMove * Math.sin(rotation)) * walkSpeed;
//      
//      System.out.println("X= " + x + " Z= " + z + " Rotation= " + rotation);
     
      double rotationSpeed = 1;
      double walkSpeed = 1;
      double xMove = 0;
      double zMove = 0;
     
      if (forward) {
         if (!back) {
            zMove++;
         }
      }
      if (left) {
         if (!right) {
            xMove--;
         }
      }
      if (back) {
         if (!forward) {
            zMove--;
         }
      }
      if (right) {
         if (!left) {
            xMove++;
         }
      }
      if (turnLeft) {
         if (!turnRight) {
            rotationa += rotationSpeed;
         }
      }
      if (turnRight) {
         if (!turnLeft) {
            rotationa -= rotationSpeed;
         }
      }
     
      xa += (xMove * Math.cos(rotation) + zMove * Math.sin(rotation)) * walkSpeed;
      za += (xMove * Math.cos(rotation) - zMove * Math.sin(rotation)) * walkSpeed;
   
      x += xa;
      z += za;
      xa *= 0.1;
      za *= 0.1;
      rotation += rotationa;
      rotationa += 0.8;
   }
}
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  
package com.game.Fearless.graphics;

import com.game.Fearless.Game;

public class Render3D extends Render {

   public Render3D(int width, int height) {
      super(width, height);
   }

   public void floor(Game game) {
     
      double floorPos = 8;
      double ceilingPos = 8;
      double xMove = game.controls.x;
      double zMove = game.controls.z;
      double rotation = game.controls.rotation;
      double cos = Math.cos(rotation);
      double sin = Math.sin(rotation);
     
      for (int y = 0; y < HEIGHT; y++) {
      double ceiling = (y  - HEIGHT / 2.0) / HEIGHT;
         
        double floor = floorPos / ceiling;  
     
      if (ceiling < 0){
            floor = ceilingPos / -ceiling;
        }      
         
        for (int x = 0; x < WIDTH; x++) {
            double depth = (x - WIDTH / 2.0) / HEIGHT;
            depth *= floor;
            double xx = (depth * cos) + (floor * sin);
            double yy = (floor * cos) - (depth * sin);
            int xPix = (int) (xx + xMove);
            int yPix = (int) (yy + zMove);
            pixels[x + y * WIDTH] = ((yPix & 15) * 16) | ((xPix & 15) * 16) << 8;
         }
      }  
   }
}

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline ReBirth
« Reply #1 - Posted 2012-04-21 03:37:19 »

What do you mean by "moving screen"? I mean, what's wrong?

Offline jonjava
« Reply #2 - Posted 2012-04-21 03:37:26 »

:o That's quite the wall of text you've got there..

What I suggest, and excuse me for my assumptions, is that you look over the tutorial ( I haven't seen it ) and instead of copying the code, try and understand what each part does. Start slow and debug along the way instead of the end product.

If you're interested in learning 3D, I might suggest you look into one of the awesome java OpenGL libraries like lwjgl, jogl or even libgdx.

:}

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline deadteck

Senior Newbie





« Reply #3 - Posted 2012-04-21 04:07:36 »

the character will move around randomly

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline deadteck

Senior Newbie





« Reply #4 - Posted 2012-04-21 04:08:58 »

Ive looked around for some lwjgl tuts but I havent found any good ones, I already have the lib its just that I cant find any place to learn it, and Im pretty sure I know what most parts do, but I cant figure out how to fix it

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline deadteck

Senior Newbie





« Reply #5 - Posted 2012-04-21 04:26:45 »

What do you mean by "moving screen"? I mean, what's wrong?
the char will move randomly

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline ReBirth
« Reply #6 - Posted 2012-04-21 04:39:41 »

Okay there're so many lines of code above. Gueesing that somethign wrong with your logic (coordinates, speeds).

Offline philfrei
« Reply #7 - Posted 2012-04-21 04:49:22 »

Why are all the mouse listener methods overridden so that none of them do anything? is it some generalized sort of all-in-one input handler? Where is it used in the rest of the code?

"It's after the end of the world! Don't you know that yet?"
Offline deadteck

Senior Newbie





« Reply #8 - Posted 2012-04-21 15:02:49 »

Why are all the mouse listener methods overridden so that none of them do anything? is it some generalized sort of all-in-one input handler? Where is it used in the rest of the code?
thats because im doing that later on, and I just want to start on the maain movement

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
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.

SHC (24 views)
2014-11-25 12:00:59

SHC (23 views)
2014-11-25 11:53:45

Norakomi (22 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (68 views)
2014-11-07 19:57:14
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!