Fire Bars / Pivot point Metroidvania 4.5.9

DocNES

Member
Looking for a little help with making a similar Fire Bars from Mario 1 Castles for my game. Full 360, and something shorter maybe 180 rotations. Trying to figure out the easiest ways to do this. Maybe a Tile, as the base then
 

SciNEStist

Well-known member
Your problem is twofold. you need to first figure out how to move the balls individually in circles, then you need to figure out a new collision system to detect when the fireball hits a player, since having 6-12 individual objects moving around with their own collision wouldnt work well in Nesmaker. (it would lag and slow down a lot)

So you would likeluy need some sort of math equation to determine positioning (a lookup table is possible, but would get longer the smoother you want the spinning to be)
you would have to use drawsprite to show the fireballs instead of using nesmakers object system
and some custom code to check if they are in proximity to the player.

not an easy problem, but it is doable if you really want it. good luck!
 

DocNES

Member
Agreed. For the first problem I was thinking it would be 1 Monster Object. Just a long bar of several repeating sprites with one bounding box.
Trying to figure something out, looks like we don't have a lot of options for things to move in a circular pattern. The Sin Wave Tutorial was a good use of a table.

Maybe someone could look at this logic and see if it some what useful:

; Define constants
PivotX = $00 ; x-coordinate of the pivot point
PivotY = $01 ; y-coordinate of the pivot point
Width = $30 ; width of the Fire Bar's rectangle (24 / 8 = 3 tiles, each tile is 8 pixels wide)
Height = $08 ; height of the Fire Bar's rectangle
Angle = $04 ; current angle of rotation
Step = $05 ; amount to increment/decrement the angle each frame
Direction = $06 ; user variable that controls direction of rotation

; Initialize variables
lda #0 ; initialize angle to 0
sta Angle
lda #1 ; initialize step to 1
sta Step
lda #0 ; initialize direction to clockwise
sta Direction

; Main loop
Loop:
; Calculate new angle based on direction and step
lda Direction
beq RotateClockwise
; if direction is counterclockwise
dec Angle ; decrement angle by step
jmp CalculateCoordinates
RotateClockwise:
; if direction is clockwise
inc Angle ; increment angle by step

; Calculate new coordinates based on angle and pivot point
CalculateCoordinates:
; Convert angle to radians
lda Angle
clc
adc #90 ; adjust for starting angle of 0
asl ; multiply by 2 (since angle is in 0.5 degree increments)
tax
lda #0
sta sinTable+2
lda #>sinTable
sta $00
lda #<sinTable
sta $01
lda ($00),y
sta $02
lda #0
sta $03
lda ($00,x)
sta $04
lda ($00),y
sta $05

; Calculate sine and cosine of angle
lda Angle
clc
adc #90 ; adjust for starting angle of 0
lda #0
sta temp1
sta temp2
cmp #360 ; if angle exceeds 360, wrap around to 0
bcc SkipWrap
lda #0
SkipWrap:
jsr CalculateSine
sta temp1
jsr CalculateCosine
sta temp2

; Calculate new coordinates of rectangle based on angle, sine, cosine, and pivot point
lda PivotX
sta x
lda PivotY
sta y
lda temp1
clc
adc y
sta y
lda temp2
clc
adc x
sta x
lda Width
clc
adc x
sta x2
lda Height
clc
adc y
sta y2

; Draw the Fire Bar's rectangle on the screen using the calculated coordinates
; (code for drawing the rectangle is not shown here)

; Wait for the next frame
jmp Loop

; Subroutine to calculate sine of angle (in 0.5 degree increments)
CalculateSine:
pha
ldy #0
tay
lda #0
sta sinTable,y
lda #0
sta sinTable+1,y
lda #1
sta temp1
Loop1:
lda temp1
sta temp3

; Subroutine to calculate cosine of angle (in 0.5 degree increments)
CalculateCosine:
pha
ldy #0
tay
lda #256
sta cosTable+1,y
lda #0
sta cosTable,y
lda #1
sta temp1
Loop1:
lda temp1
sta temp3
sta temp4
Loop2:
lda cosTable+1,y
sbc temp3
sta cosTable+1,y
lda cosTable,y
sbc temp4
sta cosTable,y
ldx #0
Loop3:
lda cosTable+1,y
rol
sta cosTable+1,y
lda cosTable,y
rol
sta cosTable,y
inx
cpx #8
bne Loop3
lda cosTable,y
and #%11110000
sta cosTable,y
pla
rts
cosTable:
ds 2
temp1:
ds 1
temp3:
ds 1
temp4:
ds 1
 
Top Bottom