| |
Richard
Registered: Dec 2001 Posts: 621 |
Sprite inertia
I am having trouble with inertia, for my sub hunter project.
For example, I want to make the sub move up, using the speed of inertia.
;MOVEMENT DIRECTIONS FOR THE PLAYER'S SUB
MOVEUP: LDX OBJPOS+$01
SEC
P1SPEEDUP: SBC #$01
STX OBJPOS+$01
DEX
CPX #$4C
BCS SETUP
LDX #$4C
SETUP: STX OBJPOS+$01
RTS
;READ PLAYER JOYSTICK CONTROLS VIA PORT 2
READJOY: LDA $DC00
UP: LSR
BCS DOWN
INC INERTIAY
LDA INERTIAY
STA P1SPEEDUP+1
JSR MOVEUP
LDA INERTIAY
CMP #$08
BNE FASTUP
FASTUP LDA #$08
STA INERTIAY
JMP DOWN
RESETI1: LDA #$00
STA INERTIAY
;REST OF CODE
Where am I going wrong? Please can anyone help? |
|
| |
tlr
Registered: Sep 2003 Posts: 1790 |
Quoting RichardMOVEUP: LDX OBJPOS+$01
SEC
P1SPEEDUP: SBC #$01
STX OBJPOS+$01
DEX
CPX #$4C
BCS SETUP
LDX #$4C
SETUP: STX OBJPOS+$01
RTS
Shouldn't this be more like:
MOVEUP: LDA OBJPOS+$01
SEC
P1SPEEDUP: SBC #$01
CMP #$4C
BCS SETUP
LDA #$4C
SETUP: STA OBJPOS+$01
RTS
You are trying to do a SBC #$01 from the X-register. (or maybe this is C64DTV code?) |
| |
Richard
Registered: Dec 2001 Posts: 621 |
Quote: Quoting RichardMOVEUP: LDX OBJPOS+$01
SEC
P1SPEEDUP: SBC #$01
STX OBJPOS+$01
DEX
CPX #$4C
BCS SETUP
LDX #$4C
SETUP: STX OBJPOS+$01
RTS
Shouldn't this be more like:
MOVEUP: LDA OBJPOS+$01
SEC
P1SPEEDUP: SBC #$01
CMP #$4C
BCS SETUP
LDA #$4C
SETUP: STA OBJPOS+$01
RTS
You are trying to do a SBC #$01 from the X-register. (or maybe this is C64DTV code?)
Thanks.
Yes, maybe I should have done it this way. I have now. The ship can still move up down left & right ;)
However, I am having a problem with this inertia thing.
READUP: LDA $DC00
LSR
BCS NOTUP
INC INERTIAY1
LDA INERTIAY1
CMP #$01
BEQ INITIALIZE1
MOVEIT1: LDA OBJPOS+$01
SEC
SBC INERTIAY1
STA OBJPOS+$01
LDA OBJPOS+$01
CMP #$4C
BCS SETA
LDA #$4C
SETA: STA OBJPOS+$01
INITIALIZE1: LDA #$01
STA INERTIAY1
RTS
NOTUP: LDA #$08
STA INERTIAY1
STA INERTIAY2
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
if you want a sprite to accelerate while the joystick is kept left/right or whatever direction, and deccelerate and stop if the joystik is left alone you should do something like this:
ifjoystickdirectionwhatever:
lda speedhigh
cmp #maxspeedhigh
bcc/bcs noadd ;yeah I'm dummy dunno which we need here
;(you might want to check speedlow against maxspeedlow aswell..)
lda accelerationlow
clc
adc speedlow
sta speedlow
lda accelerationhigh
adc speedhigh
sta speedhigh
jmp updatecoordinates
ifjoystickleftalone:
lda speedlow
beq nodeccelerate
lda speedhigh
beq nodeccelerate
lda speedlow
sec
sbc deccelerationlow
sta speedlow
lda speedhigh
sbc deccelerationhigh
sta speedhigh
bpl nofix
lda #$00
sta speedhigh
sta speedlow
nofix:
updatecoordinates:
lda coordinatelow
clc
adc speedlow
sta coordinatelow
lda coordinatehigh
adc speedhigh
sta coordinatehigh
sta yourspriteX
noadd:
checkspritemovement
...
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
(that was just an example from the top of my head, I'm waiting impatiently for the rest with their X cycle faster versions :) |
| |
A Life in Hell Account closed
Registered: May 2002 Posts: 204 |
Quote: I am having trouble with inertia, for my sub hunter project.
For example, I want to make the sub move up, using the speed of inertia.
;MOVEMENT DIRECTIONS FOR THE PLAYER'S SUB
MOVEUP: LDX OBJPOS+$01
SEC
P1SPEEDUP: SBC #$01
STX OBJPOS+$01
DEX
CPX #$4C
BCS SETUP
LDX #$4C
SETUP: STX OBJPOS+$01
RTS
;READ PLAYER JOYSTICK CONTROLS VIA PORT 2
READJOY: LDA $DC00
UP: LSR
BCS DOWN
INC INERTIAY
LDA INERTIAY
STA P1SPEEDUP+1
JSR MOVEUP
LDA INERTIAY
CMP #$08
BNE FASTUP
FASTUP LDA #$08
STA INERTIAY
JMP DOWN
RESETI1: LDA #$00
STA INERTIAY
;REST OF CODE
Where am I going wrong? Please can anyone help?
Rich, look in the protecoid code - it does this with almost the the same variable names, i think. |