Simple Bitwise Elemental System

After learning to use the shift operators correctly, I've thought up of a way to do a very simple element system with using bitwise operations.

This is how the system goes:
Fire>Wood>Elec>Water>Fire

#define FIRE  8//1000
#define WOOD  4//0100
#define ELEC  2//0010
#define WATER 1//0001

proc/strength_of(element) 
     return ((element<=1)? (element >> 1) : (8))

proc/weakness_of(element)
     return ((element>=8)? (element << 1) : (1))

Hope the parenthesis didn't bother you, I've formed a habit of enclosing all kinds of expressions in parenthesis even if it would do the same without.

Constructive comments/suggestions are appreciated.(I wonder if there is a way to work around the fact that shifting WATER to the left will make it 0.

Posted by Kakashi24142 on Saturday, July 12, 2008 03:06PM - 0 comments / Members say: yea +0, nay -0

Overlays

The reason I'm writing this blog post is to help out people who are in the dark on how to handle overlays well. (I've been asked what's the problem in someone's code when it involves adding an icon to the overlays and it's been quite annoying since I've had to repeat myself to various people about it.)

Well here it goes, most of this stuff is copy/pasted from my Megaman source and I commented out the lines so it'll make it easier to understand and modify for you own purpose.

Overlay code:
//This is defined for atom/movable, but it could be changed based on what you need it for.
atom/movable

    //The Overlays list, that will have our overlays in readable datums.
    var/list/Overlays
    
    proc
    
        //This proc only accepts only /image arguments 
        overlayAdd()
            
            //Checks if the list is initialized, and if not, the list gets initialized
            if(!Overlays)Overlays=new
            
            //Loops through all the /image objects in the arguments
            for(var/image/I in args)
                //Adds each one to the Overlays list
                Overlays.Add(I)
                
            //Call the update proc
            overlayUpdate()

        //All the arguments can either be text strings 
        //that correspond to the tag on a /image object in the Overlays list
        //or /image objects that are equivalent to objects already existing in the list.
        overlayRem()
        
            //Loops through the arguments
            for(var/o in args)
                //Checks to make sure there's something in the Overlays list
                if(Overlays && Overlays.len)
                    //Variable I that is of type /image
                    var/image/I
                    //The following if checks if the argument is a tag,
                    //and if so, it will use locate() to retrieve an image with that tag.
                    if(istext(o))
                        I=locate(o)
                    
                    //The following else if checks if the argument is an image
                    //and if so it set's I equal to the argument
                    else if(istype(o,/image))
                        I=o
                    
                    //Removes I from the Overlays list and checks if the Overlays list should
                    //be cleaned up.
                    Overlays.Remove(I)
                    if(!Overlays.len)Overlays=null
                    
                else
                    //Breaks if there is nothing in the Overlays list to remove
                    break
                    
            //Call the update proc
            overlayUpdate()

        //This proc should be called whenever the Overlays list is updated,
        //or if anything inside the Overlays list is updated.
        overlayUpdate()
        
            //Nulls overlays list
            overlays=null
            
            //Searches for all the /image objects in the Overlays list,
            //and adds it to the overlays list.
            for(var/image/I in Overlays)
                overlays.Add(I)

//This proc is pretty self-explanatory, it returns a /image given certain arguments
proc/Image(icon/icon,icon_state,atom/loc,pixel_x=0,pixel_y=0,layer=FLY_LAYER,tag)
    var/image/I=new
    I.icon=icon
    I.icon_state=icon_state
    I.loc=loc
    I.pixel_x=pixel_x
    I.pixel_y=pixel_y
    I.layer=layer
    I.tag=tag
    return I


Some simple examples of use:
overlayAdd(Image('sword.dmi'))
//with icon_state
overlayAdd(Image('sword.dmi',"wield"))


This method of handling overlays is foolproof and works every time given that you use it correctly. (It has worked for me every time, but this code is altered from the actual code I use in my game, so it'd be great if someone tested it and let me know if it works well.)

Posted by Kakashi24142 on Saturday, July 05, 2008 06:36AM - 6 comments / Members say: yea +1, nay -0
(Edited on Friday, July 11, 2008 08:46AM)

Kakashi's Programming Challenge #1

This guild has been close to dead for about a few weeks now and I want to liven up a little bit. To start, I will try to have a programming challenge ready for you guys every month, just for fun. The winner will appear in this guild's "Wall of Fame" and there can be up to 2 winners per challenge. I will try to make them harder and harder every week. You may send entries to kakashi24142@hotmail.com (that's also my MSN)

The winners will the programmers who have the most efficient and readable code. There is no size limit.
(I won't have time on weekdays to check over entries.) You may NOT use libraries or demos. (On special challenges, I will allow them.) I can tell if you copy/pasted so don't bother. (It is very easy to tell programming styles apart.)

Now with the introduction set aside, I present you my first challenge:

---------
KPC#1
---------

Make a Minimap that can appear on the screen, browser, a pop-up window, or in some interface control that can adjust to any size specified by the programmer who uses it through arguments.

The Minimap should be able to display the entire world or a certain range.

What you can't do:
-Use libraries/demos.
-Have another programmer program it for you. (I would laugh to death if anyone does this.)

What you can do:
-Learn how minimaps can be displayed from current libraries or think of your own way of displaying them.

*Please let me know if you're going to submit an entry. (Just post a comment/IM me/Email me.)

All submissions due by: Sunday, June 1, 2008. (Just get them in before 12:00 AM of the next day.)

Prize:?
If I really am impressed, I might possibly buy someone a membership or pay in cash (for those who are already members and don't care to renew it right now).
---------

On a side note, if anyone is good with CSS, I would really appreciate help redesigning this guild since the guild looks somewhat like crap compared to the others.

Posted by Kakashi24142 on Tuesday, May 20, 2008 02:11PM - 20 comments / Members say: yea +1, nay -0

Preview of K_Dialogue

Hello everyone, it's been quite sometime since I've made my last blog post, but I'm still here! And I've been working on a library called K_Dialogue and here's a preview of what it is capable of:





NOTE: Don't mind the cut-off part of the y's, the icon that has all the letters is messed up, I will fix it by the time of release.

For both of those, I used mugshots from MMBN 6 Gregar to use as an example. The dialogue they say is completely made up by me to also use as an example.

K_Dialogue currently features:
-Musgshots(Size: 32x32)
-Text printed on the screen
-If a word is much too long to fit on a line the Dialogoue/Print() proc will crash.
-Basic chat box for the background.
-Heavily commented code so that you can understand how it works.
-When a long string is passed as an argument the same type of thing that occurs in GBA games occurs here, the previous text is erased and the remaining text is printed (if there is still remaining text after that it will go on until there is no more remaining text.)

Will soon feature:
-Customizable size of the chat box( although it already adjusts to the screen based on the value of client.view and already checks for that too).
-Bigger Mugshot size(possibly, I have to think about this.)
-A command that trigger the access to the next part of the string rather than having it automatically be done.(Waits for user input.)

Libraries to anticipate:
-K_Administration
-K_Artificial_Intelligence
-K_Minimap(this is a maybe, this minimap is supposed to be in the browser, but I need to work things out)
-K_Server_Control-Allows complete control of all the servers of a certain game. (Obviously, only the servers of your game.)
-K_Map_Handler(This is a big iffy, I might or might not do this based on my mood.)

Posted by Kakashi24142 on Friday, April 18, 2008 09:24AM - 12 comments / Members say: yea +0, nay -0

New Libraries!

Hello everyone! I have released two new libraries:
K_Pixel_Movement:
-This library focuses on efficient and smooth pixel movement.(I added a few lines of code so that the camera follows each movement, this only works for users with BYOND v4.0 Build 413+). Not only does this library support movement, it also supports collision. I used Rectangle Box Collision for the type of collision as opposed to the Circular Collision(in which you compare the radii and distance).
K_Network_Save:
-This library allows you to save players' savefiles on a remote server and with you making a few modifications. It also supports loading and deleting savefiles on that server.

If there are any bugs please either leave comments on this post or post in the guild forums or contact me on MSN at kakashi24142@hotmail.com

Posted by Kakashi24142 on Saturday, March 29, 2008 11:24AM - 2 comments / Members say: yea +0, nay -0

Kakashi24142

Joined: Apr 05, 07

Home page Email

Anime Fan and Programmer

Blog Calendar

September 2008
Su Mo Tu We Th Fr Sa
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
 
«Aug