almost spawnining missiles
This commit is contained in:
parent
0285ec619c
commit
37e998eb7e
@ -15,4 +15,4 @@ clean:
|
|||||||
# Rule to run the final cartridge .nes file in the FCEUX emulator
|
# Rule to run the final cartridge .nes file in the FCEUX emulator
|
||||||
###############################################################################
|
###############################################################################
|
||||||
run:
|
run:
|
||||||
on-workspace 6 "fceux atlantico.nes"
|
on-workspace 4 "fceux atlantico.nes"
|
||||||
|
@ -12,6 +12,4 @@
|
|||||||
Type .byte
|
Type .byte
|
||||||
XPos .byte
|
XPos .byte
|
||||||
YPos .byte
|
YPos .byte
|
||||||
XVel .byte
|
|
||||||
YVel .byte
|
|
||||||
.endstruct
|
.endstruct
|
||||||
|
@ -6,17 +6,22 @@
|
|||||||
|
|
||||||
.segment "ZEROPAGE"
|
.segment "ZEROPAGE"
|
||||||
Buttons: .res 1 ; Pressed buttons (A|B|Select|Start|Up|Dwn|Lft|Rgt)
|
Buttons: .res 1 ; Pressed buttons (A|B|Select|Start|Up|Dwn|Lft|Rgt)
|
||||||
|
PrevButtons: .res 1 ; Pressed buttons (A|B|Select|Start|Up|Dwn|Lft|Rgt) PREVIOUSLY
|
||||||
|
|
||||||
XPos: .res 2 ; Player X 16-bit position (8.8 fixed-point): hi+lo/256px
|
XPos: .res 1 ; Player X 16-bit position (8.8 fixed-point): hi+lo/256px
|
||||||
YPos: .res 2 ; Player Y 16-bit position (8.8 fixed-point): hi+lo/256px
|
YPos: .res 1 ; Player Y 16-bit position (8.8 fixed-point): hi+lo/256px
|
||||||
|
|
||||||
XVel: .res 1 ; Player X (signed) velocity (in pixels per 256 frames)
|
XVel: .res 1 ; Player X (signed) velocity (in pixels per 256 frames)
|
||||||
YVel: .res 1 ; Player Y (signed) velocity (in pixels per 256 frames)
|
YVel: .res 1 ; Player Y (signed) velocity (in pixels per 256 frames)
|
||||||
|
|
||||||
|
PrevSubmarine: .res 1 ; how long ago we added previous submarine in seconds
|
||||||
|
|
||||||
Frame: .res 1 ; Counts frames (0 to 255 and repeats)
|
Frame: .res 1 ; Counts frames (0 to 255 and repeats)
|
||||||
IsDrawComplete: .res 1 ; Flag to indicate when vblank is done drawing
|
IsDrawComplete: .res 1 ; Flag to indicate when vblank is done drawing
|
||||||
Clock60: .res 1 ; Counter that increments per second (60 frames)
|
Clock60: .res 1 ; Counter that increments per second (60 frames)
|
||||||
|
|
||||||
BgPtr: .res 2 ; Pointer to background address - 16bits (lo,hi)
|
BgPtr: .res 2 ; Pointer to background address - 16bits (lo,hi)
|
||||||
|
SprPtr: .res 2 ; pointer to the sprite address - 16bits (lo,hi)
|
||||||
|
|
||||||
XScroll: .res 1 ; Store the horizontal scroll position
|
XScroll: .res 1 ; Store the horizontal scroll position
|
||||||
CurrNametable: .res 1 ; Store the current starting nametable (0 or 1)
|
CurrNametable: .res 1 ; Store the current starting nametable (0 or 1)
|
||||||
@ -27,8 +32,11 @@ SourceAddr: .res 2 ; The source address in ROM of the new c
|
|||||||
ParamType: .res 1 ; Used as param to subrouting
|
ParamType: .res 1 ; Used as param to subrouting
|
||||||
ParamXPos: .res 1 ; Used as param to subrouting
|
ParamXPos: .res 1 ; Used as param to subrouting
|
||||||
ParamYPos: .res 1 ; Used as param to subrouting
|
ParamYPos: .res 1 ; Used as param to subrouting
|
||||||
ParamXVel: .res 1 ; Used as param to subrouting
|
ParamTileNum: .res 1 ; Used as param to subrouting
|
||||||
ParamYVel: .res 1 ; Used as param to subrouting
|
ParamNumTiles: .res 1 ; Used as param to subrouting
|
||||||
|
ParamAttribs: .res 1 ; Used as param to subrouting
|
||||||
|
|
||||||
|
PrevOAMCount: .res 1 ; Store previous number of bytes sent to the OAM
|
||||||
|
|
||||||
; Store enough space for an array of actors
|
; Store enough space for an array of actors
|
||||||
ActorsArray: .res MAX_ACTORS * .sizeof(Actor)
|
ActorsArray: .res MAX_ACTORS * .sizeof(Actor)
|
||||||
@ -215,7 +223,7 @@ LoopButtons:
|
|||||||
;AddNewActor
|
;AddNewActor
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Subroutine to add new actor to the array in the first empty slot found
|
;; Subroutine to add new actor to the array in the first empty slot found
|
||||||
;; Params: ParamType, ParamXPos, ParamYPos, ParamXVel, ParamYVel
|
;; Params: ParamType, ParamXPos, ParamYPos, ParamYVel
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
.proc AddNewActor
|
.proc AddNewActor
|
||||||
ldx #0
|
ldx #0
|
||||||
@ -231,6 +239,7 @@ LoopButtons:
|
|||||||
adc #.sizeof(Actor)
|
adc #.sizeof(Actor)
|
||||||
tax
|
tax
|
||||||
jmp ArrayLoop
|
jmp ArrayLoop
|
||||||
|
|
||||||
AddNewActorToArray:
|
AddNewActorToArray:
|
||||||
lda ParamType
|
lda ParamType
|
||||||
sta ActorsArray+Actor::Type,x
|
sta ActorsArray+Actor::Type,x
|
||||||
@ -238,14 +247,239 @@ LoopButtons:
|
|||||||
sta ActorsArray+Actor::XPos,x
|
sta ActorsArray+Actor::XPos,x
|
||||||
lda ParamYPos
|
lda ParamYPos
|
||||||
sta ActorsArray+Actor::YPos,x
|
sta ActorsArray+Actor::YPos,x
|
||||||
lda ParamXVel
|
|
||||||
sta ActorsArray+Actor::XVel,x
|
|
||||||
lda ParamYVel
|
|
||||||
sta ActorsArray+Actor::YVel,x
|
|
||||||
EndRoutine:
|
EndRoutine:
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
.proc SpawnActors
|
||||||
|
SpawnSubmarine:
|
||||||
|
lda Clock60 ; Submarines added in 3 second intervals
|
||||||
|
sec ;
|
||||||
|
sbc PrevSubmarine ;
|
||||||
|
cmp #3 ; Only add if 3 seconds have pased
|
||||||
|
bne :+ ;
|
||||||
|
lda #ActorType::SUBMARINE ;
|
||||||
|
sta ParamType ; Load Param for the actor type
|
||||||
|
lda #223 ;
|
||||||
|
sta ParamXPos ; Load X Pos
|
||||||
|
lda #185 ;
|
||||||
|
sta ParamYPos ;
|
||||||
|
;
|
||||||
|
jsr AddNewActor ; Call subroutine
|
||||||
|
;
|
||||||
|
lda Clock60 ;
|
||||||
|
sta PrevSubmarine ; Save the current clocktime as the submarine clock spawn time
|
||||||
|
:
|
||||||
|
rts
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
|
.proc UpdateActors
|
||||||
|
ldx #0 ; counter of how many actors
|
||||||
|
ActorsLoop:
|
||||||
|
lda ActorsArray+Actor::Type,x
|
||||||
|
|
||||||
|
cmp #ActorType::MISSILE
|
||||||
|
bne :+
|
||||||
|
;;Update y Pos
|
||||||
|
;; y--
|
||||||
|
lda ActorsArray+Actor::YPos,x
|
||||||
|
sec
|
||||||
|
sbc #1 ; Decrement Y Position
|
||||||
|
sta ActorsArray+Actor::YPos,x ;
|
||||||
|
bcs SkipMissile
|
||||||
|
;; Delete Missile
|
||||||
|
lda #ActorType::NULL
|
||||||
|
sta ActorsArray+Actor::Type,x ;
|
||||||
|
SkipMissile:
|
||||||
|
jmp NextActor
|
||||||
|
:
|
||||||
|
|
||||||
|
cmp #ActorType::SUBMARINE
|
||||||
|
bne :+
|
||||||
|
;;Update x Pos
|
||||||
|
;; x--
|
||||||
|
lda ActorsArray+Actor::XPos,x
|
||||||
|
sec
|
||||||
|
sbc #1 ; Decrement X Position
|
||||||
|
sta ActorsArray+Actor::XPos,x ;
|
||||||
|
bcs SkipSubmarine
|
||||||
|
;; Delete SUB
|
||||||
|
lda #ActorType::NULL
|
||||||
|
sta ActorsArray+Actor::Type,x ;
|
||||||
|
SkipSubmarine:
|
||||||
|
jmp NextActor
|
||||||
|
:
|
||||||
|
|
||||||
|
NextActor:
|
||||||
|
txa
|
||||||
|
clc
|
||||||
|
adc #.sizeof(Actor)
|
||||||
|
tax
|
||||||
|
cmp #MAX_ACTORS * .sizeof(Actor)
|
||||||
|
bne ActorsLoop
|
||||||
|
rts
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.proc RenderActors
|
||||||
|
lda #$02 ;
|
||||||
|
sta SprPtr+1 ;
|
||||||
|
lda #$00 ;
|
||||||
|
sta SprPtr ; set SprPtr to $0200
|
||||||
|
|
||||||
|
ldy #0 ; counter of how many tiles
|
||||||
|
ldx #0 ; counter of how many actors
|
||||||
|
ActorsLoop:
|
||||||
|
lda ActorsArray+Actor::Type,x
|
||||||
|
|
||||||
|
cmp #ActorType::SPRITE0
|
||||||
|
bne :+
|
||||||
|
;; Load Params with Y, TileNumber, Attribs, X,NumTiles=4
|
||||||
|
lda ActorsArray+Actor::XPos,x
|
||||||
|
sta ParamXPos
|
||||||
|
lda ActorsArray+Actor::YPos,x
|
||||||
|
sta ParamYPos
|
||||||
|
lda #$70
|
||||||
|
sta ParamTileNum
|
||||||
|
lda #%00100000
|
||||||
|
sta ParamAttribs
|
||||||
|
lda #1
|
||||||
|
sta ParamNumTiles
|
||||||
|
jsr DrawSprite
|
||||||
|
jmp NextActor
|
||||||
|
:
|
||||||
|
|
||||||
|
cmp #ActorType::PLAYER
|
||||||
|
bne :+
|
||||||
|
;; Load Params with Y, TileNumber, Attribs, X,NumTiles=4
|
||||||
|
lda ActorsArray+Actor::XPos,x
|
||||||
|
sta ParamXPos
|
||||||
|
lda ActorsArray+Actor::YPos,x
|
||||||
|
sta ParamYPos
|
||||||
|
lda #$60
|
||||||
|
sta ParamTileNum
|
||||||
|
lda #%00000000
|
||||||
|
sta ParamAttribs
|
||||||
|
lda #4
|
||||||
|
sta ParamNumTiles
|
||||||
|
jsr DrawSprite
|
||||||
|
jmp NextActor
|
||||||
|
:
|
||||||
|
|
||||||
|
cmp #ActorType::MISSILE
|
||||||
|
bne :+
|
||||||
|
;; Load Params with Y, TileNumber, Attribs, X,NumTiles=1
|
||||||
|
lda ActorsArray+Actor::XPos,x
|
||||||
|
sta ParamXPos
|
||||||
|
lda ActorsArray+Actor::YPos,x
|
||||||
|
sta ParamYPos
|
||||||
|
lda #$50
|
||||||
|
sta ParamTileNum
|
||||||
|
lda #%00000001
|
||||||
|
sta ParamAttribs
|
||||||
|
lda #1
|
||||||
|
sta ParamNumTiles
|
||||||
|
jsr DrawSprite
|
||||||
|
jmp NextActor
|
||||||
|
:
|
||||||
|
|
||||||
|
cmp #ActorType::SUBMARINE
|
||||||
|
bne :+
|
||||||
|
;; Load Params with Y, TileNumber, Attribs, X,NumTiles=1
|
||||||
|
lda ActorsArray+Actor::XPos,x
|
||||||
|
sta ParamXPos
|
||||||
|
lda ActorsArray+Actor::YPos,x
|
||||||
|
sta ParamYPos
|
||||||
|
lda #$04
|
||||||
|
sta ParamTileNum
|
||||||
|
lda #%00000000
|
||||||
|
sta ParamAttribs
|
||||||
|
lda #4
|
||||||
|
sta ParamNumTiles
|
||||||
|
jsr DrawSprite
|
||||||
|
jmp NextActor
|
||||||
|
:
|
||||||
|
|
||||||
|
NextActor:
|
||||||
|
txa
|
||||||
|
clc
|
||||||
|
adc #.sizeof(Actor)
|
||||||
|
tax
|
||||||
|
cmp #MAX_ACTORS * .sizeof(Actor)
|
||||||
|
|
||||||
|
beq :+
|
||||||
|
jmp ActorsLoop
|
||||||
|
:
|
||||||
|
|
||||||
|
tya
|
||||||
|
pha ; Save Y to the Stack
|
||||||
|
|
||||||
|
LoopTrailingTiles:
|
||||||
|
;; Loop all bytes until we reach PrevOAMCount
|
||||||
|
cpy PrevOAMCount
|
||||||
|
bcs :+
|
||||||
|
lda #$FF
|
||||||
|
sta (SprPtr),y ; set Y position to $ff to hide
|
||||||
|
iny ;
|
||||||
|
sta (SprPtr),y ; Set tile number as $FF
|
||||||
|
iny ;
|
||||||
|
sta (SprPtr),y ; Set attribs as $FF
|
||||||
|
iny ;
|
||||||
|
sta (SprPtr),y ; Setr X Position to $FF to hide tile
|
||||||
|
iny ;
|
||||||
|
jmp LoopTrailingTiles
|
||||||
|
:
|
||||||
|
|
||||||
|
pla
|
||||||
|
sta PrevOAMCount
|
||||||
|
rts
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Routine to loop "NumTiles" times, sending bytes to the OAM-RAM
|
||||||
|
;; Params = ParamXPos, ParamYPos, ParamTileNum, ParamAttribs, ParamNumTiles
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
.proc DrawSprite
|
||||||
|
txa ;push x to stack
|
||||||
|
pha ; save value of X register before anything
|
||||||
|
|
||||||
|
ldx #0
|
||||||
|
TileLoop:
|
||||||
|
lda ParamYPos
|
||||||
|
sta (SprPtr),y ; Send Y Position to Ram
|
||||||
|
iny
|
||||||
|
|
||||||
|
lda ParamTileNum ; Send Tile# to the OAM
|
||||||
|
sta (SprPtr),y ;
|
||||||
|
inc ParamTileNum ; ParamTileNum++
|
||||||
|
iny
|
||||||
|
|
||||||
|
lda ParamAttribs ; Send Attribs to the OAM
|
||||||
|
sta (SprPtr),y
|
||||||
|
iny
|
||||||
|
|
||||||
|
lda ParamXPos ; Send X Position to the OAM
|
||||||
|
sta (SprPtr),y
|
||||||
|
clc
|
||||||
|
adc #8
|
||||||
|
sta ParamXPos ; increment X Pos 8 pixels
|
||||||
|
|
||||||
|
iny
|
||||||
|
|
||||||
|
inx ; X++
|
||||||
|
cpx ParamNumTiles ; loop NumTiles times
|
||||||
|
bne TileLoop
|
||||||
|
|
||||||
|
; pop x from stack
|
||||||
|
pla
|
||||||
|
tax ; pull value of X from stack and transfer to x
|
||||||
|
|
||||||
|
rts
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Reset handler (called when the NES resets or powers on)
|
;; Reset handler (called when the NES resets or powers on)
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -274,9 +508,6 @@ AddSprite0:
|
|||||||
sta ParamXPos
|
sta ParamXPos
|
||||||
lda #27
|
lda #27
|
||||||
sta ParamYPos
|
sta ParamYPos
|
||||||
lda #0
|
|
||||||
sta ParamXVel
|
|
||||||
sta ParamYVel
|
|
||||||
jsr AddNewActor
|
jsr AddNewActor
|
||||||
|
|
||||||
AddPlayer:
|
AddPlayer:
|
||||||
@ -286,9 +517,6 @@ AddPlayer:
|
|||||||
sta ParamXPos
|
sta ParamXPos
|
||||||
lda YPos
|
lda YPos
|
||||||
sta ParamYPos
|
sta ParamYPos
|
||||||
lda #0
|
|
||||||
sta ParamXVel
|
|
||||||
sta ParamYVel
|
|
||||||
jsr AddNewActor
|
jsr AddNewActor
|
||||||
|
|
||||||
InitBackgroundTiles:
|
InitBackgroundTiles:
|
||||||
@ -361,6 +589,9 @@ EnableRendering:
|
|||||||
|
|
||||||
;;;;;;; START GAME LOOP
|
;;;;;;; START GAME LOOP
|
||||||
GameLoop:
|
GameLoop:
|
||||||
|
lda Buttons
|
||||||
|
sta PrevButtons
|
||||||
|
|
||||||
;Perform Game Logic Here
|
;Perform Game Logic Here
|
||||||
jsr ReadControllers
|
jsr ReadControllers
|
||||||
|
|
||||||
@ -368,26 +599,21 @@ CheckAButton:
|
|||||||
lda Buttons
|
lda Buttons
|
||||||
and #BUTTON_A
|
and #BUTTON_A
|
||||||
beq :+
|
beq :+
|
||||||
lda YPos
|
lda Buttons
|
||||||
|
and #BUTTON_A ; DEBOUNCE A PRESS
|
||||||
|
cmp PrevButtons ; Compare current buttons and check if A was previously pressed
|
||||||
|
beq:+
|
||||||
lda #ActorType::MISSILE
|
lda #ActorType::MISSILE
|
||||||
sta ParamType
|
sta ParamType
|
||||||
lda XPos
|
lda XPos
|
||||||
sta ParamXPos
|
sta ParamXPos
|
||||||
lda YPos
|
lda YPos
|
||||||
sta ParamYPos
|
|
||||||
lda #0
|
|
||||||
sta ParamXVel
|
|
||||||
lda #255
|
|
||||||
sta ParamYVel
|
|
||||||
jsr AddNewActor
|
jsr AddNewActor
|
||||||
:
|
:
|
||||||
|
|
||||||
;; TODO
|
jsr SpawnActors
|
||||||
;;------------------
|
jsr UpdateActors
|
||||||
;jsr SpawnActors
|
jsr RenderActors
|
||||||
;jsr UpdateActors
|
|
||||||
;jsr RenderActors
|
|
||||||
;;------------------
|
|
||||||
|
|
||||||
WaitForVBlank: ; we lock execution
|
WaitForVBlank: ; we lock execution
|
||||||
lda IsDrawComplete ; check and only perform game loop call once NMI is done drawing
|
lda IsDrawComplete ; check and only perform game loop call once NMI is done drawing
|
||||||
@ -433,26 +659,26 @@ NewAttribsCheck:
|
|||||||
jsr DrawNewAttribs
|
jsr DrawNewAttribs
|
||||||
:
|
:
|
||||||
|
|
||||||
;SetPPUNoScroll:
|
SetPPUNoScroll:
|
||||||
; lda #0
|
lda #0
|
||||||
; sta PPU_SCROLL
|
sta PPU_SCROLL
|
||||||
; sta PPU_SCROLL
|
sta PPU_SCROLL
|
||||||
;
|
|
||||||
;EnablePPUSprite0:
|
EnablePPUSprite0:
|
||||||
; lda #%10010000
|
lda #%10010000
|
||||||
; sta PPU_CTRL
|
sta PPU_CTRL
|
||||||
; lda #%00011110
|
lda #%00011110
|
||||||
; sta PPU_MASK
|
sta PPU_MASK
|
||||||
;
|
|
||||||
;WaitForNoSprite0:
|
WaitForNoSprite0:
|
||||||
; lda PPU_STATUS
|
lda PPU_STATUS
|
||||||
; and #%01000000
|
and #%01000000
|
||||||
; bne WaitForNoSprite0
|
bne WaitForNoSprite0
|
||||||
;
|
|
||||||
;WaitForSprite0:
|
WaitForSprite0:
|
||||||
; lda PPU_STATUS
|
lda PPU_STATUS
|
||||||
; and #%01000000 ; PPU address $2002 bit 6 is the sprite hit flag
|
and #%01000000 ; PPU address $2002 bit 6 is the sprite hit flag
|
||||||
; beq WaitForSprite0 ; loop until we do NOT have a sprite 0 hit
|
beq WaitForSprite0 ; loop until we do NOT have a sprite 0 hit
|
||||||
|
|
||||||
ScrollBackground:
|
ScrollBackground:
|
||||||
inc XScroll ; XScroll++
|
inc XScroll ; XScroll++
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user