Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 45 46 [47] 48 49 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100859 times)

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #690 on: June 26, 2012, 09:38:00 am »

I want to be able to assign special effects to weapons later (like spells, abilities etc), so I think it would be better to keep them as class. Am I thinking in a right direction?
Personally, for all normally shared (if varying) qualities, I'd essentially build a 2D array/hash/other structure of data, primary index for weapon type, secondary index being what that weapon type's "weight, cost, sharpness, hands-needed, throwable?(true/false), etc..." values might be.

For the special effects, I suppose the most general purpose method would be to include a "special effects" sub-item of list or pointer-to-list or pointer-to-linked-list type.  Then each weapon can contain an arbitrary number (zero or more) of special instructions for that weapon without wasting an entire field for an oft-unused situation.

Within the list (of whatever format) you could fit everything from "Against cold spells, reduces armour effectiveness" to "when dual wielded with <list of other weapons>, increase effectiveness", to "cannot be used when out of <foo> alignment", etc.  Those are plaintext explanations, for things you could do.  What might actually be stored could be a reference to an effect-class/procedure, or an encoding of some form[1] for parsing by a single central handler that can be altered as future effects demand further special interactions.

But this might not be the best way of doing it, and I'm rather more Procedurally-orientated in my programming approaches than Object-wise, anyway.


[1] e.g. "Dam==Cold:Armour-5", "Wield.Other==[Knife,Fork,Spoon]:Att+10]" or "Align!=Good+-2:Unusable", as totally made up examples that could easily be improved upon.  But in this example you'd parse "<condition>:<effect>" with various handlers to work out if you're trying to find an equality or other relationship with a battle-condition, equipment condition, character stats, etc, (as specified by the <condition>) and then apply an adjustment/amendment to the transient state of the stats.  Could be as simple or as complicated as you want, if you write your own parser to satisfy the extents of your intended game-logic.  e.g. "(Day==Monday&&Equip.Found[Leather *])) || (Day==Tuesday,Thursday&&Locale==Holy) || (Day==!Monday,!Tuesday,!Wednesday&&RND(10)=1):Dam=5&&Alert-10" for a weapon that doesn't like its wielders to wear leather items on Mondays, fight on sacred ground on Tuesdays or Thursdays, and the rest of the week will just randomly decide to invoke its "hurt the wielder, and send him/her into a stupor" effect, in this on-the-spot made-up syntax that I've spent absolutely no time validating at all, but which ought to easy to produce an engine to do this for... ;)
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #691 on: June 26, 2012, 12:51:47 pm »

I understand most of what you've said (not all, especially the syntax of that code unless it's meant to be definined by making special structures as operators for the class, I am a total noob, remember that I learn this language for 3-4 days only), and I think I will eventually come to it. Right now it should be basic for me to build a framework which will WORK, and then improving it.

Regarding that simple example with movement, is it fine to draw the game that way? Basically in a loop, redrawing the whole thing (after Console.Clear()) whenever something changes?

I plan to separate that clusterfuck into a more readable version as soon as possible. I want to move all the drawing code from the main.cs, make draw_display() function which will host other functions like that:

draw_display()
{
 Console.Clear();
 draw_interface(); // border for the window, pseudo-graphical elements using symbols
 draw_stats(); // character name, stats and other info
 draw_terrain();  // tiles which will all be a property of a map[,] 2d array.
 draw_objects(); // objects which can be removed/destroyed, like doors, windows and the like.
 draw_items(); // items
 draw_creatures(); // npc and player
}

It's more of a design question, but if anything of that sounds wrong from the programming perspective, please let me know.

Also I want to remove the terrible cases when you press up/down/left/down arrows which check "if the next coord is wall", instead it should be move_to(dir) function. This function will be in a separate tile and will check the terrain[], then objects[], then creatures[] arrays for passability and then assign the coordinates of that tile to the player if the tile is not blocked/dense.
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #692 on: June 27, 2012, 05:50:13 am »

That is correct, although a doublebuffer is probably preferable to the clear-then-draw method, but maybe the framework you're using does that in the background.

What I usually do, is have just the Weapon class, and initialise it using a WeaponTypes-list. Personally, I use a Typemanager for that.

What it means is that I can do (code is in pseudo-C++ because my C# is so rusty it'll cause infections):
Code: [Select]
new Weapon(WeaponTypeManager->getWeaponType('copper_sword'));
// Although you can make the Weapon constructor do that for you so you could also do a
new Weapon('copper_sword');
And the WeaponTypeManager just stores an array of WeaponTypes with default values. This can either be hardcoded in the constructor:
Code: [Select]
WeaponTypeManager() {
  addWeaponType(new WeaponType('copper_sword', 5, 32, 20, 10));
}
or gotten from a config file (which is eventually preferable).

Then just make sure a Weapon can be initialised using a WeaponType (either copy as I do here or keep a reference to WepaonType, your choice):
Code: [Select]
Weapon(WeaponType* t) : name(t.name), density(t.density), size(t.size) {}
For effects you can add an effect-list to the Weapon object, and add Effect objects to that list, where an Effect object can have methods that should be called whenever the weapon is used (or something), and can be either hardcoded, or have a "general" effect that can parse strings such as in Starver's example.

Start with hardcoding everything to get it working, and then expand as needed. Making something able to do everything is a common coder's mistake (but what if I later want to do X?), and can cost you enormous amounts of time for something you may never use.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #693 on: June 27, 2012, 10:09:42 am »

Honestly, I don't know does that work.

I don't see any declarations whether WeaponTypeManager is a function, class or something else (no void, no class before it etc). Also I should check how does the operator "->" work, it does not exist in my C# textbook :).

By the way, when I Console.Clear() and redraw stuff, when I press down the movement key which forces quick redrawing, the console screen flickers. Is there a way to reduce or remove this "flickering" when the console screen is redrawn?
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #694 on: June 27, 2012, 10:34:02 am »

Hello friends!  So I'm trying to make a roguelike, except it's proving very difficult to start... seeing as I've never started this sort of project before and I'm not sure how.  In particular, I can't get the ncurses/pdcurses/what-have-you to work right, and for the life of me cannot find a good tutorial anywhere.  Anyone got a good link or good writing skills on "how the hell do I get my compiler to acknowledge the damn library?"

Windows 7, using Dev-C++ (Bloodshed C++ might be the real name?) but I think I've installed Code::Blocks as well.  It's just that Dev-C++ provides a fairly simple, low-frills environment where I don't have to shuffle through any awkward trees to find my program.  I'm also able to dual-boot onto Linux (Mint 7) but I'd like for this to be able to run in Windows.

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #695 on: June 27, 2012, 11:32:38 am »

Anyone got a good link or good writing skills on "how the hell do I get my compiler to acknowledge the damn library?"

Windows 7, using Dev-C++ (Bloodshed C++ might be the real name?) but I think I've installed Code::Blocks as well.  It's just that Dev-C++ provides a fairly simple, low-frills environment where I don't have to shuffle through any awkward trees to find my program.  I'm also able to dual-boot onto Linux (Mint 7) but I'd like for this to be able to run in Windows.

Does not setting -lncurses on the compiler command work. Although likely there is a nice graphical list you can add the library too as well.

If it can't find it then it's going to be that the library paths aren't setup correctly so you need to add the directory where the ncurses.ddl / ncurses.lib file is. (or .so / .a for linux). This can be done with either -Lpath on the complier command line or again via the graphical list the IDE provides.

I've not used Dev-C++, but assuming it's like pretty much every other IDE there will be a project->settings option somewhere which will have a build section. This might be broken down further to 'linker'. Which is were you'll find the option lists for paths and libraries.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #696 on: June 27, 2012, 12:14:58 pm »

See, I'm not entirely sure what most of that means...

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #697 on: June 27, 2012, 12:20:29 pm »

Quote
Does not setting -lncurses on the compiler command work.
Compiler options have a "command line" field where you can add your own parameters. Write -lncurses there.

Quote
If it can't find it then it's going to be that the library paths aren't setup correctly so you need to add the directory where the ncurses.ddl / ncurses.lib file is.
In your references make sure the environment has a path to these files set. If not, add them (I think it's right click -> add reference, or something like that in Visual Studio; I don't know about your environment).
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #698 on: June 27, 2012, 12:39:59 pm »

Honestly, I don't know does that work.

I don't see any declarations whether WeaponTypeManager is a function, class or something else (no void, no class before it etc). Also I should check how does the operator "->" work, it does not exist in my C# textbook :).
It's a class, but I skipped all the trivial stuff :) operator -> works like the fullstop "."
Objects (instantiated classes) can also be things like managers. However, me talking in C++ is more likely to confuse you than to help you, I'd better stop :)

Quote
By the way, when I Console.Clear() and redraw stuff, when I press down the movement key which forces quick redrawing, the console screen flickers. Is there a way to reduce or remove this "flickering" when the console screen is redrawn?
Yeah, that's what I meant with double buffering. It means you first draw everything on a new canvas, then switch the new with the current canvas, and then discard the old canvas. It depends on the library where you got "Console" on how that exactly works.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #699 on: June 27, 2012, 01:24:31 pm »

I use the standard Console class from the System namespace/library (Microsoft Visual Studio 2010). Any suggestions for a better library to add double buffering? :)
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

GlyphGryph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #700 on: June 27, 2012, 04:32:04 pm »

I forget, does either Dev-C++ or Code Blocks compile with gcc?
Logged

anzki4

  • Bay Watcher
  • On the wings of maybe
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #701 on: June 27, 2012, 04:40:13 pm »

I forget, does either Dev-C++ or Code Blocks compile with gcc?
Code::Blocks does, although you can select other compilers as well if you so desire.
Logged

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #702 on: June 27, 2012, 04:47:49 pm »

I still have no idea how to get any sort of curses to work ._.

anzki4

  • Bay Watcher
  • On the wings of maybe
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #703 on: June 27, 2012, 05:08:30 pm »

I still have no idea how to get any sort of curses to work ._.
Here you go. I used that tutorial to set up PDCurses on Code::Blocks.
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #704 on: June 27, 2012, 05:49:00 pm »

For some reason, Firefox freezes when these functions run in JavaScript:

Code: [Select]
function actionMenuLeave (xOne, xTwo, xThree, xFour, xTwoMove, xThreeMove, xFourMove, i) {
    if (xOne > 0) { xOne = xOne - .1; }
    if (xOne = 0.5) { xTwoMove = 1;}
    if (xTwoMove = 1) {xTwo = xTwo - .1;}
    if (xTwo = 0.5) { xThreeMove = 1;}
    if (xThreeMove = 1) {xThree = xThree - .1;}
   
    if (xThree = 0.5) { xFourMove = 1;}
    if (xFourMove = 1) {xFour = xFour - .1;}
   
    if (xFour = 0) {i = 1;}
    panelTransition (xOne, xTwo, xThree, xFour) ;
   
    if(i == 0){
        setInterval (function () {actionMenuLeave(xOne, xTwo, xThree, xFour, xTwoMove, xThreeMove, xFourMove, i)}, 10);
        }   
    }
Code: [Select]
function panelTransition (xOne, xTwo, xThree, xFour) {
        panelContext.clearRect (0,0,400,100);
       
        if (menu == 0) { //Main
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#A89058";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#AAAAFF";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#BBBBBB";
            panelContext.fillRect (300,0,400,(100*xFour));
            }
       
        if (menu == 1) { //Attack
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (300,0,400,(100*xFour));
            }
        if (menu == 2) { //Defense
            panelContext.fillStyle = "#A89058";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#A89058";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#A89058";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#A89058";
            panelContext.fillRect (300,0,400,(100*xFour));
            }
       
        if (menu == 3) { //Contigency
            panelContext.fillStyle = "#AAAAFF";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#AAAAFF";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#AAAAFF";
            panelContext.fillRect (300,0,400,(100*xFour));
            }
       
        if (menu == 4) { //Movement
            panelContext.fillStyle = "#BBBBBB";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#BBBBBB";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#BBBBBB";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#BBBBBB";
            panelContext.fillRect (300,0,400,(100*xFour));
            }
}

I know that at they're being called, so I assume that actionMenuLeave must be screwing up somehow. I checked for mistakes I had made before, and the only thing I haven't gotten to work in the past is setInterval. Am I doing something wrong with that command?
Logged
Pages: 1 ... 45 46 [47] 48 49 ... 91