Merci Daniel,
Ces dernières semaines j'ai purgé tous les bugs (ils y en avait une dizaine) en préparation de la vidéo.
Même s'il manque encore plein de choses dans le niveau, il fallait bien sortir une version jouable à un moment donné.
Pour les ponts, chaque rondin est géré individuellement.
On ajuste l'enfoncement en fonction de la position du personnage et de la longueur du pont (tables de valeurs).
On a également un timer qui permet de faire l'enfoncement ou le relâchement du pont de manière progressive.
Je vous recopie pas tout le code qui est sur le github, mais voici la partie interessante :
Code:
* ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
* ; subroutine to make the bridge push down where Sonic or Tails walks over
* ; loc_F9E8:
Obj11_Depress * Obj11_Depress:
ldb Obj11_depressTimer,u ; get timer value * move.b objoff_3E(a0),d0
jsr CalcSine ; apply sin * jsrto (CalcSine).l, JmpTo_CalcSine ; apply sine function to depress timer
std glb_d4 * move.w d0,d4
ldx #byte_FB28 * lea (byte_FB28).l,a4
anda #0 * moveq #0,d0
ldb subtype,u ; get bridge length * move.b subtype(a0),d0
_lsld
_lsld
_lsld
_lsld ; bridge length *16 * lsl.w #4,d0
std glb_d0
anda #0 * moveq #0,d3
ldb Obj11_p1_log_pos,u * move.b objoff_3F(a0),d3
stb glb_d2_b * move.w d3,d2
addd glb_d0
std glb_d3 * add.w d0,d3
* moveq #0,d5
ldy #Obj11_DepressionOffsets-$80 * lea (Obj11_DepressionOffsets-$80).l,a5 ; table begin at length 8 so apply an offset of 8x16 bytes
lda d,y * move.b (a5,d3.w),d5
sta glb_d5_b
anda #0
ldb glb_d2_b ; faster to get value in d2 * andi.w #$F,d3
_lsld
_lsld
_lsld
_lsld ;ply log pos*16 * lsl.w #4,d3
leax d,x * lea (a4,d3.w),a3
ldy Obj11_child1,u * movea.l Obj11_child1(a0),a1
sty glb_a1
leay sub9_y_pos+next_subspr,y * lea sub9_y_pos+next_subspr(a1),a2
sty glb_a2 ; set end loop position
ldy glb_a1
leay sub2_y_pos,y * lea sub2_y_pos(a1),a1
; process logs on player's left *
@loop anda #0 * - moveq #0,d0
ldb ,x+ * move.b (a3)+,d0 ; load factor based on player position
addd #1 * addq.w #1,d0 ; add one to factor ($FF gives $100)
tsta
bne >
lda glb_d5_b
mul ; depression offset * bend factor * mulu.w d5,d0
bra @skip
! lda glb_d5_b ; multiply by $100
andb #0
@skip stx @x
tfr d,x ; depression offset * bend factor (9bits)
ldd glb_d4 ; sin of timer value (9bits)
jsr Mul9x16 * mulu.w d4,d0
ldx #0
@x equ *-2
tfr a,b * swap d0
anda #0
addd Obj11_baseYPos,u * add.w objoff_3C(a0),d0
std ,y ; set y_pos * move.w d0,(a1)
leay next_subspr,y * addq.w #6,a1
sty glb_a1
cmpy glb_a2 ; end of first sub object ? * cmpa.w a2,a1
bne > * bne.s +
ldy Obj11_child2,u ; yes load 2nd sub obj * movea.l Obj11_child2(a0),a1 ; a1=object
leay sub2_y_pos,y * lea sub2_y_pos(a1),a1
! dec glb_d2_b ; dec nb of log * + dbf d2,-
bpl @loop
*
; * moveq #0,d0
; * move.b subtype(a0),d0
anda #0 * moveq #0,d3
ldb Obj11_p1_log_pos,u ; we are processing * move.b objoff_3F(a0),d3
incb ; from the first log on player's right * addq.b #1,d3
subb subtype,u * sub.b d0,d3
negb * neg.b d3
bmi @rts ; p1 is on last bridge log * bmi.s ++ ; rts
std glb_d2 ; store nb of log to process * move.w d3,d2
_lsld
_lsld
_lsld
_lsld ; *16 to get the desired line in factor table
std glb_d3 * lsl.w #4,d3
ldx #byte_FB28
leax d,x ; select the line * lea (a4,d3.w),a3
ldd glb_d2
leax d,x ; add remaining nb logs, point on $FF value * adda.w d2,a3
dec glb_d2_b ; decrement nb of log to process * subq.w #1,d2
bmi @rts * bcs.s ++ ; rts
; process logs on player's right *
@loop anda #0 * - moveq #0,d0
ldb ,-x ; decrement and load, get the value on the left of $FF * move.b -(a3),d0
addd #1 * addq.w #1,d0
tsta
bne >
lda glb_d5_b
mul * mulu.w d5,d0
bra @skip
! lda glb_d5_b ; multiply by $100
andb #0
@skip stx @x
tfr d,x
ldd glb_d4 ; sin of timer value
jsr Mul9x16 * mulu.w d4,d0
ldx #0
@x equ *-2
tfr a,b * swap d0
anda #0
addd Obj11_baseYPos,u * add.w objoff_3C(a0),d0
std ,y ; set y_pos * move.w d0,(a1)
leay next_subspr,y * addq.w #6,a1
cmpy glb_a2 * cmpa.w a2,a1
bne > * bne.s +
ldy Obj11_child2,u * movea.l Obj11_child2(a0),a1 ; a1=object
leay sub2_y_pos,y * lea sub2_y_pos(a1),a1
! dec glb_d2_b * + dbf d2,-
bpl @loop
@rts * +
rts * rts
* ; ===========================================================================
* ; seems to be bridge piece vertical position offset data
; maximum vertical position offset for each log of each bridge size
; (vertical depth of the bridge according to its length)
; the value read is the one that match player position
; this max value is applied to all logs
; first line is for bridge of length 8 and so on
Obj11_DepressionOffsets * Obj11_DepressionOffsets: ; byte_FA98:
fcb 2,4,6,8,8,6,4,2,0,0,0,0,0,0,0,0 * dc.b 2, 4, 6, 8, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0; 16
fcb 2,4,6,8,$A,8,6,4,2,0,0,0,0,0,0,0 * dc.b 2, 4, 6, 8, $A, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0; 32
fcb 2,4,6,8,$A,$A,8,6,4,2,0,0,0,0,0,0 * dc.b 2, 4, 6, 8, $A, $A, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0; 48
fcb 2,4,6,8,$A,$C,$A,8,6,4,2,0,0,0,0,0 * dc.b 2, 4, 6, 8, $A, $C, $A, 8, 6, 4, 2, 0, 0, 0, 0, 0; 64
fcb 2,4,6,8,$A,$C,$C,$A,8,6,4,2,0,0,0,0 * dc.b 2, 4, 6, 8, $A, $C, $C, $A, 8, 6, 4, 2, 0, 0, 0, 0; 80
fcb 2,4,6,8,$A,$C,$E,$C,$A,8,6,4,2,0,0,0 * dc.b 2, 4, 6, 8, $A, $C, $E, $C, $A, 8, 6, 4, 2, 0, 0, 0; 96
fcb 2,4,6,8,$A,$C,$E,$E,$C,$A,8,6,4,2,0,0 * dc.b 2, 4, 6, 8, $A, $C, $E, $E, $C, $A, 8, 6, 4, 2, 0, 0; 112
fcb 2,4,6,8,$A,$C,$E,$10,$E,$C,$A,8,6,4,2,0 * dc.b 2, 4, 6, 8, $A, $C, $E,$10, $E, $C, $A, 8, 6, 4, 2, 0; 128
fcb 2,4,6,8,$A,$C,$E,$10,$10,$E,$C,$A,8,6,4,2 * dc.b 2, 4, 6, 8, $A, $C, $E,$10,$10, $E, $C, $A, 8, 6, 4, 2; 144
*
* ; something else important for bridge depression to work (phase? bridge size adjustment?)
; bridge curve for left or right log segment from player position
; factor = (table value+1)*(1/256)
; factor is applied on the depression offset of a log
; left log segment: select table line that matches segment length (bridge start to player pos), read values from left to right
; right log segment: select table line that matches remaining logs (player pos to bridge end), select column=nb remaining log , read values from right to left
byte_FB28 * byte_FB28:
fcb $FF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 * dc.b $FF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 16 ; segment length 1
fcb $B5,$FF,0,0,0,0,0,0,0,0,0,0,0,0,0,0 * dc.b $B5,$FF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 32 ; segment length 2
fcb $7E,$DB,$FF,0,0,0,0,0,0,0,0,0,0,0,0,0 * dc.b $7E,$DB,$FF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 48 ; segment length 3
fcb $61,$B5,$EC,$FF,0,0,0,0,0,0,0,0,0,0,0,0 * dc.b $61,$B5,$EC,$FF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 64 ; ...
fcb $4A,$93,$CD,$F3,$FF,0,0,0,0,0,0,0,0,0,0,0 * dc.b $4A,$93,$CD,$F3,$FF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 80
fcb $3E,$7E,$B0,$DB,$F6,$FF,0,0,0,0,0,0,0,0,0,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E,$93,$A7,$BD,$CD,$DB,$E7,$F3,$F9,$FE,$FF,0 * dc.b $19,$31,$4A,$67,$7E,$93,$A7,$BD,$CD,$DB,$E7,$F3,$F9,$FE,$FF, 0; 240 ; ...
fcb $19,$31,$4A,$61,$78,$8E,$A2,$B5,$C5,$D4,$E1,$EC,$F4,$FB,$FE,$FF * dc.b $19,$31,$4A,$61,$78,$8E,$A2,$B5,$C5,$D4,$E1,$EC,$F4,$FB,$FE,$FF; 256 ; segment length 16