Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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  
  [SOLVED] How to bind display() with the KeyBehaviour class?  (Read 735 times)
0 Members and 1 Guest are viewing this topic.
Offline Cyrus

Senior Newbie




Lean Mean Programming Machine


« Posted 2008-02-10 22:28:45 »

Sorry, it's very late, sometimes i make simple mistakes.

You can ofc always access variables/methods from other files by calling filename.variable

somehow it totally slipped my mind.




------------------------------------------
I have two seperate classes for handeling GLEvents and KeyEvents.

I want to bind the classes so, that if i press "W" that,the boolean statement becomes true.
now, nothing happens.

What should i do? Any tips are welcome!

(yeah ok, i'm new)


Greetings, Cyrus



///GfxFactory.java (GLEventListener)
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import java.awt.event.*;

public class GfxFactory extends KeyBehaviour implements GLEventListener {
   private final GLU glu = new GLU();
   ObjectLibrary ol = new ObjectLibrary();
   KeyBehaviour kb = new KeyBehaviour();
   
   float rot;
   
   public void display(GLAutoDrawable gld) {
      final GL gl = gld.getGL();
      
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      
      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();
      
      ol.camera(gl, kb.posx, kb.posy, kb.posz, kb.rotx, kb.roty, kb.rotz);
      
      gl.glTranslatef(0.0f, 0.0f, -5.0f);
      gl.glRotatef(rot, 1.0f, 0.0f, 0.0f);
      ol.cube(gl);
      
      rot += 4.0f;
      
      System.out.println(kb.FORWARD);
   }
   
   public void init(GLAutoDrawable gld) {
      final GL gl = gld.getGL();
      
      gl.glShadeModel(GL.GL_SMOOTH);
      gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      gl.glClearDepth(1.0f);
      gl.glEnable(GL.GL_DEPTH_TEST);
      gl.glDepthFunc(GL.GL_LEQUAL);
      gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
   }
   
   public void reshape(GLAutoDrawable gld, int x, int y, int width, int height) {
      final GL gl = gld.getGL();
      
      if(height < 1)
         height = 1;
         
      float ratio = (float)width / (float)height;
      gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity();
      glu.gluPerspective(50.0f, ratio, 1.0f, 1000.0f);
      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();
   }
   
   public void displayChanged(GLAutoDrawable gld, boolean modeChanged, boolean deviceChanged) {
   }
}


///KeyBehaviour.java
import java.awt.event.*;
import java.awt.*;
import javax.media.opengl.*;

public class KeyBehaviour implements KeyListener, MouseListener, MouseMotionListener {
   
   /*****************************
      GAME VARIABLES
   *****************************/
   
   final float SPEED = 2.0f;
   final float ANGLESPEED = 1.0f;
   
   float posx, posy, posz;
   float rotx, roty, rotz;
   float angle;
   
   boolean FORWARD = false;
   boolean BACKWARD = false;
   boolean STRAFELEFT = false;
   boolean STRAFERIGHT = false;
   
   
   /*****************************
      INTERFACE METHODS
   *****************************/
   
   GLCanvas glc;
   
   public void getGLCanvas(GLCanvas glc) {
      this.glc = glc;
   }
   
   
   /*****************************
      KEY PROCESSING
   *****************************/
   
   
   /*****************************
         KEYBOARD EVENTS
   *****************************/
   
   public void keyPressed(KeyEvent e) {
      switch(e.getKeyCode()) {
         case KeyEvent.VK_W:
               FORWARD = true;
            break;
         case KeyEvent.VK_S:
               BACKWARD = true;
            break;
         case KeyEvent.VK_A:
               STRAFELEFT = true;
            break;
         case KeyEvent.VK_D:
               STRAFERIGHT = true;
            break;
         case KeyEvent.VK_ESCAPE:
         case KeyEvent.VK_F10:
            System.exit(0);
            break;
      }
            
      glc.repaint();
   }
   
   public void keyReleased(KeyEvent e) {
      switch(e.getKeyCode()) {
         case KeyEvent.VK_W:
               FORWARD = false;
            break;
         case KeyEvent.VK_S:
               BACKWARD = false;
            break;
         case KeyEvent.VK_A:
               STRAFELEFT = false;
            break;
         case KeyEvent.VK_D:   
               STRAFERIGHT = false;
            break;
      }
            
      glc.repaint();
   }
   
   public void keyTyped(KeyEvent e) {
   }
   
   
   /*****************************
         MOUSE EVENTS
   *****************************/
   
   public void mousePressed(MouseEvent e) {
   }
   
   public void mouseReleased(MouseEvent e) {
   }
   
   public void mouseClicked(MouseEvent e) {
   }
   
   public void mouseEntered(MouseEvent e) {
   }
   
   public void mouseExited(MouseEvent e) {
   }
   
   
   /*****************************
      MOUSE MOTION EVENTS
   *****************************/
   
   public void mouseMoved(MouseEvent e) {
   }
   
   public void mouseDragged(MouseEvent e) {
   }
}

http://www.wehaveinternet.com

*Always driving the Learning Car of Programming*
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.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (37 views)
2014-12-09 22:41:13

BurntPizza (73 views)
2014-12-08 04:46:31

JscottyBieshaar (34 views)
2014-12-05 12:39:02

SHC (47 views)
2014-12-03 16:27:13

CopyableCougar4 (42 views)
2014-11-29 21:32:03

toopeicgaming1999 (110 views)
2014-11-26 15:22:04

toopeicgaming1999 (96 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
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!