This site requires JavaScript, please enable it in your browser!
Greenfoot back
senor_ribs
senor_ribs wrote ...

2015/2/6

Player movement based on player type

senor_ribs senor_ribs

2015/2/6

#
I'm trying to make a game where instead of having an actor respond to key presses to move, the actor moves based on what the player types into the game. The player would be able to jump between 5 spots on the map, lets say these spots are 50 units apart. So basically I want the player to be able to type in something like "move left;" to get the actor to move left 50 units left, and if the player types "move right" the player would move to the right 50 units right. Also there would be a text box on the bottom of the game that shows what the player most recently typed as well as what the code for that action looks like within the game. I'm not sure exactly how to get this to work but I imagine the code would look something like this: int dx = 0, dy = 0; if (the player types "move left" \ and the player hits enter) \ { \ dx--; \ game deletes any text that may be in the textbox \ game ads "move left" the textbox <repeat for all directions game ads "dx--" to the textbox underneath "move left" / } / if(the player's position is -100 / and the player types "move left") / { / game ads "move left to the textbox" game ads "cannot move any farther left" to the textbox, underneath "move left" } if (dx == 0 && dy == 0) return; setLocation(getX()+dx*2, getY()+dy*2 if ( the player types anything that is not "move left") \ { \ text box shows what the player typed <repeat underneath what was entered the textbox says "could not compute" / } /
senor_ribs senor_ribs

2015/2/6

#
Just wanted to add that I am new to Greenfoot and java game development but have experience with game development using C++
danpost danpost

2015/2/6

#
What part of this, specifically, are you having problems with? What have you tried? To get started: * use an Actor object for the textbox * keep a reference to this textbox actor in your World instance * use GreenfootImage methods to manipulate the image of the textbox actor as needed * have the World object detect the keyboard events and build the input strings * the World object can either call methods in the class of the textbox or directly alter the image of the textbox actor in its own class (that of the World object) * use several methods for specific changes in the image of the textbox; something like one for each of the following actions - clear text input area and redraw input string (or an image of the input string) - clear the output - processing the input and returning the line(s) of output text to display - drawing the output string(s) (or images of them) in the output area of the image of the textbox actor
senor_ribs senor_ribs

2015/2/7

#
I have not tried anything yet because I do not know what any of the code would look like. I've never coded anything like this before.
danpost danpost

2015/2/7

#
Maybe you should go over the Greenfoot tutorials (for basic info on using the application and getting started). You can also view some short videos (linked on the same page) for how-to on various topics. As far as the code itself, which is pure java, you can check out the Java tutorials. The second section, Trails Covering the Basics, would be the place to start.
You need to login to post a reply.