Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - taffer

Pages: [1] 2
1
Quote
I strongly disagree.

Well; _distance_ calculation should be the responsibility of a point class, right. But with some static methods like "isInAreaOfEffect(AreaOfEffect area, Point reference)" you are going the wrong way.

Instances of ConeAreaOfEffect, Square..., Circle... should calculate that - discard the enumerations, polymorphism is the way to go. By using enumerations you end with ugly switch case statements.

If you add another area of effect, do you really want to change multiple code locations?

Never thought of that I agree here Polymorphism would be the best way.   With my current code it was only working with circles I started to forget about Square, Cone and Beam.  I'm going to take the advice about killing the enumerations.  And Poly-morphing the different kind of AreaOfEffects. 

This has been a good thread for me I am learning quite a bit from all of you.  This is my first attempt at a real game.  I've made Pong, Tic Tac Toe, Tetris.  I've never had a program that was so complex as a roguelike.  Truthfully I am walking into this blindly, I thought it was an easy game to program, but this has been a very fun experience so far.

Taffer

2
Again Thanks guys I really appreciate everyone's opinions.  All advice is always welcomed and accepted.

Funny this class started making a list of Tiles and I just checked through the list.  But when I started making the AreaOfEffect class movable I need to redo the list per move. I thought maybe this would be too slow so I redid that idea and came up with what I have now.

In all honesty after much thought I realized I needed to rework my class structure.   I'm going to keep 90% of the code but just rewrite The actual structure of the game. 

Quote
In C++ I would probably use a helper function to determine if a point is in an Area of Effect.  But that would be hard for Java.
E.g bool isInAreaOfEffect(AreaOfEffect area, Point reference);
Because I dont believe it is the AreaOfEffect class's job to determine that.

I agree with this.  In my rewriting I created a little class that contains public methods like your bool isInAreaOfEffect(AreaOfEffect area, Point reference).  I do come from C/C++ and I really dislike Java's everything must be a class idea.  Most of my distance from Point to Point, Monster to Player, line of sight methods will be in this little class.  The class has no data just C like Global Methods that's all.

Point Class added to game Thankyou.

Redundant and vague comments noted and will be much better.

Method comments are coming back but all those end of comments will never come back.

Thankyou corremn, TSMI,and Krice for the new advice.


Taffer

3
Wow thanks purestrain and Z, I will try to incorporate this

Yes I like using interfaces but I thought they were used only for global declares and global methods.  I'm very happy you guys are willing to help teach me. 

Purestrain your two methods are a little above my Math comprehension ATM but I will change those methods and play around.  I am very intrigued.

Z your example makes a lot of sense thankyou.

I love coding, but sadly I'm still very new at Math coding. You two are great help.

Taffer

 

4
Here is updated code much smaller half the size:

Code: [Select]
package eracia;

/**
 *
 * @author Jeff Desrosiers
 */
import java.awt.Dimension;

//This class calculates every square given within an Area of Effect
public class AreaOfEffect
{
    
    //------------------------InClass Declarations------------------------------
    public enum AOEType {CIRCLE, BEAM, CONE}    //The enumeration of AOE    
    public  AOEType             Type;           //The Type of Area Of Effect    
    private int                 intSize;        //The Size of Area of Effect
    private Dimension           dimCenter;      //The Center of the AOE
    
    public AreaOfEffect(AOEType Type, int intSize, Dimension dimCenter)
    {
        
        this.Type = Type;
        this.intSize = intSize;
        this.dimCenter = dimCenter;
                
    }    
    //----------------------------Public Methods--------------------------------
    public boolean isInAOE(int ix, int iy)
    {
                
        int intLine = 1;                //What line to calculate for X axis
        int ix2 = 0;                    //The length of the line for ix
                
        if(iy >= this.dimCenter.height - this.intSize &&
           iy <= this.dimCenter.height + this.intSize)
        {
            
            for(int iy2 = iy; iy2 != this.dimCenter.height -
                this.intSize; iy2--)
                    intLine++;
            
            ix2 = this.findXNum(intLine);                        
            if(ix >= this.dimCenter.width - (ix2 / 2) &&
               ix <= this.dimCenter.width + (ix2 / 2))
                    return true;
                
        }
        
        return false;  
        
    }    
    
    public int distanceFromCenter(int ix, int iy)
    {
        
        int intDistance = 0;        
        int iyd = Math.abs(this.dimCenter.height - iy);
        int ixd = Math.abs(this.dimCenter.width - ix);
        
        if(iyd == 0)
            intDistance = ixd;
        else if(ixd == 0)
            intDistance = iyd;
        else
        {
            
            if(iyd > ixd)
                intDistance = iyd;
            else
                intDistance = ixd;
            
        }        
        
        if(intDistance == 0)
            intDistance = 1;
                  
        return intDistance;
        
    }    
    public void updatePosition(Dimension dimPos)
    {
        
        this.dimCenter = dimPos;
        
    }    
    private int findXNum(int iy)
    {
                
        int ix =                0;      //The x value
        
        int imStart =           this.intSize - (this.intSize / 2) + 1;
        int imEnd   =           imStart + this.intSize - 1;
                
        if(iy >= imStart && iy <= imEnd)
            ix = (this.intSize * 2) + 1;
        else if(iy < imStart)
        {
                        
            ix = (this.intSize * 2) + 1;
            for(int ii = iy; ii < imStart; ii++)
                ix -= 2;
            
        }
        else
        {            
            
            ix = this.intSize;
            for(int ii = (this.intSize * 2) + 1; ii > iy; ii--)
                ix += 2;

        }
        
        return ix;
        
    }
    
}



I hope its a little better without all those comments

Taffer

5
Thank you.  The comments is the style my teacher in college taught me.  I honestly hate doing them like that I can always delete that and be much happier.  Less typing on my part. 

I like the empty lines to me it looks better for readability.

And my methods being bloated does this mean Im doing unnecessary calculations?

I'm doing this to become a better programmer.  I'm always open for more criticism.

Taffer

6
Programming / I Feel Like Sharing some Code - My Unfinished AOE Class
« on: July 29, 2011, 07:25:47 PM »
Code: [Select]
package eracia;

/**
 *
 * @author Jeff Desrosiers
 */

//imports
import java.awt.Dimension;

//This class calculates every square given within an Area of Effect
public class AreaOfEffect
{
   
    //------------------------InClass Declarations------------------------------
    public enum AOEType {CIRCLE, BEAM, CONE}    //The enumeration of AOE
   
    public AOEType              Type;           //The Type of Area Of Effect
   
    private int                 intSize;        //The Size of Area of Effect
    private Dimension           dimCenter;      //The Center of the AOE
   
    public AreaOfEffect(AOEType Type, int intSize, Dimension dimCenter)
    {
       
        this.Type = Type;
        this.intSize = intSize;
        this.dimCenter = dimCenter;
               
    }//end of Constructor
   
    //----------------------------Public Methods--------------------------------
    //This method finds out if the current tile in question is in the Area of
    //Effect's range
    //ix:       The X Axis value
    //iy:       The Y Axis value
    public boolean isInAOE(int ix, int iy)
    {
       
        //--------------------InMethod Declarations-----------------------------
        int intLine = 1;                //What line to calculate for X axis
        int ix2 = 0;                    //The length of the line for ix
       
        //Checks to see if it is in the Y axis of the AOE if true go on if false
        //return false
        if(iy >= this.dimCenter.height - this.intSize &&
           iy <= this.dimCenter.height + this.intSize)
        {
           
            //It was true so find out which line iy is in the AOE
            for(int iy2 = iy; iy2 != this.dimCenter.height -
                this.intSize; iy2--)
            {
               
                intLine++;              //increment intLine
               
            }//end of for(int iy2 = iy; iy2 != this.dimCenter.height -
             //this.intSize; iy2--)
           
            //Found the right line so now find the size of the line for X Axis
            ix2 = this.findXNum(intLine);
           
            //Check to see if it reaches the X Axis limit to the line in
            //question
            if(ix >= this.dimCenter.width - (ix2 / 2) &&
               ix <= this.dimCenter.width + (ix2 / 2))
            {
               
                return true;            //Both x and y are in the AOE
               
            }//end of if(ix >= this.dimCenter.width - (ix2 / 2) &&
             //          ix <= this.dimCenter.width + (ix2 / 2))
           
        }//end of if(iy >= this.dimCenter.height - this.intSize &&
         //          iy <= this.dimCenter.height + this.intSize)
       
        return false;  //The Tile is not in the AOE
       
    }//end of isInAOE(int ix, int iy)
   
    //Returns the number of Tiles from the Tile in Question to the Center of the
    //AOE
    //ix:           The X Axis value
    //iy:           The Y Axis value
    public int distanceFromCenter(int ix, int iy)
    {
       
        int intDistance = 0;        //The Distance between Center to Tile
        int iyd = Math.abs(this.dimCenter.height - iy); //The change in Y
        int ixd = Math.abs(this.dimCenter.width - ix);  //The change in X
       
        //Check to see if iyd = 0 if so The Distance is ixd
        if(iyd == 0)
        {
           
            intDistance = ixd;
           
        }//end of if(iyd == 0)
        //Check of ixd = 0 if so the distance is iyd
        else if(ixd == 0)
        {
           
            intDistance = iyd;
           
        }//end of else if(ixd == 0)
        //Else it is the larger of the two
        else
        {
           
            if(iyd > ixd)
            {
               
                intDistance = iyd;
               
            }//end of if(iyd > ixd)
            else
            {
               
                intDistance = ixd;
               
            }//end of else
           
        }//end of else
       
        //If both are 0 set intDistance to 1 so there will be no division by 0
        if(intDistance == 0)
        {
           
            intDistance = 1;
           
        }//end of if(intDistance == 0)
       
        return intDistance; //Done
       
    }//end of distanceFromCenter(int ix, int iy)
   
    //This method updates the Center of AOE
    public void updatePosition(Dimension dimPos)
    {
       
        this.dimCenter = dimPos;
       
    }//end of updatePosition(Dimension dimPos)
   
    //-------------------------Private Methods----------------------------------
    //This method finds the X value in a given line of the AOE
    //iy:       is the Y Axis of the AOE not the map
    private int findXNum(int iy)
    {
       
        //------------------InMethod Declarations-------------------------------
        int ix =                0;      //The x value
       
        //These variables calculate the middle of the AOE
        int imStart =           this.intSize - (this.intSize / 2) + 1;
        int imEnd   =           imStart + this.intSize - 1;
       
        //If iy is in the middle of the AOE
        if(iy >= imStart && iy <= imEnd)
        {
           
            ix = (this.intSize * 2) + 1;  //ix = 2 * The Size of AOE + 1
           
        }//end of if(iy >= imStart && iy <= imEnd)
        //If iy is before the middle of the AOE
        else if(iy < imStart)
        {
           
            //Set ix to the The size of the middle and for each line ii travels
            //minus 2 to ix
            ix = (this.intSize * 2) + 1;
            for(int ii = iy; ii < imStart; ii++)
            {
               
                ix -= 2;
               
            }//end of for(int ii = iy; ii < imStart; ii++)
           
        }//end of else if(iy < imStart)
        //If iy is after the middleof the AOE
        else
        {
           
            //Set ix to the size of the AOE and add two for every line ii
            //travels through
            ix = this.intSize;
            for(int ii = (this.intSize * 2) + 1; ii > iy; ii--)
            {
               
                ix += 2;
               
            }//end of for(int ii = (this.intSize * 2) + 1; ii > iy; ii--)
           
        }//end of else
       
        return ix;
       
    }//end of findXNum(int iy)
   
}//end of AreaOfEffect

Post any constructive criticism that you can.  I love to learn new ideas. 

I also want to know how my documentation / coding style is.  Any tips will be welcomed.  Thankyou in advance

Taffer
eraciarl.blogspot.com

7
Traditional Roguelikes (Turn Based) / Re: Eracia
« on: July 29, 2011, 01:53:01 AM »
Wow its been awhile since I updated, but here is my small update on Eracia:

1.) Finally got my light sources to work well and much faster than before.  The map  generator will start randomly putting torches in rooms and hallways.

2.) Started working on small support for Tiles.  This will be the last thing I honestly will be working on even if it never gets done.

3.) Started working on Player Input, Updating Entities, and updates to the map in a well polished MainGameLoop().

4.) Started cleaning up my classes and using encapsulation to a way that I feel is good.

5.) My map generator now deletes excess walls.

6.) Started working on The Title Screen and Character Creation Screen

7.) Started working on my Stats Class both Monsters and the Player will share this class.

8.) Worked on the Panels so I can show and hide them when needed. And made a Class that they inherit with the same functions.

9.) Started a better version of my input engine.

Taffer
eraciarl.blogspot.com

8
Programming / Re: Java rogues that are open source?
« on: July 25, 2011, 11:59:09 AM »
At the moment I am writing a rogue in java.  How I am doing it is creating a class that extends JPanel which has char[][] and Color[][] Buffers.  Writing the map to the screen all you need to do is override the JPanel's paintComponent(Graphics g) method:
Code: [Select]
public class MyJPanel extends JPanel
{

      private Color[][] cColors;  //The Colors of the map
      private char[][]   chChar;  //The characters of the map

      public MyJPanel()
      {

             cColors = new Color[20][20];
             chChar = new char[20][20];

             for(int iy = 0; iy < 20; iy++)
                 for(int ix  = 0; ix < 20; ix++)
                 {

                      cColor[ix][iy] = Color.WHITE;
                      chChar[ix][iy] = '#';

                  }

      }
      //This overrides JPanel's paintComponent method
      public void paintComponent(Graphics g)
      {

            super.paintComponent(g);  //Always do this first when overriding paintComponent

             for(int iy = 0; iy < 20; iy++)
                 for(int ix  = 0; ix < 20; ix++)
                 {

                        g.setColor(cColors[ix][iy];
                        g.drawString(String.valueOf(chChar[ix][iy]),
                             StartX + (CharSpace * ix),
                             StartY + (LineSpace * iy));                     

                  }     

      }

}

In the g.drawString method:

StartX:         is the pixel you wish to start drawing on the X axis,
StartY:         is the pixel you wish to start drawing on the Y axis
CharSpace:   is how I create spacing between each character - X axis spacing
LineSpace:    is how I create spacing between each Line - Y axis spacing

Now if you wish to use tile graphics instead g has a many drawImage methods.
g has many methods in it to draw graphics onto a JPanel. 

I hope this helps

Taffer

9
Traditional Roguelikes (Turn Based) / Re: Eracia
« on: July 23, 2011, 05:33:09 AM »
   Yes I will be adding a hunger system.  And thank you for your kind words. 

   Today I dedicated my time to clean up my code, proper documentation and comments.  I did add support for 800x600 and 1280x1024 resolutions.  I was creating everything at 1024x768.

   Also I found out my light source idea was fast enough for anything up to 300 x 300 maps, but when I had larger maps it flickered.  Even though 300 x 300 is very large for a roguelike, I've yet to implement monsters AI, so I have to change my algorithm for that, I think I came up of a solution and will test that tomorrow.

Taffer
eraciarl.blogspot.com

10
Traditional Roguelikes (Turn Based) / Re: Eracia
« on: July 22, 2011, 05:34:36 PM »
Thank you getter77, you seem to be a great motivator on this site.

I have added support for light sources in Eracia.  They still are not where I want them to be.  But they can light a tile from -1.0 to 1.0.  -1.0 being black and 1.0 being the brightest on a the color's RGB scale.  Also I made the Map class have a default light value.  Most caves or dungeons will have a -.20 to -.35.

How the lights work on the colors is simple:

Every tile has a light value - if a tile has no light source then it will use the map's default light value.  A light source will update a tile's light value if it is on that tile and that tile is in the radius of the light source.  The farther the tile is from the light source it will effect the tile's light value a little less until it wont effect the tiles at all.

When Eracia draws the map it make each tile the map's default light value and then it will take the color of each tile, its light value and make calculations on the actual color to draw.  It then will draw it on the screen.

There is probably better ways to do this.  But its dealing with text so I know it will not lag the system.  At the moment it runs well and I am happy with it.

Taffer
eraciarl.blogspot.com

11
Traditional Roguelikes (Turn Based) / Re: Eracia
« on: July 19, 2011, 07:15:56 PM »
Funny I realized I never really talked about my plans for Eracia.

First this is my first real project Ive ever started, and  I'm writing it in Java.

At the moment I'm thinking about having the game take place on a small island named Eracia.  I have a few ideas for a storyline but none in concrete yet.

I'm not "new" to game programming; however,  I am new to large scale projects.  I have many ideas, but I'm really not sure if I have the capabilities to do everything I want.  I'm going with the flow and learning things everyday that I work on Eracia.  The main reason I am using these forums and having my blog is to keep me focused on the game, and not just stop like I do all the time.  I promise that this is the longest I have worked on a project and I am happy with that

The things I feel I need to add to the game:

1.) Light sources.  Maybe some light spells.  Fireballs flying down hallways.
2.) Rivers and lakes in some maps.  Bridges will be added.
3.) Game Objects - Buttons that open gates, switches that create pits.  Movable statues that might unlock something. 
4.) A very small scripting language.  That can change an objects character, move an object, tell an object to do something, change its color, edit the map in some way.
5.) A skill based system, weapon/ armor skills.
6.) I have an idea for weapons where I will make the basic weapons, but randomize a suffix and a prefix to it - something like Steel Long Sword of Fireballs.  It would do a little more damage than a regular long sword and if used may cast a level one fireball.  Same for armor.  Iron Chain Mail of Poison - gives a little boost to Defense value and helps protect you from poison.
7.) I will have permadeath.
8.) At the moment the map generator can create cave-like tunnels, and if I tweak it a little it can make something that looks like a forest map.  I do want to add Mazes, dungeons very similar to Rogue, maps that are just full of rooms.  Random city like maps.  And some more.

These things are in debate:

1.) Not entirely sure if I want to make the outside map randomized or not.
2.) Not entirely sure if I am going to have "classes" in the game, or just allow the character choose which skills to bring up during his/her lifespan.
3.) The types of Races are in question too.  Do I want to use Humans, elves, dwarfs.  Maybe allow Kobolds, Goblins, Orcs,  or maybe all Human but different countries they are from.

I have noticed the more I work on Eracia the more ideas I come up with, which can be a bad thing in a Design Way, but I am new at this. 

I hope this adds a little interest in my little roguelike, its been really fun so far :)

Taffer
eraciarl.blogspot.com

12
Traditional Roguelikes (Turn Based) / Re: Eracia
« on: July 18, 2011, 07:39:24 PM »
Eracia now has some sort of cave-like generation system.  Screenshots of it at:
eraciarl.blogspot.com

Taffer

13
Traditional Roguelikes (Turn Based) / Eracia
« on: July 14, 2011, 04:53:21 PM »
For the last two weeks I have been creating a fantasy roguelike in Java named Eracia.  At the moment it supports:

1. A player Stats Panel to the left
2. A scrolling event log on the bottom.  No user scrolling yet
3. An Entity list on the bottom also.
4. Maps that scroll with the position of the Player.
5. Maps need to be mapped out with a very crude Player view.

At the moment I am working on:

1. The Map Generator and its Map Template class.

After  I get a little bit of "logical randomness" I will start posting screen shots. 

I also have a blog of Eracia in my Signature:

Taffer
eraciarl.blogspot.com

14
Off-topic (Locked) / Re: Hello RogueTemple
« on: July 06, 2011, 08:06:29 PM »
Alright after a few days I finally got a small update to Eracia.  I added the EventLog and EntityList to the GUI and Im quite happy with it so far.

Thankyou for all your views so far.

Taffer
http://eraciarl.blogspot.com/

15
Off-topic (Locked) / Re: Hello RogueTemple
« on: June 29, 2011, 04:57:28 PM »
Thankyou getter77.

I updated Eracia's blog with a first small screenshot of what I would like the UI to look like.  I used JLabels and JTextAreas but fell to the problem of text manipulation so I came up with another idea.  To directly paint text to a JPanel. 

Taffer

Pages: [1] 2