Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (686)
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 1422 times)
0 Members and 1 Guest are viewing this topic.
Offline rouncer

Junior Devvie

« 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 Devvie

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 Devvie

« 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 Devvie

« 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 Devvie

« 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:

public abstract class ActiveMode
  public abstract ActiveMode exec();

public class TitleScreen extends ActiveMode
  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 Devvie

« 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.

Dwinin (63 views)
2015-11-07 13:29:08

Rems19 (77 views)
2015-10-31 01:36:56

Rems19 (69 views)
2015-10-31 01:32:37

williamwoles (104 views)
2015-10-23 10:42:59

williamwoles (91 views)
2015-10-23 10:42:45

Jervac_ (105 views)
2015-10-18 23:29:12

DarkCart (132 views)
2015-10-16 00:58:11

KaiHH (115 views)
2015-10-11 14:10:14

KaiHH (153 views)
2015-10-11 13:26:18

BurntPizza (167 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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‑
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!