Language…
19 users online: 7 up, Ahrion,  bebn legg, Centipede,  Donut, FrozenQuills, GangsterJerby, Gulaschko, issun, KungFuFurby, LiamBLOL,  MarioFanGamer, Mariotag1, Murphmario, nanec, OEO6, RenkoV2, Romano338,  Segment1Zone2 - Guests: 134 - Bots: 217
Users: 55,680 (2,387 active)
Latest user: shinkintoad

Sprite Programming [Legacy]

How can I forget that? Thanks YCZ!
Originally posted by Iceguy
The second check makes sure that the sprite doesn't do anything when sprites are locked or frozen. You know like when you collect a Mushroom or get hit, sprites are temporarily frozen right? We make our sprite do that as well, it won't do anything if you get a powerup or anything that freezes sprites temporarily.


This is from lesson 5. I understand how the following check locks the sprite when necessary. My problem is while it locks the sprite, the graphics are not affected. How do you lock both the sprite and the graphics. It is very noticeable in some of the later lessons when I am working with 16X32 and 32X32 sprites.

LDA $9D ; \ if sprites locked, return
BNE RETURN ; /

A good example of this problem is in my Fryguy sprite that I am coding.


Thanks
Check my page http://marioepicjourney.blogspot.com to find more updates about my hack Super Mario: The Epic Journey.
Originally posted by Iceguy
In the MAIN routine, we'll need a routine that will draw the graphics. For simplicity, we can just JSR to another routine that will draw the graphics.

Here is an example of what I mean.

The links are broken -.-'

When I click the Here it takes me to a blank page with a random advert. This happens to all the other links as well. So I can't really progress on this tutorial...

Dose this happen to anybody else? :/

Originally posted by zKiP

zKiP had the files since Iceguy's hard drive broke down a while ago and he lost all the files.
I change my layout every 4-5 months
is there a way to make a sprite only get hit when it comes in contact with another Custom sprite?

Like say, a custom projectile?
Anime List
Manga List
D³ Releases: RL1, [RL2], [RL3], RiS
SMWHacking? I rest my case.
SMWCentral? I leave it to rest.

Yes. Here is an example of code that you can use. I am giving you a piece of my Fryguy Boss code as seen below:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; sprite interact routine
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


KILLED_X_SPEED dcb $F0,$10


SPRITE_INTERACT LDY #$0B ; sprite is being kicked
INTERACT_LOOP LDA $14C8,y ; \ if the sprite status is..
CMP #$09 ; | ...shell-like
BCS PROCESS_SPRITE ; /
NEXT_SPRITE DEY
BPL INTERACT_LOOP
RTS

PROCESS_SPRITE PHX
TYX
JSL $03B6E5 ; get sprite clipping B routine
PLX
JSL $03B69F ; get sprite clipping A routine
JSL $03B72B ; check for contact routine
BCC NEXT_SPRITE

PHX
TYX

JSL $01AB72 ; show sprite contact gfx routine

LDA #$02 ; \ Kill thrown sprite
STA $14C8,x ; /

LDA #$D0 ; \ Set killed Y speed
STA $AA,x ; /

LDY #$00 ; Set killed X speed
LDA $B6,x
BPL SET_SPEED
INY

SET_SPEED LDA KILLED_X_SPEED,y
STA $B6,x

NO_KILL PLX

HANDLE_HIT LDA #$28 ; \ Play sound effect
STA $1DFC ; /

LDA #$01 ; \ Set stunned state
STA $C2,x ; /

LDA #$20 ; \ Set stunned timer
STA $1564,x ; /

INC $1534,x ; Increase hit counter and...
LDA $1534,x ; \ Check if the sprite has been hit 3 times
CMP #HIT_POINTS ; /
BCC RETURN3

; When the boss dies he becomes a Stalking Flame that can be killed using a shell

LDA #$11
STA $7FAB9E,x
LDA #$08
STA $14C8,x
JSL $07F7D2
JSL $0187A7
LDA #$08
STA $7FAB10,x

LDA #$11
STA $7FAB9E,x
LDA #$08
STA $14C8,x
JSL $07F7D2
JSL $0187A7
LDA #$08
STA $7FAB10,x

RETURN3 RTS

PROCESS_CACHED_HIT LDA $1534,x
BPL RETURN3
AND #$7F
STA $1534,x
BRA HANDLE_HIT

Check my page http://marioepicjourney.blogspot.com to find more updates about my hack Super Mario: The Epic Journey.
Adding to Iceguy's Tutorial:

Lesson 14: More Complicated 32X32 animation

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Graphics Routine
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PROPERTIES: dcb $77,$37

;The tables must now have 16 bytes.
;THE LAST 8 ARE ONLY CREATED BECAUSE OF XDISP.

;0-4 BYTE - FRAME 1 RIGHT
;4-8 BYTE - FRAME 2 RIGHT
;8-12 BYTE - FRAME 3 RIGHT
;12-16 BYTE - FRAME 4 RIGHT
;16-20 BYTE - FRAME 1 LEFT
;20-24 BYTE - FRAME 2 LEFT
;24-28 BYTE - FRAME 3 LEFT
;28-32 BYTE - FRAME 4 LEFT

TILEMAP:
dcb $48,$4A,$68,$6A ; WALK 1 ;\ RIGHT
dcb $44,$46,$64,$66 ; WALK 2 ;/ RIGHT
dcb $4C,$4E,$6C,$6E ; WALK 3 ;\ RIGHT
dcb $44,$46,$64,$66 ; WALK 4 ;/ RIGHT
dcb $40,$42,$60,$62 ; TURN 1 ;\ RIGHT
dcb $40,$42,$60,$62 ; TURN 2 ;/ RIGHT
dcb $40,$42,$60,$62 ; TURN 3 ;\ RIGHT
dcb $40,$42,$60,$62 ; TURN 4 ;/ RIGHT
dcb $0C,$0E,$2C,$2E ; STUNNED 1 ;\ RIGHT
dcb $0C,$0E,$2C,$2E ; STUNNED 2;/ RIGHT
dcb $0C,$0E,$2C,$2E ; STUNNED 3;\ RIGHT
dcb $0C,$0E,$2C,$2E ; STUNNED 4;/ RIGHT
dcb $44,$46,$64,$66 ; DYING 1 ;\ RIGHT
dcb $44,$46,$64,$66 ; DYING 2 ;/ RIGHT
dcb $44,$46,$64,$66 ; DYING 3 ;\ RIGHT
dcb $44,$46,$64,$66 ; DYING 4 ;/ RIGHT

dcb $48,$4A,$68,$6A ; WALK 1 ;\ LEFT
dcb $44,$46,$64,$66 ; WALK 2 ;/ LEFT
dcb $4C,$4E,$6C,$6E ; WALK 3 ;\ LEFT
dcb $44,$46,$64,$66 ; WALK 4 ;/ LEFT
dcb $40,$42,$60,$62 ; TURN 1 ;\ LEFT
dcb $40,$42,$60,$62 ; TURN 2 ;/ LEFT
dcb $40,$42,$60,$62 ; TURN 3 ;\ LEFT
dcb $40,$42,$60,$62 ; TURN 4 ;/ LEFT
dcb $0C,$0E,$2C,$2E ; STUNNED 1 ;\ LEFT
dcb $0C,$0E,$2C,$2E ; STUNNED 2 ;/ LEFT
dcb $0C,$0E,$2C,$2E ; STUNNED 3 ;\ LEFT
dcb $0C,$0E,$2C,$2E ; STUNNED 4 ;/ LEFT
dcb $44,$46,$64,$66 ; DYING 1 ;\ LEFT
dcb $44,$46,$64,$66 ; DYING 2 ;/ LEFT
dcb $44,$46,$64,$66 ; DYING 3 ;\ LEFT
dcb $44,$46,$64,$66 ; DYING 4 ;/ LEFT

YDISP:
dcb $F0,$F0,$00,$00 ; WALK 1 ;\ RIGHT
dcb $F0,$F0,$00,$00 ; WALK 2 ;/ RIGHT
dcb $F0,$F0,$00,$00 ; WALK 3 ;\ RIGHT
dcb $F0,$F0,$00,$00 ; WALK 4 ;/ RIGHT
dcb $F0,$F0,$00,$00 ; TURN 1 ;\ RIGHT
dcb $F0,$F0,$00,$00 ; TURN 2 ;/ RIGHT
dcb $F0,$F0,$00,$00 ; TURN 3 ;\ RIGHT
dcb $F0,$F0,$00,$00 ; TURN 4 ;/ RIGHT
dcb $F0,$F0,$00,$00 ; STUNNED 1 ;\ RIGHT
dcb $F0,$F0,$00,$00 ; STUNNED 2 ;/ RIGHT
dcb $F0,$F0,$00,$00 ; STUNNED 3 ;\ RIGHT
dcb $F0,$F0,$00,$00 ; STUNNED 4 ;/ RIGHT
dcb $F0,$F0,$00,$00 ; DYING 1 ;\ RIGHT
dcb $F0,$F0,$00,$00 ; DYING 2 ;/ RIGHT
dcb $F0,$F0,$00,$00 ; DYING 3 ;\ RIGHT
dcb $F0,$F0,$00,$00 ; DYING 4 ;/ RIGHT

dcb $F0,$F0,$00,$00 ; WALK 1 ;\ LEFT
dcb $F0,$F0,$00,$00 ; WALK 2 ;/ LEFT
dcb $F0,$F0,$00,$00 ; WALK 3 ;\ LEFT
dcb $F0,$F0,$00,$00 ; WALK 4 ;/ LEFT
dcb $F0,$F0,$00,$00 ; TURN 1 ;\ LEFT
dcb $F0,$F0,$00,$00 ; TURN 2 ;/ LEFT
dcb $F0,$F0,$00,$00 ; TURN 3 ;\ LEFT
dcb $F0,$F0,$00,$00 ; TURN 4 ;/ LEFT
dcb $F0,$F0,$00,$00 ; STUNNED 1 ;\ LEFT
dcb $F0,$F0,$00,$00 ; STUNNED 2 ;/ LEFT
dcb $F0,$F0,$00,$00 ; STUNNED 3 ;\ LEFT
dcb $F0,$F0,$00,$00 ; STUNNED 4 ;/ LEFT
dcb $F0,$F0,$00,$00 ; DYING 1 ;\ LEFT
dcb $F0,$F0,$00,$00 ; DYING 2 ;/ LEFT
dcb $F0,$F0,$00,$00 ; DYING 3 ;\ LEFT
dcb $F0,$F0,$00,$00 ; DYING 4 ;/ LEFT

XDISP:
dcb $F8,$08,$F8,$08 ; WALK 1 ;\ RIGHT
dcb $F8,$08,$F8,$08 ; WALK 2 ;/ RIGHT
dcb $F8,$08,$F8,$08 ; WALK 3 ;\ RIGHT
dcb $F8,$08,$F8,$08 ; WALK 4 ;/ RIGHT
dcb $F8,$08,$F8,$08 ; TURN 1 ;\ RIGHT
dcb $F8,$08,$F8,$08 ; TURN 2 ;/ RIGHT
dcb $F8,$08,$F8,$08 ; TURN 3 ;\ RIGHT
dcb $F8,$08,$F8,$08 ; TURN 4 ;/ RIGHT
dcb $F8,$08,$F8,$08 ; STUNNED 1 ;\ RIGHT
dcb $F8,$08,$F8,$08 ; STUNNED 2 ;/ RIGHT
dcb $F8,$08,$F8,$08 ; STUNNED 3 ;\ RIGHT
dcb $F8,$08,$F8,$08 ; STUNNED 4 ;/ RIGHT
dcb $F8,$08,$F8,$08 ; DYING 1 ;\ RIGHT
dcb $F8,$08,$F8,$08 ; DYING 2 ;/ RIGHT
dcb $F8,$08,$F8,$08 ; DYING 3 ;\ RIGHT
dcb $F8,$08,$F8,$08 ; DYING 4 ;/ RIGHT

dcb $08,$F8,$08,$F8 ; WALK 1 ;\ LEFT
dcb $08,$F8,$08,$F8 ; WALK 2 ;/ LEFT
dcb $08,$F8,$08,$F8 ; WALK 3 ;\ LEFT
dcb $08,$F8,$08,$F8 ; WALK 4 ;/ LEFT
dcb $08,$F8,$08,$F8 ; TURN 1 ;\ LEFT
dcb $08,$F8,$08,$F8 ; TURN 2 ;/ LEFT
dcb $08,$F8,$08,$F8 ; TURN 3 ;\ LEFT
dcb $08,$F8,$08,$F8 ; TURN 4 ;/ LEFT
dcb $08,$F8,$08,$F8 ; STUNNED 1 ;\ LEFT
dcb $08,$F8,$08,$F8 ; STUNNED 2 ;/ LEFT
dcb $08,$F8,$08,$F8 ; STUNNED 3 ;\ LEFT
dcb $08,$F8,$08,$F8 ; STUNNED 4 ;/ LEFT
dcb $08,$F8,$08,$F8 ; DYING 1 ;\ LEFT
dcb $08,$F8,$08,$F8 ; DYING 2 ;/ LEFT
dcb $08,$F8,$08,$F8 ; DYING 3 ;\ LEFT
dcb $08,$F8,$08,$F8 ; DYING 4 ;/ LEFT

SUB_GFX:
JSR GET_DRAW_INFO ; after: Y = index to sprite tile map ($300)
; $00 = sprite x position relative to screen boarder
; $01 = sprite y position relative to screen boarder
LDA $1602,x
STA $03 ; | $03 = index to frame start (0 or 4)

LDA $14 ;\ Frame counter ..
LSR A ; |
LSR A ; | Add in frame animation rate; More LSRs for slower animation.
LSR A ; |
AND #$03 ; | 4 walking frames
ASL A ; |
ASL A ; | ASL x2 (0-4) makes it switch between the first byte and fifth byte,
STA $03 ;/ i.e. first animation and second animation. The result is stored into $03.

If you are working on a 32X32 sprite and want to use a more complicated animation scheme, you can animate between four frames as above.
Check my page http://marioepicjourney.blogspot.com to find more updates about my hack Super Mario: The Epic Journey.
Nice new section dahnamics. How do you make your sprite do a certain animation based on a condition (such as getting hurt, or hitting a wall) though?
Ok. Here's an example for animation for a condition:

IF_DEAD:
LDA $14C8,x ; If killed...
CMP #$02
BNE NOT_DEAD
LDA $03
CLC
ADC #$30 ; ...set killed frame
STA $03

BRA DONE_WALKING

NOT_DEAD:
LDA Invuln_Timer,x ; \ If sprite is stunned...
CMP #$00 ; |
BEQ IF_TURN ; |
LDA $03 ; |
CLC ; |
ADC #$20 ; | ...use stun frames.
STA $03 ; /
BRA DONE_WALKING

IF_TURN:
LDA $1534,x ; If turn
CMP #$01
BCC DONE_WALKING ; |
LDA $03 ; |
CLC ; | ...use turning frames.
ADC #$10 ; |
STA $03 ; /

DONE_WALKING:
LDA $157C,x
STA $02 ; Store direction to $02 for use with property routine later.
BNE NoAdd
LDA $03 ;\
CLC ; | If sprite faces left ..
ADC #$40 ; | skip some tiles if facing the other way
STA $03 ;/ So we can invert XDISP to not mess up the sprite's appearance.

The above are used for my Lololo and Lalala sprites that I'm working on. Let's look at my code for IF_TURN:

Code
IF_TURN:
	LDA $1534,x ; If turn
	CMP #$01	
	BCC DONE_WALKING		; | 
	LDA $03					; |
	CLC						; | ...use turning frames.
	ADC #$10				; |
	STA $03					; /


Here I am calling the RAM address $1534 and checking to see if its not zero. Earlier in the sprite, I increment the RAM address to 20 (32 in decimal). If it is zero I call the DONE_WALKING routine; however if it is not zero I calculate the turning frames. Based on the way I wrote the code, the turning frames begin after 16 frames (10 in hex) and since it animates between four frames I load $03 into A and store $03 into A. Hope that made sense.
Check my page http://marioepicjourney.blogspot.com to find more updates about my hack Super Mario: The Epic Journey.
OK, thanks for the help.
This is somewhat offtopic, but how do I view Iceguy's example code? When I click the link, all I get is an advertisment. The URL is http://iceyoshi09.bplace.net/*insert_file_name_here*.asm
Iceguy lost them but if you go a few pages back, you will find someone who backed them up so you then download it
I change my layout every 4-5 months
I recently uploaded all of the files elsewhere (and made new diagrams), so I'll edit the links when the edit feature is back up.
How do you code a 48X48 sprite? I understand that I now have a 3X3 matrix which means that I am going to have to more tiles to X and Y displace. My issue is what are the other changes that are necessary to create a 48X48 sprite, since both Tryclyde and Wart use such a Tilemap.
Check my page http://marioepicjourney.blogspot.com to find more updates about my hack Super Mario: The Epic Journey.
Originally posted by Iceguy
- The appropriate tile for the fire flower would be 26. (0x326)
- The appropriate tile for the key would be 26. (0x3EC)

Eh, is that a typo? You said both the key, and the fireflower were 26 0.o
Fixed, it's actually EC. Not sure how I didn't notice that o_o

And also, may as well mention that all links work correctly now, and they shouldn't break anymore now.
Originally posted by Iceguy
Fixed, it's actually EC. Not sure how I didn't notice that o_o

And also, may as well mention that all links work correctly now, and they shouldn't break anymore now.

this made my day, easier to follow now :3
i have a problem , i insert the tutorial sprite withiout errors , but when the sprite enters in the screen , the game freezes and the screen goes black, i'm sure thet i wrote the code bad, but i don't know where is the problem!

Code
dcb "INIT"
RTL

dcb "MAIN"
JSR Graphics 	
RTL 		


;===================================
; GRAPHICS ROUTINE HERE
;===================================

Graphics:	JSR GET_DRAW_INFO 


GET_DRAW_INFO:
LDA $00 
STA $0300,y

LDA $01
STA $0301,y

LDA #$E6
STA $0302,y

LDA #%00000110
ORA $64
STA $0303,y

INY
INY
INY
INY

LDY #$02 
LDA #$00 
JSL $01B7B3


can someone tell me where i failed?

Thanks Ladida for this EPIC and Awesome layout!

Originally posted by dahnamics
How do you code a 48X48 sprite? I understand that I now have a 3X3 matrix which means that I am going to have to more tiles to X and Y displace. My issue is what are the other changes that are necessary to create a 48X48 sprite, since both Tryclyde and Wart use such a Tilemap.


Something like this:

Tilemap:
dcb $00,$02,$04
dcb $20,$22,$24
dcb $40,$42,$44

dcb $00,$02,$04
dcb $20,$22,$24
dcb $40,$42,$44

XDisp:
dcb $F0,$00,$10
dcb $F0,$00,$10
dcb $F0,$00,$10

dcb $10,$00,$F0
dcb $10,$00,$F0
dcb $10,$00,$F0

YDisp:
dcb $F0,$00,$10
dcb $F0,$00,$10
dcb $F0,$00,$10

dcb $F0,$00,$10
dcb $F0,$00,$10
dcb $F0,$00,$10

Prop:
dcb $07,$47

GFX:
JSR GET_DRAW_INFO
LDA $157C,x
STA $02
BEQ NoAdd
LDA $03
CLC
ADC #$09
STA $03
NoAdd:
PHX
LDX #$08

Loop:

PHX
TXA
CLC
ADC $03
TAX

LDA $00
SEC
SBC XDisp,x
STA $0300,y

LDA $01
SEC
SBC YDisp,x
STA $0301,y

LDA Tilemap,x
STA $0302,y
PHX
LDX $02
LDA Prop,x
ORA $64
STA $0303,y
PLX

PLX
INY
INY
INY
INY
DEX
BPL Loop


PLX
LDY #$02
LDA #$08
JSL $01B7B3
RTS

If you want animation, just add the normal animation code.
LDA $14
LSR A
LSR A
AND #$04
ASL A
ASL A
STA $03
@link - you don't return from the graphics routine. (need a RTS)
I change my layout every 4-5 months