Physics Engine

By BlueThen on Mar 24, 2008

A very simple physics engine I made in a hour or two. It's not really... accurate, but it has gravity and friction, and you can throw the ball around too. ;o

To install, paste this code into your Remotes (Alt + R)
then type /phys or right click a channel or status window and click "Physics Engine."
Use your mouse to throw the ball around if you like.

Updates:
Fixed the "drawdot error" when closing.
Lowered the hang time a bit.
Now unsets all the variables.

;mIRC Physics Engine 1.03
;Made by BlueThen on March 24, 2008.
;To install, paste this code into your Remotes (Alt + R)
;then type /phys or right click a channel or status window and click "Physics Engine."
;BlueThen.com for more mIRC scripts and snippets!
menu channel,status {
  Physics Engine: {
    phys
  }
}
alias phys {
  window -poCzdk0 +tnbL @Phys1 -1 -1 400 400
  window -poChzdk0 +tnbL @buffer -1 -1 800 800
  %phys.e = n
  phys.spawn
  phys.loop
}
alias -l phys.loop {
  if (%phys.h = 0) {
    if ((%phys.y < 750) && (%phys.d == d)) {
      inc %phys.y %phys.d.v
      %phys.d.v = $calc(%phys.d.v * 1.2)
    }
    if ((%phys.y > 750) && (%phys.d == d)) {
      %phys.d = u
      %phys.d.v = $calc(%phys.d.v * 0.78)
    }
    if ((%phys.d = u) && (%phys.d.v > 2)) {
      dec %phys.y %phys.d.v
      %phys.d.v = $calc(%phys.d.v * 0.7)
    }
    if ((%phys.d = u) && (%phys.d.v < 2)) {
      %phys.d = d
      %phys.d.v = 2
    }
    if (%phys.y < 50) {
      %phys.d = d
    }
    if (%phys.s.v > 0.05) && (%phys.s == r) {
      dec %phys.x %phys.s.v
      %phys.s.v = $calc(%phys.s.v * 0.95)
    }
    if (%phys.s.v > 0.05) && (%phys.s == l) {
      inc %phys.x %phys.s.v
      %phys.s.v = $calc(%phys.s.v * 0.95)
    }
    if (%phys.x > 750) {
      %phys.s = r
    }
    if (%phys.x < 50) {
      %phys.s = l
    }
  }
  else {
    %phys.y = $calc(2*$mouse.y)
    %phys.x = $calc(2*$mouse.x)
  }
  if (%phys.e != y) {
    drawdot @buffer 15 20 %phys.x %phys.y
    drawtext @buffer 12 Tahoma 30 20 25 Made By BlueThen
    drawtext @buffer 12 Tahoma 30 20 55 BlueThen.com
    drawcopy -m @buffer 0 0 800 800 @phys1 0 0 400 400
    clear @buffer
    .timer -ho 1 0 phys.loop
  }
}
alias -l phys.spawn {
  %phys.h = 0
  %phys.d = d
  %phys.d.v = 1
  %phys.x = 400
  %phys.y = 400
  drawdot @buffer 15 20 400 400
}
menu @phys1 {
  sclick: {
    %phys.h = 1
    %phys.x = $calc(2*$mouse.x)
    %phys.y = $calc(2*$mouse.y)
  }
  uclick: {
    %phys.d.v = $calc(4*%phys.m.y.s)
    %phys.d = %phys.m.y.d
    %phys.h = 0
    %phys.s.v = $calc(3*%phys.m.x.s)
    %phys.s = %phys.m.x.d
  }
  leave: {
    if (%phys.h == 1) {
      %phys.h = 0
    }
    %phys.l = y
  }
  mouse: {
    if (%phys.l = y) {
      %phys.l = n
    }
    if ($mouse.y > %phys.m.y) {
      %phys.m.y.d = d
    }
    else {
      %phys.m.y.d = u
    }
    if ($mouse.x > %phys.m.x) {
      %phys.m.x.d = l
    }
    else {
      %phys.m.x.d = r
    }
    %phys.m.x.s = $abs($calc($mouse.x - %phys.m.x))
    %phys.m.y.s = $abs($calc($mouse.y - %phys.m.y))
    %phys.m.x = $mouse.x
    %phys.m.y = $mouse.y
  }
}
on *:close:@phys1: {
  %phys.e = y
  window -c @buffer
  unset %phys.h %phys.d %phys.d.v %phys.x %phys.y %phys.m.y.d %phys.m.x.d %phys.m.x.s %phys.m.y.s %phys.m.x %phys.m.y %phys.s.v %phys.s %phys.l
}

Comments

Sign in to comment.
Mitchell   -  Apr 28, 2008

very nice script :)
just wondering, but why are the backgrounds of all your scripts appearing white for me?

 Respond  
guest598594   -  Apr 02, 2008

Well gravitational acceleration = 9.8 m/s2, I don\'t know if that helps at all :p

 Respond  
BlueThen   -  Apr 01, 2008

Thanks. :D It\'s sort of hard to make it realistic, since I barely even know anything about gravity or friction. Maybe I\'ll do some research and make it exact next time.

 Respond  
Phoenix847   -  Apr 01, 2008

Wow, 13 and you\'re making all these scripts?! Dang kid, this is career you might wanna take with all the scripting like I am. I\'m not as good as you with scripting but I know some basics.

But yeah, I like it. The physics of the ball does look a little weird. It seems to drop just quickly after moving a short distance and it does seem a little rough on the moving but doesn\'t matter. Just try to fix it up a bit on the ball dropping quickly and thats all.
9/10 :]

 Respond  
BlueThen   -  Mar 25, 2008

The buffer box should be hidden (you\'d need 6.21 or higher for that to work), and for such a complicated script, there was no other way to make it work without variables, unless I were to use Hash Tables or INI files.

I tried to make the ball move as realisticly and smoothly as possible, but it was difficult, since I\'m only 13 years old, and I have a basic understanding of physics. :/

 Respond  
Eugenio   -  Mar 25, 2008

This is annoying....the ball moves weird....and I hate that silly buffer box at the bottom. Why so Many variables ?!?

 Respond  
Eugenio   -  Mar 25, 2008

This is annoying....the ball moves weird....and I hate that silly buffer box at the bottom.

 Respond  
Gummo   -  Mar 25, 2008

Nice work. :)

 Respond  
BlueThen   -  Mar 24, 2008

Ok, fixed.

 Respond  
guest598594   -  Mar 24, 2008

When I x out, I get:

* /drawdot: invalid window (line 58, script83.mrc)
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.