Author Topic: Physics Lessons  (Read 51179 times)

0 Members and 1 Guest are viewing this topic.

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Physics Lessons
« Reply #90 on: July 08, 2011, 07:54:20 pm »
But the matrix part is what's confusing me.  What purpose does it serve?
Vy'o'us pleorsdti thl'e gjaemue

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Physics Lessons
« Reply #91 on: July 08, 2011, 07:56:23 pm »
I think it's just the pointer to the tilemap.
« Last Edit: July 08, 2011, 07:56:42 pm by squidgetx »

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Physics Lessons
« Reply #92 on: July 08, 2011, 07:58:31 pm »
Ok, so what this does is it computes what square the (x,y) is inside of, then compares it to a sprite to see if that one bit is true? 
...in one line? O.O wow
« Last Edit: July 08, 2011, 08:07:58 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Physics Lessons
« Reply #93 on: July 08, 2011, 08:08:02 pm »
Wait, Builderboy might've messed something up...let me give my (i think) fixed code with explanation
Code: [Select]
 

{{r2/8*W+   // get tile row, multiply by width
(r1/8)+   //get tile column
L1}*8+  // now we have the value of the tile you are in, then multiply by 8 because 8 bytes per sprite
(r2^8)+      //get pixel row # with respect to the tile you are in
Str1}    //we add this to the pointer to the mask table, thus returning the exact byte of the sprite mask
e r1    // and now we check if the appropriate pixel is lit or not in the given row
Return

Where r1 is your X position, r2 is your Y position, W is the width of your tilemap (in tiles), L1 is the location of your matrix data buffer, and Str1 is the start of your Mask Sprite table.

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Physics Lessons
« Reply #94 on: July 08, 2011, 08:38:27 pm »
So, he put the *W in the wrong place?

Anyway, what I'm trying to do with this (and am not too sure how to implement) is detect an object that moves by 1,2,4, or 8 pixels every frame.  Would I have to make multiple sprites or something?
Vy'o'us pleorsdti thl'e gjaemue

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Physics Lessons
« Reply #95 on: July 08, 2011, 10:59:22 pm »
No, he forgot to multiply the tile value by eight.

You would not need multiple sprites, I don't think, just run a loop like any other variable velocity physics engine and use that piece of code for collision checks.

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Physics Lessons
« Reply #96 on: July 09, 2011, 12:22:09 am »
Ok I'm kind of new to this physics stuff :P

What would the loop do, and where would it go? (I'm guessing just before the line above but you never know)
Vy'o'us pleorsdti thl'e gjaemue

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Physics Lessons
« Reply #97 on: July 09, 2011, 01:13:15 am »
So you're using 4x4 tiles. That's kind of a problem because your character can move at max 8 pix/frame, which means we can't simply move it back when it moves into a tile.
I would go with a for loop from 0 to the velocity, in which for each iteration you add one to your positional value, check it with the map, then if it's empty, keep going, and if it's occupied, move it back and stop the loop.
That's horribly inefficient, so I suggest going at max 1px/frame or if you really want to 3 px/frame with your 4x4 tiles.
In-progress: Graviter (...)

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Physics Lessons
« Reply #98 on: July 09, 2011, 01:18:14 am »
What I'm planning on doing after ds is 8*8 ;)
« Last Edit: July 09, 2011, 01:18:24 am by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Physics Lessons
« Reply #99 on: July 09, 2011, 02:08:10 am »
Hm Builder's code worked for me though. I'll check and see what I did (I didn't end up using masked tiles in Graviter)
In-progress: Graviter (...)

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Physics Lessons
« Reply #100 on: July 18, 2011, 01:49:36 pm »
Bump,
Just to clarify I'm not writing a physics game atm, but I'm re-writing TWHG in a way that doesn't use all pixel-testing :P
So I'm testing for
  ████
████████
████████
  ████

b/c that's the enemy sprite (everything else atm is 8*8 squares)

Wait, Builderboy might've messed something up...let me give my (i think) fixed code with explanation
Code: [Select]
{{r2/8*W+   // get tile row, multiply by width
(r1/8)+   //get tile column
L1}*8+  // now we have the value of the tile you are in, then multiply by 8 because 8 bytes per sprite
(r2^8)+      //get pixel row # with respect to the tile you are in
Str1}    //we add this to the pointer to the mask table, thus returning the exact byte of the sprite mask
e r1    // and now we check if the appropriate pixel is lit or not in the given row
Return
Where r1 is your X position, r2 is your Y position, W is the width of your tilemap (in tiles), L1 is the location of your matrix data buffer, and Str1 is the start of your Mask Sprite table.
So, do I need a masked sprite for everything or just the one tile?  I'm guessing a tile value (from L1) of 0 is the first sprite, 1, second sprite, etc?
« Last Edit: July 18, 2011, 01:52:16 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Physics Lessons
« Reply #101 on: October 10, 2011, 07:34:56 pm »
So, I've actually compiled these into a FlashBook App, so now you can have them in a single-page app on your calc! It's only compressed at lv. 1, so you don't need to have any free RAM available either (Either way it would have taken a whole page)

Enjoy!  :trollface:

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Physics Lessons
« Reply #102 on: October 10, 2011, 07:39:09 pm »
sweet thanx!!! +1 by the way

Offline boot2490

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 607
  • Rating: +54/-36
    • View Profile
    • Boot2490's Stuff
Re: Physics Lessons
« Reply #103 on: October 10, 2011, 09:55:42 pm »
man, EVERYBODY is using my trollface!
Together, we will take over the web! :trollface:
I'm not worried about SOPA creating censorship, that will not stand for long. I'm worried that they'll succeed in stopping piracy!

Spoiler For Signature, updated march 23, 11:28 PM EST:















An useful tool!

PM me if you need some help. I am glad to be of assistance and part of the TI Communnity.

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Physics Lessons
« Reply #104 on: October 10, 2011, 10:40:20 pm »
I should have stuck it in the tut app :P I had about 2k of space left in the page......

Edit: Done! :trollface: Check the bottom  >:D
« Last Edit: October 10, 2011, 10:44:54 pm by willrandship »