KeyListener kinda deaf (in simple game)

Hey everyone...
I'm trying to write a simple word-guessing game (Lingo, user should guess 5 letter words etc).
I've created some custom AWT Components (sorry for the dutch naming):
Lettervak: extends Canvas
Woordveld: extends Container and contains Lettervak's
Speelveld: extends Container and contains Woordveld's
The Speelveld (playing field in english) is the main component I want to talk to from the applet itself.
I don't care where a key is typed, I just want to be able to send the message to the correct component so the letter can be drawn in a Lettervak. So I though I'd add a KeyListener to the Applet itself.
It registers (I can see in the debugger), but it doesn't receive any key events (I can tell by adding a breakpoint there, so it's not in code further down).
Can anyone tell me what I'm doing wrong? Below is the code of the Applet itself:
(may look a bit messy, because I've been fooling around to get it to work, sorry...)
package lingo;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class LingoWeb
extends Applet {
private boolean isStandalone = false;
// Components
Speelveld grid;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
//Construct the applet
public LingoWeb() {
this.addKeyListener( new SpeelveldListener() );
//Initialize the applet
public void init() {
try {
jbInit();
catch (Exception e) {
e.printStackTrace();
//Component initialization
private void jbInit() throws Exception {
Speelveld grid = new Speelveld( 10, 20, 5, 5, 40 );
this.setFocusable( true );
this.requestFocusInWindow();
this.setLayout(null);
this.add(grid);
this.repaint();
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
//Get parameter info
public String[][] getParameterInfo() {
return null;
class SpeelveldListener implements KeyListener {
public void keyTyped( KeyEvent e ) {
char c = e.getKeyChar();
grid.invoer(c);
public void keyPressed( KeyEvent e ) {
System.out.println( e.getKeyChar() );
public void keyReleased( KeyEvent e ) {}
Thanks!
Tim.

/*  <applet code="AppletKeyTest" width="400"
height="300"></applet>
*  use: >appletviewer AppletKeyTest.java
import java.applet.Applet;
import java.awt.*;
import java.awt.font.*;
import java.awt.event.*;
public class AppletKeyTest extends Applet
public void init()
setLayout(new BorderLayout());
add(new Speelveld());
public static void main(String[] args)
Applet applet = new AppletKeyTest();
Frame f = new Frame(applet.getClass().getName());
f.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
f.add(applet);
f.setSize(400,300);
f.setLocation(200,200);
applet.init();
applet.start();
f.setVisible(true);
class Speelveld extends Canvas
Font font;
String text;
public Speelveld()
font = new Font("lucida bright regular", Font.PLAIN,
48);
text = "a";
addKeyListener(new SpeelveldListener(this));
setFocusable(true);
requestFocusInWindow();
public void paint(Graphics g)
super.paint(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int w = getWidth();
int h = getHeight();
g2.setFont(font);
FontRenderContext frc = g2.getFontRenderContext();
float textWidth = (float)font.getStringBounds(text,
frc).getWidth();
LineMetrics lm = font.getLineMetrics(text, frc);
float x = (w - textWidth)/2;
float y = (h + lm.getHeight())/2 - lm.getDescent();
g2.drawString(text, x, y);
public void update(Graphics g)
paint(g);
public void setText(String text)
this.text = text;
repaint();
class SpeelveldListener extends KeyAdapter
Speelveld speelveld;
public SpeelveldListener(Speelveld s)
speelveld = s;
public void keyPressed(KeyEvent e)
String s = KeyEvent.getKeyText(e.getKeyCode());
speelveld.setText(s);
}Yikes!
don't do much processing in the listener methods.
Certainly DONT call drawn out methods. I wouldn't call ANY methods.
Here is a quote...
"The most important rule to keep in mind about event listeners that they should execute very quickly. Because all drawing and event-listening methods are executed in the same thread, a slow event-listener method can make the program seem unresponsive and slow to repaint itself. If you need to perform some lengthy operation as the result of an event, do it by starting up another thread (or somehow sending a request to another thread) to perform the operation. For help on using threads, see How to Use Threads."
From here.
http://java.sun.com/docs/books/tutorial/uiswing/events/generalrules.html
There are those who will tell you that calling methods and adding other
general inefficiencies to you code doesn't matter, but it in fact does and this
is one area where it is readilly apparent.
In my HyperView API my listener routines simply bit codes the event,
pops it on a list, and then calls notify() to another thread which then does the processing.
This allows more cycles for the AWT-Event thread to grab events because it doesn't
have to then process them. It also smooths out the differences between different
operating system event models.
Good Luck!
(T)

Similar Messages

  • KeyListener for a simple game?

    I am begining to write a simple game, and I can't get the keyListener to work. I had written a pong game on jdk 1.3.1 and it worked fine. I used public boolean keyDown(Event e,int key){. I have been looking all over and can't find a keyListener that works on 1.4.1. Any help would be appreciated. So far I have:
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class Game extends Applet implements KeyListener,Runnable {
         Toolkit toolkit = Toolkit.getDefaultToolkit();
         static Image picture;
         Graphics offscreen,g;
         Image image;
         int x=1,y=10;
         static final int REFRESH_RATE = 200;
         Thread animation;
         public void update(Graphics g) {
              paint(g);
         public void init(){
              image=createImage(500,300);
              offscreen = image.getGraphics();
              picture = toolkit.getImage("Neo1.gif");
         public void start(){
              animation = new Thread(this);
              if(animation!=null){
                   animation.start();
         public void paint(Graphics g){
              offscreen.drawImage(picture,75+y,60,32,46,this);
              g.drawImage(image,0,0,this);
         public void keyTyped(KeyEvent e){
            //Anything I put here does not work???
         public void keyPressed(KeyEvent e){
         public void keyReleased(KeyEvent e){
         public void run(){
              while(true){
                   repaint();
                   try{
                        Thread.sleep (REFRESH_RATE);
                   } catch(Exception exc) { };
         public void stop(){
              if(animation!=null){
                   animation.stop();
                   animation=null;
    } [code/]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Heres my actual code that does work:
      class PlayingPanel extends JPanel implements KeyListener {
        public PlayingPanel() {
          this.setBackground(Color.black);
          this.grabFocus();
        public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.setColor(Color.black);
          g.drawRect(0, 0, this.getWidth(), this.getHeight());
          g.setColor(Color.white);
          g.drawString("Right: " + keys[0], 10, 15);
          g.drawString("Up: " +    keys[1], 10, 30);
          g.drawString("Left: " +  keys[2], 10, 45);
          g.drawString("Down: " +  keys[3], 10, 60);
          g.drawString("Released: " +  keys[4], 10, 75);
          g.drawString("Typed: " +  keys[5], 10, 90);
          g.drawString("Pressed: " +  keys[6], 10, 105);
        public boolean isFocusTraversable() {
          return true;
        public void keyReleased(KeyEvent e) {
          if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
            keys[0] = false;
          } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
            keys[2] = false;
          if (e.getKeyCode() == KeyEvent.VK_UP) {
            keys[1] = false;
          } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
            keys[3] = false;
          keys[4] = true;
        public void keyPressed(KeyEvent e) {
          keys[6] = true;
        public void keyTyped(KeyEvent e) {
          if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
            keys[0] = true;
          } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
            keys[2] = true;
          if (e.getKeyCode() == KeyEvent.VK_UP) {
            keys[1] = true;
          } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
            keys[3] = true;
          keys[5] = true;
      }Hope this helps.
    CoW

  • Can Flex be used to create simple games?

    Hi. I'm thinking of creating some simple games for children 6 - 10 years of age.The games can be things such as drag-and-drop and multiple choice. I'd like to store the results on a database. Can I use Flex Builder to do this or do you recommend Flash? Can you point me to a resource on this?
    The reason I ask is that I've built web apps using Flex and have some basic experience with Flash. Will building games be very challenging if I have to use Flash? The project in question will start in January and have to be completed by the end of March 2010. Thank you.

    As per your description for games Flex should be fine. It also depends on the skills and experience you have in the technology.

  • What's wrong with my ipad2? I just can't bear it always restart again and again when I just play a simple game!

    What's wrong with my ipad2? I just can't bear it always restart again and again when I just play a simple game! What's wrong with the apple without Jobs?!

    Try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until the screen blacks out or you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.

  • How to design a simple game?

    my programming skills are pretty much limited and as most beginners i was coding simple things by build and fix method, but wanna try to do it properly so i'm looking for help. i've been trying to design simple Connect4 game and as i'm coding in java i taken oo aproach. i'll explain exactly steps i've taken and i'd really appreciate if someone familiar with oo design and software engineering in all would point out what i'm douing wrong and if theres is anything ok with my approach.
    1. i've started with use-case modelling and created first scenario
    scenario created:
    1. user clicks start button
    2. player1 is presented with empty board and asked to insert token in column of his choice
    3. player1 clicks on column where he wants to insert token. token drops (appears) in chosen column
    4. player2 is asked to insert token into column
    5. player2 clicks on column where he wants to insert token
    token drops (appears) in chosen column
    6. steps 2-5 are repeated
    7. player1 connects 4 in a row and information is displayed player1 has won
    i know scenarios should include every possible way of utilizing the software but it gives countless possbilities and i was wonder if scenario for every single way of utilizing the product should be created or maybe not? i suppose that number of scenarios depends on how the product is complicated but in case of very simple game like connect4 aproximately how many scenarios would be expected?
    2. having above scenario ready i've used noun extraction method to extract candidate classes and so i have:
    players inserts tokens into the board consisting of 7 rows and 6 columns. players trying to connect their four tokens in a row (horizontally, vertically or diagonally) to win.
    classes extracted:
    player
    token
    board
    row
    column
    assuming that state of token, row, column will not change, i skipped those and left only two classes board and player. after a while i also noticed that another class named connect4 would be needed to put it all together.
    3. having one scenario ready and classes extracted i went directly to drawing sequence state diagram which i've put here
    4. next i draw detailed class diagram (here) and more or less decided on methods for every class
    5. then i started writing pseudocode but while writing i'm finding myself adding additional methods, variables etc and keep changing design while coding, what dosent seem to be a good practice. i was wonder how it works in real life and what is the chance to get application designed correctly for the first time, i mean extract the classes with methods etc.
    to be honest i got lost a little cause according to shach's book i missed state diagram and few other things and dont know how important those bit are in real life and designing real software. as i said i'm real beginner in software engineering and any help would be much appreciated. than you very much in advance for any comments regarding my design and help

    i know scenarios should include every possible way of
    utilizing the software but it gives countless
    possbilities and i was wonder if scenario for every
    single way of utilizing the product should be created
    or maybe not? i suppose that number of scenarios
    depends on how the product is complicated but in case
    of very simple game like connect4 aproximately how
    many scenarios would be expected?Very few. This program is small and the interaction
    with the user is minimal.
    2. having above scenario ready i've used noun
    extraction method to extract candidate classes and so
    i have:
    player
    token
    board
    row
    column
    assuming that state of token, row, column will not
    change, i skipped those and left only two classes
    board and player. after a while i also noticed that
    another class named connect4 would be needed to put it
    all together.Things like "player" or "person" are rarely if ever real classes.
    Imagine you were designing the control program for an
    elevator. Just because a person clicks on the button for
    a floor doesn't mean you make them a class in your design.
    Likewise, just because a player clicks on a column doesn't
    mean you make them a class.
    In reality, this program is small enough for one major class,
    the gameboard itself. You may have an enum for the token
    color but that's about it.
    What can you do with this gameboard? Not much:
    1. Add a token to column X.
    2. Check for a win.
    3. Obtain a copy of the board.
    Your gameboard only has to maintain the state of the
    board and allow you to add a token or check for a win.
    Your class to display the gameboard and accept user
    input will probably be larger than anything else.
    You can write this program with only two classes. The
    gameboard and the display.
    3. having one scenario ready and classes extracted i
    went directly to drawing sequence state diagram which
    i've put hereOverkill for a program of this size.
    4. next i draw detailed class diagram (here) and more
    or less decided on methods for every classAlso overkill for a program of this size. Unless this is
    an assignment at work or school, all of these documents
    are unnecessary and likely to be several times larger than
    your entire program.
    5. then i started writing pseudocode but while writing
    i'm finding myself adding additional methods,
    variables etc and keep changing design while coding,
    what dosent seem to be a good practice. i was wonder
    how it works in real life and what is the chance to
    get application designed correctly for the first time,
    i mean extract the classes with methods etc.If you find your design doesn't work while writing code
    then yes, you should go back and change your design
    document. This isn't too big of a sign of disaster unless
    you need to step back another step and change the
    requirements document. That's usually a sign you
    really messed up.
    By all means, go back and change the design document
    if you need to before you finish coding.
    In this case however, its probably overkill.
    to be honest i got lost a little cause according to
    shach's book i missed state diagram and few other
    things and dont know how important those bit are in
    real life and designing real software. as i said i'm
    real beginner in software engineering and any help
    would be much appreciated. than you very much in
    advance for any comments regarding my design and helpIts next to impossible to go through a structured design
    process on a project this small while working by yourself.
    You really need a bigger project with multiple team members
    to see how its all supposed to play out.
    Projects of this size are written almost as soon as you start
    thinking about them and any documentation you generate will
    dwarf your source code printout.

  • Daughter mostly plays simple games on iPad mini. Now reached stage where it says can't download not enough storage although showing 14.9 gbs of storage available. How can I overcome this ICloud,dropbox or what ?

    Daughter mostly plays simple games on iPad mini. Now reached stage where says "can't download not enough storage2 although showing 14.9 gbs storage available.How do I overcome this icloud,dropbox or what?
    Thank you in anticipation.

    Try a reset: Simultaneously hold down the Home and On buttons until the device shuts down. Ignore the off slider if it appears. Once shut down is complete, if it doesn't restart on it own, turn the device back on using the On button. In some cases it also helps to double click the Home button and close all apps from the tray before doing the reset.

  • Simple game performance question

    Hi all!
    Today I installed a simple Mah Jong game on my mothers Mac mini Core 2 Duo 1.83 GHz. The CPU performance should be roughly the same as on my iMac(as specified below). She uses a VGA display and has 1GB of RAM and this game doesn´t require very much RAM. How important is the graphics adapter for the performance of this very simple game with very little 3D effects as compared to the latest games on a pc? Do I get a speed boost because of 256 MB instead of 128 MB VRAM? Is it just Intel GMA 950 to blame for less performance or has it something to do with the VGA display?
    I´m very curious about this. Thanks for your replies.

    +is it just Intel GMA 950 to blame for less performance+
    Probably. Integrated graphics can't match a dedicated graphics card.
    Another possible contributor would be if the Mini with 1 Gig of RAM has a significant number of other memory-consuming programs running at the same time. This would be especially true if any of the programs invoke Rosetta emulation.
    The 2 gig of RAM in the iMac would be a real advantage if it reduces virtual memory activity vis-a-vis the Mini with 1 Gig.
    A fair test would be to make sure no other programs or widgets are running, and then test the game.

  • Comments/Suggestions for Simple Game?

    I have a super simple game I made. You can download it here:
    http://www.filedropper.com/catchphrase2
    Anybody have suggestions/ideas?

    TokyoTony wrote:
    I'd like to try something else please. The reason is as follows:
    When I put in a name for the document and then scan the documents, the file still comes up as untitled. I don't get that.
    When I want to rotate a page that is supposed to be landscape and do the rotation in Image Capture, all it does is cut the top and bottom out--it rotates the selection, not the image. I know I can do this in a PDF editor but why not have everything I need done in one application?
    When I do want to select A4 size, I don't see it unless I hide details. Seems a bit strange.
    Thanks,
    Tony
    Are you scanning into a program, or to a file? Either way, it seems to work for me with Preview. I didn’t try another app.
    I can’t replicate your other problems, either. Rotation works as expected and I have both Letter and A4 available on both interfaces.
    I have an Epson all-in-one, though.
    Perhaps if you listed your HP model number, others with that same printer/scanner could help.
    One thing to try, though. Log into another user on the Mac and try to scan. Same results?
    Boot into Safe Mode and try to scan. Same results?
    OS X: What is Safe Boot, Safe Mode?
    Those two steps will see if the problem is system-wide or caused by some additional software you have running at startup.

  • DVD simple games??

    HI can anyone tell me if it's possible to write simple games for children in DVD studio Pro or do I need to do them in other software first?
    Does anyone know if there are books or tutorials on this subject?
    I am not a programmer so it would only be the most basic of games I would want to create.
    Thanks

    OK - let's have a think about the HP example, but in a more simple way.
    Imagine a menu screen which has three potion buttons and three jug buttons. The user first selects a potion and the DVD records the button selection, returning the user to the same menu. They then select a jug and this choice is also recorded. If potion 1 has a value of '1', and jug 1 has a value of '10' then the ability to say the 'correct' choice has been made is done by simply adding the potion values and the jug values. A result of '11' will show a 'well done' clip, whereas any other result will give a 'you failed' clip. You can use more than one 'well done' or 'you failed' clips, selecting them to play at random to keep the user interested.
    All of this is done with two scripts - the first records the potion choice into a GPRM (by tracking the button number using SPRM8) and looks to see if you need to go back to the menu (i.e. no jug has been chosen). It then adds on the jug value when that button has been selected (so far, one menu, one script). When this has been done the total value is passed to the second script. Depending on what it finds, a random selection of 'right' or 'wrong' clips is used to display back to the screen... the viewer gets their visual feedback.
    If you wanted to keep a score, you'd need to add a new script which simply tracked how many 'right' clips were played throughout the duration of the game.
    None of this is actually very hard - the tricky bit is setting up the menus and clips and understanding the flow of the logic that needs to be applied. You could, for example, have differnt menus for the jugs and the potions. Selecting a potion then plays a short clip which zooms in to the view and then jumps to a new menu which has the selected potion in view ready to pour into a jug. Selecting a jug then activates a clip which zooms in to see the poition being poured... and a result (explosion, pleasant green potion, black faced Ron Weasley... whatever). This takes a few more menus and short clips to build, and you'd need to allow for every combination of potion and jug. The more exciting you want it to be, the more intense the menu and clip creation will get. The scripting will stay relatively easy!

  • Creating simple game map

    Hi,
    I would like to know that what can be used to create a simple game.. VERY SIMPLE game.. not 3D or Java 2D api used i guess..
    game
    A board with lots of circles (which user can draw) representing territories and links (editable) between the territories representing paths between territories ...
    I jsut need to know what can be used to represent a territory? a JLabel? a JPanel?
    The state of these objects(territories ) will change over time and so does the links i.e. the paths between the territories.
    I just need to draw the map.
    Any help will be appreciated.
    Thank,

    If you are writing an app with that sort of GUI you are going to have to bite the bullet and learn the 2D graphics API: http://java.sun.com/docs/books/tutorial/2d/index.html

  • Simple game design,

    so I have a basic understanding of java, I took a class on it this spring and did well. I am wanting to make a simple game, a single picture, a map, that is clicked.
    based on the location clicked, the player gets an item. this is an online game.
    I am going to use SQL for this game on the back end. it will have a db with two tables, users, and map.
    users will have user name, user ID, items owned, tools, and searched today.
    map Im not quite sure about yet.
    so basically, Im trying to figure out how I should go about this. Im not quite ready to hack code yet, I need to get a good plan together and make sure I go about this correctly.
    can I open this for discussion and get some help on designing this. Im trying to stay really very simple, so as not to undertake too much.
    this is my outline right now:
    login: a screen with name and pass fields, an ok button. when the button is clicked, the program checks the db for the name, and verifies the password, if everything is in order, goto the account screen, possibly a cookie or session of some sort is set.
    account screen: show the username, items owned and number of each, any tools or special items owned. button to logout, button to goto map. radio buttons on the tools to determine which one, if any, is equipped. there should also be a special area near the top that shows what item was found on the previous day.
    map screen: this is a small image of a map. the user clicks and shows a pin placed, as well as any other pins currently on the map for the day. a search button that when clicked, locks in the location untill the end of the day.
    the user can search one location per 24 hour period, server time.once a location is picked, its locked in till server is rolled to new day. based on the location, and the tool selected, the player gains an item, these will be used for creating items and such in a later game that is tied to the IP.
    pretty simple, login, pick a tool, pick a location, complain in the forum that you can't find good items, and that the main game isnt done, move on till tomorrow :)
    I need to go over each part in detail and do this right. I should mostly be SQL with a graphic frontend, which as of now Im choosing Java for, so this can run in a web browser. Im also considering PHP, but I fear it wont be dynamic enough. Flash is my other choice. I would like to get a good idea of what I need to do for each aspect before I make it. The screens I will make in netBeans, probably using Swing, and all of my actual logic will be in click events.
    Help me out guys, I need to talk about this step by step with someone.

    lord_midnight wrote:
    ]morgair: I have done some small projects here n there, mostly just demos, I am almost finished with a retro styled platformer, just placing tiles and entities, finishing up the art, code is done except for a few custom routines for a boss. this project is actually pretty small, other than being online, its a good choice for a first game type of project. Im confident it is within my skillset.Thank you for the reply, I was unsure what level of help you needed, many on here come in and have never done any programming before, let alone, an actual game on-line or otherwise. It's nice to hear where you're at.
    ]mrw: yeah, its not so much that I have a problem, I just want to make sure I think everything through before I start. Im trying to get a good grasp of what Im doing, so I don't have very many problems, Im sure I'll have a few though, somehow no matter how much I plan, something goes awry.
    ]soultech2012: Im actually in college, I took java this spring, and Im taking advanced java as soon as its offered online. still, its not so much instruction I want, as discussion.
    maybe I was not being so clear, Im not looking for anyone to write code, or tell me what to do, I want to talk with people, Im sure I will have direct questions at some point, but right now, I want to think it through. If anything, another set of eyes looking at the design, pointing out possible snags or logic problems. its pretty simple as far as games go, I did some prototyping in flash last night, I think this will be pretty easy. does anyone see any serious problems in the design ?
    I think it will make a nice little game, its not meant to take much time out of the players day, just a 2-5 minute jaunt into my website. login, pick a spot on the map, select a tool to use to help gather items, and slowly over several weeks, have accumulated a collection of goods for a game Im doing at a later date.
    getting the x,y will be easy, I have done a couple of very simple apps that interact with SQL,
    the only real logic parts of this are some ifs or a switch, and adding to a field in SQL.
    getting pixel color might be tricky, it was easy in flash, and Im pretty sure I saw a similar function last time I browsed the javadocs, so Im not too concerned.I like to use getRGB and setRGB from a BufferedImage.
    honestly, I looked around and I can all but make this in javascript and PHP/SQL, java might be overkill.
    anyone see any obvious ways to cheat the game ?If you store any logic on the client side they can easliy find and modify it, that way they can have a super character or all of the items. Runescape is perfect example of this, they run client server and there are groups that have made their own client to cheat with.
    am I underestimating the complexity of the task ? I have plenty of time to work on it, no hurry, but Im hoping to have something on the site within the next month or so.That is doable, If you are careful in your implementation, you can build a basic game engine and then work on map and support making for facilitate different levels.
    I need to make a list of terrains, the colors Im using for them, and items found, and I need to draw out a table that Im using to plot out the sql.
    Im taking PHP/SQL this fall, Im starting to get the hang of it, and I have a pretty good grasp of basic programming concepts. this should be well within reach, honestly, its glorified tic-tac-toe, or match-findingThe big things that seem to pop up for people are:
    Picking up items
    putting down an item
    weilding an item
    using an item
    combat
    breaking off combat
    automatic path plotting (least cost algo from map)
    frequency of random events
    regeneration of items
    regeneration of health
    real language interaction with characters (pattern matching for content)
    Just remember: choose what you want and don't let the scope of your game creap or you'll have a bunch of code that has no implementation end in sight. Keep your compiles short and changes departmentalize so you can have running code that works from one feature to another. I see a lot of people--experirenced too--that literally throw hundreds of lines of code out and then try to debug it after they make changes thorughout the stable code base to allow integration of the new feature; this can be very daunting, keep it as simple as possible to integrate new features--small steps are good.
    thanks for the input, and comments are welcome, best I can offer is thanks and bonus tools in the game once its done, so thank you.

  • Simple games run very slowly on iPad

    I gave the iPhone packager a spin last night and tested it using the demos off of Flixel, a popular bitmap game engine to benchmark performance. Although I was happy that I could get these demos running on my iPad rather quickly, the performance of the games was disappointing, averaging around 10 FPS, which is well below playable. These are very simple demos that run at 60 FPS on any desktop.
    This is one such example.
    http://flixel.org/flxinvaders/
    Am I expecting too much from the packager, or is this cause for concern?

    I would not say that the devguide is memorized by me yet, but I have read it and I get the gist.  I did overlook the portion discussing vector drawn objects being slower and removing nested children to make them siblings (though that nesting seems a bit of a limitation and might require a number of design pattern hoops to jump through to implement that well in a large game).  I understand cacheAsBitmap and use it when needed - but lack of scaling and rotation (which is what I first animated if you reread above) invalidates cacheAsBitmap anyway and is a huge limitation.
    I wasn't stating anything as fact or proof anywhere in ANY of my posts.  I came to this forum as someone open to learning, but also to see other developers experiences.  There is very little on the web as of today that discusses the ins and outs of the limitations or constraints of the translation of SWF to IPA by the Packager.  I have yet to see any app created in this fashion that does animate smoothly so that along with as I said very initial and preliminary tests have disappointed me.
    I mentioned my experience as a developer for no other reason that to indicate that I am an AS3 person who loves Flash and wants to set the tone so it didn't appear that I'm coming in here trolling or bashing flash.  The fact is I have done alot of high end AS3 work in Flash and Flex and totally dig it as a platform - I want Flash apps to work well on iOS.
    Apparently I was naive to think my AS3 knowledge was enough to create simplistic but smooth animations quickly with the translation.  Clearly something is going on with the approach the Packager takes and that introduces constraints in the way the drawing is handled which results in poor frame rates without GPU (if that is indeed what is happening in my initial test).
    I'm happy to reread that section in the pdf and scour it for optimization techniques of sibiling children etc and do that.  Clearly I missed some of that and was hoping to get some pointers here from the horse's mouth so to speak of developers who DO have it working.
    It's easy to say "you're no advanced coder" and sit back and say "I've done it you suck- how dare you besmirch Flash". But believe me mr12Fingers I am not claiming something can't be done.  I am saying I could not achieve decent animation quickly and have not seen one single animation in ANY iPhone or iPad Packager app that is as smooth as a typical high framerate 2D game written in xcode Obj C.
    Saying I'm blindly conducting tests is innaccurate.  I hardly said I've exhaustively benchmarked the Flash Packager's performance.  I said it was my first time "taking it for a spin" and it was a hello world app and that I had problems with the results and haven't seen anything to tell me different.  It's kind of blind in my opinion to have blinders on to anyone who doesn't have the same experience as you.
    Please take the time to help or assist or point me in the direction of achieving that, or confirm my very preliminary but disheartening results which my hello world type apps and what is actually out there seem to indicate to me.  Or if you can't do any of that then please don't muddy the conversation with being adversarial.  I don't intend to be and would love to hear what you or anyone who has a different experience than my initial ones with the Packager.
    thank you for telling me that you had no trouble with your cert.  Can you please elaborate on what steps you took to use the same Mac cert from the keychain and use it in a windows 7 bootcamp with the packager.  Whenever I tried that the Packager would fail with "invalid certificate" (though that cert works in Xcode on the mac) and the only way I could get the Packager to work was to regenerate the cert on Windows using the OpenSSL method after revoking the original one.
    Clearly I am new to the DRM methods of iOS development, but the steps in the pdf didn't fully work for me.
    Thanks for any assistance, and please let's make this conversation a bit more helpful for each other rather than adversarial.

  • How to keep score in a simple game?

    Hi - I'm building a simple multiple choice game. There is 5
    questions, each with 2 different answers.
    Which ever answer the user chooses on each question - they
    will either gain or lose money - eg.
    Answer A: Lose £2
    Answer B: Gain £4
    I'm looking for the simplest way I can keep track of the
    users score throughout the game. I've looked at a few quiz
    tutorials but they seem too advanced for what I'm trying to do...
    Thanks.

    To keep track of the user's score you just need to declare a
    variable to hold that value, probably a global variable, and then
    change that variable's value based on a set of rules that you
    define.
    To display the result of the change in the score, you need to
    convert the value of the variable to something that the user can
    use. In your case it looks like you want to show a value in pounds.
    One way to achieve this is to declare a global variable at
    the start of your movie, and then give it an inital value in a
    function at the start of the movie. Something like this in a movie
    script window would work:
    global score
    on startMovie
    score = 0
    end
    Then you will need to set up a method to record the user's
    choice for each question. In that method, probably a behavior
    attached to the answer selectors, you can change the value of the
    global variable.
    Then you will need a text or field member instance on the
    stage to show the score. You can show the result something like
    this:
    member("show score").text = "£" & score
    Be sure to declare the global at every point where you want
    to use it.

  • A simple game: name that pkg

    I don't know what gave me this idea, but here it is anyway... a simple multiple choice game that presents a package description followed by 4 package names. All  you have to do is pick the right name.
    By default it uses locally installed packages. You can pass it the option "--all" to use all packages from the sync database. Passing it a number will change the number of default options.
    It keeps track of the number of correct answers and winning streaks. It's not difficult because many of the package descriptions mention the package. Some of them are tricky though, and it can be interesting to see the descriptions of some of the things on  your system.
    At the end of the day though, this is basically pointless.
    name_that_pkg.pl
    #!/usr/bin/perl
    use warnings;
    use strict;
    use Term::ANSIColor;
    my $info = (grep {$_ eq '--all'} @ARGV) ? `pacman -Si` : `pacman -Qi`;
    push @ARGV, 4;
    my $a = (grep {($_ =~ m/^\d+$/) and $_ > 0} @ARGV)[0];
    my @list;
    my $name;
    $info =~ s/\n\s\s+/ /g;
    foreach my $line (split "\n", $info)
    if ($line =~ m/^Name\s+:\s+(\S+)/)
    $name = $1;
    elsif ($line =~ m/^Description\s+:\s+(.+)$/)
    push @list, "$name : $1";
    my $n = scalar @list;
    my ($correct, $total, $streak, $best_streak) = (0,0,0,0);
    my $ans;
    while (1)
    my $c_name;
    my $c_desc;
    my @names;
    my $c = int(rand($a));
    for (my $i=0; $i<$a; $i++)
    my ($name,$desc) = &split_line($list[int(rand($n))]);
    if (grep {$name eq $_} @names)
    $i--;
    next;
    push @names, $name;
    if ($i == $c)
    ($c_name,$c_desc) = ($name,$desc);
    $c_desc =~ s/\Q$c_name\E/*/gi;
    print "description: $c_desc\n";
    my $j = 1;
    foreach my $name (@names)
    print "$j) $name\n";
    $j++;
    print "x) exit\n";
    print "answer: ";
    my $ans = <STDIN>;
    chomp $ans;
    last if (lc($ans) eq 'x');
    $total++;
    print "\n";
    if ($ans == $c + 1)
    $correct++;
    $streak++;
    $best_streak = $streak if ($streak > $best_streak);
    print color ('bold green'), 'correct', color ('reset'), "\n";
    else
    $streak = 0;
    print color ('bold red'), 'incorrect', color ('reset'), " (answer: $c_name)\n";
    print "current score: $correct/$total ",int(100 * $correct / $total),"%\n";
    print "current streak: $streak\n";
    print "best streak: $best_streak\n\n";
    sub split_line
    return ($_[0] =~ m/^(\S+) : (.+?)\s*$/);
    Last edited by Xyne (2009-02-24 19:08:51)

    It's not that I have too much time on my hands (the opposite, actually), just that I'm easily sidetracked. This only took 10-15 minutes anyway.
    I've updated the script to replace the package name with "*", which works well enough for most descriptions with some notable exceptions:
    description: * is a language and envi*onment fo* statistical computing and g*aphics
    1) shared-mime-info
    2) gen-init-cpio
    3) r
    4) medit
    Last edited by Xyne (2009-02-24 19:13:17)

  • J2me simple game application

    when i select the new Game option Game Screen doesn't work properly.please help me ican't find problem in this program but the project build sucsessfully;
    Midlet class....
    //@Author Lasantha PW
    //Title Java Developer
    //Project Name Simple Midlet Game Application
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    //main midlet
    public class Mario extends MIDlet{
    Display display; //display object
         //private String player,background;
         private Image splashLogo;//splash image
         MainMenuScreen mainMenuScreen;//main menu object
         AboutScreen about;
         boolean isSplash=true; //splash condition
         MarioCanvas marioCanvas;//=new MarioCanvas(this);
         public int noOfLives=3; //player lives
         public Mario(){
              marioCanvas=new MarioCanvas(this);
              about=new AboutScreen(this);
         public void startApp(){
              display=Display.getDisplay(this);
              mainMenuScreen=new MainMenuScreen(this);
              if(isSplash) {
              isSplash=false;
                   try {
                   splashLogo=Image.createImage("/splash.png");
                   new SplashScreen(display,mainMenuScreen,3000,splashLogo);
              catch(Exception ex){}
         public void pauseApp(){
         public void destroyApp(boolean unconditional){
              notifyDestroyed();
         public void mainMenuScreenQuit(){
              destroyApp(true);
         public void mainMenuScreenShow(){
              display.setCurrent(mainMenuScreen);
         public void gameScreenShow(){
              display.setCurrent(marioCanvas);
              marioCanvas.start1();
         public void aboutScreenShow(){
              display.setCurrent(about);
         public void gameScreenQuit(){
              destroyApp(true);
         public Display getDisplay(){
              return display;
    Main Menu class..................................
    //@Author Lasantha PW
    //Title Java Developer
    //Project Name Simple Midlet Game Application
    import javax.microedition.lcdui.*;
    import java.io.IOException;
    public class MainMenuScreen extends List implements CommandListener{
         //create midlet object
         private Mario midlet;
         //create command objects
         private Command exit=new Command("Exit",Command.EXIT,1);
         private Command select=new Command("Select",Command.ITEM,1);
         //private MarioCanvas marioCanvas;
         public MainMenuScreen(Mario midlet){
         super("Tank32",Choice.IMPLICIT);
         this.midlet=midlet;
         append("New Game",null);
         append("Settings",null);
         append("High Score",null);
         append("Help",null);
         append("About",null);
         addCommand(exit);
         addCommand(select);
         setCommandListener(this);
         public void commandAction(Command c,Displayable d){
         if(c==exit){
         midlet.mainMenuScreenQuit();return;
         else if(c==select){
         processMenu();return;
         else{
         processMenu();return;
         private void processMenu(){
         List down=(List)midlet.display.getCurrent();
         switch(down.getSelectedIndex()){
         case 0:scnNewGame();break;
         case 1:scnSettings();break;
         case 2:scnHighScore();break;
         case 3:scnHelp();break;
         case 4:scnAbout();break;
         //private methods for processMenu method
         private void scnNewGame(){     
              midlet.gameScreenShow();     
         private void scnSettings(){}
         private void scnHighScore(){}
         private void scnHelp(){}
         private void scnAbout(){
              midlet.aboutScreenShow();
    GameScreen......................................
    //@Author Lasantha PW
    //Title Java Developer
    //Project Name Simple Midlet Game Application
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    import java.util.*;
    public class MarioCanvas extends GameCanvas implements Runnable,CommandListener{
    //command objects
         private Command exit=new Command("Exit",Command.EXIT,1);
         //main midlet
         public Mario midlet;
         public boolean isPlay=true;
         public int dx=4;
         public int dy=4;
         public int BASE=(2*getHeight())/3;
         public Vector allObstacles;
         //Resourse for player
         public Image playerPic;
         Player player;
         public boolean leftTrueRightFalse=true;
         //Power power;
         Image powerPic;
         //resourse for devils
         public Image devilPic;
         Devil devil1;
         LayerManager layerManager;
         public MarioCanvas(Mario midlet){
              super(true);
              this.midlet=midlet;
              addCommand(exit);
              setCommandListener(this);
         public void start1(){
              try{
                   //initialize all image objets
                   playerPic=Image.createImage("/player.png");
                   //powerPic=Image.createImage("/power.png");
                   devilPic =Image.createImage("/Devil.png");
                   //player object
                   Player player=new Player(playerPic,0,BASE-15,this);
                   //obstacle objects
                   devil1=new Devil(devilPic,player,100,BASE-15);
                   //vector object
                   allObstacles=new Vector(0,100);
                   //bullets=new Vector();
                   //add obstacles to the vector
                   allObstacles.addElement(((Sprite)devil1));
                   //set all obstacles to player
                   player.setAllObstacles(allObstacles);          
                   layerManager=new LayerManager();
                   //append to the layermanager     
                   layerManager.append(player);
                   layerManager.append(devil1);
                   Thread t=new Thread(this);
                   t.start();
              catch(Exception ex){
                   System.err.println("Error"+ex);
         public void run(){
              while(isPlay){
                   userInput();
                   verifyGameState();
                   updateBackground();
                   updateGameScreen();
              try{Thread.currentThread().sleep(15);}
              catch(Exception ex){}                    
         public void updateBackground(){
              Graphics g=getGraphics();
              g.setColor(0,124,0);
              g.fillRect(0,0,this.getWidth(),this.getHeight());
              g.setColor(0,224,0);
              g.fillRect(0,BASE+30,this.getWidth(),80);
         public void updateGameScreen(){
              Graphics g=this.getGraphics();
              if(player.Y<BASE){
              //player.incrementY(dy);
              else if(player.Y>BASE){
              player.Y=BASE;
              player.setY(BASE);}
              g.setColor(0,244,0);
              g.fillRect(0,BASE+30,1500,80);
              layerManager.paint(g,0,0);
              flushGraphics();
         public void userInput(){
              if((this.getKeyStates()&LEFT_PRESSED)!=0){}
              if((this.getKeyStates()&RIGHT_PRESSED)!=0){}
              if((this.getKeyStates()&FIRE_PRESSED)!=0){}     
         public void verifyGameState(){
         public void commandAction(Command c,Displayable d){
              if(c==exit){
                   midlet.gameScreenQuit();
    }

    pwlasantha wrote:
    when i select the new Game option Game Screen doesn't work properly.please help me ican't find problem in this program but the project build sucsessfully;
    ...If it "doesn't work properly", there's "something going wrong".

Maybe you are looking for

  • Is Active Directory's ExtensionAttributes9 a field in user object and how to retrieve it in the class type userprincipal?

    Hi, I'm using VS2012. I want to use this ExtensionAttributes9 field to store date value for each user object.  I use UserPrincipal class, a collection of these objects are then bind to a gridview control.  Is ExtensionAttributes9 a field in AD user o

  • Integration with MS VC++ DLL

    Dear Forte - colleagues I've got the following questions to clarify. They are mainly regarding integration with External Systems. 1. To invoke my C function from Forte, I've created a project that wraps C function, configured this as a library and ma

  • Security Update 2008-001

    Well I did this afternoon's security update like a good little user, and now on the restart all my machine does is sit there and spin on startup. Anyone else? What to do from here? Couldn't have come at a worse time. shannon

  • Best way to increase root and home part sizes

    Just want to check what means to increase size of root and home. Here's the drive with them now: Device Boot Start End Blocks Id System (xp) /dev/sdc1 * 1 7649 61440561 7 HPFS/NTFS /dev/sdc2 7650 8865 9767520 83 Linux (root) /dev/sdc3 8866 12512 2929

  • Cant find sourcesystem

    Hi all We are extracting some data from a source system but suddenly that source system is changed to client 200 to client 400 When we want to load some data  in dev we cant find old source system again what will be the solution we have assign new so