ID:164873
 
Hey, i've seen alot of cool things out there such as projectiles going exactly the way the mouse was, strings that begin to stretch and then fling back and coil up with just a couple pixels used (not an animation), 3d engine games, and smooth walking, like he's moving one pixel each time.

If anyone can tell me how this kind of stuff is done, that would be great. Perhaps etc would be nice. I'm very fascinated by that sort of thing and would like to learn more. All helps, answers, advice would be nice, sincerely, Speedro.
Your asking for a lot, but I can sure send you in the right direction.

Search the libraries and demos for:

'pixel movement'
'pixel projectiles'
'3d maze engine'

a few examples of what your talking about should come up with the source codes. You can test them out and study how they are done.
That's all trigonometry, my friend :p
So, you can either learn it on your own, or wait until you get to it in school. There should be plenty of online examples about using sin, cos, tan, arcsin, arccos, and arctan.

Here's a few of the basics:
-All of the functions are based on the unit circle (circle with radius equal to 1)

The cos of an angle ("cos(angle)") is equal to the x value of the point at the end of the radius on the unit circle. (Note, angle will be represented from now on by θ (Greek letter theta)

The sin of an angle ("sin(θ)") is equal to the y value of the point at the end of the radius on the unit circle.


<font size=1>(Thanks Wikipedia for the image...)</font>


tan(θ) is equal to sin(θ)/cos(θ) (The slope of the line from the origin (center of circle) to the point (blue line))

Now, arcsin, arccos, and arctan are the inverse functions. What that means is, where sin(θ)=y, arcsin(y)=θ. This might not seem overly helpful in the case of sin and cos, but it is extremely important with arctan.

If tan(θ)=sin(θ)/cos(θ), then arctan(sin(θ)/cos(θ))=θ. And since we already know sin(θ)=y and cos(θ)=x, we can change the equation to arctan(y/x)=θ

It's from this equation that you originally get your angle from.

The rest I leave to you to find out :)

You can fairly easily find some source code for some of this, which might help your understanding. For example:

Isometric engine: http://developer.byond.com/hub/Jp/IsoEngine
That's a library (Written by me. PLUG PLUG PLUG) for drawing everything around you as an isometric map. It's actually just simple mathematics.

Pixel-by-pixel movement:
http://members.byond.com/Jp/files/JpGameInADay_src.zip
Also by me, but possibly not the best resource, because it was written for the Game-In-A-Day competition. Regardless, it contains a fairly robust and decently fast pixel-by-pixel movement engine that just overrides the basic movement procs.
In response to DarkCampainger
Ok, yeah, i'm looking up a 'trig' guide now.


EDIT: Ok, that's just not for me. Way too confusing. Ill wait till I get it in school... What grade do I get it in?
In response to Jp
Thank you very much, but I really don't catch on too easily with coding, but rather explained to me. Are there any simple challenges I could do working with this? Like perhaps a super simple idea of how to do it so I can build off of that until i'm ready to look over your pixel movement demo?
In response to Speedro
Depends where you live, around Grade 10 if I recall correctly for myself... I always found trig easy because of "SOH CAH TOA" :P

- GhostAnime
In response to GhostAnime
Ok, so basically another 2 years (unless i'm not counting this year). Gosh, that's a long time to be without the really cool things. I'm not the best in math, (always a B and hardley that) because I have trouble understanding alot of things. Once I get it though, i'm very good at math. This is probably the most retarded code i've ever made, but it prooves I at least tried to use sin and cos >_>
atom
Click(atom/O)
new/obj/string(null,usr,O.loc)
obj
string
New(_loc,mob/A,atom/location)
src.loc=A.loc
for(var/i=1,i<8,i++)
var/N=get_step(sin(A.dir),cos(location.loc))
new/obj/trail(N)
location=N
trail
icon='dot.dmi'
God, I really want those stretchy strings and stuff.
In response to Speedro
It's not a demo - it's a simple game I wrote for the game-in-a-day challenge, and as such, is quite likely a little interestingly written in places. I'm fairly sure that the pixel movement is robust, however (Although if you go too fast you can 'jump over' obstacles).

The way I did it for Deep Space Pirates was something like this:

- Give /atom a 'radius', 'px', and 'py' var.
- Give /atom/movable a 'vx' and 'vy' variable.
- Override /atom/movable/Move() so that it does the following:

- Takes two arguments - mx, and my.
- If mx is an object, do the default proc.
- Store src.px in an 'ox' variable, and src.py in an 'oy' variable.
- src.px+=mx, src.py+=my
- Work out which turf that pixel corresponds to using px>>5 and py>>5 (==px/32 and py/32, as long as they're absolute value is under 65535 and an integer. But it's much faster)
- Loop through all the turfs in a given range of this turf.
- Loop through all atom/movables in those turfs
- If the distance between that atom/movable and src is less then the sum of their radii, then they've collided. Call bump, and set src's px and py variables back to ox and oy, call Bump()
- Otherwise, set loc to locate(px>>5, py>>5, z), and pixel_x to px%32, and pixel_y to py%32.

That's the basics. That'll work well if everything you've got is roughly a circle. If they're not, you can get it working by giving atom/movables a function that returns a /circle datum (With centre and radius), or a list of /circle datums, and then you can check all the circles in both objects for a collision. That's a lot slower, though, but it won't matter if you won't have many things near you at once.

Be careful not to have src collide with itself!
In response to Speedro
I just went over to my friends house and my friends sisters soon-to-be husband was over and he's in university. Anyways, I got him to explain to me SOH CAH and TOA. So I got his help for about 2 hours and now that I know that SOH = S, Obtuse/Hypotenuse, etc etc. Anyways, I also learned about forcesgoing against it at different directions etc. How do I find the angles coming off of it? I know what they do now, but I don't know what to do with them to make it go the exact direction you clicked >_>