I need an example of a bump proc for a certain game I am making. The kind of example I am looking for is the kind where you bump an obj and it goes a certain distance. Please help me out if you can!
Thank you,
Jeff Talscor
ID:173308
Jan 23 2004, 1:34 am
|
|
In response to Madpeter
|
|
Thanks, but, that didn't work. It came up with 4 error messages which I didn't know how to fix. What I need is something like this:
obj/bump(o as obj) o(puck).loc = (*,* - 2,*) something like that, that actually tells what the obj is. Still, thanks for the coding anyway! Thank you, Jeff Talscor |
In response to TerminatorX13
|
|
mob//a mob
Bump(obj/WHATEVER/O) if(istype(O,/obj/Whatever) O.step(src.dir) else ..() |
In response to Airjoe
|
|
Airjoe wrote:
mob//a mob I am sorry but what does this actually do ?? |
In response to Madpeter
|
|
As usual, this should be handled by writing your own Bumped() proc. Follow along, now:
atom //Everything that you can place on the map is an atom (except for image objects) And that is your rather robust ball-kicking system. It also implements a movement delay system, because they're linked together rather importantly. Also, notice that I don't use usr anywhere there. That's because usr is not to be used outside of procs. Any errors in that code snippet I apologize for, and I hope someone will correct me. I've spent a while typing this up, so I expect a simple favor from you: If you don't understand ANY portion of this, ANY PORTION AT ALL, then you MUST ask me what it does. Do NOT use this if you do not understand ALL of it. This goes for anyone reading this, too. If ANYONE wants ANYTHING in here clarified, just ask.. Finally, I'll explain the parts that are rather confusing. newdir^=(NORTH|SOUTH) Now, I'm using ^=, which is a contraction. What it would read, if it were expanded, is this: newdir = newdir ^ ( NORTH | SOUTH ) Still doesn't make much sense though, so I'll explain. First of all, you must realize that all data is stored in binary format. 1's and 0's. It seems confusing, but it really isn't. With the decimal system, we start at 0, and when we reach 9, we add 1 to the next digit, and start back at 0. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, etc. Makes sense. Binary is the same, but instead of counting to 9 before adding 1 to the next digit, we only count to 1. So: 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1100, 1101, 1110, etc. Now, the operators: | is the binary OR operator. That means we take the number on the left, put it on top of the number on the right, and the result is a combination of the two, where for each digit that's 1, that same digit in the final answer will be one. So, 11010 | 01100 would be: 11010 01100 ----- 11110 Imagine the 1's being lasers shining down, and the 0's being darkness. Lasers on the bottom block lasers on the top, but darkness doesn't block the lasers. Silly analogy. Anyway, so now we have NORTH | SOUTH. Now, I'll point out how directions work. NORTH is 1, SOUTH is 2, EAST is 4, WEST is 8. 1, 10, 100, 1000 in binary. The other directions, NORTHWEST, SOUTHEAST, etc. are just a combination of the two cardinal directions. NORTHWEST is the same as NORTH | WEST. Specifically, it's 9, binary 1001. So, what is NORTH | SOUTH? It's 3. That's not a direction. How can you be facing both north and south at the same time? Still, it's important for our next step. newdir ^ (NORTH|SOUTH) ^ is the XOR, or EXCLUSIVE OR operator. It is similar to |. The difference, however, is that two 1's on top of each other cancel each other out. So, 11010 ^ 01100 would be: 11010 01100 ----- 10110 See the difference? Essentially, it acts like a switch. You take the first number, and for every 1 in the second number, you toggle that digit in the first number, for every 0, you leave that digit the same. So, 1^0 = 1, 0^1 = 1, 0^0 = 0, 1^1 = 0. So, what does that have to do with our invalid direction of NORTHSOUTH (3)? Well, 3 is binary 11. ^ will toggle the binary digit (bit is short for Binary digIT) whenever there is a 1. The dir var is 4 bits, WESN. If N is set, then it will be unset. Since both N and S won't be set under normal circumstances, that means S is unset, and will now be set. Essentially, we're swapping the north / south direction. Here's another confusing line: var/NSdir = (dir & (NORTH|SOUTH)) Looks similar, doesn't it? This time, instead of ^, we have &. Can you guess what & does? We already have an operator which takes either or both bits being 1, one that takes either but not both bits being 1, so logically, this one needs BOTH bits to be one. Essentially, what this line is doing is determining if we're moving north or south. We already know we're moving diagnolly, so we want to ditch the E and W bits (remember, NSEW). So, WESN & 0011: WESN 0011 ---- 00SN So, we're left with either 0001 (NORTH) or 0010 (SOUTH). We could be left with 0011 (NORTHSOUTH), but that would be in a weird case, and you would have to do it quite intentionally. And that covers the silly little bitwise operators I was using. I might add that there are two more commonly used bitwise operators: << and >>. Yes, the same things used for input/output. They have a simple purpose: A >> B shifts A's bits B spaces to the right, A << B shifts them to the left. These have the same effect as A / 2 ** B (** being the power operator, so 2 to the Bth power), and A * 2 ** B, respectively. The one difference is that when dividing, decimals get truncated. That means you lose the decimal. No rounding up because it's .5, it's just chopped off. Remember, if there's anything you don't understand, just ask. Don't use this code snippet if you don't get it what it does. Help me help you help everyone else. That is, help me by telling me you don't understand so I can help you understand so you don't make ignorant mistakes due to not understand it so that you help everyone else not have to deal with your problems which wouldn't be there if you understood your program in the beginning. Oh, and sorry for breaking the H-scroll. |
o.loc = locate(*,* - 2,*)
i think thats how its done but i dont use bump that much you will prob need to edit it a bit and add a check in (is new to byond to)