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: 1790
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: 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
...
2005-11-07 07:45
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 :)
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
Thierry
Urban Space Cowboy
Meikel aka ZUX/Sparks
E$G/HF ⭐ 7
Guests online: 134
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Diskmag Editors
1 Magic  (9.8)
2 hedning  (9.6)
3 Jazzcat  (9.5)
4 Elwix  (9.1)
5 Remix  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.04 sec.