Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Remo

Pages: 1 2 [3] 4 5
31
Support / Re: Gamepad?
« on: May 06, 2007, 11:44:58 am »
I've worked with jInput and it works. Here's the source code from my asteroids project. Hope it helps you getting started!

Here's jinput homepage also: https://jinput.dev.java.net/

Code: [Select]
package asteroids;
import net.java.games.input.*;
/**
 *
 * @author Remo
 */
public class JoyManager {
    private static final int NUM_BUTOTONS = 6;
    private Controller controller;
    private Component[] comps;
    private int xAxisIdx, yAxisIdx, zAxisIdx, rzAxisIdx; // for the x- and y- axes
    private int buttonsIdx[];
   
    /** Creates a new instance of JoyManager */
    public JoyManager() {
        xAxisIdx = -1;
        yAxisIdx = -1;
        zAxisIdx = -1;
        rzAxisIdx = -1;
        buttonsIdx = new int[NUM_BUTOTONS];
        for (int i = 0; i < buttonsIdx.length; i++) {
            buttonsIdx[i] = -1;
        }
        Controller[] cs = getContollers();
        controller = findJoystick(cs);
        System.out.println("Using "+ controller.getName() + ":" + controller.getType());
       
        comps = controller.getComponents();
        getComponentsIndicies(comps);
    }
   
    private Controller findJoystick(Controller[] cs) {
        Controller.Type type;
        int index = 0;
        while(index < cs.length) {
            type = cs[index].getType();
            if (type == Controller.Type.STICK) break;
            index++;
        }
        if (index == cs.length) {
            System.out.println("No Joystick found!!! Closing Asteroids.");
            System.exit(0);
        }
        return cs[index];
    }

    private Controller[] getContollers() {
        ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
        Controller[] controllers = ce.getControllers();
        return controllers;
    }

    private void getComponentsIndicies(Component[] comps) {
        if (comps.length <= 0) {
            System.out.println("No components found for Joystick");
            System.out.println("Aborting asteroids.");
            System.exit(0);
        }
        int numButtons = 0;
        Component c;
        for (int i = 0; i < comps.length; i++) {
            c= comps[i];
            if (c.getIdentifier() == Component.Identifier.Axis.X) {
                xAxisIdx = i;
                System.out.println("Found X Axis. Component number: " + i);
            }
            if (c.getIdentifier() == Component.Identifier.Axis.Y) {
                yAxisIdx = i;
                System.out.println("Found Y Axis. Component number: " + i);
            }
            if (c.getIdentifier() == Component.Identifier.Axis.Z) {
                zAxisIdx = i;
                System.out.println("Found Z Axis. Component number: " + i);
            }
            if (c.getIdentifier() == Component.Identifier.Axis.RZ) {
                rzAxisIdx = i;
                System.out.println("Found RZ Axis. Component number: " + i);
            }
            if (isButton(c)) {
                if (numButtons == NUM_BUTOTONS) {
                    System.out.println("Found too many buttons. Ignoring the rest.");
                }
                else {
                    buttonsIdx[numButtons] = i;
                    numButtons++;
                    System.out.println("Found Button. Component number: " + i);
                }
            }
            else {
                System.out.println("Unknown component. Ignoring.");
            }
        }
        if (xAxisIdx==-1 || yAxisIdx == -1 || buttonsIdx[0] ==-1) {
            System.out.println("Could not find enough components to launch Asteroids. Aborting");
            System.exit(0);
        }
        if (zAxisIdx == -1) System.out.println("Could not find Z Axis.");
        if (rzAxisIdx == -1) System.out.println("Could not find RZ Axis.");
        if (numButtons < NUM_BUTOTONS) System.out.println("Not all buttons were found.");
    }
   
    private boolean isButton (Component c) {
        if (!c.isAnalog() && !c.isRelative() && c.isNormalized()){
            String className = c.getIdentifier().getClass().getName();
            if (className.endsWith("Button")) return true;
        }
        return false;
    }
   
    public void poll() {
        controller.poll();
    }
    public float getXAxis() {
        return comps[xAxisIdx].getPollData();
    }
    public float getYAxis() {
        return comps[yAxisIdx].getPollData();
    }
    public float getZAxis() {
        if (zAxisIdx == -1) return 0f;
        return comps[zAxisIdx].getPollData();
    }
    public float getRZAxis() {
        if (rzAxisIdx == -1) return 0f;
        return comps[rzAxisIdx].getPollData();
    }
    public boolean fireButtonPressed() {
        return ((comps[buttonsIdx[0]].getPollData() == 0.0f) ? false : true);
    }
   
}

And here's how I used it in the game:

Code: [Select]
package asteroids;
import com.threed.jpct.*;

/**
 *
 * @author Remo
 */
public class CameraManager {
    JoyManager joystick;
    public float speedx = 0f;
    public float speedy = 0f;
    public float sens;
    public SimpleVector direction;
    private Camera camera;
    private Camera skycam;
   
    /** Creates a new instance of CameraManager */
    public CameraManager(Camera camera, Camera sky) {
        joystick = new JoyManager();
        this.camera = camera;
        skycam = sky;
        sens = .001f;
    }
   
    public void moveSpaceship() {
        //skycam.setPosition(new SimpleVector(0f,0f,0f));
        speedx+= joystick.getYAxis()*-sens;
        speedy+= joystick.getXAxis()*sens;
        if (speedx > .1f) speedx = .1f;
        if (speedy > .1f) speedy = .1f;
        camera.rotateCameraX(speedx);
        skycam.rotateCameraX(speedx);
        camera.rotateCameraY(speedy);
        skycam.rotateCameraY(speedy);
        SimpleVector oldCamDir = camera.getDirection();
        camera.moveCamera(oldCamDir, joystick.getZAxis() *-10);
    }
   
    public void pollJoystick(){
        joystick.poll();
    }
   
    public boolean fireButtonPressed(){
        return joystick.fireButtonPressed();
    }
   
    public void incSens() {
        sens += .001f;
        System.out.println("Sensibility multiplier:" +sens);
    }
    public void decSens() {
        sens -= .001f;
        if(sens < 0) sens = 0f;
        System.out.println("Sensibility multiplier:" +sens);
    }
}


32
Feedback / Found jpct in Swash wiki!
« on: March 15, 2007, 02:43:52 pm »
Was taking a look at the new Java Swash site so I decided to run the new webstart demo and check the wiki, only to find out that swash might implement jpct.


http://wiki.java.net/bin/view/Javadesktop/Swash

Look into "Features to come".


jpct is going places :D.

33
News / Driving a tank *offtopic*
« on: May 10, 2006, 07:20:03 pm »
Egon thats awsome. Im going to try that when I go too germany :D.

34
Support / remove an Object from the World
« on: April 30, 2006, 11:13:19 am »
You need access to the world! get the id of the object and get rid of it.

You do build the object by itself but removing is the contrary of addtoworld() not to build().

What I am doing to remove objects is send them to a pool of unused object (somewhat like in the car demo with the bullets) and when I need an object I get it from that pool.

35
Support / Sky
« on: April 18, 2006, 09:13:39 am »
You can also use a more simple method like raft did here :
http://www.jpct.net/forum/viewtopic.php?p=1854#1854

36
Projects / Flier Match
« on: April 07, 2006, 06:11:50 am »
Im not sure if you guys know about this but theres a Java game server, its was made mostly for MMOs but you can change some stuff :).

Im already coding jpct for this server but have nothing to show yet.
Anyway heres the link:

https://games-darkstar.dev.java.net/

37
Support / Using Blender to create a 3ds file
« on: April 04, 2006, 08:22:25 am »
You can work with Milkshape 3D. You can use it to do some modeling or importing a MDL file ( Blender can export to mdl right?) and export to 3DS.

http://www.swissquake.ch/chumbalum-soft/ms3d/index.html

38
Projects / "Visual" JPCT
« on: March 28, 2006, 07:34:12 pm »
Nice work on that :D.

Will it come with an animation window also?

39
Projects / jPCT 3D Asteroids!
« on: March 27, 2006, 09:55:59 pm »
Digital devices are not a problem.
The problem is on my side. I think the problem may be that I forced the joystick to use Z axis and Z rotation for the aplication to work and not all joysticks have that (should have tought of that :( ).
I will change that along with some other things to get a more friendly way to deal with it.

Hopefully I will have it today (my today! gmt  -6).


Edit:
Ok. I only cutted the forced Z and RZ axis. Im still working on some other stuff but you should be able to try it now Egon.
Same url: http://www.jdudes.com/asteroids.zip

40
Projects / jPCT 3D Asteroids!
« on: March 27, 2006, 10:48:51 am »
Ok so I started to work on my jPCT project.
Its more like a demo of jPCT and jinput working together. So its basically a joystick test.
You will NEED a joystick for this thing to work (unless you modify the source code included).
The game is going to be based on the old Asteroids game.
Im having some problems figuring out some stuff but at least I got something to work hehe.
Its my first app with jPCT so dont go that hard on me!.


Anyway, here's the file:
http://www.jdudes.com/asteroids.zip


I already have some ideas for a better management such as using a list insted of an array to process asteroids so I can dinamically add or remove asteroids.
Im starting to work on an Asteroid radar also. And some other stuff...

Well I would apreciate some feedback.

41
Projects / Technopolies
« on: March 26, 2006, 10:37:32 am »
Sorry to hear that rolz.

I hope things work out the way you want!
I wish the best to you and your family.

42
Projects / Technopolies
« on: November 20, 2005, 10:13:35 pm »
Hey Rolz Ive recently saw your game on javagaming forums :D ehehe. Nice job, tthat teaser looks really good.

43
Projects / ¿how much pleople still using jpct?
« on: October 31, 2005, 04:13:41 am »
Im planning to start a project soon but Its hard to find time. I will post about it here when I have something that its worth it.

44
Feedback / Another link of jpct
« on: October 27, 2005, 07:09:07 am »
Throws an error for me but that is a weird site indeed. Wheres egon!


I speak spanish and english. Seems like that information they hae in that site is a bad translation from this page right here http://wiki.java.net/bin/view/Games/JPCT but I still dont know what that other site is.

45
Projects / Technopolies
« on: October 10, 2005, 10:53:14 pm »
Looks nice! keep up the goos work.

Pages: 1 2 [3] 4 5