Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Action committed May 7, 2024
1 parent 9dfb3bb commit d4517b5
Show file tree
Hide file tree
Showing 23 changed files with 347 additions and 335 deletions.
16 changes: 9 additions & 7 deletions it/part3/bullets.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ <h1 id="bullets"><a class="header" href="#bullets">Bullets</a></h1>
; how many bullet's we've updated
wUpdateBulletsCounter: db


; Bytes: active, x , y (low), y (high)
wBullets:: ds MAX_BULLET_COUNT*PER_BULLET_BYTES_COUNT


SECTION &quot;Bullets&quot;, ROM0

bulletMetasprite::
Expand All @@ -244,7 +246,7 @@ <h2 id="initiating-bullets"><a class="header" href="#initiating-bullets">Initiat
<p>In our “InitializeBullets” function, we’ll copy the tile data for the bullet sprites into VRAM, and set every bullet as inactive. Each bullet is 4 bytes, the first byte signaling if the bullet is active or not. </p>
<p><img src="../assets/part3/img/BulletBytesVisualized.png" alt="BulletBytesVisualized.png" /></p>
<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::
<pre><code class="language-rgbasm linenos start=31">InitializeBullets::

xor a
ld [wSpawnBullet], a
Expand Down Expand Up @@ -285,7 +287,7 @@ <h2 id="initiating-bullets"><a class="header" href="#initiating-bullets">Initiat
</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=68">UpdateBullets::
<pre><code class="language-rgbasm linenos start=70">UpdateBullets::

; Make sure we have SOME active enemies
ld a, [wSpawnBullet]
Expand Down Expand Up @@ -326,7 +328,7 @@ <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=111">UpdateBullets_PerBullet:
<pre><code class="language-rgbasm linenos start=113">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
Expand Down Expand Up @@ -430,7 +432,7 @@ <h2 id="updating-bullets"><a class="header" href="#updating-bullets">Updating Bu
</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=212">
<pre><code class="language-rgbasm linenos start=214">
push hl

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -464,7 +466,7 @@ <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=244">UpdateBullets_DeActivateIfOutOfBounds:
<pre><code class="language-rgbasm linenos start=246">UpdateBullets_DeActivateIfOutOfBounds:

; if it's y value is grater than 160
; Set as inactive
Expand All @@ -480,7 +482,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=90">UpdateBullets_Loop:
<pre><code class="language-rgbasm linenos start=92">UpdateBullets_Loop:

; Check our counter, if it's zero
; Stop the function
Expand All @@ -507,7 +509,7 @@ <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=258">FireNextBullet::
<pre><code class="language-rgbasm linenos start=260">FireNextBullet::

; Make sure we don't have the max amount of enmies
ld a, [wActiveBulletCounter]
Expand Down
22 changes: 7 additions & 15 deletions it/part3/collision.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ <h1 id="collision-detection"><a class="header" href="#collision-detection">Colli
<p>For this, we’ve created a basic function called “CheckObjectPositionDifference”. This function will help us check for overlap on the x or y axis. When the (absolute) difference between the first two values passed is greater than the third value passed, it jump’s to the label passed in the fourth parameter.</p>
<p>Here’s an example of how to call this function:</p>
<blockquote>
<p>We have the player’s x &amp; y position in registers d &amp; e respectively. We have the enemy’s x &amp; y position in registers b &amp; c respectively. If there is no overlap on the x or y axis, the program jumps to the “NoCollisionWithPlayer” label.</p>
<p>We have the player’s Y position in the <code>d</code> register. We’ll check it’s value against the y value of the current enemy, which we have in a variable named <code>wCurrentEnemyY</code>.</p>
</blockquote>
<pre><code class="language-rgbasm linenos start=696">
<pre><code class="language-rgbasm linenos start=67">
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Check the absolute distances. Jump to 'NoAxisOverlap' on failure
; Check the y distances. Jump to 'NoCollisionWithPlayer' on failure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


ld a, b
ld a, [wCurrentEnemyY]
ld [wObject1Value], a

ld a, d
Expand All @@ -240,17 +240,9 @@ <h1 id="collision-detection"><a class="header" href="#collision-detection">Colli
call CheckObjectPositionDifference

ld a, [wResult]
cp a, 0
jp z, NoAxisOverlap

OverlapExists:

... There is an overlap

NoAxisOverlap:

... no overlap

and a
jp z, NoCollisionWithPlayer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

</code></pre>
<p>When checking for collision, we’ll use that function twice. Once for the x-axis, and again for the y-axis.</p>
Expand Down
26 changes: 15 additions & 11 deletions it/part3/enemies.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ <h1 id="enemies"><a class="header" href="#enemies">Enemies</a></h1>
; Bytes: active, x , y (low), y (high), speed, health
wEnemies:: ds MAX_ENEMY_COUNT*PER_ENEMY_BYTES_COUNT


</code></pre>
<p>Just like with bullets, we’ll setup ROM data for our enemies tile data and metasprites.</p>
<pre><code class="language-rgbasm linenos start=18">SECTION &quot;Enemies&quot;, ROM0
<pre><code class="language-rgbasm linenos start=19">SECTION &quot;Enemies&quot;, ROM0

enemyShipTileData:: INCBIN &quot;src/generated/sprites/enemy-ship.2bpp&quot;
enemyShipTileDataEnd::
Expand All @@ -256,7 +257,7 @@ <h1 id="enemies"><a class="header" href="#enemies">Enemies</a></h1>
</code></pre>
<h2 id="initializing-enemies"><a class="header" href="#initializing-enemies">Initializing Enemies</a></h2>
<p>When initializing the enemies (at the start of gameplay), we’ll copy the enemy tile data into VRAM. Also, like with bullets, we’ll loop through and make sure each enemy is set to inactive.</p>
<pre><code class="language-rgbasm linenos start=28">InitializeEnemies::
<pre><code class="language-rgbasm linenos start=29">InitializeEnemies::

ld de, enemyShipTileData
ld hl, ENEMY_TILES_START
Expand Down Expand Up @@ -295,7 +296,7 @@ <h2 id="initializing-enemies"><a class="header" href="#initializing-enemies">Ini
</code></pre>
<h2 id="updating-enemies"><a class="header" href="#updating-enemies">Updating Enemies</a></h2>
<p>When “UpdateEnemies” is called from gameplay, the first thing we try to do is spawn new enemies. After that, if we have no active enemies (and are not trying to spawn a new enemy), we stop the “UpdateEnemies” function. From here, like with bullets, we’ll save the address of our first enemy in hl and start looping through.</p>
<pre><code class="language-rgbasm linenos start=65">UpdateEnemies::
<pre><code class="language-rgbasm linenos start=66">UpdateEnemies::

call TryToSpawnEnemies

Expand All @@ -320,7 +321,7 @@ <h2 id="updating-enemies"><a class="header" href="#updating-enemies">Updating En
</code></pre>
<p>When we are looping through our enemy object pool, let’s check if the current enemy is active. If it’s active, we’ll update it like normal. If it isn’t active, the game checks if we want to spawn a new enemy. We specify we want to spawn a new enemy by setting ‘wNextEnemyXPosition’ to a non-zero value. If we don’t want to spawn a new enemy, we’ll move on to the next enemy.</p>
<p>If we want to spawn a new enemy, we’ll set the current inactive enemy to active. Afterwards, we’ll set it’s y position to zero, and it’s x position to whatever was in the ‘wNextEnemyXPosition’ variable. After that, we’ll increase our active enemy counter, and go on to update the enemy like normal.</p>
<pre><code class="language-rgbasm linenos start=108">UpdateEnemies_PerEnemy:
<pre><code class="language-rgbasm linenos start=109">UpdateEnemies_PerEnemy:

; The first byte is if the current object is active
; If it's not zero, it's active, go to the normal update section
Expand Down Expand Up @@ -367,7 +368,7 @@ <h2 id="updating-enemies"><a class="header" href="#updating-enemies">Updating En
<blockquote>
<p>The “hl” registers should always point to the current enemies first byte when this label is reached.</p>
</blockquote>
<pre><code class="language-rgbasm linenos start=87">UpdateEnemies_Loop:
<pre><code class="language-rgbasm linenos start=88">UpdateEnemies_Loop:

; Check our coutner, if it's zero
; Stop the function
Expand All @@ -388,7 +389,7 @@ <h2 id="updating-enemies"><a class="header" href="#updating-enemies">Updating En
ld h, a
</code></pre>
<p>For updating enemies, we’ll first get the enemies speed. Afterwards we’ll increase the enemies 16-bit y position. Once we’ve done that, we’ll descale the y position so we can check for collisions and draw the ennemy.</p>
<pre><code class="language-rgbasm linenos start=151">UpdateEnemies_PerEnemy_Update:
<pre><code class="language-rgbasm linenos start=152">UpdateEnemies_PerEnemy_Update:

; Save our first bytye
push hl
Expand Down Expand Up @@ -444,7 +445,7 @@ <h2 id="player--bullet-collision"><a class="header" href="#player--bullet-collis
<blockquote>
<p>Our “hl” registers should point to the active byte of the current enemy. We push and pop our “hl” registers to make sure we get back to that same address for later logic.</p>
</blockquote>
<pre><code class="language-rgbasm linenos start=202">UpdateEnemies_PerEnemy_CheckPlayerCollision:
<pre><code class="language-rgbasm linenos start=203">UpdateEnemies_PerEnemy_CheckPlayerCollision:

push hl

Expand All @@ -468,7 +469,7 @@ <h2 id="player--bullet-collision"><a class="header" href="#player--bullet-collis
jp UpdateEnemies_DeActivateEnemy
</code></pre>
<p>If there is no collision with the player, we’ll draw the enemies. This is done just as we did the player and bullets, with the “DrawMetasprites” function.</p>
<pre><code class="language-rgbasm linenos start=240">UpdateEnemies_NoCollisionWithPlayer::
<pre><code class="language-rgbasm linenos start=241">UpdateEnemies_NoCollisionWithPlayer::

; See if our non scaled low byte is above 160
ld a, [wCurrentEnemyY]
Expand All @@ -477,6 +478,8 @@ <h2 id="player--bullet-collision"><a class="header" href="#player--bullet-collis

push hl



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; call the 'DrawMetasprites function. setup variables and call
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -499,6 +502,7 @@ <h2 id="player--bullet-collision"><a class="header" href="#player--bullet-collis
; Actually call the 'DrawMetasprites function
call DrawMetasprites


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -512,10 +516,10 @@ <h2 id="deactivating-enemies"><a class="header" href="#deactivating-enemies">Dea
<blockquote>
<p>Here, we can just use the current address in HL. This is the second reason we wanted to keep the address of our first byte on the stack.</p>
</blockquote>
<pre><code class="language-rgbasm linenos start=226">UpdateEnemies_DeActivateEnemy:
<pre><code class="language-rgbasm linenos start=227">UpdateEnemies_DeActivateEnemy:

; Set as inactive
xor
xor a
ld [hl], a

; Decrease counter
Expand All @@ -533,7 +537,7 @@ <h2 id="spawning-enemies"><a class="header" href="#spawning-enemies">Spawning En
<p>All enemies are spawned with y position of 0, so we only need to get the x position.</p>
</blockquote>
<p>If we have a valid x position, we’ll reset our spawn counter, and save that x position in the “wNextEnemyXPosition” variable. With this variable set, We’ll later activate and update a enemy that we find in the inactive state.</p>
<pre><code class="language-rgbasm linenos start=281">TryToSpawnEnemies::
<pre><code class="language-rgbasm linenos start=285">TryToSpawnEnemies::

; Increase our spwncounter
ld a, [wSpawnCounter]
Expand Down
10 changes: 3 additions & 7 deletions it/part3/object-pools.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,14 @@ <h1 class="menu-title">GB ASM Tutorial</h1>
<h1 id="object-pools"><a class="header" href="#object-pools">Object Pools</a></h1>
<p>Galactic Armada will use “object pools” for bullets and enemies. A fixed amount of bytes representing a specific maximum amount of objects. Each pool is just a collection of bytes. The number of bytes per “pool” is the maximum number of objects in the pool, times the number of bytes needed for data for each object.</p>
<p>Constants are also created for the size of each object, and what each byte is. These constants are in the “src/main/utils/constants.inc” file and utilize RGBDS offset constants (a really cool feature)</p>
<pre><code class="language-rgbasm linenos start=528">
; from https://rgbds.gbdev.io/docs/v0.6.1/rgbasm.5#EXPRESSIONS
<pre><code class="language-rgbasm linenos start=28">; from https://rgbds.gbdev.io/docs/v0.6.1/rgbasm.5#EXPRESSIONS
; The RS group of commands is a handy way of defining structure offsets:
RSRESET
DEF bullet_activeByte RB 1
DEF bullet_xByte RB 1
DEF bullet_yLowByte RB 1
DEF bullet_yHighByte RB 1
DEF PER_BULLET_BYTES_COUNT RB 0


</code></pre>
<p>The two object types that we need to loop through are Enemies and Bullets.</p>
<p><strong>Bytes for an Enemy:</strong></p>
Expand All @@ -234,8 +231,7 @@ <h1 id="object-pools"><a class="header" href="#object-pools">Object Pools</a></h
<li>Speed - How fast they move</li>
<li>Health - How many bullets they can take</li>
</ol>
<pre><code class="language-rgbasm linenos start=540">
; Bytes: active, x , y (low), y (high), speed, health
<pre><code class="language-rgbasm linenos start=15">; Bytes: active, x , y (low), y (high), speed, health
wEnemies:: ds MAX_ENEMY_COUNT*PER_ENEMY_BYTES_COUNT

</code></pre>
Expand All @@ -247,7 +243,7 @@ <h1 id="object-pools"><a class="header" href="#object-pools">Object Pools</a></h
<li>Y (low) - The lower byte of their 16-bit (scaled) y position</li>
<li>Y (high) - The higher byte of their 16-bit (scaled) y position</li>
</ol>
<pre><code class="language-rgbasm linenos start=523">
<pre><code class="language-rgbasm linenos start=15">
; Bytes: active, x , y (low), y (high)
wBullets:: ds MAX_BULLET_COUNT*PER_BULLET_BYTES_COUNT

Expand Down
5 changes: 3 additions & 2 deletions it/part3/project-structure.html
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,17 @@ <h2 id="background--sprite-resources"><a class="header" href="#background--sprit
$&lt;
</code></pre>
<p>From there, INCBIN commands are used to store reference the binary tile data.</p>
<pre><code class="language-rgbasm linenos start=2">
<pre><code class="language-rgbasm">; in src/main/states/gameplay/objects/player.asm
playerShipTileData: INCBIN &quot;src/generated/sprites/player-ship.2bpp&quot;
playerShipTileDataEnd:

; in src/main/states/gameplay/objects/enemies.asm
enemyShipTileData:: INCBIN &quot;src/generated/sprites/enemy-ship.2bpp&quot;
enemyShipTileDataEnd::

; in src/main/states/gameplay/objects/bullets.asm
bulletTileData:: INCBIN &quot;src/generated/sprites/bullet.2bpp&quot;
bulletTileDataEnd::

</code></pre>
<div class="box tip"><p class="box-title">Including binary files</p>
<p>You probably have some graphics, level data, etc. you’d like to include. Use <strong><code>INCBIN</code></strong> to include a raw binary file as it is. If the file isn’t found in the current directory, the include-path list passed to <a href="https://rgbds.gbdev.io/docs/v0.6.1/rgbasm.1">rgbasm(1)</a> (see the <strong><code>-i</code></strong> option) on the command line will be searched.</p>
Expand Down
Loading

0 comments on commit d4517b5

Please sign in to comment.