Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Sprite inertia
2005-11-06 13:53
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?
2005-11-06 14:35
tlr

Registered: Sep 2003
Posts: 1814
Quoting Richard
MOVEUP: 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?)
2005-11-06 15:10
Richard

Registered: Dec 2001
Posts: 621
Quote: Quoting Richard
MOVEUP: 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

2005-11-07 07:36
Oswald

Registered: Apr 2002
Posts: 5127
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
...
2005-11-07 07:45
Oswald

Registered: Apr 2002
Posts: 5127
(that was just an example from the top of my head, I'm waiting impatiently for the rest with their X cycle faster versions :)
2005-11-07 12:14
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.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Guests online: 325
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Codeboys & Endians  (9.7)
4 Mojo  (9.6)
5 Coma Light 13  (9.6)
6 Edge of Disgrace  (9.6)
7 Signal Carnival  (9.6)
8 Wonderland XIV  (9.5)
9 Uncensored  (9.5)
10 Comaland 100%  (9.5)
Top onefile Demos
1 Nine  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.5)
6 Scan and Spin  (9.5)
7 Onscreen 5k  (9.5)
8 Grey  (9.5)
9 Dawnfall V1.1  (9.5)
10 Rainbow Connection  (9.5)
Top Groups
1 Artline Designs  (9.3)
2 Booze Design  (9.3)
3 Performers  (9.3)
4 Oxyron  (9.3)
5 Censor Design  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Acidchild  (9.7)
4 Cash  (9.6)
5 Violator  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.045 sec.