It is currently Mon Jun 25, 2018 8:49 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Sat Jun 09, 2018 7:08 am 
Online

Joined: Sat May 26, 2018 6:14 am
Posts: 14
Location: Italy
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


Top
 Profile  
 
PostPosted: Sat Jun 09, 2018 8:15 am 
Offline
User avatar

Joined: Sat Feb 16, 2013 11:52 am
Posts: 283
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

_________________
This is a block of text that can be added to posts you make. There is a 255 character limit.


Top
 Profile  
 
PostPosted: Sat Jun 16, 2018 7:54 am 
Online

Joined: Sat May 26, 2018 6:14 am
Posts: 14
Location: Italy
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


Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 12:14 am 
Online

Joined: Sat May 26, 2018 6:14 am
Posts: 14
Location: Italy
Image

Hello! Some progress here and new doubts! The collision detection works great with background. But I've a couple of question about the way to address the nametables where I want to compute the collision.

I load the background in this way:

Code:
LDX #$00
LoadBackgroundLVLLoop:
  LDA bg_lvl_1_0, x     
  STA $2007               
  INX                     
  CPX #$00               
  BNE LoadBackgroundLVLLoop
 
  LDX #$00
LoadBackgroundLVLLoop1:
  LDA bg_lvl_1_1, x     
  STA $2007               
  INX                     
  CPX #$00               
  BNE LoadBackgroundLVLLoop1

  LDX #$00
LoadBackgroundLVLLoop2:
  LDA bg_lvl_1_2, x     
  STA $2007               
  INX                     
  CPX #$00               
  BNE LoadBackgroundLVLLoop2

  LDX #$00
LoadBackgroundLVLLoop3:
  LDA bg_lvl_1_3, x     
  STA $2007               
  INX                     
  CPX #$80               
  BNE LoadBackgroundLVLLoop3


With 4 loop because I can't count over 256, so now I'm calculating the collision only on
Code:
bg_lvl_1_0
in this way:

Code:
PerformBallColWithBrickLeft:
  LDX BALL_POS_X_ON_TILE
  LDA bg_lvl_1_0, x
  CMP #$2D
  BEQ PerformBallCollisionWithBrick


So, there is a way to switch dynamically
Code:
bg_lvl_1_0
with, for example,
Code:
bg_lvl_1_1
? I need this not only to compute the collision on the portion of the background, but also to load a new background for a new level.

Can I do something like this? :

Code:
LDA bg_lvl_1_0
  STA NAMETABLE_TO_LOAD

  LDX #$00
LoadBackgroundLVLLoop:
  LDA NAMETABLE_TO_LOAD, x     
  STA $2007               
  INX                     
  CPX #$00               
  BNE LoadBackgroundLVLLoop


So I can change only NAMETABLE_TO_LOAD? Thanks a lot!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 7 hours


Who is online

Users browsing this forum: kikutano and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group