Slick2D Movement Issue - java

So, I converted a game to Slick2D. The movement is broke, and I am at a loss. Before, we used KeyPressed and keyReleased methods, but now with Slick2D movement isn't working right.
Yea, nothing has gone right with converting to Slick2D. First the launcher, which I had a help topic on before, and now this. Though, the other topic was an issue with WebStart hating code.
You can only move right, using A. And you can't stop moving. Am I using the right methods? How can I fix it? Any help is greatly appreciated!
Here is a PasteBin link to the code, if it helps! http://pastebin.com/GRH86Yuw

I'm a fan of Slick, and I'd be happy to help.
The fundamental difference is that Slick is a polling model, not an event-driven model when it comes to input. Basically, in your logic update method you loop through the keys bound to your events, and check to see if any of the keys are currently pressed, and then trigger those events. For a number of reasons that I can go into if you like, polling tends to work better for games, especially with a large number of keys. It's just a different way of doing things, an not that complicated. The biggest upside is that you get centralized input processing a single method, instead of having it spread across multiple KeyListener instance objects.
If you want to look at Pedestrians - a simple pedestrian sim implemented in Slick - you can see an example of how to handle input in Slick.
Specifically, I handle input in this file (lines 192-295), inside the processInput method. Basically, you pass in a reference to the GameContainer object (the Slick object that contains your game), and from that you can get an instance to the Input instance that will allow you to check which keys are pressed, what mouse buttons are clicked, etc.

Related

Swapping JButtons in Java

I made an array list of strings and assigned an image to each string. Then, I randomized these images. I want to now make a method that swaps one button to the button adjacent to it, but I have no idea how to do this. Any suggestions about how to go about it? Thanks
First suggestion: Don't. Don't swap JButtons as you're making things much harder than they need to be. Instead if possible swap images or more specifically ImageIcons, and this can be easily done using the JButton method, setIcon(...).
It almost sounds as if you're trying to create a memory game, and if so there are plenty of examples of just this sort of thing to be found on this site, at least one created by me.
As always in these sorts of things, first concentrate on the program's model, that is, its logical underpinnings, and only after getting that working, apply it to the program's view or its GUI representation of the model's state.

How can you send a mouse event to another program without moving the cursor?

Doing it with the Robot class doesnt seem to work for me, unless there is a way without moving the cursor.
So what i need is a way to get the Component of another program (by creating a new MouseEvent) or just another way to use the Robot class.
Thanks already.
Use MouseInfo.getPointerInfo().getLocation() to get the mouse position right before you move it, then move it (and do whatever you'd like), and then return the mouse to its previous location.
The alternative is fairly complicated, and even more complicated if it's not a Java program - you'd need to provide much more information about that program, and your odds of getting a clean answer would be slim.

Changing 2 images at mousePressed

I have 2 images of legs of a character, I want them to be changing while I pressed the keyboard for example left or right arrow key. It's like the character is walking. How to do this in java slick2d? I have no codes to provide because I have no Idea how to start coding it. Thank you very much.
If you just want to handle basic input and you don't need to use slick2D then you can just use a KeyListener or MouseListener for input. These are Java features and are very simple to use.
To use Slick2D, my best guess would be to start here,
Slick Commands
These are for more advanced inputs I believe but you should do some research on each to see what you need to use.

Java: Interface with squares (to drag), lines (to link the squares) and animation (square follows the line)

I'm starting to create a Industrial Simulation (IS) interface, using Java.
The problem I'm pointing here is the interface.
A IS interface will have some big squares (geometrical figure) (unfilled, instead of it they will have their "names" inside it), one or more lines linking the squares, and while time will be going, some "mini-squares" will get out of one big square to another, following the line that links both.
I have to construct a interface that is able to have either the geometric (square) figures and the animation with the "minisquares" following the link (that will be the line).
Is there any API, or tool, whatever, in java, that could help me starting this part of the project?
If you can use javafx... runs on the JVM... that might be easiest way. Here's a link to a tutorial for animating along a path
Otherwise I guess you'll be looking at Swing, but I suspect it's a lot trickier. Here's a similar link.
Visual editors like Matisse can help you get started with layout etc., but I don't know of anything that will let you point-and-click your way round animation.

Java | I need to make an applet but I don't know how to begin

I need to make kind of a game in Java but I am a total beginner. It has to be applicable to the web and I need to use images on it and action listeners. So, do you recommend any site to know how to begin?
The description of the game (it is not really a game but it implements things that usually are in a game) is this:
Show a matrix of images of 3x3 elements, then, hide them and put instead empty squares. The images shown in the matrix, must remain in the lower part of the screen just below the empty squares and they must be randomly positioned. The user, must click one image and put it on the correct empty square. The result, must be, how many images were correctly positioned, the time it took to end the game, the time between mouse clicked and released for each image.
For additional information, I want you to know that this application is for a friend of mine who studies medicine. He wants this program to test patients who accident and receive hits on their heads. You may think that the description I gave you may not be a good software for that purpose, and in fact, it may be not, but, once I know the management of all that is required (Images, MouseListeners, how to introduce it to a web etc), I will be able to make a better product. So, please tell me, how can I begin?. What do I need to know?
I would start here. Except for some startup boilerplate and the restrictions of the sandbax (which, based on your description, you will b unlikely to encounter), there is no fundamental difference in an applet from normal code.

Categories

Resources