Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 393 394 [395] 396 397 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886090 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5910 on: May 23, 2014, 07:46:29 pm »

GUI work from scratch is so infuriatingly annoying :( It makes me really appreciate the event-drivin GUI framework that Javascript uses. Working on a GUI for my ship game to equip parts is taking me forever just because I don't like it and can't concentrate.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: if self.isCoder(): post() #Programming Thread
« Reply #5911 on: May 23, 2014, 07:53:24 pm »

Yeah, I'm doing GUI work for the Agora Client right now, and it is indeed a pain in the ass, even with the library features included in java.
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5912 on: May 24, 2014, 07:18:50 pm »

Hi, I'm looking for some advice on the best packages to drop a user accounts system into a php-based website. I made a thread about it in life advice, here but thought I'd mention it here since many people probably don't check out that board.. If anyone has any advice on where to look, please let me know, it would be highly appreciated.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5913 on: May 24, 2014, 08:47:04 pm »

GUI work from scratch is so infuriatingly annoying :( It makes me really appreciate the event-drivin GUI framework that Javascript uses. Working on a GUI for my ship game to equip parts is taking me forever just because I don't like it and can't concentrate.

Why not use an already existing GUI framework then?
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5914 on: May 24, 2014, 09:16:48 pm »

Well, I'm using libtcod. I doubt that there is a libtcod widget framework...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5915 on: May 24, 2014, 10:15:20 pm »

Oh jeez, I hope you're not still using that crummy libtcod engine I made sky. :P

But yes, gui work is extremely tedious; the longer the iteration time, the worse it gets. Run the program, tweak the button position, run it again, now you have to move that divider over for more room, run it again...
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5916 on: May 24, 2014, 10:34:10 pm »

I actually am using that libtcod engine, how did you know? :o In fact, I'm using the very first one you made and tacked on a crummy state system that's nevertheless serviceable for simple menus. It also has a pretty bad interstate communication system, which helps in giving me a headache when doing menus.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5917 on: May 24, 2014, 10:49:51 pm »

I made quite a few changes to that engine, and most of it was taking things out. I think the problem a lot of coders run into with OOP (myself formerly included) is making functions, classes, etc. that just try to do too much. A function or class should do its job, hand back the data it needs to, then just get out of the way. things are so much cleaner and simpler that way.

The state system ended up just being a stack of them, with each state having a pointer to the previous one on the stack. So you could make a call like
Code: [Select]
prev->render();at the beginning of the current state's render function, and it would draw that state on top of the previous one. I'm sure there are more sophisticated ways to do it, but meh. On the other hand, nothing I ever try makes gui programming any less tedious. :'(
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5918 on: May 24, 2014, 10:59:37 pm »

The change i did to your engine was to not use the prev pointer and not pass around a reference to the main stack. Instead, the TCODEngine class calls the render() function by traversing the stack from front to back, meaning I can do pretty cool color blending things. The states can now easily look like windows popped up.

I think the TCODEngine thing is perfectly fine, though. It has a set of inheritable functions that do discrete things (render this, handle key event, update internal logic, clean up pointers...), all linked into a logical class of 'TCODEngine'.

One weird thing though was that it kinda felt that the states didn't call ~State() before being popped.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5919 on: May 25, 2014, 01:08:38 am »

Yeah, the reason for the prev pointer was JUST IN CASE I didn't want stacks to print in order like that. It works either way really. Glad you got some use out of it anyway. :)
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Johuotar

  • Bay Watcher
    • View Profile
    • Some game projects
Re: if self.isCoder(): post() #Programming Thread
« Reply #5920 on: May 26, 2014, 11:40:30 pm »

So I'm following this roguelike tutorial but I'm using c# and I don't know how I should translate the sneaky trick #1 on article 3 to c#.

http://www.kathekonta.com/rlguide/article3.html

I thought about making the tileindex object array, but I heard its not very efficient and this needs to be used a lot. Friend suggested using 4 arrays, with one as the index number list and the others could have the char, int and bool. I've also googled about hashtables and dictionaries and now I'm just confused at what solution would be simplest and would not cause me troubles later on when expanding the game.

Can you suggest good future proof solution? I really want to learn the best practices early on.
Logged
[img height=x width=y]http://LINK TO IMAGE HERE[/img]
The Toad hops in mysterious ways.
This pure mountain spring water is indispensable. Literally. I'm out of paper cups.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5921 on: May 27, 2014, 12:55:58 am »

For starters, "making the tileindex object array is not very efficient" is not good reason to not use it. Optimization without info about how inefficient it actually is is a bad thing to do. It makes programming slower and gives you a headache for like 10 cpu ticks' efficiency.

If you'd ask me, I'd make a Struct with all your data (tile shape, color, ...), then put them in a Dictionary <(index type), Tile>. The index type could be a int or it could be a string--I like using strings for IDs because they're immediately readable and in the case of Python and maybe C#, they're immutable so aren't very inefficient.

The reason I would use a struct for Tile is because C# is not duck-typed, so I can't easily stuff all the data I want into a single data structure.

Using 4 arrays is not something you'd want to do for future-proofing. What happens if you want to make another data type? You need to create another array and all the annoying stuff thst goes with it.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5922 on: May 27, 2014, 02:21:41 am »

So I'm following this roguelike tutorial but I'm using c# and I don't know how I should translate the sneaky trick #1 on article 3 to c#.

http://www.kathekonta.com/rlguide/article3.html

I thought about making the tileindex object array, but I heard its not very efficient and this needs to be used a lot. Friend suggested using 4 arrays, with one as the index number list and the others could have the char, int and bool. I've also googled about hashtables and dictionaries and now I'm just confused at what solution would be simplest and would not cause me troubles later on when expanding the game.

Can you suggest good future proof solution? I really want to learn the best practices early on.
Couldn't you just use classes? Or enums if you feel brave.

Code: (Pseudocode) [Select]
public class Tiles {

    private Map<Integer, Tile> tiles

    //Insert constructor to read in tiles from say a text file with injection.

    public int nColorCode(int type) {return tiles.get(type).color();}
    public char nCharacter(int type) {return tiles.get(type).character();}

}

public class Tile {

    private int color;
    private char character;

    //Insert constructor

    public int color() {return color;}
    public char character() {return character;}

}
« Last Edit: May 27, 2014, 02:25:33 am by da_nang »
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Johuotar

  • Bay Watcher
    • View Profile
    • Some game projects
Re: if self.isCoder(): post() #Programming Thread
« Reply #5923 on: May 27, 2014, 09:10:43 am »

Thank for the answers, they mean much to me and very helpful.  :) Here is what I ended up doing:

Code: [Select]
public class Tile
    {
        public struct TILE_TYPE
        {
            public string nCharacter;
            public int nColorCode;
            public bool bPassable;
        }
        //this is made to save colors as int values instead of as strings which cant be converted intrically to Console.color
        public ConsoleColor[] colors = (ConsoleColor[])ConsoleColor.GetValues(typeof(ConsoleColor));
        //int key followed by values for the tile's char, colorcode and passability
        public Dictionary<int, TILE_TYPE> sTileIndex = new Dictionary<int, TILE_TYPE>()
        {
            { 0, new TILE_TYPE {nCharacter=".", nColorCode= 1, bPassable=true}},
            { 1, new TILE_TYPE {nCharacter="#", nColorCode= 2, bPassable=false}},
            { 2, new TILE_TYPE {nCharacter=">", nColorCode= 8, bPassable=true}},
            { 3, new TILE_TYPE {nCharacter="<", nColorCode= 5, bPassable=true}},
            { 4, new TILE_TYPE {nCharacter="|", nColorCode= 4, bPassable=true}},
            { 5, new TILE_TYPE {nCharacter="+", nColorCode= 9, bPassable=false}}
        };
    }

Code: [Select]
void DrawTile(int x, int y)
        {
            Tile tile = new Tile();

            Console.SetCursorPosition(x, y);
            int nType = Map.nMapArray[y, x];
            //x and y position is saved to nType
            Console.ForegroundColor = tile.colors[tile.sTileIndex[nType].nColorCode];
            //Writing Color is changed to colorcode of the value of nType in the tileindex in Tile class
            Console.Write(tile.sTileIndex[nType].nCharacter);
        }
Logged
[img height=x width=y]http://LINK TO IMAGE HERE[/img]
The Toad hops in mysterious ways.
This pure mountain spring water is indispensable. Literally. I'm out of paper cups.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5924 on: May 30, 2014, 04:32:47 pm »

Quote from: PHP
"string" == 0
"string" == TRUE
TRUE != 0
The comparison operator does not have the transitive property.

The comparison operator has no transitive property.
When using it on basic built-in types.

Why hasn't this whole language been nuked from orbit again?
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU
Pages: 1 ... 393 394 [395] 396 397 ... 796