Foundation work for aiming crosshair

This commit is contained in:
blondie7575 2023-06-21 20:07:30 -07:00
parent 730bce2601
commit 509af5c166
13 changed files with 270 additions and 20 deletions

BIN
Art/015Crosshair.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

BIN
Art/015Crosshair.xcf Normal file

Binary file not shown.

View File

@ -15,12 +15,14 @@
700F21E01F4A3A5500D7007D /* GenerateTrigTables.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateTrigTables.py; sourceTree = "<group>"; };
700F72872112428D00225B17 /* RenumberSpriteFiles.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = RenumberSpriteFiles.sh; sourceTree = "<group>"; };
700FFAFB1F40F3BF00A442DE /* font.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = font.s; sourceTree = "<group>"; };
705456862A43E03B00A2B866 /* GeneratePixelCircle.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GeneratePixelCircle.py; sourceTree = "<group>"; };
7059502B1F37A0BE00BBE90F /* GenerateVRAMTable.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateVRAMTable.py; sourceTree = "<group>"; };
705AAFA920040B0D001BB0ED /* terrain_e1.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = terrain_e1.s; sourceTree = "<group>"; };
705C54E62124B7F300515A6B /* fan.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = fan.s; sourceTree = "<group>"; };
706DF1641F2D39F700AA6680 /* loader.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = loader.s; sourceTree = "<group>"; };
706DF1651F2D4A8100AA6680 /* terrain.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = terrain.s; sourceTree = "<group>"; };
7088096D1F2ECE8D00D4C950 /* GenerateRenderSpans.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateRenderSpans.py; sourceTree = "<group>"; };
708D1B1E27B9A1A600909AFC /* crosshair.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = crosshair.s; sourceTree = "<group>"; };
709175C01F60D263008FAFAB /* GenerateCircles.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateCircles.py; sourceTree = "<group>"; };
7099E3841F41022100182A82 /* gameobject.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameobject.s; sourceTree = "<group>"; };
7099E3851F4107B100182A82 /* GenerateVRAMYOffset.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateVRAMYOffset.py; sourceTree = "<group>"; };
@ -66,6 +68,7 @@
700B5E6F2069831000B31C00 /* inventory.s */,
700F21DF1F4A364600D7007D /* projectile.s */,
705C54E62124B7F300515A6B /* fan.s */,
708D1B1E27B9A1A600909AFC /* crosshair.s */,
70A80FB01F43D7F200BD34C9 /* gamemanager.s */,
70E554C41F807ADB00F3C871 /* spritebank.s */,
70E9D8611F2BD95400555C19 /* gscats.s */,
@ -77,6 +80,7 @@
7059502B1F37A0BE00BBE90F /* GenerateVRAMTable.py */,
7099E3851F4107B100182A82 /* GenerateVRAMYOffset.py */,
700F21E01F4A3A5500D7007D /* GenerateTrigTables.py */,
705456862A43E03B00A2B866 /* GeneratePixelCircle.py */,
709175C01F60D263008FAFAB /* GenerateCircles.py */,
70BDCBCA200A99F200CB51F1 /* ParseMapFile.py */,
);

85
GeneratePixelCircle.py Executable file
View File

@ -0,0 +1,85 @@
#!/usr/bin/env python3
import sys
import math
def main(argv):
print ("pixelCircle90X:\t\t; X values of half a 90 pixel-radius circle, indexed by angle",end="")
print ("\n\t.word ", end="")
rowCount=0
endAngle = 181
for y in range(0,endAngle):
x = math.trunc(math.cos(math.radians(y)) * 90)
print ("%d" % x, end="")
rowCount += 1
if (rowCount<10 and y<endAngle-1):
print (",", end="")
elif (y<endAngle-1):
print ("\n\t.word ", end="")
rowCount=0
print("")
print ("\npixelCircle90Y:\t\t; Y values of half a 90 pixel-radius circle, indexed by angle",end="")
print ("\n\t.word ", end="")
rowCount=0
endAngle = 181
for x in range(0,endAngle):
y = math.trunc(math.sin(math.radians(x)) * 90)
print ("%d" % y, end="")
rowCount += 1
if (rowCount<10 and x<endAngle-1):
print (",", end="")
elif (x<endAngle-1):
print ("\n\t.word ", end="")
rowCount=0
print("")
print ("pixelCircle45X:\t\t; X values of half a 45 pixel-radius circle, indexed by angle",end="")
print ("\n\t.word ", end="")
rowCount=0
endAngle = 181
for y in range(0,endAngle):
x = math.trunc(math.cos(math.radians(y)) * 45)
print ("%d" % x, end="")
rowCount += 1
if (rowCount<10 and y<endAngle-1):
print (",", end="")
elif (y<endAngle-1):
print ("\n\t.word ", end="")
rowCount=0
print("")
print ("\npixelCircle45Y:\t\t; Y values of half a 45 pixel-radius circle, indexed by angle",end="")
print ("\n\t.word ", end="")
rowCount=0
endAngle = 181
for x in range(0,endAngle):
y = math.trunc(math.sin(math.radians(x)) * 45)
print ("%d" % y, end="")
rowCount += 1
if (rowCount<10 and x<endAngle-1):
print (",", end="")
elif (x<endAngle-1):
print ("\n\t.word ", end="")
rowCount=0
print("")
if __name__ == "__main__":
main(sys.argv[1:])

Binary file not shown.

105
crosshair.s Normal file
View File

@ -0,0 +1,105 @@
;
; crosshair
; Code and data structures related to the aiming crosshair
;
; Created by Quinn Dunki on 2/13/21
;
crosshairGameObject:
.word 100 ; X pos in pixels (from right terrain edge)
.word 100 ; Y pos in pixels (from bottom terrain edge)
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 128 bytes
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; updateCrosshair
;
; Y = Player index to render for
; Trashes SCRATCHL, PARAML0, PARAML1
;
updateCrosshair:
SAVE_AX
PLAYERPTR_Y
; Calculate X offset
lda playerData+PD_ANGLE,y
asl
tax
lda pixelCircle45X,x
bmi updateCrosshairNegX
; Compute screenspace X
sta SCRATCHL
clc
lda playerData+GO_POSX
adc SCRATCHL
sta crosshairGameObject+GO_POSX
bra updateCrosshairCalcY
updateCrosshairNegX:
eor #$FFFF
inc
; Compute screenspace X
sta SCRATCHL
sec
lda playerData+GO_POSX
sbc SCRATCHL
sta crosshairGameObject+GO_POSX
updateCrosshairCalcY:
; Calculate Y offset
lda playerData+PD_ANGLE,y
asl
tax
lda pixelCircle45Y,x
sta SCRATCHL
; Compute screenspace Y
clc
lda playerData+GO_POSY
adc SCRATCHL
sta crosshairGameObject+GO_POSY
updateCrosshairDone:
RESTORE_AX
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderCrosshair
;
;
renderCrosshair:
SAVE_AXY
lda #crosshairGameObject
sta PARAML0
lda #15
jsr renderGameObject
renderCrosshairDone:
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; unrenderCrosshair
;
;
unrenderCrosshair:
pha
lda #crosshairGameObject
sta PARAML0
jsr unrenderGameObject
unrenderCrosshairDone:
pla
rts

View File

@ -84,7 +84,10 @@ gameplayLoop:
; Check for pause
lda paused
bne gameplayLoopEndFrame
beq gameplayLoopBeginUpdate
jmp gameplayLoopEndFrame
gameplayLoopBeginUpdate:
;;;;;;;;;;;
; Update
@ -110,9 +113,15 @@ gameplayLoopScroll:
gameplayLoopAngle:
; Update aim angle if needed
lda angleDeltaRequested
beq gameplayLoopPower
beq gameplayLoopAim
jsr changeAngle
gameplayLoopAim:
jsr unrenderCrosshair
ldy currentPlayer
jsr updateCrosshair
jsr renderCrosshair
gameplayLoopPower:
; Update power if needed
lda powerDeltaRequested
@ -123,7 +132,7 @@ gameplayLoopFire:
lda fireRequested
beq gameplayLoopRender
jsr fire
; BORDER_COLOR #$2
gameplayLoopRender:

View File

@ -51,6 +51,7 @@ quitGame:
.include "projectile.s"
.include "inventory.s"
.include "dirt.s"
.include "crosshair.s"
endMainBank2:

View File

@ -80,13 +80,13 @@ kbdScanQ:
kbdScanA:
BITS16
lda #1
lda #2
sta angleDeltaRequested
rts
kbdScanZ:
BITS16
lda #-1
lda #-2
sta angleDeltaRequested
rts

View File

@ -40,10 +40,10 @@ main:
EMULATION
; Load rest of code into bank 0 (needed if code size exceeds BUFFERSIZE)
; jsr PRODOS
; .byte $ca
; .addr fileRead
; bne ioError
jsr PRODOS
.byte $ca
.addr fileRead
bne ioError
; Close the file
jsr PRODOS
@ -52,11 +52,11 @@ main:
NATIVE
; Copy rest code into bank 2 (needed if code size exceeds BUFFERSIZE)
; ldx fileReadLen
; lda #2
; ldy #0
; jsr copyBytes
; Copy rest of code into bank 2 (needed if code size exceeds BUFFERSIZE)
ldx fileReadLen
lda #2
ldy #BUFFERSIZE
jsr copyBytes
EMULATION

View File

@ -16,7 +16,7 @@ playerData:
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 25 ; Angle in degrees from +X
.word 24 ; Angle in degrees from +X
.word 2 ; Power
.word 100 ; Anger
.byte 8,"SPROCKET " ; Name
@ -38,7 +38,7 @@ playerData:
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 155 ; Angle in degrees from +X
.word 154 ; Angle in degrees from +X
.word 2 ; Power
.word 100 ; Anger
.byte 8,"TINKER " ; Name

View File

@ -2,18 +2,18 @@
DrawSpriteBank :
ASL ; A=Sprite Number ($0000-$000E)
ASL ; A=Sprite Number ($0000-$000F)
TAX ; Y=Target Screen Address ($2000-$9D00)
LDA SpriteBankNum,X ; Relative Sprite Number Table
JMP (SpriteBankBank,X) ; Bank Number Table
SpriteBankNum :
.dbyt $0100,$0000,$0A00,$0500,$0600,$0900,$0D00,$0C00
.dbyt $0800,$0700,$0B00,$0E00,$0200,$0300,$0400
.dbyt $0100,$0000,$0A00,$0500,$0600,$0900,$0E00,$0D00
.dbyt $0800,$0700,$0C00,$0F00,$0200,$0300,$0400,$0B00
SpriteBankBank :
.addr SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00
.addr SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00
.addr SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00,SpriteBankBank00
SpriteBankBank00 :
JSL $AA0000

View File

@ -152,4 +152,50 @@ vramYOffset:
.word $6400,$64a0,$6540,$65e0,$6680,$6720,$67c0,$6860,$6900,$69a0,$6a40,$6ae0,$6b80,$6c20,$6cc0,$6d60,$6e00,$6ea0,$6f40,$6fe0
.word $7080,$7120,$71c0,$7260,$7300,$73a0,$7440,$74e0,$7580,$7620,$76c0,$7760,$7800,$78a0,$7940,$79e0,$7a80,$7b20,$7bc0,$7c60
pixelCircle45X: ; X values of half a 45 pixel-radius circle, indexed by angle
.word 45,44,44,44,44,44,44,44,44,44
.word 44,44,44,43,43,43,43,43,42,42
.word 42,42,41,41,41,40,40,40,39,39
.word 38,38,38,37,37,36,36,35,35,34
.word 34,33,33,32,32,31,31,30,30,29
.word 28,28,27,27,26,25,25,24,23,23
.word 22,21,21,20,19,19,18,17,16,16
.word 15,14,13,13,12,11,10,10,9,8
.word 7,7,6,5,4,3,3,2,1,0
.word 0,0,-1,-2,-3,-3,-4,-5,-6,-7
.word -7,-8,-9,-10,-10,-11,-12,-13,-13,-14
.word -15,-16,-16,-17,-18,-19,-19,-20,-21,-21
.word -22,-23,-23,-24,-25,-25,-26,-27,-27,-28
.word -28,-29,-30,-30,-31,-31,-32,-32,-33,-33
.word -34,-34,-35,-35,-36,-36,-37,-37,-38,-38
.word -38,-39,-39,-40,-40,-40,-41,-41,-41,-42
.word -42,-42,-42,-43,-43,-43,-43,-43,-44,-44
.word -44,-44,-44,-44,-44,-44,-44,-44,-44,-44
.word -45
pixelCircle45Y: ; Y values of half a 45 pixel-radius circle, indexed by angle
.word 0,0,1,2,3,3,4,5,6,7
.word 7,8,9,10,10,11,12,13,13,14
.word 15,16,16,17,18,19,19,20,21,21
.word 22,23,23,24,25,25,26,27,27,28
.word 28,29,30,30,31,31,32,32,33,33
.word 34,34,35,35,36,36,37,37,38,38
.word 38,39,39,40,40,40,41,41,41,42
.word 42,42,42,43,43,43,43,43,44,44
.word 44,44,44,44,44,44,44,44,44,44
.word 45,44,44,44,44,44,44,44,44,44
.word 44,44,44,43,43,43,43,43,42,42
.word 42,42,41,41,41,40,40,40,39,39
.word 38,38,38,37,37,36,36,35,35,34
.word 34,33,33,32,32,31,31,30,30,29
.word 28,28,27,27,26,25,25,24,23,23
.word 22,21,21,20,19,19,18,17,16,16
.word 15,14,13,13,12,11,10,10,9,8
.word 7,7,6,5,4,3,3,2,1,0
.word 0
.include "circleTable.s"