Should I be proud of this code?

Started by MiteWiseacreLives!, Wed 16/01/2013 07:49:33

Previous topic - Next topic

MiteWiseacreLives!

Code: ags
So it's a little late and my wife is asleep, so I have no one to tell.. I don't think she'd appreciate it like I do anyways.
I wrote a bit of code to place a wig on my character's head, regardless of where he is in the room or which room. And the real treat: it takes into acount character size (scaling) AND scales the wig accordingly. I [b]didn't[/b] even post my problem and let someone else tell me how to do it :-D
Am I a loser? I was pretty excited when I got it to work...

[spoiler]
[code/]
function cKarrsen_UseInv()
{
  if (cKarrsen.ActiveInventory == iEWig)
  {
  R_Scale = cKarrsen.Scaling;
  cKarrsen.LockViewFrame(9, 0, 3);
  Current_Room = cKarrsen.Room ;
  cWig.ChangeRoom( (Current_Room), (cKarrsen.x + 0), ( (cKarrsen.y) - ((74 * R_Scale) / 100 ))  );
  cWig.Scaling = ( (170 * R_Scale) /100);
  cWig.Baseline = 400;
  cWig.Transparency = 0;
  Wait(40);
  cKarrsen.Animate(0, 4, eOnce, eBlock);
  
  cWig.Transparency = 100;
  cKarrsen.UnlockView();
  }
}

[/spoiler]

I'm a loser... but did I do it right? I only hope some other amatuers get happy like me  :~(

Gilbert

I think it's quite nice. Haven't read deeply into the codes (clearly some of the brackets in expressions can be ditched but that's no big deal) but I suppose those values 74 and 170, etc. are related to the dimension of the wig sprite or something, so you can also change them to using the width, height, etc. properties of sprites to make the codes more flexible.

One thing that may cause minor graphical glitch, is the baseline part, that by setting it to 400 you want to put the wig always in front of the character, right? But when there are other characters, objects or walk behind areas that lies in between the wig and the character it may look a bit funny. You may try to compute this baseline such that the wig is just "slightly in front of" the character to remedy this issue.

Crimson Wizard

If you know the relative position of the wig, you may create a set of dynamic sprites for each animation frame of the character view.
The benefit would be that you won't have to worry about scaling, transparency, tinting, and baselines.
The drawback would be an increase in memory usage. But, hey, it would be like a Skins system for your character!

MiteWiseacreLives!

Sounds like I have to do some research on dynamic sprites, haven't used them yet, sounds like the way to go.
Iceboty. Thanks man, I took your suggestion and worked in a line to put the baseline 1 pixel below the Char's.
Having lots of fun (obsessive strange fun) working on this game, all the help here is terrific!

SMF spam blocked by CleanTalk