Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 25, 2013 12:11 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: applet
PostPosted: Wed Mar 21, 2007 12:05 am 
Offline

Joined: Mon Mar 19, 2007 9:29 pm
Posts: 74
Where can I find example of applet game? In wiki tutorial it is difficult to get how to do it =(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 1:11 am 
Offline

Joined: Mon Mar 19, 2007 9:29 pm
Posts: 74
Another question (may be it better suit as Idea for RFE section):

May be it already done, but I cant find this things, in API. The main point that there no need to have field for each key.

Why not to make input like that:
1) when user press key it flag that current key pressed(e.g. in some array)
2) when user release key, it flag that this key released (in same array)
3) when we need some input, we simply check key state in array

Just short example how it works for me:
- when any key pressed it records as AWT event in LinkedList ():
Code:
    public void keyPressed(KeyEvent e)
        { eventProcessor.addEvent(e); }

- every game loop I execute all events from that list (calss with game loop should implement eventhandler):
Code:
//method in class with main loop
public boolean handleEvent(AWTEvent e)
{
    switch(e.getID())
    {
         case KeyEvent.KEY_PRESSED:
            keyboard.keyState[((KeyEvent)e).getKeyCode()] = true;

- then during game, in update method I can do this:
Code:
//this is in game state class
if (keyboard.keyState[KeyEvent.VK_UP])
   makejump();



If someone needed it I can present code and how it works.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 1:44 am 
Offline

Joined: Mon Mar 19, 2007 9:29 pm
Posts: 74
And again 1 thing that I can't find...

Is there are any class with collection (not java collection, just set) of static variables

Example what I mean:
Code:
public class Globals
{
    public static Game game;

    public static Keyboard keyboard;
    public static Mouse mouse;

    public static BasicGameState currentState;
    public static GameLevel currentLevel;

    public static int DISPLAY_WIDTH = 800;
    public static int DISPLAY_HEIGHT = 600;
    public static String WINDOW_TITLE = "game name";
}


Using it I don't need always pass reference to parent in constructor.

What do you think about it? :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 2:45 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Firstly, welcome to the boards! :) Requests for enhancements (RFE) should go in the Bug/RFE forum. :)

Applet Example:
Here's a slick game that uses an applet.
http://slick.cokeandcode.com/demos/appl ... ipong.html

Input:
Using AWT events in an OpenGL-based library is a poor idea. The input system in Slick is quite flexible. If you feel compelled to introduce AWT key events into a small non-Swing library you may do so with custom Input and InputListeners.

Also, keyboard codes are all found in the Input class, and you can check if a specific key is down at any time:
Code:
  if (container.getInput().isKeyDown(Input.KEY_SPACE) {
     System.out.println("spacebar is down");
  }


keyPressed and keyReleased (and similar mouse/controller implementations) are useful for handling single key presses/releases. These methods are better off being "event-driven" rather than having to poll them every update.


Static Collection:
Again, not something suitable for a light-weight library. This is too specific to your own game. This sort of idea would be more of an extension Extension. ;) However, you should note that many games may vary game settings, such as window title and dimesions, through the course of gameplay. Using final variables wouldn't allow one to change these properties.

Hope it helps. :)

PS: why would you pass your Globals class down to children? As all the members are static, they can be accessed without passing the class Globals (eg: through Globals.WINDOW_TITLE).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 3:49 am 
Offline

Joined: Mon Mar 19, 2007 9:29 pm
Posts: 74
Applet Example:
It appear to me as white space... there are nothing except white color.
Also I wan't some source to understand how it works.

Input:
thx, that's clear

Static Collection:
>PS:
I exactly use in a way that you describe: Globals.game when I need reference to my game calss.

It was just example what to put there :)
I think base class can store just reference to Game object and maybe Graphics. And who want more, thouse can extend it, and add more references.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 8:15 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Pretty much ditto DaveDes,

The applet explanation is here:

http://slick.cokeandcode.com/wiki/doku.php?id=applets

Essentially you write a game implementation like any other and then stick the html up with a parameter that points to the game. All the things you need are included in the applet directory of the distribution. You do need to sign anything you distribute.

You don't implement an applet anywhere, slick has that done.

Event based input is already supported. Override keyPressed in the Game object. It's not AWT based because games can exist in and outside of the AWT context.

Static holders for things like the container, context and graphics prevent the library doing anything useful in the background. The reason it's passed in every time is because the library might change it later - for instance if there are effects being generated.

You can take a static copy if it works for your game, but thats really the intention of the container framework.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 12:05 pm 
Offline

Joined: Mon Mar 19, 2007 9:29 pm
Posts: 74
I tried it...
I create html file, add all packages to same dir(), in htm file I change "value" to calss name of my main applet, and when I try to start it - it says in status bar: "Applet com....AppletGameContainer notinitied" and then "Loading applet failed".

But if I launch appletviewer from ide it works well...

Can you give any working example of applet with source?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 12:53 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
As I said above, the source for the Applet is the distribution, any game can be shown as an Applet. If you're getting errors at the browser then you need to check the Java console log which can be enabled from your browser.

However, LWJGL applets (what slick uses) are known not to work consistently on Opera.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 2:02 pm 
Offline

Joined: Mon Mar 19, 2007 9:29 pm
Posts: 74
here what I get in console (I use IE):

Quote:
Wed Mar 21 15:49:18 EET 2007 ERROR:access denied (java.util.PropertyPermission java.home read)
java.security.AccessControlException: access denied (java.util.PropertyPermission java.home read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at sun.plugin.security.PluginClassLoader.getPermissions(Unknown Source)
at java.security.SecureClassLoader.getProtectionDomain(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.newdawn.slick.AppletGameContainer.init(AppletGameContainer.java:74)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.RuntimeException: Unable to create game container
at org.newdawn.slick.AppletGameContainer.init(AppletGameContainer.java:85)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


and html file:
Code:
<html>
<body>
   <applet code="org.newdawn.slick.AppletGameContainer"
archive="slick.jar,lwjgl_applet.jar,lwjgl.jar,lwjgl_util_applet.jar,natives.jar,jinput.jar"
width="800" height="600">
      <param name="game" value="BountyHunter">
   </applet>
</body>
</html>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 3:27 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Means you don't have everything signed I believe.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 12:41 pm 
Offline

Joined: Fri Nov 24, 2006 7:56 pm
Posts: 10
maybe I`m being dumb, but I don't see where your HTML describes your game jar file.


you have:
Code:
archive="slick.jar,lwjgl_applet.jar,lwjgl.jar,lwjgl_util_applet.jar,natives.jar,jinput.jar"


where I have:
Code:
archive="SmitsGame.jar,slick.jar,lwjgl_applet.jar,lwjgl.jar,lwjgl_util_applet.jar,natives.jar,jinput.jar"


just my 2 pence.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 4:52 pm 
Offline
Site Admin

Joined: Mon Nov 13, 2006 3:26 am
Posts: 121
look at the <param> tag that comes after <applet> and before </applet>

it will say something like:

Code:
<param name="game" value="puzzle.Puzzle">


(at least, that is the case for KitiPong)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 8:43 am 
Offline

Joined: Mon Mar 19, 2007 9:29 pm
Posts: 74
thx, kevglass, I get a point :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group