Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Action committed Apr 17, 2024
1 parent 1b1a990 commit 9dfb3bb
Show file tree
Hide file tree
Showing 35 changed files with 1,123 additions and 1,207 deletions.
82 changes: 40 additions & 42 deletions it/part3/bullets.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ <h1 id="bullets"><a class="header" href="#bullets">Bullets</a></h1>

SECTION &quot;BulletVariables&quot;, WRAM0

wSpawnBullet:db
wSpawnBullet: db

; how many bullets are currently active
wActiveBulletCounter:: db

; how many bullet's we've updated
wUpdateBulletsCounter:db
wUpdateBulletsCounter: db

; Bytes: active, x , y (low), y (high)
wBullets:: ds MAX_BULLET_COUNT*PER_BULLET_BYTES_COUNT
Expand All @@ -246,7 +246,7 @@ <h2 id="initiating-bullets"><a class="header" href="#initiating-bullets">Initiat
<p>We’ll iterate through bullet object pool, named “wBullets”, and activate the first of the the four bytes. Then skipping the next 3 bytes, to go onto the next bullet. We’ll do this until we’ve looped for each bullet in our pool.</p>
<pre><code class="language-rgbasm linenos start=29">InitializeBullets::

ld a, 0
xor a
ld [wSpawnBullet], a

; Copy the bullet tile data intto vram
Expand All @@ -256,54 +256,52 @@ <h2 id="initiating-bullets"><a class="header" href="#initiating-bullets">Initiat
call CopyDEintoMemoryAtHL

; Reset how many bullets are active to 0
ld a,0
xor a
ld [wActiveBulletCounter],a

ld b, 0
ld b, a
ld hl, wBullets
ld [hl], a

InitializeBullets_Loop:

ld a, 0
ld [hl], a

; Increase the address
ld a, l
add a, PER_BULLET_BYTES_COUNT
add PER_BULLET_BYTES_COUNT
ld l, a
ld a, h
adc a, 0
adc 0
ld h, a

; Increase how many bullets we have initailized
ld a, b
inc a
ld b ,a
ld b, a

cp a, MAX_BULLET_COUNT
cp MAX_BULLET_COUNT
ret z

jp InitializeBullets_Loop
</code></pre>
<h2 id="updating-bullets"><a class="header" href="#updating-bullets">Updating Bullets</a></h2>
<p>When we want to update each of bullets, first we should check if any bullets are active. If no bullets are active we can stop early.</p>
<pre><code class="language-rgbasm linenos start=70">UpdateBullets::
<pre><code class="language-rgbasm linenos start=68">UpdateBullets::

; Make sure we have SOME active enemies
ld a, [wSpawnBullet]
ld b, a
ld a, [wActiveBulletCounter]
or a,b
cp a, 0
or b
cp 0
ret z

; Reset our counter for how many bullets we have checked
ld a, 0
xor a
ld [wUpdateBulletsCounter], a

; Get the address of the first bullet in hl
ld a, LOW(wBullets)
ld l, a
ld l, a
ld a, HIGH(wBullets)
ld h, a

Expand All @@ -328,28 +326,28 @@ <h2 id="updating-bullets"><a class="header" href="#updating-bullets">Updating Bu
<li>Descale the y position we have in c &amp; d, and jump to our deactivation code if c (the low byte) is high enough</li>
<li>Draw our bullet metasprit, if it wasn’t previously deactivated</li>
</ul>
<pre><code class="language-rgbasm linenos start=113">UpdateBullets_PerBullet:
<pre><code class="language-rgbasm linenos start=111">UpdateBullets_PerBullet:

; The first byte is if the bullet is active
; If it's NOT zero, it's active, go to the normal update section
ld a, [hl]
cp a, 0
and a
jp nz, UpdateBullets_PerBullet_Normal

; Do we need to spawn a bullet?
; If we dont, loop to the next enemy
ld a, [wSpawnBullet]
cp a, 0
and a
jp z, UpdateBullets_Loop

UpdateBullets_PerBullet_SpawnDeactivatedBullet:

; reset this variable so we don't spawn anymore
ld a, 0
xor a
ld [wSpawnBullet], a

; Increase how many bullets are active
ld a,[wActiveBulletCounter]
ld a, [wActiveBulletCounter]
inc a
ld [wActiveBulletCounter], a

Expand All @@ -360,7 +358,7 @@ <h2 id="updating-bullets"><a class="header" href="#updating-bullets">Updating Bu
ld [hli], a

; Get the unscaled player x position in b
ld a, [wPlayerPositionX+0]
ld a, [wPlayerPositionX]
ld b, a
ld a, [wPlayerPositionX+1]
ld d, a
Expand All @@ -381,10 +379,10 @@ <h2 id="updating-bullets"><a class="header" href="#updating-bullets">Updating Bu
ld [hli], a

; Set the y position (low)
ld a, [wPlayerPositionY+0]
ld a, [wPlayerPositionY]
ld [hli], a

;Set the y position (high)
; Set the y position (high)
ld a, [wPlayerPositionY+1]
ld [hli], a

Expand All @@ -403,11 +401,11 @@ <h2 id="updating-bullets"><a class="header" href="#updating-bullets">Updating Bu

; get our 16-bit y position
ld a, [hl]
sub a, BULLET_MOVE_SPEED
sub BULLET_MOVE_SPEED
ld [hli], a
ld c, a
ld a, [hl]
sbc a, 0
sbc 0
ld [hl], a
ld d, a

Expand All @@ -425,14 +423,14 @@ <h2 id="updating-bullets"><a class="header" href="#updating-bullets">Updating Bu

; See if our non scaled low byte is above 160
ld a, c
cp a, 178
; If it below 160, continue on to deactivate
cp 178
; If it's below 160, deactivate
jp nc, UpdateBullets_DeActivateIfOutOfBounds

</code></pre>
<h3 id="drawing-the-bullets"><a class="header" href="#drawing-the-bullets">Drawing the Bullets</a></h3>
<p>We’ll draw our bullet metasprite like we drew the player, using our “DrawMetasprites” function. This function may alter the ‘h’ or ‘l’ registers, so we’ll push the hl register onto the stack before hand. After drawing, we’ll pop the hl register off of the stack to restore it’s value.</p>
<pre><code class="language-rgbasm linenos start=214">
<pre><code class="language-rgbasm linenos start=212">
push hl

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -442,20 +440,20 @@ <h3 id="drawing-the-bullets"><a class="header" href="#drawing-the-bullets">Drawi
; Save the address of the metasprite into the 'wMetaspriteAddress' variable
; Our DrawMetasprites functoin uses that variable
ld a, LOW(bulletMetasprite)
ld [wMetaspriteAddress+0], a
ld [wMetaspriteAddress], a
ld a, HIGH(bulletMetasprite)
ld [wMetaspriteAddress+1], a

; Save the x position
ld a, b
ld [wMetaspriteX],a
ld [wMetaspriteX], a

; Save the y position
ld a, c
ld [wMetaspriteY],a
ld [wMetaspriteY], a

; Actually call the 'DrawMetasprites function
call DrawMetasprites;
call DrawMetasprites

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -466,11 +464,11 @@ <h3 id="drawing-the-bullets"><a class="header" href="#drawing-the-bullets">Drawi
</code></pre>
<h3 id="deactivating-the-bullets"><a class="header" href="#deactivating-the-bullets">Deactivating the Bullets</a></h3>
<p>If a bullet needs to be deactivated, we simply set it’s first byte to 0. At this point in time, the “hl” registers should point at our bullets first byte. This makes deactivation a really simple task. In addition to changing the first byte, we’ll decrease how many bullets we have that are active.</p>
<pre><code class="language-rgbasm linenos start=246">UpdateBullets_DeActivateIfOutOfBounds:
<pre><code class="language-rgbasm linenos start=244">UpdateBullets_DeActivateIfOutOfBounds:

; if it's y value is grater than 160
; Set as inactive
ld a, 0
xor a
ld [hl], a

; Decrease counter
Expand All @@ -482,7 +480,7 @@ <h3 id="deactivating-the-bullets"><a class="header" href="#deactivating-the-bull
</code></pre>
<h3 id="updating-the-next-bullet"><a class="header" href="#updating-the-next-bullet">Updating the next bullet</a></h3>
<p>After we’ve updated a single bullet, we’ll increase how many bullet’s we’ve updated. If we’ve updated all the bullets, we can stop our “UpdateBullets” function. Otherwise, we’ll add 4 bytes to the addressed stored in “hl”, and update the next bullet.</p>
<pre><code class="language-rgbasm linenos start=92">UpdateBullets_Loop:
<pre><code class="language-rgbasm linenos start=90">UpdateBullets_Loop:

; Check our counter, if it's zero
; Stop the function
Expand All @@ -492,15 +490,15 @@ <h3 id="updating-the-next-bullet"><a class="header" href="#updating-the-next-bul

; Check if we've already
ld a, [wUpdateBulletsCounter]
cp a, MAX_BULLET_COUNT
cp MAX_BULLET_COUNT
ret nc

; Increase the bullet data our address is pointingtwo
ld a, l
add a, PER_BULLET_BYTES_COUNT
add PER_BULLET_BYTES_COUNT
ld l, a
ld a, h
adc a, 0
adc 0
ld h, a
</code></pre>
<h2 id="firing-new-bullets"><a class="header" href="#firing-new-bullets">Firing New Bullets</a></h2>
Expand All @@ -509,11 +507,11 @@ <h2 id="firing-new-bullets"><a class="header" href="#firing-new-bullets">Firing
<blockquote>
<p>Our bullets only use one 8-bit integer for their x position, so need to de-scale the player’s 16-bit scaled x position</p>
</blockquote>
<pre><code class="language-rgbasm linenos start=260">FireNextBullet::
<pre><code class="language-rgbasm linenos start=258">FireNextBullet::

; Make sure we don't have the max amount of enmies
ld a, [wActiveBulletCounter]
cp a, MAX_BULLET_COUNT
cp MAX_BULLET_COUNT
ret nc

; Set our spawn bullet variable to true
Expand Down
25 changes: 12 additions & 13 deletions it/part3/changing-game-states.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,23 @@ <h1 id="changing-game-states"><a class="header" href="#changing-game-states">Cha
<blockquote>
<p>It will be the responsibility of the “init” function for each game state to turn the LCD back on.</p>
</blockquote>
<pre><code class="language-rgbasm linenos start=50">
<pre><code class="language-rgbasm linenos start=48">
NextGameState::

; Do not turn the LCD off outside of VBlank
call WaitForOneVBlank

call ClearBackground;
call ClearBackground


; Turn the LCD off
ld a, 0
xor a
ld [rLCDC], a

ld a, 0
ld [rSCX],a
ld [rSCY],a
ld [rWX],a
ld [rWY],a
ld [rSCX], a
ld [rSCY], a
ld [rWX], a
ld [rWY], a
; disable interrupts
call DisableInterrupts

Expand All @@ -258,20 +257,20 @@ <h1 id="changing-game-states"><a class="header" href="#changing-game-states">Cha

; Initiate the next state
ld a, [wGameState]
cp a, 2 ; 2 = Gameplay
cp 2 ; 2 = Gameplay
call z, InitGameplayState
ld a, [wGameState]
cp a, 1 ; 1 = Story
cp 1 ; 1 = Story
call z, InitStoryState
ld a, [wGameState]
cp a, 0 ; 0 = Menu
and a ; 0 = Menu
call z, InitTitleScreenState

; Update the next state
ld a, [wGameState]
cp a, 2 ; 2 = Gameplay
cp 2 ; 2 = Gameplay
jp z, UpdateGameplayState
cp a, 1 ; 1 = Story
cp 1 ; 1 = Story
jp z, UpdateStoryState
jp UpdateTitleScreenState

Expand Down
19 changes: 9 additions & 10 deletions it/part3/collision.html
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,13 @@ <h1 id="collision-detection"><a class="header" href="#collision-detection">Colli
<p>NOTE: We don’t need to test the y-axis if the x-axis fails. </p>
</blockquote>
<p>The source code for that function looks like this:</p>
<pre><code class="language-rgbasm linenos start=1">include &quot;src/main/utils/hardware.inc&quot;
include &quot;src/main/utils/constants.inc&quot;
<pre><code class="language-rgbasm linenos start=1">include &quot;src/main/utils/constants.inc&quot;
include &quot;src/main/utils/hardware.inc&quot;

SECTION &quot;CollisionUtilsVariables&quot;, WRAM0

wResult::db;
wSize::db;
wResult:: db
wSize:: db
wObject1Value:: db
wObject2Value:: db

Expand All @@ -287,24 +286,24 @@ <h1 id="collision-detection"><a class="header" href="#collision-detection">Colli
; carry means e&lt;b, means enemy.bottom is visually above bullet.y (no collision)

ld a, e
add a, d
cp a, b
add d
cp b

; carry means no collision
jp c, CheckObjectPositionDifference_Failure

; subtract enemy.y-8 (aka e) - bullet.y (aka b)
; no carry means e&gt;b, means enemy.top is visually below bullet.y (no collision)
ld a, e
sub a, d
cp a, b
sub d
cp b

; no carry means no collision
jp nc, CheckObjectPositionDifference_Failure

ld a,1
ld a, 1
ld [wResult], a
ret;
ret


CheckObjectPositionDifference_Failure:
Expand Down
Loading

0 comments on commit 9dfb3bb

Please sign in to comment.