nesdev.com
http://forums.nesdev.com/

Collision detection problem with my project.
http://forums.nesdev.com/viewtopic.php?f=2&t=17392
Page 3 of 3

Author:  kikutano [ Sat Jun 09, 2018 7:08 am ]
Post subject:  Re: Collision detection problem with my project.

Code:
LDA BALL_POS_X
  SEC
  SBC #$0F                ; subtrack 16 pixel to put x in the same x space of the tiles
 
  LSR A
   LSR A
   LSR A
   LSR A                   ; Divide by 16
  STA BALL_POS_X_ON_TILE

  LDA BALL_POS_Y
  SEC
  SBC #$0F

  LSR A
  LSR A
  LSR A
  LSR A                   ; Divide by 16
  STA BALL_POX_Y_ON_TILE


Now I've the position ( x, y ) of the ball on Tile. Now I need to understand how to take the tile from the X and Y position stored in $2007 with this method:

Code:
bg_raw:
  .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ; 0 raw background
bg_lvl_top_corner: 
  .db $24,$2B,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2C,$2B,$24,$24,$24,$24,$24,$24,$24 ; 1 top corner
bg_lvl_1_0:
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 2
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 3
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$1C,$1D,$1E,$0D,$12,$18 ; 4
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$15,$0E,$0A,$1F,$0E,$1C ; 5
  .db $24,$2B, $2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E, $2B,$24,$24,$24,$02,$00,$01,$08 ; 6
  .db $24,$2B, $2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E, $2B,$24,$24,$24,$24,$24,$24,$24 ; 7
  .db $24,$2B, $2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E, $2B,$24,$24,$24,$24,$24,$24,$24 ; 8
  .db $24,$2B, $2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E,$2D,$2E, $2B,$24,$24,$24,$24,$24,$24,$24 ; 9

bg_lvl_1_1:
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 10
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 11
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 12
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 13
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 14
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 15
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 16
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 17

bg_lvl_1_2
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 18
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 19
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 20
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 21
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 22
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 23
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 24
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 25

bg_lvl_1_3
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 26
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 27
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 28
  .db $24,$2B, $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27, $2B,$24,$24,$24,$24,$24,$24,$24 ; 29

Author:  Punch [ Sat Jun 09, 2018 8:15 am ]
Post subject:  Re: Collision detection problem with my project.

Kikutano: Check collision.asm on my code if you're trying to figure out angular and subpixel movement, especially this section:

Code:
;This table shows the amount of pixels
;that you should travel in the x/y directions
;in order to move with a certain speed (1-8)
;in 30, 45 or 60 degrees.
Vector_Angle_Table:
   .db 0, 1, 2, 3, 4, 5, 6, 6 ;30 degree X
   .db 0, 1, 1, 2, 2, 3, 3, 4 ;30 degree Y
   
   .db 0, 1, 2, 2, 3, 4, 4, 5 ;45 degree X
   .db 0, 1, 2, 2, 3, 4, 4, 5 ;45 degree Y
   
   .db 0, 1, 1, 2, 2, 3, 3, 4 ;60 degree X
   .db 0, 1, 2, 3, 4, 5, 6, 6 ;60 degree Y
   
;base 256 fractions to represent the angle as floating point
Vector_Fraction_Table:
   .db 223, 186, 153, 119, 84, 50, 23, 246 ;30 deg X
   .db 128, 0, 128, 0, 128, 0, 128, 0 ;30 deg Y
   .db 181, 106, 31, 212, 137, 62, 243, 168 ;45 deg X
   .db 181, 106, 31, 212, 137, 62, 243, 168 ;45 deg Y
   .db 128, 0, 128, 0, 128, 0, 128, 0 ;60 deg X
   .db 223, 186, 153, 119, 84, 50, 23, 246 ;60 deg Y
   
   
   
   


Ain't nothing as fast as reading fron a table... :lol: Not that it would be difficult to generate such a table, but to save you the trouble:

I, the author, release the code snippet above as Public Domain and forfeit my exclusive Author Intellectual Property Rights (so go ahead and copy it if you want without crediting me). :p

Author:  kikutano [ Sat Jun 16, 2018 7:54 am ]
Post subject:  Re: Collision detection problem with my project.

I'm working on collision, and it start to works finally :D. All bricks are on background, the next step is to compute the bouncing and update the background. Programming for Nes is a pain in the ass, but hey, it's so funny! :D I will post here the collision detection code, I hope to upload on Github the entire project when I will finish it.

Image

Page 3 of 3 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/