Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 7 8 [9] 10
 81 
 on: 2014-04-15 12:40:49 
Started by Anju_Maaka - Last post by superminer362
Do this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
abstract class Spell {
    public abstract void doStuff();
}
class Fire_Spell extends Spell {
    @Override
    public void doStuff() {
        // do stuff
   }
}
...
spell.doStuff();

 82 
 on: 2014-04-15 12:35:51 
Started by Anju_Maaka - Last post by StrideColossus
if(spell.getClass() == Fire_Spell.class){
     doStuff();
}

or

spell.getClass().isAssignableFrom( Fire_Spell.class )

or

spell instanceof Fire_Spell

 83 
 on: 2014-04-15 12:34:58 
Started by Anju_Maaka - Last post by ags1
spell instanceof FireSpell

But it would be better to structure your code to avoid the need to use instanceof, it tends to be ugly code, and you will have long tails of if...else...else... for all your subclasses. Rather have a method like AbstractSpell.cast() that each spell implements, then you can ask a spell to act (or display or whatever) without needing to know which subclass you have.

 84 
 on: 2014-04-15 12:31:31 
Started by CTucker1327 - Last post by ags1
Hmmm... Programming is creative, there are many right solutions to any given problem, and all the right solutions have different bugs and limitations. Five people will tell you five different things - some will be quite similar (with telling differences) but some of the things they say will be poles apart. So I'm not sure how much it would benefit you if someone "told" you "exactly" how to do it.

 85 
 on: 2014-04-15 12:30:08 
Started by Anju_Maaka - Last post by Anju_Maaka
I am making a simple 2D platform game and I have run into a slight problem with the Spells I want the player and NPCs to use.
I have an abstract class Spell and a set of subclasses extending Spell. These subclasses indicate the element of the spell, so one subclass might be Fire_Spell. I want to be able to receive a Spell and do something like
1  
2  
3  
if(spell.getClass() == Fire_Spell){
     doStuff();
}

But I can't figure out how to identify if spell is a certain subclass since whenever I try to compare the instance of Spell I have (which will never really be a Spell, always one of the subclasses of Spell) I just can't find a way that doesn't either end in an error or which gives a faulty answer.

I have tried something like "attack.isAssignableFrom(Fire_Spell)" and "attack.getClass().isAssignableFrom(Fire_Spell)" but those just say that "Fire_Spellcannot be resolved to a variable" so I wonder what I'm doing wrong.

 86 
 on: 2014-04-15 12:09:12 
Started by Gibbo3771 - Last post by Gibbo3771
Hi,

I have a NodeMap class for my A* algorithm that holds all my nodes in an array with some methods to do things.

I am struggling to make a decision about 2 fields in specific within this NodeMap:

1  
2  
3  
4  
5  
   /** The nodes that are passable */
   private boolean[][] nodesPassable;

   /** The value of the nodes */
   private int[][] nodeValues;


These 2 fields, hopefully are self explanatory. Basically when I create my NodeMap I pass in 2 arrays that holds information about what is passable and the values of the nodes.

The array of nodes is just a 2D array like the above.

I also have a PathFinder class that has a one of these maps, well in this case they all have the same map.

Which is bad, because after I have finished moving to a path, the map needs reset. To my knowledge that means if I do this:

1  
2  
3  
4  
5  
6  
      /* Create our map and give it the array of passable nodes */
      Map map = new NodeMap(8, 8, nodesPassable, nodeValues);
     
      /* Create our apth finder and give it the map */
      PathFinder pathFinder = new PathFinder(map, new Heuristic());
      PathFinder pathFinder2 = new PathFinder(map, new Heuristic());


I pass the exact same map to both path finders, ideally every single NPC in my game will have their own path finder. No idea if that is wise or now, or if they should all use the same one.

Well now say one NPC just finished its path, I then call:

1  
pathFinder.map.reset();


I feel stupid for asking this, but is that not going to reset the map for both pathfinders since I passed them the same map? Objects are pass by reference right?

So back to the problem with those 2 fields, if I was to go into my NPC class and create a new NPC, say I don't have access to the array of passable nodes and node values, or say they have changed (The map can change), now what?

Well I was thinking I would make those 2 fields static and set them at run time, then I can adjust them for all maps with NodeMap.updateNodes() or something.

Would this be a viable work around? Or anyone got a better idea?

I would rather not have to fire those arrays around in a ton of constructors or even make them static, it seems to make more sense to make the actual fields inside the array static themself.

Means if the map changes I can simply get the position of the node within the array and change all the values from within any class.

EDIT: Might want to tell you reset actually does, it basically goes through all the nodes in the map and resets their previous node to null. As the path is built by setting the next node to check as the current node we just checked.

So the path gets build from destination to start.

 87 
 on: 2014-04-15 11:45:11 
Started by Gibbo3771 - Last post by Gibbo3771
Yeah of course it is Smiley

You might want to look into Destructible terrain, GameDevTuts+ always makes very, very good gamedevelopment articles ^^

Thank you!

I'll have a look over it soon as I am home Cheesy

 88 
 on: 2014-04-15 11:43:37 
Started by hhfjkehfe - Last post by hhfjkehfe
Well I want to render the background which is 20MB and I want to use vertices.[20MB per level]

 89 
 on: 2014-04-15 11:39:14 
Started by Gibbo3771 - Last post by matheus23
Yeah of course it is Smiley

You might want to look into Destructible terrain, GameDevTuts+ always makes very, very good gamedevelopment articles ^^

 90 
 on: 2014-04-15 11:18:45 
Started by Gibbo3771 - Last post by Gibbo3771
Yeah I thought it was something like that, but that is quit a few sprites for something so trivial.

Is it not possible to generate a little bit of noise on the current sprite for every damage level and alpha the pixels? lol

Pages: 1 ... 7 8 [9] 10
 

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 (11 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (182 views)
2014-04-01 02:16:10
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

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