Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How would I go about making a 2D applet-based game with a database?  (Read 1247 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Posted 2012-05-07 17:33:21 »

Hello everybody.

We're doing a lot of simple web applications at my school, getting data from a Glassfish database, using jsp and EJB.
I've been doing game-programming in Java during my spare-time for about a year now, and I'm progressing really well,
thanks to this amazing forum.

Now I'd like to combine the two things, to make something like this (with much worse graphics ofcourse ^^):
http://www.youtube.com/watch?v=gwq1HcUzhCM

Game layout:
I would like to start developing a 2D side-scroller, much like Metal Slug.
I'd like for people to be able to log in, get their character info (inventory, weapon-layout and such)
from the database, using simple ids. These ids would then be converted into game-objects through
an initPlayer method. Then the user gets to the menu, choses his layout, chooses the level he wants
to play, and enters. He plays the level, gets a score, which is saved in the database for that particular
player. He can then compare his score to the scores other players have recieved.
Then he can buy new stuff using the money he earned playing the level, and try to get a better score.
When done, he can hit "Save & Quit", and the database is updated with his new content.

I've written up a relational model for my database, so I know which entities I have to work with.
What I really want to know is: What do I need to make this kind of project come true? I'm not afraid to
start learning new processes. In fact, I'm hoping to. I'd just like to keep it in a Java-context.

I was recommended to do it in a J2EE environment, but since I've only been using it to make simple
JQuery-based database listings (like listing fictional orders and users, and right now we're doing a dating-
site project) in school, I'm anxious to know how I'd be able to implement a graphics-canvas.

I'm guessing it's a good idea to have a thread handling all requests to the database, and that my
game-frame could call methods in that thread to get the information it needs to show scores and such.
But since I have no idea how to combine these elements, web-applets with a game-frame and a database,
I'm unsure of what can be achieved. I know "Gun Bros" (the game in the video I linked) have all these features
to some extent, but then I don't know which languages they did it in.

I'd very much like to be able to post it as an app on Facebook too, using an IFrame.
Not interact with Facebook as such, cuz it's a pain in the bum as far as I can see. Just to have an easy link-up
to a large user-base, you know? It'd all still be running on my own server anyway.

Cheers!

- Jonas
Offline jonjava
« Reply #1 - Posted 2012-05-07 17:45:14 »

Well the way I do it is I host the server and the applet on the same host, this way I can freely talk to my server from the applet.

The way I handle my data is simple java object serialization that I save into a folder on the server.

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #2 - Posted 2012-05-07 18:20:14 »

Well, that seems almost too easy to be true ^^ But then I can completely throw out the database. I guess that's not a bad idea.
I do plan on hosting the applet and the server on the same host anyway.

What I wanted to know, being a newbie, is what do I use to show the graphics? How do I throw a canvas on a homepage?
What do I need to learn? Is it as easy as making a game-frame that extends Applet, and then throw a link on a HTML-page, or what?

- Jonas
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-05-07 18:29:28 »

Yup it is as easy as extend Applet. Have a look at this post to start using Java2D.

Offline jonjava
« Reply #4 - Posted 2012-05-07 18:30:29 »

Yeah, wrap the the applet inside a html page.

1  
2  
3  
4  
5  
6  
<html>
<body>
<applet code="com.main.AppletStarter.class" archive="/games/mygame/Game.jar">
</applet>
</body>
</html>


If you're using good ol' standard java, just draw everything on a Canvas and then when you make the Applet, just add it to the applets contentpane.

Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-05-07 22:01:06 »

Yeah, wrap the the applet inside a html page.

1  
2  
3  
4  
5  
6  
<html>
<body>
<applet code="com.main.AppletStarter.class" archive="/games/mygame/Game.jar">
</applet>
</body>
</html>


If you're using good ol' standard java, just draw everything on a Canvas and then when you make the Applet, just add it to the applets contentpane.
Remove the .class from the end. All you need is the class's full name (package + name).

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #6 - Posted 2012-05-07 22:21:18 »

Thanks a lot, guys! This has been a real eyeopener for me. I think I'll start by serializing things to files using an assembler-class, and practice using MD5 to cover up passwords and such.

But what if I wanted to extend the project later, and have a database underneath it, as described in the first post? Would it be a real hazzle, or is it as simple as writing a new assembler-class, which handles things by querying the database, and relaying the information to the applet? Or would I need to make an entirely different setup than just "extend Applet"?

- Jonas
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-05-07 22:22:56 »

I say you skip the serialization and use the database. Since you have lots of experience with databases, that would be the easiest and fastest (both programming-wise and performance-wise) way for you to make this game.

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #8 - Posted 2012-05-07 22:57:53 »

I say you skip the serialization and use the database. Since you have lots of experience with databases, that would be the easiest and fastest (both programming-wise and performance-wise) way for you to make this game.

Really? Awesome! So there's no problem using the assembler-approach I've been using for jsp-purposes, and applying that to an applet? Wow, that's so simple. Thanks ra4king. Your advice has been SO helpful to me in many cases (posts). Thank the world for you (and all the other helpful people on this forum) Smiley

- Jonas
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-05-07 23:22:27 »

Just make sure not to make your database public towards the internet. Have a java server listening at a certain port on your server, which does all the database handling. Your client (game) would then connect to your custom java server, request/send data, and the server will query the database appropriately. This way, things stay secure.

Pages: [1]
  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.

BurntPizza (25 views)
2014-09-19 03:14:18

Dwinin (39 views)
2014-09-12 09:08:26

Norakomi (68 views)
2014-09-10 13:57:51

TehJavaDev (93 views)
2014-09-10 06:39:09

Tekkerue (47 views)
2014-09-09 02:24:56

mitcheeb (68 views)
2014-09-08 06:06:29

BurntPizza (51 views)
2014-09-07 01:13:42

Longarmx (38 views)
2014-09-07 01:12:14

Longarmx (44 views)
2014-09-07 01:11:22

Longarmx (40 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!