Exploring Retro Arcade Days - Simple Yet Challenging Breakout
Lab-2
Introduction
In this lab I got to explore and relive the experience that my dad gained . I wanted to build a game in 6502 assembly language using an online emulator . With the help of online resources and YouTube tutorials , I managed to create a simple game
Concept
To experiment , I chose a simple breakout game in which the player has to judge an incoming ball(pixel) , which bounces off of a platform . Player can reposition the platform along the X-axis and the velocity of the ball increase each time it bounces off the platform. Player earns a point each time the ball bounces off the platform . Game ends when the ball hits the bottom of the screen .
Development Process
Using a 6502 assembly language emulator and a text editor, I began writing the code for my game. I defined variables for the ball's position, velocity, paddle size, score, and collision detection flags. Then, I set up the initial game state, including placing the ball and paddle on the screen.
Next, I implemented the game mechanics. I wrote routines to move the ball, update its position based on velocity, handle collisions with the screen borders and the paddle, and increment the score upon successful hits.
Throughout the development process, I encountered several challenges. Debugging assembly code proved to be tricky, especially with limited tooling compared to modern programming environments. I had to meticulously trace through the code, inspecting register values and memory locations to identify and fix bugs.
Boundary Checking
One of the early challenges Ifaced was ensuring that the ball and platform stayed in the bounds of the screen . At one point Iforgot to apply bitwise and operations to restrict row and column values to valid ranges , which lead to erratic behaviour when the ball reached the edges of screen.
To fix this issue , I added necessary boundary checks using appropriate masks .This ensured that the ball and platform remained within the screen range .
; Boundary checking
draw: lda Row ; ensure Row is in range 031
and #$1f
sta ROW
lda COL ; ensure COL is in range 031
and #$1f
sta COL
Handling Collision Detection
I had to fix one more issue when implementing collision detection between the ball , platform and screen borders. There was an error in my collision routine that caused the game to behave unpredictably .
To fix this , the looked and the conditional logic andadjusted it to set correct flags
; Collision Detection for Screen Boundary
colidR: lda COL
cmp #$1f
bne colidL
sta BOUNCEY
Optimizing Performance
I wanted to make the game more refined and smooth for the User Experience as Inoted that certain sections weren'tas efficient as others , leading to subpar performance . For example , the delay loop used for game accelerating was consuming more CPU cycles than necessary which impacted on responsiveness of the game
To improve this , I changed the delay loop by reducing the number of iterations and adjusting the loop counter values. This resulted in smoother gameplay and reduced CPU overhead.
; Performance Optimization - Delay Loop
delaya: ldy #$00 ; Delay processor to slow down game
ldx #$00
delay : any
cpy #$FF
bne delay
lay #$00
inx
cpx #$06
bne delay
Conclusion
By addressing issues such as boundary checking, collision detection, and performance optimization, I gained valuable insights into low-level programming techniques and game development principles.
References : https://www.youtube.com/watch?v=yfntWv0U8Pw&t=57s
https://fotino.me/breakout-in-assembly/
Source Code : https://github.com/sjani5/SPO600/blob/main/Lab-2.asm
Gameplay :
Comments
Post a Comment