4 - Adding enemies: Java 2D Side Scrolling Game Tutorial

Loading...

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

Uploaded by on Dec 24, 2010

This video shows how to add enemy(ies) to the side scrolling game. It also shows how to make the enemies move with the character and move off the screen (collision detection in next video!). This adds yet another class to the program for the enemy which can be reused again and again for enemies

Think about other attributes the enemy class might have: Such as int hitPoints or int attackPower. This way, each object of the enemy class can actually make completely different enemies (different image, health, power) but use the same code!

Please let me know if you have any questions and I will be happy to answer them. The code for the video can be found below:

Frame class: http://pastebin.com/rnqMSELn
Board Class: http://pastebin.com/it5TqCF7
Dude Class: http://pastebin.com/tUY5uxXz
Bullet Class: http://pastebin.com/4R5S01Nm
Enemy Class: http://pastebin.com/GiHj9GbS

The images used can be found at http://img401.imageshack.us/g/bulletd.png/ or:

bullet.png: http://img401.imageshack.us/i/bulletd.png/
still.png: http://img829.imageshack.us/i/still.png/
test.jpg: http://img40.imageshack.us/i/testcjc.jpg/
enemy.png: http://img811.imageshack.us/i/enemyt.png/
left.png: http://img641.imageshack.us/i/leftvn.png/
jump.png: http://img560.imageshack.us/i/jumpv.png/

Thanks and good luck!

-MrJavaHelp

  • likes, 1 dislikes

Link to this comment:

Share to:

Top Comments

  • 11:40 for demonic voice.

  • public Enemy LOL

see all

All Comments (34)

Sign In or Sign Up now to post a comment!
  • Nice thx

  • Don't get me wrong, these guides helps a lot to get into game programming, but you repeat the same figures over and over and misplace a lot of code.

    Instead of calling for the image path twice in Board for the enemies, why not call for it once in the enemy class?

    Instead of writing the numbers over and over for the image positions (this goes for all images), why not create a variable for each?

    Also, if you're using shortcode in if's, why not do the same for bools? if(x) instead of if(x==true)

  • MY ENEMY WONT MOVE LEFT, im not doing a scrolling background

  • Around 3:53, learn to scroll down!

  • Hey, when you press and hold VK_SPACEBAR, you can spam shoot it, can you do another video giving us the code for a JAVA SLEEP for it please? please, THUMBS UP TO LET THEM HEAR THIS!

  • where is the game?Why no postin a result?

  • Hi there Mr java . I just want to know how make image with transparent backgrounds in java. I am trying to make a game with my own images and am facing this problem. Any suggestion please email me to elpablon@yahoo.com

  • @Thelordberzerker97 collision detection

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