1 - Java 2D Game Tutorial/Help (part 2) - Side-scrolling game

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
32,792
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jan 1, 2010

(This is part 2 of 2) This tutorial will teach you how to make a Java side scroller 2D game such as Super Mario.

Code from this video:

Frame class:
http://pastebin.com/f222e082e

Board class:
http://pastebin.com/f2f8e693c

Dude class:
http://pastebin.com/f12be30da

Images I used:

Background:
http://img718.imageshack.us/img718/7369/testp.jpg

Character:
http://img718.imageshack.us/img718/7026/still.png
Enjoy!

Points to note:

A) You can loop the background so that your character stays in one spot and the background moves (like how it is in old Mario games)

B) You can use different images for your "main character" such as one of him walking left, crouching, etc. so that when you press left it seems as if the character actually turns left

C) You can add jumping capabilities by using a thread and a run method to make it look like the jump is animated (I've talked about this in previous videos)

D) For every other object you add (such as an "enemy" that must be killed or a missile that is shot) you must create another class to hold that item's x coordinates, y coordinates, etc.

If you need help implementing any of the above items send me a message and I will send you code to do so since I'm working on a full side scroller (2D and 3D) with enemies, missiles, save points, etc. Also, I will make videos in the future talking about some basics of these items.

Thank you

Category:

Education

Tags:

License:

Standard YouTube License

  • likes, 3 dislikes

Link to this comment:

Share to:

Top Comments

  • Guys there is a slight error in the program...

    In the Dude class, the if statements inside the keyPressed and keyReleased must look like this:

    if(key == KeyEvent.VK_LEFT){ dx = -1; } if(key == KeyEvent.VK_RIGHT){ dx = +1; }

  • Thanks for the tutorial, I'm learning how to organize with this tutorial.

    For the guys asking about Referring images....

    The easiest way is to:

    Go to the SRC Folder and create a new folder where your classes are. Call it images.

    Place all your images there. Now everytime you initialize an ImageIcon, instead of passing a String, type in getClass().getResource("images­/img.png")));

    Easier and cleaner like this.

see all

All Comments (153)

Sign In or Sign Up now to post a comment!
  • get better audio plz

  • in order to place an image in any java code you can code it like this instead

    ImageIcon i = new ImageIcon("C:\\Users\\Brad\\De­sktop\\TEMP FOR 1 DAY\\still.png");

    add the double slashes because one slash means something else.

    i figured this out :)

  • hmmm now how to turn it into a jar :P

  • @Robot9595 Thanks, I already solved it a while ago xD

  • @SuperBoombyebye Even though it's been about a month since this comment... Delete the semicolon after "if (key == KeyEvent.VK_LEFT / RIGHT)", that fixed the problem for me.

  • im having trouble changing the speed of the character. When i change dx = 1 to dx = 2 the guy moves faster but the background only loops twice and then stops at after the second and doesnt draw anymore. if anyone has tips on how to fix this left me know.

  • in Board.java when i type the keyrealeased and keypressed, i receive an error under p even though at the top, Dude p; and p = new Dude();

  • @SCARHExtendedMags - One lined if statements don't require the curly brackets to be used... But it won't cause any issues if you do use them.

  • @SCARHExtendedMags no cuz in the Dude.move() method, there is already a plus. no ur kidding right? u knew it

  • @PXP217 are you sure they are in the C:// drive?

    That can be the only problem because, although horribly spaghetti, the code does work.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more