Basic AI and Animation

Prime

Basic AI and Animation

Post by Prime »

Alittle update,I've also included WinRAR files if you want to compile it yourself.
Tools used SpritePad, KickassIDE so there's no confusion.
Music By (ECO) giving credit where credit is do!
http://www.uploadmb.com/dw.php?id=1414999292

http://www.uploadmb.com/dw.php?id=1414997203
For the nosey REMOVED unregistered people.

Code: Select all

.pc = $801
		.byte $0b, $08, $06, $00, $9e, $32, $30, $36, $34, 0,0,0 
 		.pc = $810 

		jmp Start
		
.var _TmpOffset = $02		
.var _ObjectDirection = $03
.var _ObjectDataPtr = $05
.var _ObjectFrameTic = $07
.var _ObjectFrameStructPtrOffset = $09
.var _Counter = $20	
//////////////////////////////////////////////////////////////////////////////////
.const Black = 0
.const White = 1
.const Red = 2
.const Cyan = 3
.const Purple = 4
.const Green = 5
.const Blue = 5 
.const Yellow = 7
.const Orange = 8
.const Brown = 9
.const Pink = 10
.const DarkGrey = 11
.const MediumGrey = 12
.const LightGreen = 13
.const LightBlue = 14
.const LightGrey = 15
.const EndMarker = $ff	
.const ObjectFrameDataPointer = $07f8
.const ObjectXMSBReg = $d010
.const ObjectMultiColorReg = $d01c		
.const ObjectColorReg = $d027		
//////////////////////////////////////////////////////////////////////////////////		
	.pc = $8000-2	
Start:
	jsr Do_ClearScreen
	lda #Black
	sta $d020							//BorderColorReg = Black	
	sta $d021							//BackRoundColor Reg = Black
	lda	#%00000011						//Enable 3 objects
	sta $d015
	lda #%00000010
	sta ObjectMultiColorReg
	lda #5
	sta ObjectColorReg
	lda #1
	sta ObjectColorReg+1
	lda #13
	sta $d025
	lda #3
	sta $d026
	ldx #$ad
	stx ObjectFrameDataPointer
	dex
	stx ObjectFrameDataPointer+1
	ldx #0
	stx _ObjectDirection
	stx _ObjectDirection+1
	stx _ObjectFrameStructPtrOffset
	stx _ObjectFrameTic
	
	lda #50
	sta $d000							//Object 1 xposition
	sta $d002						   //Object 2 x poosition		
	lda #160
	sta $d001						   //Object 1 y position	
	sta $d003                          //Object 2 y position
	jsr do_initIRQ
GameLoop:
	jsr Do_HandleVblank
	jsr Do_HandleAnimation
	jsr Do_HandleObjects
	inc _Counter
	jmp GameLoop
	
	
	
	
//////////////////////////////////////////////////////////////////////////////////
Do_HandleVblank:
	lda $d012
	bpl Do_HandleVblank
VblankWait:	
	lda $d012
	bmi VblankWait
	rts			
//////////////////////////////////////////////////////////////////////////////////
Do_HandleAnimation:
	ldx #0
	lda _ObjectFrameTic,x
	bne HandleAnimationCont3
//////////////////////////////////////////////////////////////////////////////////
//Used For Pointer Creation [Clarity]
//Added Code Incoming As I Add Additional Objects
//Conversing with TMR on Irc And Learning The Amount Of Frames Armour Storm Used,I've Modified My Animation Function
//No worries This will Progress Into A Dynamic Animation Function /Macro Once I Think It Through
//////////////////////////////////////////////////////////////////////////////////	
	lda #<BlobDataTab
	sta _ObjectDataPtr
	lda #>BlobDataTab
	sta _ObjectDataPtr+1
	ldy #0 
	lda _ObjectFrameStructPtrOffset,x
HandleAnimationCont:	
	sta _TmpOffset
	asl
	asl
	tay
	inc _ObjectFrameStructPtrOffset,x
	lda (_ObjectDataPtr),y
	cmp #EndMarker
	bne HandleAnimationCont2
	lda #0
	sta _ObjectFrameStructPtrOffset,x
	beq HandleAnimationCont
HandleAnimationCont2:
	sta $07f8
	sec
	sbc #1
	sta $07f9
	iny
	iny
	lda (_ObjectDataPtr),y
	sta _ObjectFrameTic,x
HandleAnimationCont3:
	dec _ObjectFrameTic,x	
HandleAnimationDone:
	rts			
//////////////////////////////////////////////////////////////////////////////////
//Object Direction
//1 = east
//0 = west
//Temp Object Handling Function
//////////////////////////////////////////////////////////////////////////////////			
Do_HandleObjects:
	lda _Counter
	and #1
	bne HandleObjectsDone
	ldy #1
	ldx #2
HandleObjectsCont:	
	lda _ObjectDirection,y
	beq ObjectDirectionWest
ObjectDirectionEast:
	inc $d000,x
	lda $d000,x
	cmp #254
	bne NextObject
InvertDirection:
	lda _ObjectDirection,y
	eor #1
	sta _ObjectDirection,y
	jmp NextObject
ObjectDirectionWest:	
	dec $d000,x
	lda $d000,x
	cmp #26
	bne NextObject
	jmp InvertDirection		
NextObject:
	dex
	dex
	dey
	bpl	HandleObjectsCont
HandleObjectsDone:	
	rts	
//////////////////////////////////////////////////////////////////////////////////	
do_initIRQ:
	sei	
	ldx #1
	stx $d019
	stx $d01a
	lda #<do_tune
	sta $314
	lda #>do_tune
	sta $315
	dex
	stx $d012
	lda #$7f
	sta $dc0d
	sta $dd0d
	txa
	jsr $1000
	cli
	rts
//////////////////////////////////////////////////////////////////////////////////
do_tune:
	inc $d019
	jsr $1003
	jmp $ea31	
//////////////////////////////////////////////////////////////////////////////////
Do_ClearScreen:
	ldx #0
	lda #32
ClearScreenLoop:
	sta $400,x
	sta $500,x
	sta $600,x
	sta $700,x
	inx
	bne ClearScreenLoop
	rts	
//////////////////////////////////////////////////////////////////////////////////	
	
	
	
//////////////////////////////////////////////////////////////////////////////////	
BlobFrameStructurePtr:				//not used yet
.word BlobDataTab					//not used yet
//////////////////////////////////////////////////////////////////////////////////	
BlobDataTab:	
.byte $ad							//currentframe
.byte $00							//not used yet
.byte $0c							//frame tic counter				
.byte $40							//not used yet
//////////////////////////////////////////////////////////////////////////////////
.byte $af							//currentframe
.byte $00							//not used yet
.byte $0c							//frame tic counter				
.byte $40							//not used yet
//////////////////////////////////////////////////////////////////////////////////
.byte $b1							//currentframe
.byte $00							//not used yet
.byte $0c							//frame tic counter				
.byte $40							//not used yet	
//////////////////////////////////////////////////////////////////////////////////
.byte $af							//currentframe
.byte $00							//not used yet
.byte $0c							//frame tic counter				
.byte $40							//not used yet
.byte EndMarker
//////////////////////////////////////////////////////////////////////////////////

		
	
	
		
	
	
	

	
	
	
	
	
	
	.pc = $2000-2
	.import binary "BubObjects.prg"
	.pc = $1000-$7e
	.import binary "Love_Is_a_Shield.sid"


dudz
Member
Member
Posts: 140
Joined: Tue Jun 17, 2014 5:40 am
Contact:

Re: Basic AI and Animation

Post by dudz »

Do_HandleVblank:
lda $d012
bpl Do_HandleVblank
VblankWait:
lda $d012
bmi VblankWait
rts
... that should be $d011 instead, you want to wait for line $100 and not $80 :)

that said, its probably better to put the rasterline irq somewhere to the bottom of the screen (around line $f8) and then increment a frame counter inside the interrupt, which you can then wait for in the main loop.
Prime

Re: Basic AI and Animation

Post by Prime »

Thanks for the tip dudz, I don't want to introduce irq's just yet for raster but I will in the future.


Do_HandleVblank:
lda $d012
bpl Do_HandleVblank
VblankWait:
lda $d012
bmi VblankWait
rts


... that should be $d011 instead, you want to wait for line $100 and not $80 :)

How did you get line 128?
Last edited by Prime on Thu Nov 06, 2014 2:51 pm, edited 1 time in total.
dudz
Member
Member
Posts: 140
Joined: Tue Jun 17, 2014 5:40 am
Contact:

Re: Basic AI and Animation

Post by dudz »

I don't want to introduce irq's just yet for raster but I will in the future.
? but you ARE using a raster irq already!
Wanax
Member
Member
Posts: 17
Joined: Sat Apr 12, 2014 6:15 pm
Location: italy
Contact:

Re: Basic AI and Animation

Post by Wanax »

Excellent tutorial Prime...but I'm not a nosey :)
Prime

Re: Basic AI and Animation

Post by Prime »

Wanax wrote:Excellent tutorial Prime...but I'm not a nosey :)
Lol thanks my friend
Prime

Re: Basic AI and Animation

Post by Prime »

dudz wrote:
I don't want to introduce irq's just yet for raster but I will in the future.
? but you ARE using a raster irq already!
Yes I am I mainly through it in there for the music but yes your correct.
Wanax
Member
Member
Posts: 17
Joined: Sat Apr 12, 2014 6:15 pm
Location: italy
Contact:

Re: Basic AI and Animation

Post by Wanax »

@Prime: Finished the RGCD (Falling) I have some code to share if you are interested... :)
Prime

Re: Basic AI and Animation

Post by Prime »

Wanax wrote:@Prime: Finished the RGCD (Falling) I have some code to share if you are interested... :)
Absolutely I'm interested there's always something to learn from another person.
Thank you My Friend.
Wanax
Member
Member
Posts: 17
Joined: Sat Apr 12, 2014 6:15 pm
Location: italy
Contact:

Re: Basic AI and Animation

Post by Wanax »

Well, I have a video of Falling in my channel Youtube that showing my little physics engine.
Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 2 guests