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 - Perdurabo

Pages: 1 ... 3 4 [5] 6 7
61
Programming / Re: Handling Transient Events and Effects: an example
« on: August 07, 2009, 12:08:50 AM »
I've created a video example of this code in action at:

http://kharne-rl.blogspot.com/2009/08/implementing-transient-events-example.html


62
Programming / Re: What this code is supposed to do?
« on: August 06, 2009, 12:43:55 PM »
Assuming the origin is at top left.

C is the cell bring checked. r is river tile, L is non-river tile (call it Land)

It checks for either of these cases:


     C r
     r L

     r L
     C r



and if found sets the Cell C to river

I think. My C is a tad rusty.

It looks as if it has been written to ensure rivers are more than 1 cell wide on the diagonal?

63
Programming / Handling Transient Events and Effects: an example
« on: August 06, 2009, 12:38:51 PM »
Hey all, I wrote the class before to handle transient effects (like drinking a potion of might) in Kharne. It was a pain to grasp and define the concepts, so I'm guessing others may have problems with it as well. Written in Delphi, but should compile in FPC/Lazarus as well without too many changes. (apart from defining an ICommonObject interface with a getstringvalue method of course)

Its in the public domain so knock yourself out with it.


unit UnitTimers;

interface

uses SysUtils;

{ Timer Handling

  A TGameTimer represents a transient event that has a duration.

  An example would be the side-effects of drinking a Potion of Might - it increases
  strength for a limited number of turns. We optionally define a number of procedure
  pointers to point to events that occur at the beginning and end of the duration,
  and also on every turn.

  For example, upon drinking a Potion of Might, the event might display a message
  stating you feel mighty (as well as increasing your strength). As the duration
  of the effects decrease, further messages will be displayed stating that the
  effects of the potion are wearing off, and then when the duration has expired,
  your strength reverts back to normal

  To implement this, use the follwing steps as a guide:

  1. Set up a variable:

  DrinkMightPotionEvent: TGameTimer;

  2. Define three events as follows:

  procedure MightPotionDrink(const Turns: Integer = 0);
  procedure MightPotionTick(const Turns: Integer = 0);
  procedure MightPotionEnd(const Turns: Integer = 0);

  procedure MightPotionDrink(const Turns: Integer);
  begin
    DisplayMessage('You feel mighty!');
    Player.Strength := Player.Strength + 10;
  end;

  procedure MightPotionTick(const Turns: Integer);
  begin
    if (DrinkMightPotionEvent.Progress = 50) then
      DisplayMessage('The effects are wearing off!');
    Player.Strength := Player.Strength - 5;
  end;

  procedure MightPotionEnd(const Turns: Integer);
  begin
    DisplayMessage('You no longer feel so mighty!');
    Player.Strength := Player.Strength - 5;
  end;

  3. Instantiate the event:

  DrinkMightPotionEvent := TGameTimer.Create(timMight,
                                             DURATION_MIGHT_POTION,
                                             MightPotionTick,
                                             MightPotionDrink,
                                             MightPotionEnd);

  4. Then, on every turn that passes, simply call

     if (Assigned(DrinkMightPotionEvent)) then DrinkMightPotionEvent.Tick;

   }
   

{ Define the types of timers as an enum for simplicity }
type TGameTimerType = (timSpeed,
                         timConfusion,
                       timBlindness,
                       timSeeInvisible,
                       timParalysis,
                       timFreeAction,
                       timCombatMastery,
                       timReflexes,
                       timMight);

{ Procedure Pointer for Event Hook }      
type TGameTimerEvent = procedure(const Turns: Integer = 0);

{ Class Definition - it inherits the ICommonObject interface to gain access
  to the StringValue method to allow easy persistance }
type TGameTimer = class(ICommonObject)
private
  FTimerType: TGameTimerType;              // Timer Type, from the enum previously defined
  FTimerDuration: Integer;              // Starting Duration, in turns
  FTimerDurationLeft: Integer;            // Duration Left, in turns
  FTimerTickEvent: TGameTimerEvent;     // Optional Event to call on each decrement
  FTimerStartEvent: TGameTimerEvent;    // Optional Event to call on starting the timer
  FTimerEndEvent: TGameTimerEvent;      // Optional Event to call on ending the timer (i.e. turns left = 0)
 
  { Private functions to support class properties defined below }
  function GetStatus: Boolean;
  function GetProgress: Integer;
public

  { Standard Constructor }
  constructor Create(TimerType: TGameTimerType;
                     TimerDuration: Integer;
                     TimerTickEvent: TGameTimerEvent = nil;
                     TimerStartEvent: TGameTimerEvent = nil;
                     TimerEndEvent: TGameTimerEvent = nil);
                   
  { Decrement the Timer by one turn. Will return true if the timer has not expired }
  function Tick: Boolean;
 
  { Interface Method for Persistance }
  function GetStringValue: String;
 
  { Properties }
  property TimerType: TGameTimerType read FTimerType;      // Return the enum
  property TimerDuration: Integer read FTimerDurationLeft; // Number of Turns left
  property TimerProgress: Integer read GetProgress;        // Number of Turns left as a percantage (0-100) of the original duration
  property Active: Boolean read GetStatus;                 // True if Number of Turns left is > 0
end;

implementation

{ Standard Constructor - this is deliberately the only way to set up the duration etc }
constructor TGameTimer.Create(TimerType: TGameTimerType;
                              TimerDuration: Integer;
                              TimerTickEvent: TGameTimerEvent;
                              TimerStartEvent: TGameTimerEvent;
                                TimerEndEvent: TGameTimerEvent);
begin
  { Load the private member data }
  FTimerType := TimerType;
  FTimerDuration := TimerDuration;
  FTimerDurationLeft := TimerDuration;
  FTimerTickEvent := TimerTickEvent;
  FTimerStartEvent := TimerStartEvent;
  FTimerEndEvent := TimerEndEvent;

  { If we have a start event defined then execute it now }
  if (Assigned(FTimerStartEvent)) then
    FTimerStartEvent(FTimerDurationLeft);
end;

{ Return true if the timer hasn't expired }
function TGameTimer.GetStatus: Boolean;
begin
  Result := FTimerDurationLeft > 0;
end;

{ Decrease the duration of the timer by a turn }
function TGameTimer.Tick: Boolean;
begin
  Dec(FTimerDurationLeft);

  { Trigger events if they are defined }
  if (FTimerDurationLeft > 0) then
  begin
    { Interval Event }
    if (Assigned(FTimerTickEvent)) then
      FTimerTickEvent(FTimerDurationLeft);
  end
  else if (FTimerDurationLeft = 0) then
  begin
    { End Event }
    if (Assigned(FTimerEndEvent)) then
      FTimerEndEvent(FTimerDurationLeft);
  end;

  { Return true if the Timer is still active }
  Result := GetStatus;
end;

{ Returns the number of Turns left as a percantage (0-100) of the original duration }
function TGameTimer.GetProgress: Integer;
var
  Percentage: Double;
begin
  Percentage := FTimerDurationLeft / FTimerDuration;
  Result := Trunc(Percentage * 100);
end;

{ Get the Timer as a String }
function TGameTimer.GetStringValue: String;
begin
  { TODO: We will need to extend this to allow hashing of the attached procedures }
  Result := Format('%d%d', [Ord(FTimerType), FTimerDuration]);
end;

end.



Here's a noddy Delphi app (with two buttons and a memo on a form) as an example:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UnitTimers, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    Event: TGameTimer;

  public
    { Public declarations }
  end;

procedure EventStart(const Turns: Integer = 0);
procedure EventTick(const Turns: Integer = 0);
procedure EventEnd(const Turns: Integer = 0);

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure EventEnd(const Turns: Integer);
begin
  Form1.Memo1.Lines.Add('End ' + IntToStr(Turns) + ' Turns Left');
end;

procedure EventStart(const Turns: Integer);
begin
  Form1.Memo1.Lines.Add('Start ' + IntToStr(Turns) + ' Turns Left');
end;

procedure EventTick(const Turns: Integer);
begin
  Form1.Memo1.Lines.Add('Tick ' + IntToStr(Turns) + ' Turns Left');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Event := TGameTimer.Create(timSpeed,
                             20,
                             EventTick,
                             EventStart,
                             EventEnd);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if (Assigned(Event)) then Event.Tick;
end;

end.



64
Programming / Re: What this code is supposed to do?
« on: August 06, 2009, 08:41:49 AM »
At first glance, it looks like some sort of smoothing function, to fill in additional river tiles?

At second glance, its atrociously written and gives me a headache just looking at it.

65
Programming / Re: Handling item properties
« on: August 04, 2009, 09:34:52 AM »
Yeah, keeping it simpler is the way to go.

In Kharne, I have a TItem class, and Weapons are just a particular instance of TItem (with the member field FItemType set to 'iWeapon'). Where I differ slightly is that Magical Items have a number of instances of a class known as TItemEnchantment, attached to them. It is these that give them their properties.

For example, a Long Sword [+1,0] has a TItemEnchantment that gives a +1 to hit. A Long Sword [+1, +1] has two Enchantments, one the +1 to hit, and another that gives +1 to damage. A Long Sword [+1, +1] of Fire Resistance has, yes, a third enchantment as well, one that gives Fire Resistance. And so on. Each enchantment has a magnitude as well (which is dependent upon the level of the item). If an item is cursed, then these enchantment magnitudes are reversed.

Different tiers of magical items have different numbers and sizes of enchantments (yes, I completely ripped that off from WoW), and certain magical item types are predisposed to certain enchantments.

The Enchantment details are stored in a table in an SQLLite Database, and stored in a master list of TItemEnchantments, which I merely need to set up pointers to for the items. Both TItem and TItemEnchantment have common interfaces for producing a unique string value that can be saved to disk to represent uniquely the combination of Item and Enchantment.


66
Off-topic (Locked) / Re: Steps to create your own Roguelike
« on: August 04, 2009, 09:18:34 AM »
As others have said, Pascal is a fine language to code a roguelike in. I'm using Delphi for my own roguelike, but FreePascal/Lazarus is just tickety-boo as well.

67
Programming / Re: Kharne Alpha 1 Available
« on: July 29, 2009, 09:43:57 PM »
v0.03b is now available from http://kharne-rl.blogspot.com/2009/07/kharne-003b-available.html

Or directly from: http://sites.google.com/site/kharneroguelike/Kharne003b.zip

Another version mainly consisting of bugfixes, the changes are as follows:

* Ranged Combat now works again.
* More monsters now have actions and speech.
* Using stairs now requires < and > instead of , and ;
* The particular set of stairs taken to go down and up levels in the dungeon are now remembered.
* The standard 0 and 5 keys now allow resting as well.
* Keyboard commands that previously were only responsive to capital letters (e.g. 'S') now work with lower-case letters as well (e.g. 's').
* Font size and typeface have been made consistent across all the main window interfaces.
* The Status Bar has been redesigned.
* Attributes are no longer displayed on the Status Bar.
* There is now a short pause after death and before the Character Summary is displayed.
* Skills that are 100% progressed to the next skill level no longer have their progress indicators clipped.
* Artifact Names are now prefixed correctly whilst unidentified.

Best,
P.

68
Programming / Re: Kharne Alpha 1 Available
« on: July 27, 2009, 06:47:24 PM »
0.03 is out:

http://kharne-rl.blogspot.com/2009/07/kharne-003a-available.html

Changes in this version are:

    * Fixed the crash that occurs sometimes in character creation (hopefully!).
    * The Main Window no longer accepts keyboard input when it is not active (for example, if the character creation window is active).
    * The cursor is now positioned correctly when the main window is maximised.
    * Non-magical items no longer have extraneous item descriptions (e.g. bloodstained, gashed, rusted or corroded).
    * Monster speech is now coloured white in the Message Log.
    * The Quit (Suicide) menu option now works.
    * It is no longer possible to cause an error by pressing random keys whilst in the Hi Scores screen.
    * Fixed an error that could occur when entering a level where no unique is present. As a result the "You feel a brooding presence..." message that displays whenever a unique is present on the level is no longer displayed.
    * Starting a new game after finishing an old one will now clear the Message Log properly.
    * A Welcome Message is displayed in the Message Log when you start or continue a game.
    * The Player score calculated on the Farewell screen and the Player Score recorded in the hi-score table are now the same.
    * Monsters listed as cause of death in the hiscore table are now prefixed properly.
    * Removed the Show Inventory option on the Death Hiscore screen (Inventory Details can be viewed via the character dump opption instead).

69
Programming / Re: Kharne Alpha 1 Available
« on: July 25, 2009, 10:34:22 PM »
Very good improvements, and I'm happy that you got rid of the toolbar. It looks way better without. However, I very often get access violations after character creation (both in full and quick mode); I tried 8 times to play a human knight or warrior, but it did not work. I then had success starting a game with a half-orc mage.

Edit: And you should not use , and . to use portals and stairs ... it is confusing that < and > do not work on my QWERTZ keyboard.

Edit 2: Try to make consistent item names. "Rusted Silk Pantaloons" seem somehow strange ;-) LambdaRogue once had such random item name modifiers, but I removed it, because people got confused. Now I understand why.

Edit 3: When i died, I could neither press 'i' nor 'I' to view my inventory a last time.

Cheers Mario, I'm going to release a version as soon as I can, with those fixes

70
Programming / Re: Kharne Alpha 1 Available
« on: July 23, 2009, 11:11:44 PM »
Alpha 0.03 now available.

Get it at http://sites.google.com/site/kharneroguelike/Kharne003.zip

Full change log is at http://kharne-rl.blogspot.com/2009/07/kharne-003-available.html, but to summarise:

New Front End
Uniques
Monsters can wield items.
Hi-Scores
New Wizard Console
Many Atmospheric Touches added
Combat Balancing.

71
Programming / Things monsters would say!
« on: July 21, 2009, 07:15:54 PM »
As the title says, "Things monsters would say". Let's get our creative juices flowing and let's make our dungeons more atmospheric and our monsters more realistic!

I'll start with a few:

"I want to stab you in the head"
"You'll make a tasty stew"
"mine! all mine!"
"I won't let you steal my treasure!"
"I'll stick you full of arrows like a porcupine"
"shinies!"

72
Programming / Re: Kharne Alpha 1 Available
« on: July 08, 2009, 09:03:51 PM »
Finally got a v0.02c out the door. Get it at http://sites.google.com/site/kharneroguelike/Kharne002c.zip

Not a biggie in terms of changes (that will be the next few version), but it's nice to get something out (its been a while since the last release)

Changes:


- Gold is now automatically picked up.
- Varying Radius FoV has been implemented - randarts with the 'alertness' property can increase and decrease (if cursed) the radius of the FoV.
- Moving the mouse over a creature or item in the dungeon now displays pertinent information on the main screen.
- Food found in the dungeon is no longer flagged as unidentified.
- Fountains that have been drunk from cannot be drunk from again.
- The player avatar ('@') is now transparent.
- The main menu has been given a graphical overhaul.

73
Programming / Re: Kharne Alpha 1 Available
« on: May 03, 2009, 08:57:00 PM »
v0.02b is now available.

See http://kharne-rl.blogspot.com/ for version information.

The direct download link is http://rapidshare.com/files/228826277/Kharne002b.zip

This is mainly a refactoring and bugfix version, with the only major change being the introductions of fountains found throughout most of the dungeons. The next version will be a big release with the implementation of proper ranged combat (complete with ammunition)

74
Programming / Re: Kharne Alpha 1 Available
« on: April 20, 2009, 10:26:12 PM »
A bugfix for 0.02, conveniently called 0.02a is now available at:

http://kharne-rl.blogspot.com/2009/04/kharne-002a-available.html

or directly via http://rapidshare.com/files/223762778/Kharne002a.zip

Fixes are:

    * Item Anonymity and Identification has now been implemented (wear/wield an item to identify)
    * Item stacking now works properly.
    * Eating stacked food now only consumes one of the stack.
    * Defense Skill is now listed properly in the Skill Screen.
    * Food is now listed in the inventory in one colour. It remains colourful on the dungeon floor.
    * The font size of the message window has been reduced.
    * Wands are temporarily no longer generated in the dungeons (it makes no sense for them to be there whilst their functionality has not yet been implemented).
    * The Inventory Screen has been redesigned slightly

75
Programming / Re: Kharne Alpha 1 Available
« on: April 18, 2009, 10:18:43 PM »
v0.02 of Kharne is now available via http://kharne-rl.blogspot.com or direct via http://rapidshare.com/files/222990944/Kharne002.zip

Here are the changes over the previous version (0.01e):

* Dungeon Levels are now persistent within each Branch - exiting a Branch entirely will generate new levels.
* Food & Hunger have been implemented. Whilst starving, HP and MP do not regenerate naturally.
* Ranged Combat has now been implemented (left click on a monster to fire a projectile at it - for now, ammunition is infinite).
* The amount of HP and MP that characters gain on level up is now also dependent upon Fighting and Magic Skill levels.
* Added a Wizard Mode (accessible by pressing W)
* Monsters can no longer be generated in the walls of Vaults.
* Monster HP and Damage has been rebalanced.
* The XP required to gain a level has been increased substantially.
* Level Feelings are no longer immediately generated if you have recently navigated more than one set of stairs.
* Reduced the amount of gold that is generated.
* The elapsed game time (in real terms) is now displayed at the top of the Main Game Window. This pauses whenever the Inventory or any other subscreen is shown.
* Character Dumps now display the correct version number.
* Character Dumps now show the elapsed game time (in real terms).
* Digging now updates the visible areas of the dungeon correctly..
* Turns elapsed is now displayed in a more appropriate colour.
* Fixed a few minor grammatical errors in the Combat Text.

Best,
P.

Pages: 1 ... 3 4 [5] 6 7