My first applet

http://magnus.freewebpages.org/

cursor keys and drag screen to move around.

This is just my first ever applet was pretty cool to see it pop up in the browser, which is what got
everyone so excited bout java I guess, I felt it too my master.

Just need to get Jinput working, and this will be the engine for my little game, which hopefully in the end
will be a full networked MMO with a server and everything.
I think ill get single player working fully first tho before I even think about adding the dedicated server.

THANKS! JAVA RULES!

Looks good for the short amount of time you have been working on it. You might want to take a look at jPCT. It is a 3D engine that includes a fast software renderer. It could make things go quicker for you. Since you want to run in an Applet jPCT is a good fit. If you want to make a full application then you could look at LWJGL or JOGL.

Thanks! :smiley: Maybe I could use a 3rd party 3d engine, your right, but if I can code it from scratch maybe itll be good practice for me.

yup looks nice, but do agree if you’d like more powerful 3d go for LWJGL or JOGL. See this game its a much more advanced version of your applet :slight_smile: http://www.minecraft.net/

ha! I liked it, cube evironment, and textured too. runs nice and swish quick!

heres a shot of my “stone placer” imagine being in possibly a landscape and you can place these stones wherever you want, but what im planning on doing is possibly making a whole doungeon steps archways and all with them and see how it turns out.

Id have the applet uploaded but I havent worked out how to save the stones yet to disk so all I have is this picture of a wall and a floor I pulled up in about a minute.

Just flat shaded, havent even included point lights and shadows yet which will probably make it look pretty nice for flat coloured triangles.

dont understand why you would use jinput it will force to sign your applet

in your applet I can guess that you are updating position in the keyPressed event this is not a really smooth way, you should better try the following code to get smooth player displacment:


//Create a key array
private boolean keyPressed[]=new boolean[256];	//flags indiquant les touches appuyees

//a method that will return the state of a key
private boolean isKey(int n)
{
	return this.keyPressed[n];
}

//update the key array with the two event keypressed and key released
public void keyPressed(KeyEvent e)
{
	if(e.getKeyCode()<256)
		this.keyPressed[e.getKeyCode()]=true;
}
public void keyReleased(KeyEvent e)
{
	if(e.getKeyCode()<256)
		this.keyPressed[e.getKeyCode()]=false;
}

//then later in your animation loop the same that is performing cube rotation you can update player pos based on keyboard keys states
private void gameLoopAnimation()
{
	if(this.isKey(KeyEvent.VK_UP))
		playerPos++ ;
}

this method have a cupple of advantage :

  • it can deal with multiple key pressed at the same time
  • if your animation is FPS controled, the movment will be the same speed on all computer (and not dependend on key pressed repetition speed wich can differ betwen different computer)

hey thanks Dzzd thats wicked! ill implement it for sure.

That looks like a viable alternative, its just the site that taught me the basics only really said
the most cruddest primitive way to do things, I wasnt aware of this. thankyou.

Only prob is Dzzd, is KeyEvent isnt being identified by the compiler, so its not working… do I have to import a class?

yes,

import java.awt.event.*;

EDIT : what editor are you using to code ?

Eclipse… I imported and now its compiling but its not getting a single keypress, I looked around the net for a bit and I read something about invoking a “keylistener” but im not sure how to go about adding it.

Or should it just work and somethings gone wrong?

eclipse can auto add import (but I am not an expert in it… I really think it sucks aswell as netbean in comparaison of Jcreator :p, they both are damn toooo sloow & buggy)

to make it work now :

if you are in you applet

this.addKeyEventListener(this)

and your applet must be like :

MyApplet extends Applet implements KeyEventListener

I know this is just a typo, but to prevent the poster from wasting a few minutes:

this.addKeyListener implements KeyListener

oups… oups… :-X

bang it worked, thanks both.
I now have decent input! Congratulations me.

But you wouldnt believe it, now its disabled my mouse, dont worry ill figure it out. :slight_smile:

heres another shot of some placed stones, but now I need map saving before I can make anything
substantial, so ive got more to learn.

http://c1.ac-images.myspacecdn.com/images02/122/l_de6f3a8df6124a27be23c5b9484ff33c.png

Map-saving in an applet is not that easy. You don’t have access to basically any storage, so you’ll need to connect to your server (probably using HTTP) and write some PHP script there (as you probably cannot run any Java application serverside on freewebpages.org)

Instead of implementing the HTTP protocol yourself, you can have a look at java.net.URLConnection. It’s rather highlevel, and it mostly works. For a POST you’ll have to call setDoOutput(true) before opening the OutputStream.

Starting from scratch has a pedagogical interest in my humble opinion, it is an excellent first step. However, the second step should consist in stopping reinventing the wheel when you understand how it works, that is why I agree with CaptainJester, use at least an OpenGL binding and/or an existing engine (Ardor3D, JMonkeyEngine, 3DzzD, JPCT, Xith3D, Aviatrix3D, …).

Got an error

Java Plug-in 1.6.0_20
Using JRE version 1.6.0_20-b02 Java HotSpot(TM) Client VM
User home directory = C:\Users\Admin
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


java.security.AccessControlException: access denied (java.io.FilePermission c:\tod\neat.raw 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.checkRead(Unknown Source)
	at java.io.FileInputStream.<init>(Unknown Source)
	at java.io.FileInputStream.<init>(Unknown Source)
	at ball.load_raw(ball.java:834)
	at ball.init(ball.java:295)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception: java.security.AccessControlException: access denied (java.io.FilePermission c:\tod\neat.raw read)
Exception in thread "Thread-12" java.security.AccessControlException: access denied (java.awt.AWTPermission watchMousePointer)
	at java.security.AccessControlContext.checkPermission(Unknown Source)
	at java.security.AccessController.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPermission(Unknown Source)
	at java.awt.MouseInfo.getPointerInfo(Unknown Source)
	at ball.run(ball.java:881)
	at java.lang.Thread.run(Unknown Source)

OS is windows Vista 64bit using Google Chrome, IE and firefox web browsers (none work)

put the
c:\tod\neat.raw
file into your jar, I really want to see the dungeon live!