Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  some questions  (Read 1109 times)
0 Members and 1 Guest are viewing this topic.
Offline rouncer

Junior Member





« Posted 2010-04-19 08:59:40 »

1) whats the easiest way to make a structure in java, i.e. for making a 3 component floating point vector for a maths library

2) can you overload operators to make a 3d maths library?

3) is there some kind of function pointer like there is in c? (in java it would be more like a class reference) cause they are handy for mode switching

Offline TheMatrix154

Junior Member


Medals: 2



« Reply #1 - Posted 2010-04-19 09:07:42 »

1.) Class (or Enum should be possible in Java 1.5+)
2.) No operator overloading available in Java, use function-calls like add, sub, cross and so on and return self for chaining
3.) In Java you have no Pointer, all Object-Parameters are submitted "by ref"

Offline rouncer

Junior Member





« Reply #2 - Posted 2010-04-19 11:45:48 »

Yep, I got that, class, or enum.

But how the hell do you swap from intro screen to game play mode without a function pointer?!?!?!?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen
« Reply #3 - Posted 2010-04-19 11:55:12 »

You can overload methods.  References are equiv to pointers.
Offline Wildern

Junior Member





« Reply #4 - Posted 2010-04-19 12:14:18 »

Yep, I got that, class, or enum.

But how the hell do you swap from intro screen to game play mode without a function pointer?!?!?!?

One possibility would be to have a base class to handle drawing and the game logic, then derive new classes for intro screen and game play.  You have a reference to the current active "game screen" object and call the drawing and logic methods on that in  your game loop.  When the state changes, you just change the active "game screen".
Offline rouncer

Junior Member





« Reply #5 - Posted 2010-04-19 12:58:55 »

Roquen- references are equiv to class pointers?
I know I can go write a switch statement and contain all possible modes with different variables, but im talking about having one variable that can swap between classes.

Wildern-  So I make the intro and the game screen come out of the same class? nah... Isnt that virtual functions in c++?  god im confused.
Offline Roquen
« Reply #6 - Posted 2010-04-19 13:22:27 »

From a C-like point-of-view:

an object reference is a pointer to a data chunk which contains the object's (well) data.  This data contains a hidden pointer to its defining class.  Which in turn has a method table.

So you can have two classes which are derived from a common base class which each implement different desire behavior:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public abstract class ActiveMode
{
  public abstract ActiveMode exec();
}

public class TitleScreen extends ActiveMode
{
  @Override
  public ActiveMode exec()
  {
    // Do some stuff, if we're changing to a new mode, then return a reference to the handler of that mode.

    // Still in the title screen.
   return this;
  }
}


Is one of many possible examples. 
Offline rouncer

Junior Member





« Reply #7 - Posted 2010-04-19 13:27:06 »

extends! so I inherit both screens out of the same class, i dig.  thanks.

You know itll probably make my code neater not using c for a change. Wink

I still swear if I had basic with "goto x" id have the most powerful spaghetti of all time.
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.

Pippogeek (35 views)
2014-09-24 16:13:29

Pippogeek (28 views)
2014-09-24 16:12:22

Pippogeek (17 views)
2014-09-24 16:12:06

Grunnt (40 views)
2014-09-23 14:38:19

radar3301 (23 views)
2014-09-21 23:33:17

BurntPizza (58 views)
2014-09-21 02:42:18

BurntPizza (29 views)
2014-09-21 01:30:30

moogie (34 views)
2014-09-21 00:26:15

UprightPath (47 views)
2014-09-20 20:14:06

BurntPizza (51 views)
2014-09-19 03:14:18
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!