Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Isometric Engine (RCT style) - Major update 14.Sep  (Read 11889 times)
0 Members and 1 Guest are viewing this topic.
Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Posted 2005-07-23 13:59:02 »

This a small sample of an isometric game engine.

Download: www.jonask.com/pro/iso.zip
I've been working and improving on different iso-engines over the last year, and this is small but a very apt
sample of the isometric effect.

It is a work in progress, and in this sample i have disabled all other tiles than the flat.
I havn't written in any UI to change the tilt of the tiles (like you can in rollercoaster tycoon),
but the engine supports it. If you want any other tiles you have to hardcode them in. for now.
Im working on it.


Anyhow, this is basiclly just to show off what i've done, and to see if anyone is interested in the code for their own projects.
Any kind of criticism or suggestions are allways welcome too =)

Download: www.jonask.com/pro/iso.zip
Offline monkeyget

Senior Newbie





« Reply #1 - Posted 2005-07-24 18:38:54 »

It works nicely, good job  Smiley
Offline anarchotron

Junior Member




...precious bodily fluids.


« Reply #2 - Posted 2005-07-25 17:13:11 »

I get the following error when attempting to run it.  I'll try recompiling the classes, just thought you'd be interested. 

This is with java -version:

java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

Exception in thread "main" java.lang.UnsupportedClassVersionError: misc/MainClass (Unsupported major.minor version 49.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Matlu

Junior Member




Hasta La Victoria Siempre!


« Reply #3 - Posted 2005-07-26 11:20:23 »

same exception here, I hope it's not 1.5 only

Multiplayer Online Games
http://www.duelboard.com
Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #4 - Posted 2005-07-26 12:15:03 »

I'm sorry guys, it IS 1.5. But why not upgrade?
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2005-07-26 13:04:12 »

Because then I'd have to expect any players of a game that I wrote with your engine to upgrade.

(Incidently, I have both installed and its your isometric engine is very nice Smiley)

Kev

Offline JasonB

Junior Member





« Reply #6 - Posted 2005-07-26 13:14:19 »

Doesn't find the tiles.gif file on Linux for some strange reason...
Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #7 - Posted 2005-07-28 09:28:21 »

Thanks for the kind words guys, I'd glady send the code if anyone is interested.
Regarding the linux issue it is probably related to my image loading algorythm.
It's not well written. doesn't work in jar files, and i suspect that is why it's not working
on your platform as well
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2005-08-05 02:05:25 »

... and the easy way would be fiddling with the OpenGL Projection Matrix! Wink [size=1](me == lazy)[/size]

The projection matrix would be like:
[size=1](this one zapped a few of my brainscells while creating)[/size]

1  
2  
3  
4  
1.0,   0.0,  -1.0,   0.0   // x
0.5,   1.0,   0.5,   0.0   // y
0.0,  -0.050.0,   0.0   // depth
0.0,   0.0,   0.0,   1.0   // [nothing]


Scale a bit (in model-space), transpose and upload to gfx-card!

~~

Pros:
 - any shape of any object is supported
 - hardware accelerated gfx
 - depth-buffer to reduce fills

Cons:
 - less 1337!

~~



~~

... Grin

I really like your engine better. Rendering that in software is much harder than my 'quick' hack. Well done!

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #9 - Posted 2005-08-05 19:08:09 »

That is really interesting. I never got around to toying with hardware accelerators.
Would you mind sharing your code?

but i gotta add, the pixel method I use _can_ handle any shape too Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2005-08-05 19:45:11 »

This is the Projection Matrix:

1  
2  
3  
4  
1.0,   0.0,  -1.0,   0.0   // x
0.5,   1.0,   0.5,   0.0   // y
0.0,  -0.050.0,   0.0   // depth
0.0,   0.0,   0.0,   1.0   // [nothing]




This is the transposed Matrix:
[size=1](OpenGL works with transposed matrices)[/size]

1  
2  
3  
4  
5  
// x    y   depth  [nothing]
1.0,   0.50.0,   0.0
 0.0,   1.0, -0.050.0
-1.00.50.0,   0.0
 0.0,   0.00.0,   1.0




Store that in a FloatBuffer:

1  
2  
3  
4  
5  
6  
FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(4*4); // LWJGLs way
<or do>
FloatBuffer matrixBuffer = ByteBuffer.allocateDirect(4*4 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer().; // own way

matrixBuffer.put(new float[]{1.0F, 0.5F, 0.0F, 0.0F, 0.0F, 1.0F, -0.05F, 0.0F, -1.0F, 0.5F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F});
matrixBuffer.flip();




Send to gfx-card:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
glMatrixMode(GL_PROJECTION);
glLoadMatrix(matrixBuffer);


// scale down projection a bit, like factor 10
// otherwise a flat 1x1 quad kinda fills the screen
float s = 0.1F;
glScalef(s, s, s);


// switch to model-view matrix for further transformations
glMatrixMode(GL_MODELVIEW);




Well, for everything else you need to know your OpenGL Wink

To be honest I've never heard of Isometric stuff done in the Projection Matrix, but I thought it would be worth the adventure of figuring out how matrix-calculations are actually performed and trying to create my own matrix after I figured out the formulas of real->iso. It's always fun to share such stuff Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #11 - Posted 2005-08-08 12:06:23 »

Yeah, i havnt done any openGL in java yet. I  guess i've allways been charmed by software rendering Wink

I'll upload the formulas i use for transforming real to isometric coordinates and back..
I never thought of expressing them on matrix form, but that might be a good way to go.
Id imagine its more optimized.

Anyways, its on my laptop so i cant access it right now. stay tuned
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2005-08-08 12:43:27 »

Well, it's only more optimized when using hardware-acceleration.

As there are quite a few occurences of 0.0 in that matrix, you are constantly multiplying values by 0.0, which can be skipped if you use your own formulas. (Edit: same for 1.0 ofocurse)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #13 - Posted 2005-08-21 19:01:23 »

Thanks for the GL isometric mode stuff, seem very useful!

Kev

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #14 - Posted 2005-08-22 11:10:53 »

Correction:


This is the Projection Matrix:

1  
2  
3  
4  
1.0,   0.0,  -1.0,   0.0   // x
0.5,   2.0,   0.5,   0.0   // y
0.0,  -0.05,  0.0,   0.0   // depth
0.0,   0.0,   0.0,   1.0   // [nothing]




This is the transposed Matrix:
[size=1](OpenGL works with transposed matrices)[/size]

1  
2  
3  
4  
5  
// x    y   depth  [nothing]
1.0,   0.5,  0.0,   0.0
 0.0,   2.0, -0.05,  0.0
-1.0,   0.5,  0.0,   0.0
 0.0,   0.0,  0.0,   1.0




I changed the 1.0 @ [1][1] to 2.0. Otherwise everything is squeezed on the y-axis.

Note that that -0.05 (for depth) is pretty randomly chosen, it works for me, if it doesn't for you - when your near/far planes are off - adjust it a bit.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #15 - Posted 2005-08-22 13:07:16 »

Ah, that explain why my chaps look a little stocky Smiley

http://www.cokeandcode.com/asd/screenshots/isoasd.png

I'll adjust tonight, thanks for the update.

Only thing I had to change was to flip round the axis since I'm use Z as up/down not Y (just because I'm working in 2D really, honest).

Kev

Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #16 - Posted 2005-09-14 18:50:04 »

I've done some real improvment on the engine.
 alot of it is under the hood, like GUI-mouse handling, but one thing
i just know youre gonna like is the lanscapting tool.

This is really getting somewhere =)
Offline SluX

Junior Member





« Reply #17 - Posted 2005-09-27 12:59:48 »

Err...could u explain how it works?Maybe send some code.
I want to start coding something like this myself, but i dont know how to detect mouse entering over a tile...Plz help dude

"Intelligence is the most beautiful gift and the greatest temptation which one life can receive from the gods."Me Cheesy
Play strategic football
Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #18 - Posted 2005-09-29 19:24:34 »

Sure i'll help.

But my current GUI system i rather complex. I'll try to explain the flow...

The game runs in a seperate thread from the frame window.

Whenever a key is pressed or released or mouse moved or clikced functions are called in the frame class.
These functions store mouse and keyboard info in local variables.

Then when ever its time to update the GUI the mainloop sends these mouse states into a GUI class.
the GUI class now determins what so called GUIElement the mouse is over.

All objects you see drawn inherit from this GUIelement class, so that every object  can get mouse focus and stuff.
All the elements are stored in an ArrayList and drawn in order.
When determining what object the mouse is over you go backwards (so that the upper object is checked first) through this list,
and if the mouse IS over the element you're at now, stop reversing.
All GUIElements are square, so determining if the mouse is over it is easy. check if the mousex and mousey are within its (x,y) and (x+w,y+h)

Checking the objects in the world(buildings, tiles, people, whatever) is slightly more complicated since they are not rectangular.
But if that is what you wanna do i can show you how.

Need any code too?
Offline Mirakle

Junior Newbie





« Reply #19 - Posted 2005-09-30 13:34:33 »

Yeah, it would be great !  Roll Eyes
Offline SluX

Junior Member





« Reply #20 - Posted 2005-10-01 10:59:59 »

Yeah, rectangular checking is easy, but that iso tile stuff is a bit trickier. I could really use some code and guidance.

Btw, i m also developing an engine of my own, so i ll add your iso implementation to it. Wink

Thanx in advance.

"Intelligence is the most beautiful gift and the greatest temptation which one life can receive from the gods."Me Cheesy
Play strategic football
Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #21 - Posted 2005-10-01 22:50:55 »

The basic idea is very simple:

Every object on the map inherites a basic sprite class, in my engine called a MapObject.

Every mapobject har a function Draw(Graphics g) that draws it onto the graphics surface g.

Whenever an object is drawn, it's x and y coodinates are stored localy in variables called drawnToxX and drawnToY. (that is the screen coordinates, not the isometric/map coordinates)

Then, when you want to check if the mouse is over this object, simply check if it is between drawnToX and drawnToX+spriteWidth. same for Y coordinates.

Further, grab the color of the pixel at (mouseX-drawnToX, mouseY-drawnToY) from the MapObjects sprite.
If this pixel is opaque it means we found our object =)

If it is transparant it would mean this object (even though the mouse is within its boundingbox) is not the one we want, and we should proceed our search..

Code:


    //returns the object under the cursor
    public MapObject getClickedObject(int sx, int sy){
        for(int i=partnerWorld.getMapObjectList().size()-1; i>=0; i--){//move backwards through the list
            MapObject o = partnerWorld.getMapObjectList().get(i);
            int x = o.drewToX, y = o.drewToY;
            int w = o.spriteW, h = o.spriteH;
            //check if the mouse is within the object sprite
            if(sx>x && sx<x+w)//are we within this objects bounding box x-wise?
                if(sy>y && sy<y+h){//are we within this objects bounding box y-wise?
                    //get color at coord. and correct for frame and rotation sprite offset and stuff. idunno, tired now               
                    if(o.getImage().getRGB(sx-x+o.getFrameOffset()   ,sy-y+o.getRotationOffset()) >>> 24 == 255){//is this pixel opaque
                        return o;//if so, return this object
                    }
                }
        }
       
        return null;
    }



But as I said, you're gonna need alot more to get a fully functional GUI. You guys want the whole engine perhaps? its open source anyways Wink
Offline SluX

Junior Member





« Reply #22 - Posted 2005-10-04 13:45:21 »

Whoa neat stuff to check for transparency. I thought that i had to make up with some maths to find rombs Wink

Idea is great, thx a lot!

"Intelligence is the most beautiful gift and the greatest temptation which one life can receive from the gods."Me Cheesy
Play strategic football
Offline Aramaz

Junior Member




Java Games Rock!


« Reply #23 - Posted 2005-10-04 14:14:46 »

But you might have tiles with transparent areas in the romb... then that method doesn't work...

but that's stating the obvious of course...

Play XSW: www.xsw.se
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #24 - Posted 2005-10-04 18:31:19 »

:~/Desktop/iso$ java -classpath . misc.MainClass
ERROR LOADING IMAGE FILE: tiles.gif
----Terminating----

Could you fix a linux version, please?
the problem might be the "\\" instead File.separatorChar on the file path.

thanks  Smiley

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline anarchotron

Junior Member




...precious bodily fluids.


« Reply #25 - Posted 2005-10-04 18:57:58 »

Very nice.

I would mention that start.bat didn't work until I added a "-cp ." option to java.

Note that when you raise your foreground tiles sufficiently, their edges become visually colinear with background tiles.  This causes a loss of depth perception.  You could overcome this by shading your tiles based on height.  Even a subtle gradient would convey the necessary information.

Below I have a shot of a little map I made to demonstrate the problem, and then a photoshopped example suggestion.  You could also shade the tiles based on vertex distance from 'camera', which would basically be a fogging effect, which would be more subtle but maybe neater.

Again, very cool.

Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #26 - Posted 2005-10-06 21:09:27 »

Thanks for the feedback guys.
Im working on a linux version, and it shouldn't be much work. the only problem as I see it is my picture loading algorythm.
If anyone knows how this is best done, so it works on all platforms, I'd REALLY appreciate it.

This is my code as it is now:

    //ripped from http://wiki.java.net/bin/view/Games/TextureLoadingExample, all hail them
    private static BufferedImage loadImage(String ref) throws IOException {
      File file = new File("images\\" + ref);
        if (!file.isFile()) {
            throw new IOException("Cannot find: images\\"+ref);
        }
        BufferedImage bufferedImage = ImageIO.read(new BufferedInputStream(
           new FileInputStream(file))
        );
        System.out.println("picture preloaded: " + ref);
        return bufferedImage;
    }

To adress the height problem, ive kinda got an idea.
If you look at other engines like this you'll see that tiles that are elevated and does not
have a tile behind it at the same level have an extra line drawn on them.

This picture from RCT illustrates the solution.
I was thinking maybe i could do something like that later on, but right now im focused on other elements of the game =)
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #27 - Posted 2005-10-06 22:01:34 »

It's really no work at all to make file loading plataform independent just replace every "//" by the File.separatorChar field.

Quote
File file = new File("images\\" + ref);
by
1  
File file = new File("images"+ File.separatorChar + ref);


and

Quote
throw new IOException("Cannot find: images\\"+ref);
by
1  
throw new IOException("Cannot find: images" + File.separatorChar + ref);


separatorChar is a plataform dependant constant: "\\" on win and "/" on every other system afaik. see javadoc for sure.

[edit]quotes misplaced[/edit]

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Offline jonask84

Senior Newbie




Can't make it? Simulate it!


« Reply #28 - Posted 2005-10-07 00:54:41 »

Smart!
I did the change, it still works under windows. Im out traveling so i cant test on linux right now, but

try replacing the imagecontroller:

http://www.jonask.com/ImageController.class

that should be an updated version =)
Hope it'll work
Offline f.l.x

Senior Member


Projects: 3


there is no place like 127.0.0.1


« Reply #29 - Posted 2005-10-07 12:10:29 »

it works  Smiley

great engine, i'm taking some ideas for a future project

attached an screenshot

Litterarum radices amaras, fructus dulces
http://flx.proyectoanonimo.com
figth spam!
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (63 views)
2014-04-15 18:08:23

BurntPizza (61 views)
2014-04-15 03:46:01

UprightPath (74 views)
2014-04-14 17:39:50

UprightPath (57 views)
2014-04-14 17:35:47

Porlus (75 views)
2014-04-14 15:48:38

tom_mai78101 (100 views)
2014-04-10 04:04:31

BurntPizza (160 views)
2014-04-08 23:06:04

tom_mai78101 (255 views)
2014-04-05 13:34:39

trollwarrior1 (208 views)
2014-04-04 12:06:45

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!