Update the flea sprite as it drops. Add random routines. Thanks to John Brooks for those. Use the random routines to pick a column for the flea to drop from. Also, randomly leave behind a mushroom as it falls.

This commit is contained in:
Jeremy Rand 2020-07-19 15:15:45 -04:00
parent 3fcd2ac8a8
commit 88ea840e23
4 changed files with 123 additions and 5 deletions

View File

@ -64,6 +64,7 @@
9D1716A42491C49300C83148 /* system601.2mg */ = {isa = PBXFileReference; lastKnownFileType = file; path = system601.2mg; sourceTree = "<group>"; }; 9D1716A42491C49300C83148 /* system601.2mg */ = {isa = PBXFileReference; lastKnownFileType = file; path = system601.2mg; sourceTree = "<group>"; };
9D1716A62491C49300C83148 /* tail.mk */ = {isa = PBXFileReference; lastKnownFileType = text; path = tail.mk; sourceTree = "<group>"; }; 9D1716A62491C49300C83148 /* tail.mk */ = {isa = PBXFileReference; lastKnownFileType = text; path = tail.mk; sourceTree = "<group>"; };
9D1716A92491C49300C83148 /* BuGS.xcscheme */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = BuGS.xcscheme; path = ../../BuGS.xcodeproj/xcshareddata/xcschemes/BuGS.xcscheme; sourceTree = "<group>"; }; 9D1716A92491C49300C83148 /* BuGS.xcscheme */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = BuGS.xcscheme; path = ../../BuGS.xcodeproj/xcshareddata/xcschemes/BuGS.xcscheme; sourceTree = "<group>"; };
9D2FF6DA24C4C79A000181E5 /* random.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = random.s; sourceTree = "<group>"; };
9D3396F424AECB1D003222B3 /* explosions.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = explosions.s; sourceTree = "<group>"; }; 9D3396F424AECB1D003222B3 /* explosions.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = explosions.s; sourceTree = "<group>"; };
9D3396F524AECBB1003222B3 /* spiders.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = spiders.s; sourceTree = "<group>"; }; 9D3396F524AECBB1003222B3 /* spiders.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = spiders.s; sourceTree = "<group>"; };
9D3396F624AECC40003222B3 /* scorpions.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = scorpions.s; sourceTree = "<group>"; }; 9D3396F624AECC40003222B3 /* scorpions.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = scorpions.s; sourceTree = "<group>"; };
@ -131,6 +132,7 @@
9D8FFC612491CAF0005C9327 /* game.h */, 9D8FFC612491CAF0005C9327 /* game.h */,
9DB1505024C3801100558B87 /* gameFlea.s */, 9DB1505024C3801100558B87 /* gameFlea.s */,
9D62AF3B249871A300348F45 /* colour.s */, 9D62AF3B249871A300348F45 /* colour.s */,
9D2FF6DA24C4C79A000181E5 /* random.s */,
9D3396F324AECACC003222B3 /* sprites */, 9D3396F324AECACC003222B3 /* sprites */,
9D1716912491C49300C83148 /* main.rez */, 9D1716912491C49300C83148 /* main.rez */,
9D1716932491C49300C83148 /* Makefile */, 9D1716932491C49300C83148 /* Makefile */,

View File

@ -21,7 +21,8 @@ drawFlea entry
beq drawFlea_done beq drawFlea_done
ldy fleaScreenOffset ldy fleaScreenOffset
jsl flea1 ldx fleaSprite
jsl fleaJump
ldy numDirtyGameTiles ldy numDirtyGameTiles
@ -78,10 +79,23 @@ drawFlea_done anop
rtl rtl
fleaJump entry
lda fleaJumpTable,x
sta jumpInst+1
lda fleaJumpTable+2,x
sta jumpInst+3
jumpInst jmp >flea1
nop
updateFlea entry updateFlea entry
lda fleaState lda fleaState
beq updateFlea_done bne updateFlea_cont
rtl
updateFlea_cont anop
lda fleaHeightInTile lda fleaHeightInTile
beq updateFlea_nextTile beq updateFlea_nextTile
dec a dec a
@ -94,6 +108,22 @@ updateFlea_bottomOfTile anop
sta fleaTileOffsets+4 sta fleaTileOffsets+4
lda fleaTileOffsets+2 lda fleaTileOffsets+2
sta fleaTileOffsets+6 sta fleaTileOffsets+6
lda fleaSpriteCounter
eor #$1
sta fleaSpriteCounter
bne updateFlea_nextAction
lda fleaSprite
cmp #$c
beq updateFlea_resetSprite
clc
adc #$4
sta fleaSprite
bra updateFlea_nextAction
updateFlea_resetSprite anop
stz fleaSprite
bra updateFlea_nextAction bra updateFlea_nextAction
updateFlea_nextTile anop updateFlea_nextTile anop
@ -110,6 +140,16 @@ updateFlea_nextTile anop
lda tiles+8,x lda tiles+8,x
sta fleaTileOffsets+2 sta fleaTileOffsets+2
ldx fleaTileOffsets+4
lda tiles+4,x
bne updateFlea_nextAction
jsl rand65535
and #$7
bne updateFlea_nextAction
lda #$10
sta tiles+4,x
bra updateFlea_nextAction bra updateFlea_nextAction
updateFlea_bottom anop updateFlea_bottom anop
@ -136,7 +176,13 @@ addFlea entry
lda #$3 lda #$3
sta fleaHeightInTile sta fleaHeightInTile
lda #$40 stz fleaSpriteCounter
jsl rand25
asl a
asl a
asl a
asl a
sta fleaTileOffsets sta fleaTileOffsets
sta fleaTileOffsets+4 sta fleaTileOffsets+4
@ -161,5 +207,12 @@ fleaTileOffsets dc i2'0'
dc i2'0' dc i2'0'
dc i2'0' dc i2'0'
fleaHeightInTile dc i2'0' fleaHeightInTile dc i2'0'
fleaSpriteCounter dc i2'0'
fleaSprite dc i2'0'
fleaJumpTable dc i4'flea1'
dc i4'flea2'
dc i4'flea3'
dc i4'flea4'
end end

View File

@ -28,6 +28,7 @@
/* Globals */ /* Globals */
unsigned int userid; unsigned int userid;
unsigned int randomSeed;
/* Implementation */ /* Implementation */
@ -53,7 +54,11 @@ int main(void)
NewHandle(0x9000, userid, attrLocked | attrFixed | attrAddr | attrBank, (Pointer)0x011000); NewHandle(0x9000, userid, attrLocked | attrFixed | attrAddr | attrBank, (Pointer)0x011000);
TOOLFAIL("Unable to allocate SHR screen"); TOOLFAIL("Unable to allocate SHR screen");
srand((int)(time(NULL))); randomSeed = (int)time(NULL);
if (randomSeed == 0)
randomSeed = 1;
srand(randomSeed);
randInit();
initTiles(); initTiles();
initNonGameTiles(); initNonGameTiles();

58
BuGS/random.s Normal file
View File

@ -0,0 +1,58 @@
;
; random.s
; BuGS
;
; Created by Jeremy Rand on 2020-07-19.
;Copyright © 2020 Jeremy Rand. All rights reserved.
;
case on
mcopy random.macros
keep random
random start
randInit entry
lda randomSeed
sta seed65535
and #$1f
bne randInit_store32
lda #$1f
randInit_store32 anop
sta seed32
rtl
; Returns a number from 1 to 31
rand32 entry
lda seed32
lsr a
bcc skipEor32
eor #$0014
skipEor32 anop
sta seed32
rtl
; returns a number from 0 to 24
rand25 entry
jsl rand32
dec a
cmp #25
bge rand25
rtl
; Returns a number from 1 to 65535
rand65535 entry
lda seed65535
lsr a
bcc skipEor65535
eor #$b400
skipEor65535 anop
sta seed65535
rtl
seed65535 dc i2'0'
seed32 dc i2'0'
end