PDA

Click to See Complete Forum and Search --> : Super Mario Clone ... Getting Started


BramVandenbon
Oct 3rd, 2004, 06:00 AM
Hi

I am new to java.
That is I had 3 lessons so far.
- I know what Swing is and can make swing windows, ...
- I have a big C# background

For a schoolproject I will make a Super Mario game clone.
I do not have the time to use special classes like Direct Draw, OpenGL, ... The project needs to be finished within about 2-3 weeks
I have not started yet and I am allready stuck with 4 questions.

My vision:
I need a level: small images in a kind of table.?!

and

I need a player class:

public class Player extends ?...? {
public Player(){
...loadimages in array;
}
left {
...change the position in the frame that contains this object;
... change image;
... change it back;
}
right{
}
jump{
}
crough{
}
}


Note that the Player visual object needs to move on top of the level ...

So here are my 4 questions:
(1) What class should I extend with my Player class. Should I extend the JPanel class?

(2) What is the best way to load my images. (depends on the answer of question 1 I guess)

(3) How do I change the position of a class in the containing class.

(4) What about my level images ... is there a kind of table class in Swing ?


Can anybody give me a clear answer on my questions ?
(please do not post codelistings of more than 50 lines ^^.)

Thank you in advance

CornedBee
Oct 3rd, 2004, 12:35 PM
You confuse a few things there.

The Player should inherit GameObject at most. Perhaps nothing. It should contain(!) a PlayerImage object that handles animation and that stuff. Player has a draw function that gets passed a Graphics object. In there, it obtains the correct image to draw from the PlayerImage object based on its current state. It then paints this image in the correct location to the Graphics.

The level data file would be a descriptor: it would look something like this, XML used intentionally.
<level name="Hell's Door" backgroundSet="hell" music="hell" next="level8.xml" length="500" time="360">
<landscape baseMap="level7.png" pattern="grass.png">
<jumpThrough x="180" y="50" width="15" height="8" edgeL="cloudL.png" edgeT="cloudT.png" edgeR="cloudR.png" edgeB="cloudB.png" pattern="cloud.png" />
<decoration x="160" y="0" width="3" height="12" image="tree.png" />
</landscape>
<creatures>
<monster type="bear.mst" x="100" y="3" />
</creatures>
<objects>
<coin x="99" y="8" />
</objects>
</level>
This would define a level with the name "Hell's Door". The background graphics would be taken from the set "hell", the music from the theme "hell". The next level is descriped in "level8.xml" (the current file is "level7.xml"). The level has a horizontal length of 500 and you have 360 seconds for completion.
The basic landscape is described in the 1-bit PNG file "level7.png". Black is solid, white is air. The pattern for solid stuff is in "grass.png".
There's an additional landscape object at 180/50 with a size of 15/8, particularly a jumpThrough, which is something you can jump through from beyond, but you don't fall through. The four edge patterns are in four png files, a fifth contains the background pattern.
A decoration object (something with absolutely no influence on gameplay) is located at 160/0 with a size of 3/12 and using the image "tree.png".
A monster with the look and characteristics described in the "bear.mst" file is located at 100/3.
There's a coin at 99/8.

A proper game uses a constantly running loop and redraws the screen every iteration. Then all you have to do is to catch key events that control the player and make adjustments in Player's internal state, let the AI do its job to update the monsters, process other stuff (such as moving bars), and then redraw the updated screen.

BramVandenbon
Oct 9th, 2004, 10:18 AM
First off all, a big thank you for your help !

Allthough you didnt answer my question really you did give me some ideas.

I made a clearer line between my GUI and my Functionality. And now my work is progressing. So this thread is solved.

For people looking for making something simular I would like to leave some links to some small pieces of basic code that are useful for most projects.

You will need this to repaint your images all the time:
How to make threads (http://www.vbforums.com/showthread.php?s=&threadid=308151)

You will need images :rolleyes:. Easy but important.
http://www.vbforums.com/showthread.php?s=&threadid=308147 (Loading images of your local directory)

And instead of using the complicated XML I recommend to save it binary. This code saves an instance of whatever kind of class. Even an instance of a class you wrote yourself.
saving/loading an array to/from a file (http://www.vbforums.com/showthread.php?s=&threadid=308145)

I hope this is useful to others.