Working on a crude physic engine
Posted: Mon Nov 18, 2019 10:38 pm
I gotta say, its super fun trying something and failing again and again until that one magical moment when the code is finally lines up in a way that makes what you're trying to do actually kinda work.
After having that happen to me a few times while learning 6502 in the last couple months, I can totally see the appeal of this hobby.
After finally getting a handle on some of the basics of 6502, I decided that I want to tackle something a little more ambitious for my next project. My first attempt at a super crude physics engine for a 2nd platformer.
Nothing grand. Just a little white dot that can move back and forth, jump and land on a couple platforms.
If I can get three features working I'll consider it finished.
1. Collision Detection (I actually got that one working and I'm super proud of it, despite how crude and unoptimized it is since I can't figure out good ways to use the BIT opcode yet. So, I'm stuck using ham fisted Compare opcodes for now. I'll fix it later. I'm just happy that its working.)
2. Gravity (It actually works now but only independently from everything else. I'm still working out how attach it to the main game input loop without breaking everything lol)
3. Momentum (I haven't the foggiest idea how to pull this one off, but it'll be fun trying to find out.)
Once again, as with all my projects so far, this is designed to run on Nick Morgan's Easy 6502 virtual machine:
http://skilldrick.github.io/easy6502/
My collision subroutine is too much of an unoptimized hot mess to show right now, but here's my first working version of the gravity subroutine:
After having that happen to me a few times while learning 6502 in the last couple months, I can totally see the appeal of this hobby.
After finally getting a handle on some of the basics of 6502, I decided that I want to tackle something a little more ambitious for my next project. My first attempt at a super crude physics engine for a 2nd platformer.
Nothing grand. Just a little white dot that can move back and forth, jump and land on a couple platforms.
If I can get three features working I'll consider it finished.
1. Collision Detection (I actually got that one working and I'm super proud of it, despite how crude and unoptimized it is since I can't figure out good ways to use the BIT opcode yet. So, I'm stuck using ham fisted Compare opcodes for now. I'll fix it later. I'm just happy that its working.)
2. Gravity (It actually works now but only independently from everything else. I'm still working out how attach it to the main game input loop without breaking everything lol)
3. Momentum (I haven't the foggiest idea how to pull this one off, but it'll be fun trying to find out.)
Once again, as with all my projects so far, this is designed to run on Nick Morgan's Easy 6502 virtual machine:
http://skilldrick.github.io/easy6502/
My collision subroutine is too much of an unoptimized hot mess to show right now, but here's my first working version of the gravity subroutine:
Code: Select all
;initializing position and color and first spawn
LDX #$02 ;setting high and low byte of spawn
STX $02
LDX #$08
STX $01
LDA #$01 ;setting color
STA ($01),y ;spawning dot
gravity:
CLC
JSR delay ;calling slow down delay
LDA #$00 ;clearing last position
STA ($01),y
LDA $01 ;drop position 1 space
ADC #$20
STA $01
LDA #$01 ;redraw dot in new position
STA ($01),y
BCC gravity ;if carry flag not set, fall again
LDA #$00 ;else, increment high byte, then back to fall
STA ($01),y
INC $02
LDX $02
CPX #$06 ;check if high byte is in range of display memory
BNE gravity ;If Yes, continue falling
DEC $02 ;Else, Hit Floor and stop falling
LDA $01
SBC #$20
STA $01
LDA #$01
STA ($01),y
JMP end
delay: ;slowing down the fall
LDX #$a0
delayloop:
DEX
BNE delayloop
RTS
end:
BRK