how I would go about having a moving sprite on a page, such as a virtual pet kind of thing. I've tried searching for it through the years and I've tried it with what I know on my own, but things just act up every time. Either:
A.) The sprite moves (respondent to key strokes, of course), but leaves a trail of its image behind itself.
B.) The background image writes, but for some reason the second image does not write, or is lost behind the background.
I'm sure these are simple issues for most of you, but I've tried going about this for a while now with no luck. What I'm trying to do I'm trying to write a virtual pet game, and I would eventually love to make it move around randomly like an A.I. that's pathfinding, but I've got ideas about that, just I need to know how to make it move period first, everything else I think I could figure out on my own.
The game I am working on now is an overhead game. Anyways I have a visual issues with the sprites where they overlap. I mean its normal to have sprites overlap but I do not want one to appear like it is walking on top of the other rather than the ground. The below is an image illustration the issue I want to address. (I am really good at drawing)
On the right you see what I want my sprites to do, but on left you see overlap in the way I am trying to avoid.
Now my approach to this problem is taking my array of monsters (a class that extends JLabels) and reordering them based on which monster is higher I make this occur at every run of my thread. It seems to me that if a monster is higher it should be added to the screen before the one that is lower. So I try to keep resorting the array of monsters at every iteration of my main game loop based on who is higher to account for the overlap
if (e.getSource() == follower){ c =0; for (monster m: monsters) { //Arrays.sort(monsters, new whoHigherComparator()); //I tried having the sort happen here m.movingToPlayer(joe);//1 Arrays.sort(monsters, new whoHigherComparator());//2 layeredScene1.add(m, new Integer(3));//3
[code]...
The above is code that shows the majority of my games flow I will describe my flow with references to the commented lines above with [num] for better understanding of where I am coming from. Basically, there is a set number of monsters, the monster all locate and move to the player [1], then I attempt to sort the monster array based on height [2], then add my re-sorted monsters back onto the pane in order [3], then bumpers (a type that handle collision and make sure monsters don't overlap too much) attach the current monster [4], if bumpers are touching monsters arae moved away from each other until their bumpers are no longer touching [5], if the monster is moving leftwards set the animation to a leftwards walk [6], and likewise for rightwards walking [7]
By the way this is my comparator
public class whoHigherComparator implements Comparator<monster> { @Override public int compare(monster m1, monster m2) { System.out.println("comping?"); int h1 = m1.getY(); int h2 = m2.getY(); if (h1 < h2)
[code]...
At this point everything in my game flow works just fine, its just the annoying "walking on top of each other" effect that I am having trouble handling. And my attempt at this is line [2] & [3] from my game flow which seems like it would be an effective way to handle the "walking on top of another" effect but its surely not working. I also swapped the returns from my comparator but still no changes. It seems that maybe the array isn't being sorted and/or these changes are just not being reflected.
I am currently making a platformer game which involves a scrolling panel and a sprite. My intention is for the sprite to be able to jump. My code for the frame that the scrolling panel sits on looks like this:
Currently I have the sprite (jumpMan) displayed on the JumpPanel. This is where I have a key listener that intends to control the jumping of the sprite by incrementally moving the sprite through the space to simulate jumping slightly more accurately. The JumpPanel is laid on top of a panel called the GamePanel which sits between the main frame and the JumpPanel. I currently have a timer on the main frame which is firing off the action listener every 5ms.
My hope was that the action performed would repaint at intervals so that the you would be able to see the sprite at different stages of the jump and then as it descends as well. However when I try to make the sprite jump nothing happens, nothing changes on the screen - when I debug through I can see the code going into both the keyPressed and actionPerformed methods but this doesn't seem to do anything.
I use Eclipse (kepler version, with JDK 7) on MacBook Pro (Lion).I want to overwrite a line printed on my console. I used "" for that. I was expecting the cursor to go to the beginning of the line. Instead, it is going to the next line.
I have been working on this mouse movement code that detects which direction the mouse moves in hope to use it in a game. The only problem is that I can not figure out how to make it move to the other side of the screen so I could continue turning to the right or left without having to stop. How would I actually get the x and y coordinants of the mouse to change?
PHP Code: if(x == xscreen){ //set x to 0 }else if(x == 0){ //set x to xscreen }else if(y == yscreen){ //set y to 0 }else if(y == 0){ //set y to yscreen } mh_sh_highlight_all('php');
First, I have a figure that moves around the screen. It uses keylisteners and just subtracts or adds pixels. However, I notice the movement is not smooth at all. It is very rigid and laggy movement. How can I make it smoother movement?
Second, you get three lives in the game. The lives are subtracting correctly, but I want the game to say "GAME OVER" on a dialog box. How would I get this to happen? My JFrame and my life int are in separate classes. I know I should use an if statement, saying if lives are at or less than zero, open the box, but how do I open the box?
Third, I want to display the time on the screen. I have a swing timer, but how do I put it on the screen? DrawString is not working for me.
Fourth, I want to set an icon for the game, the code is running, but not doing anything.
I'm relatively new to Java, I'm trying to create a text based game, like those old ones where you type "north" or "east" to move as such, and "look" to inspect the area. My only problem thus far has been trying to figure out just how I should... "structure?" the movement. As in, what's the best overall way to approach this? I've tried making a new method for every area and just passing a variable called "location," but along with passing the inventory and stat arrays, it's just become messy. Or is this a good way to do it? I have a separate method for when the player enters something, but then how will it know which description to give when the player types "look?"
I am new to DreamInCode! I was creating a game using OpenGL (and slick for textures).
Using Vector3f, I make coordinates to where my camera is camera'ing (and rotation).
It was working... until I modified something. I only added shaders. When I took the shaders off I think I might of accidentally deleted something. Nonetheless the code looks perfect to me.
On the method "input()" everything runs. No errors are thrown anywhere. I have syso'd the hell outa my code. It shows no signs of breaks. I can, however, move elements I put into my program. I am 100% sure that no other class is breaking my game (soon to be).
What you should look out for: I am not really sure about the glLoadIdentity()'s and glMatrixMode(). I am, knowing a good part of, thinking it could be gluViewPort....
My problem: Can't move my camera even tho it was working before.
I just started to learn Java. In my program, I created a GRect(paddle) and I would like to move it on the x axis whenever the mouse is moved.
import acm.graphics.*; import acm.program.*; import acm.util.*; import java.awt.*; import java.awt.event.*; public class BreakoutClass extends GraphicsProgram { /** Width and height of application window in pixels */ private static final int WIDTH = 400; private static final int HEIGHT = 600;
[code]....
In this case, whenever the paddle reaches the right edge of the screen, it doesn't move off the windows, but it stops moving (even if you move the mouse).
I'm working on making a game in JAVA. To be brief, the game is on a 6x6 matrix called "blocks[][]". The game has two players and the objective is to capture the enemies pieces by moving your piece onto there's. The players do this by moving one piece per turn either forward/backward (Vertically) or right/left (horizontal) movements. Essentially checkers without jumps.I'm not very far into the development process here. So far I have the game board created and the pieces load by clicking the "Start" button (handled by the refresh function). However I'm having a few problems... Namely moving the pieces effectively at the moment.
Right now there's a lot to do:
(1) - Implement a turn system, (2) - Only allow a player to click their pieces (I've a validation function already in place to only permit valid moves [horizontal/vertical only]), (3) - getting the pieces to actually "move" what I mean by this is a player selects the piece they want to move, then they select the spot they want to move to and the icon I have placed on the button is supposed to be added to the new square and the icon for its previous position is to be made null.
Please see the "actionPerformed" section to see exactly what I'm trying to do and hopefully as well see what I'm missing as to why it is not working at the moment... Also see under the Refresh function where I commented out the for loops to add the pieces. I did this because it was resulting in an ArrayOutofBounds error so I just wrote each spot out manually where I wanted them to start.
I need the following key controlled ellipse to leave a trail behind that vanishes after 10 frames. Also, I need to create a random moving ellipse not related to the preexisting one. How to separate the two ellipses ...
I'm working on this space invaders game and I've been stuck trying to get the alien spaceships to move down in one group. The way we have to design the game is we have to implement at least these 3 classes. These classes are GameData,GamePanel, and Animator. GameData is all the action figures/models in the game. GamePanel draws all game action figures/ models on the screen. Animator updates periodicaly action figures positions,sizes, colors etc. I can get the aliens to move right but once they hit the end of the canvas I cannot figure out how to get them to move as a group down and then begin moving left. I tried to add alien objects to the GameFigures list and then have the update method in the Alien class be responsible for moving the alien ships, but I couldn't figure out how to make it work. So then I made an alienFigures list in the GameData class and I still cannot figure out what to do. Here is the GameData class
I've been creating a digital clock using Java, and have made the mouse cursor invisible after a set period of time (40-seconds) and had the thought to make it visible again if mouse was moved.
Here's the code that makes it invisible:
ActionListener mouseTimeout = new ActionListener() { public void actionPerformed(ActionEvent e) { setCursor(blankCursor); } }; /* Make mouse cursor disappear after 40 seconds */ Timer mTimeout = new Timer(40000, mouseTimeout); mTimeout.start();
And here is what I have so far for making it visible again:
MouseMotionListener mouse = new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { } @Override public void mouseMoved(MouseEvent e) { } };
I have tried using "setCursor(DEFAULT_CURSOR)" but NetBeans says that it "cannot find symbol" .....
I made a kind of maze game that includes the class keylistener and orients a object, i can't find where the program tracks this object (where its x and y coordinates are). So now my object can move freely through all walls and i want it to bounce back or at least something to happen when the object reaches a wall.
I want to find a way to limit my objects movement and because i cant find where the coordinates or variable for this object is i cannot limit its movement
How to catch the event when table view's column are re-positioned. Basically when the column is re-positioned from 1 position to 5 position , i want to do update the db.
my task is to add a few functions to an example calculator. I managed to add a divide button but I simply can't figure out how to add a working Pi and reciprocal function.
package newjavaproject; import java.awt.*; import java.awt.event.*; import java.applet.*; public class CalculateurNC extends Applet {
Why I am getting errors for this program I (tried) to write. I am new to java.
import java.util.Scanner; public class TheBarkingLot { public static void main(String args[]) { int n; Scanner input = new Scanner(System.in); System.out.println("How many large dogs are boarding today?");
im considered quite the "javanoob" as my account name states..The assignment is to basically take a number that is entered by a user, and based off what they type in, display a corresponding grade letter. For example, if they enter a number between 90-100, they should receive a response that they received an "A". Now, this is fairly simple using an if/else statement, but my professor wanted us to implement this, using a switch case to teach us the difference.
import java.util.*; public class SwitchTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in);
System.out.println("Please enter a number to find out what letter grade you have recieved");
I moved some static html pages I was hosting from apache into tomcat. (no point in running two servers) This works as expected, but I'm having trouble with the authentication part. In apache the authentication was handled by htaccess. I tried various tutorials on the web about configuring basic authentication in tomcat using WEB-INF/web.xml in tomcat, but I'm not sure this approach applies to static html pages. Using basic authentication for static html in tomcat?