Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
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  
  Block Class  (Read 2385 times)
0 Members and 1 Guest are viewing this topic.
Offline deadteck

Senior Newbie





« Posted 2012-04-22 02:57:04 »

Anyone know how to make a basic block class and how to size it (blocks like in minecraft). Im also looking for a way to have the blocks selected in the "main" method or wherever it gets selected.

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline jonjava
« Reply #1 - Posted 2012-04-22 03:09:56 »

A Class is basically just a collection of data.

What kind of data do you think a "Block" class should have?

Offline deadteck

Senior Newbie





« Reply #2 - Posted 2012-04-22 03:16:50 »

A Class is basically just a collection of data.

What kind of data do you think a "Block" class should have?
I got that, but like I dont know how to set it up and I dont know how to "call" it from my main class

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #3 - Posted 2012-04-22 03:31:54 »

Your main class, or the "public static void main(String[] args)" method?

The "public static void main(...)" method doesn't have anything to do with the class that it's in, it's just the starting point of a java program.

I highly recommend you read the java beginner tutorials http://docs.oracle.com/javase/tutorial/java/index.html.

"Setting it up" or Creating a class is fairly simple - this is all explained in the tutorials.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
class Block {
 int width = 0;
 int height = 0;

 // Constructor
public Block(int width, int height) {
  this.width = width;
  this.height = height;
  System.out.println("My area is: " + getArea() );
 }

 // Method
private getArea() {
  return width * height;
 }


 // Testing the class
public static void main(String[] argv) {
  new Block();
 }

}

Offline deadteck

Senior Newbie





« Reply #4 - Posted 2012-04-22 03:34:24 »

Your main class, or the "public static void main(String[] args)" method?

The "public static void main(...)" method doesn't have anything to do with the class that it's in, it's just the starting point of a java program.
I know that, its just I want to know how to call the block in rendering or wherever you call it into.

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline jonjava
« Reply #5 - Posted 2012-04-22 03:37:29 »

http://docs.oracle.com/javase/tutorial/2d/images/index.html

Offline deadteck

Senior Newbie





« Reply #6 - Posted 2012-04-22 03:47:25 »

Thanks, ill look into that, any help was needed Smiley  and this will work in a 3d world right?

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline jonjava
« Reply #7 - Posted 2012-04-22 04:00:01 »

I recommend you read this useful post for beginners http://www.java-gaming.org/topics/hello/24411/msg/205121/view.html#msg205121

Offline deadteck

Senior Newbie





« Reply #8 - Posted 2012-04-22 04:18:02 »

Ive looked into that already, its just that I dont know what to do now and Im stuck on block creation.

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline jonjava
« Reply #9 - Posted 2012-04-22 04:29:52 »

If I may be blunt. The lack of substance in your questions suggest, to me, that you do not have a good hold on programming basics. Therefore I suggest you start there and in the mean time shelve your current idea.

You use the word "block" as if it should mean something. I presume it's a class. Instantiating a class is very easy. You just put the "new" keyword before the class name Ie.

1  
new Block();


Nobody can understand what you're trying to do or how you're attempting to do it and why it's not working considering your vague abstract questions.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #10 - Posted 2012-04-22 04:39:14 »

Don't jump to 3D world yet, it's serious bussiness. Make it 2D first.

Offline deadteck

Senior Newbie





« Reply #11 - Posted 2012-04-22 04:46:51 »

Don't jump to 3D world yet, it's serious bussiness. Make it 2D first.
Well if I were to make it 2d first, it would take a long time to transfer it over to 3d when thats done wouldnt it?

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline ReBirth
« Reply #12 - Posted 2012-04-22 04:49:09 »

That's the road. Of course it's good to have speed progress but if we're not really ready for this, you'll spend more looooong time to debug and make it work.

Offline deadteck

Senior Newbie





« Reply #13 - Posted 2012-04-22 04:53:56 »

I suppose that is true, but its going well except that I am only having problems on specifying a block type and all, and Im also having problems sending the different blocks to the rendering class that I have setup.

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline ReBirth
« Reply #14 - Posted 2012-04-22 04:58:43 »

The block class can be modiifed so they're rendering themselves. It'll encapsuled complex function to draw various kind of block. So you just need to pass what they need to draw.

Offline deadteck

Senior Newbie





« Reply #15 - Posted 2012-04-22 05:09:28 »

What do you mean by that?  Huh

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline StumpyStrust
« Reply #16 - Posted 2012-04-22 06:31:58 »

Example method that most "renderable" things should have in java 2d

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void render(Graphics g)   // The graphics object is passed to your block by the canvas/jpanel or whatever. 
{
     render stuff here  
     .
     .
     .
     g.fillrect(x1,y1,x2,y2); //simple drawing of a rectangle.
    .
     .
     .
}


You should look at the api for the graphics and Graphics2D objects and then look at how to setup your own custom canvas, Frame, or JPanel to do the rendering. If you know how to do that then rendering a simple square/block is trivial.  Grin

Going from 2D to 3D is rather difficult early on. Get good at 2D then go to 3D. Its not that hard to switch it just takes practice....lots of it....and an ungodly amount of tutorial reading....I still suck at 3D  Cranky But I will get better as long as I keep working at it.  Grin

So don't be discouraged by asking nooby questions but I would do a quick google search before posting because what you seem to be asking is done many times in tutorials that you can find via google.

Hope this helps.

Offline Longarmx
« Reply #17 - Posted 2012-04-22 06:40:27 »

You could have a 3d array with your blocks stored in it. You can change one of the blocks' type, and the rendering code will be able to recognize that the one block is different and be able to render that block different.

You could also pass the rendering function a different type for that one block, and it will be rendered different.

If you want to be able to select a certain block, you will have to set up a coordinate system. As for rendering the actual blocks, you will have to know OpenGL and a bit of math in order to render at a certain angle and position.

I do agree with jonjava and StumpyStreet; know 2d cold, and then start getting into 3d.

Bye the way, what 3d engine are you using?

~Longarmx

Offline deadteck

Senior Newbie





« Reply #18 - Posted 2012-04-22 07:28:06 »

You could have a 3d array with your blocks stored in it. You can change one of the blocks' type, and the rendering code will be able to recognize that the one block is different and be able to render that block different.

You could also pass the rendering function a different type for that one block, and it will be rendered different.

If you want to be able to select a certain block, you will have to set up a coordinate system. As for rendering the actual blocks, you will have to know OpenGL and a bit of math in order to render at a certain angle and position.

I do agree with jonjava and StumpyStreet; know 2d cold, and then start getting into 3d.

Bye the way, what 3d engine are you using?

~Longarmx

Oh, i get it, I think, and Im using LWJGL right now but if needed I could switch I guess. And how would you even go about setting up a coordiante system? Im looking into that but I cant find anything Sad

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
Offline deadteck

Senior Newbie





« Reply #19 - Posted 2012-04-22 07:40:20 »

So don't be discouraged by asking nooby questions but I would do a quick google search before posting because what you seem to be asking is done many times in tutorials that you can find via google.
thanks a lot, I really appreciate it Cheesy

The best ideas will come from the weirdest and sometimes most f***'d up places, you just have to realize them.
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.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!