[Off-Topic] Need help coding my own Java game.

General discussion and socializing.

[Off-Topic] Need help coding my own Java game.

Postby Flascher » Wed May 26, 2010 1:29 am

I figured there'd be a wealth of knowledge about our beloved, yet simultaneously despised language of Java.

There are many things I would love to know about how to make my engine and the game I have in mind is very heavily inspired by this lovely hell we call H&H :)

I am a very basic coder, and have just begun to delve into the depths of object oriented programming and the language of Java. I can post what I currently have for the base of loading my maps, (I hope it to be a scrolling isometric game like this, no map edges where another map needs to be loaded.) but I have no idea whether this will work, and I have a few questions about how to weave the syntax to do exactly what I intend it to.

Code: Select all
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.net.*;

public class IsoEngine implements Runnable {
   double totalWidth = (tile[n]*64); //width of one single tile is 64 pixels.
   double totalHeight = (tile[n]*32); //height of one single tile is 32 piexels.
   int WIDTH = getSize().width;
   int HEIGHT = getSize().height;
   int incrX = 64;
   int incrY = 32;

public void DrawTile {
   private Image image;
   
   private URL getURL(String filename) {
      URL url = null;
      try {
         url = this.getClass().getResource(filename)
      }
      catch (Exception e) { }
      return url;
   }
   
   public void init() {
      image = getImage(getURL("isograss(small).png"));
   }
   
   
   public void paint (Graphics g) {
      Graphics2D g2d = (Graphics2D)g;
      int width = getSize().width;
      int height = getSize().height;
      g2d.setColor (Color.BLACK);
      g2d.fillRect(0, 0, getSize().width, getSize().height);
      int TILE;
      Tile[] tile = new Tile[TILE];
      int currentTiles = 0;
      tile.setX(WIDTH/2);
      tile.setY(HEIGHT/2);
      while (totalWidth < (getSize().width + 100) && totalheight < (getSize().height + 100) {
      // + 100 to each to make sure there are no blank spots on the screen.
         g2d.drawImage(image, (incrX*TILE), (incrY*TILE), this);
         n++;


Sorry for that wall of text, but I can tell I'm already doing something wrong. (It's also not finished, this is just what I have as of right now.)

I would like it to generate the tiles until they reach the edge of the game screen, and +100 pixels to that so that there are not any blank spots on the visible screen. I don't quite understand the array system to count the amount of an object/image for Tile[] tile = new Tile[TILE]; anyone who understands Java better than I is welcome to comment, correct, finish, optimize, etc.

In case any of you were wondering I am learning most of this from my book Beginning Java Game Programming: Second Edition http://www.amazon.com/exec/obidos/ASIN/1598634763/bookpriceline-20/ref/

ALSO: Loftar & Jorb, please do not feel offended that I am advertising that I am making (more like "attempting") to make a game. I do not intend to steal player base, nor was I intending to advertise my development in the first place. I was hoping to find some guidance from experienced coders on where to go from the coding aspect. If anything, maybe when/if my game gets up and running, we could have sister sites :) I would like nothing more to work with my intelligent Swedish friends.
User avatar
Flascher
 
Posts: 42
Joined: Mon Jun 08, 2009 11:30 pm

Re: [Off-Topic] Need help coding my own Java game.

Postby ViciousGamer04 » Wed May 26, 2010 1:54 am

Flascher wrote:I figured there'd be a wealth of knowledge about our beloved, yet simultaneously despised language of Java.

There are many things I would love to know about how to make my engine and the game I have in mind is very heavily inspired by this lovely hell we call H&H :)

I am a very basic coder, and have just begun to delve into the depths of object oriented programming and the language of Java. I can post what I currently have for the base of loading my maps, (I hope it to be a scrolling isometric game like this, no map edges where another map needs to be loaded.) but I have no idea whether this will work, and I have a few questions about how to weave the syntax to do exactly what I intend it to.

Code: Select all
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.net.*;

public class IsoEngine implements Runnable {
   double totalWidth = (tile[n]*64); //width of one single tile is 64 pixels.
   double totalHeight = (tile[n]*32); //height of one single tile is 32 piexels.
   int WIDTH = getSize().width;
   int HEIGHT = getSize().height;
   int incrX = 64;
   int incrY = 32;

public void DrawTile {
   private Image image;
   
   private URL getURL(String filename) {
      URL url = null;
      try {
         url = this.getClass().getResource(filename)
      }
      catch (Exception e) { }
      return url;
   }
   
   public void init() {
      image = getImage(getURL("isograss(small).png"));
   }
   
   
   public void paint (Graphics g) {
      Graphics2D g2d = (Graphics2D)g;
      int width = getSize().width;
      int height = getSize().height;
      g2d.setColor (Color.BLACK);
      g2d.fillRect(0, 0, getSize().width, getSize().height);
      int TILE;
      Tile[] tile = new Tile[TILE];
      int currentTiles = 0;
      tile.setX(WIDTH/2);
      tile.setY(HEIGHT/2);
      while (totalWidth < (getSize().width + 100) && totalheight < (getSize().height + 100) {
      // + 100 to each to make sure there are no blank spots on the screen.
         g2d.drawImage(image, (incrX*TILE), (incrY*TILE), this);
         n++;


Sorry for that wall of text, but I can tell I'm already doing something wrong. (It's also not finished, this is just what I have as of right now.)

I would like it to generate the tiles until they reach the edge of the game screen, and +100 pixels to that so that there are not any blank spots on the visible screen. I don't quite understand the array system to count the amount of an object/image for Tile[] tile = new Tile[TILE]; anyone who understands Java better than I is welcome to comment, correct, finish, optimize, etc.

In case any of you were wondering I am learning most of this from my book Beginning Java Game Programming: Second Edition http://www.amazon.com/exec/obidos/ASIN/1598634763/bookpriceline-20/ref/

ALSO: Loftar & Jorb, please do not feel offended that I am advertising that I am making (more like "attempting") to make a game. I do not intend to steal player base, nor was I intending to advertise my development in the first place. I was hoping to find some guidance from experienced coders on where to go from the coding aspect. If anything, maybe when/if my game gets up and running, we could have sister sites :) I would like nothing more to work with my intelligent Swedish friends.


Aha, g'luck.
Already Suggested H&H Ideas can be found, here!
Basic "How Do I" questions on H&H can be found, here!
User avatar
ViciousGamer04
 
Posts: 530
Joined: Sat Feb 20, 2010 8:47 am

Re: [Off-Topic] Need help coding my own Java game.

Postby Flascher » Wed May 26, 2010 2:04 am

well thank you. I do indeed have a feeling that I will be needing it.

But, I will be building my own computer soon, and I will keep the one I am running off of right now to reserve for running a dedicated server :) so thats set, now just the coding, and my local friend (JFloyd, yes he's disliked by some, but hes a good artist) will be drawing almost all, if not all the graphics. Wacom pads ftw.

Anyway, I would be willing to recruit other coders for this project, or, if you do not feel like you can be committed to a dev team, I would also welcome programming guidance :)
User avatar
Flascher
 
Posts: 42
Joined: Mon Jun 08, 2009 11:30 pm

Re: [Off-Topic] Need help coding my own Java game.

Postby sabinati » Wed May 26, 2010 3:26 am

why are you using doubles Image
User avatar
sabinati
 
Posts: 15513
Joined: Mon Jul 13, 2009 4:25 am
Location: View active topics

Re: [Off-Topic] Need help coding my own Java game.

Postby theTrav » Wed May 26, 2010 4:08 am

Flascher wrote:I don't quite understand the array system to count the amount of an object/image for Tile[] tile = new Tile[TILE];

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html will tell you a bit about what arrays are and how they work.

I highly recommend doing a lot of reading around the java site, it'll answer a lot of your questions.

Probably the most effective way of overcoming your obstacles in programming is to put a lot of thought, effort, and care into phrasing your questions. If people can see what you're trying to do, and see that you've really tried to understand things then they'll be a lot more keen on giving you help.


Also, if you're interested in programming (as opposed to just making a game or app that works, sometimes) then I've heard you would be best off reading something like the little schemerhttp://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=4825 which will teach you some good functional programming stuff and give you a good perspective on what programming actually is, which should make learning the other stuff a breeze.
User avatar
theTrav
 
Posts: 3464
Joined: Fri May 29, 2009 11:25 pm

Re: [Off-Topic] Need help coding my own Java game.

Postby Flascher » Wed May 26, 2010 4:39 am

@Sabinati: To answer your question, I have no idea at all. tbh, i haven't taken the time to find the difference between variable types. Lazy me :roll:
EDIT: indeed, now that I have actually taken the time to look at the difference, I should undoubtedly be using an int.... silly me...

@TheTrav: Thank you for the helpful links, and I will definitely be sure to do that when I get some more extra time on my hands :) sadly, I think I am headed to bed soon, so I may have to wait until tomorrow to check this out.
User avatar
Flascher
 
Posts: 42
Joined: Mon Jun 08, 2009 11:30 pm


Return to The Inn of Brodgar

Who is online

Users browsing this forum: Claude [Bot] and 3 guests