This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
tiuser1010


Member


Joined: 23 Apr 2009
Posts: 100

Posted: 09 Mar 2010 04:45:49 pm    Post subject:

okay lets say that you have 2 sprites one 16 by x, one 8 by x. You also have a background or pic. now lets say you need to make these sprites go in an animation making the 16 by x sprite
go first and the then 8 by x second. And for an added level of complexity the animation has to move across the screen while flipping back and forth. Now both sprite do have masks data. My first thought was to make both sprite 16 by x, putting zeros in the 8 by x so it would be as big as the other. but when your working with masks it make no difference because these new bytes are all zero and if i make them clear then i don't erase the 16 sprite entirely and if i make them override the sprite it will put a big white area in the background. I'm not necessarily looking for code but just ideas (although I'm not rejecting code)
Back to top
tr1p1ea


Elite


Joined: 03 Aug 2003
Posts: 870

Posted: 09 Mar 2010 08:37:34 pm    Post subject:

Are you able to illustrate your idea any further?

What kind of animation are we talking about (same amount of frames)? Is there any user input involved? Will this be something that you will be looking to expand to support more than 2 sprites?
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 10 Mar 2010 09:40:38 pm    Post subject:

If efficiency doesn't matter, just keep a copy of the background and everytime you overwrite it at $9340 when drawing some sprite, you copy it back in from some memory location you saved it at.
Back to top
tiuser1010


Member


Joined: 23 Apr 2009
Posts: 100

Posted: 15 Mar 2010 07:23:20 pm    Post subject:

Quote:
Are you able to illustrate your idea any further?

What kind of animation are we talking about (same amount of frames)? Is there any user input involved? Will this be something that you will be looking to expand to support more than 2 sprites?


Yes there will be more than two sprites and yes there will be user input. The reason i asked it so vaguely becasue i want a general idea on what do do.
Back to top
tr1p1ea


Elite


Joined: 03 Aug 2003
Posts: 870

Posted: 15 Mar 2010 10:48:49 pm    Post subject:

What you will need is some kind of object structure. Nothing too fancy just a list of structures that hold information about your sprites.

Maybe xpos, ypos, sprite pointer maybe something to hold a sprite animation frame. Then you could just step through that list and update all of your objects?

You could have a type variable instead of a sprite pointer that you could use to index *another* table with sprite pointers and sprite sizes.

Just a couple of ideas?

Couple possibly whip up some example code if you like.

EDIT:

I managed to whip this small example up during my break today Smile:



Not much to look at (xor'd sprites over background :X), but it demonstrates a player controlled object along with 2 other objects of different sizes, each executing a simple predefined animation.


Code:
;------------------------------------------------------------
; tr1p1ea - Simple Engine Demo
;------------------------------------------------------------
; [url="http://img36.imageshack.us/img36/4885/simpler.gif"]http://img36.imageshack.us/img36/4885/simpler.gif[/url]

.nolist
#include "ion.inc"
#include "keys.inc"

#define OBJECTSIZE 4            ; each object is 4 bytes
#define OBJECTX 0
#define OBJECTY 1
#define OBJECTTYPE 2
#define OBJECTANIMFRAME 3
.list

#ifdef TI83P
   .org progstart-2
   .db $BB,$6D
#else
   .org progstart
#endif
   ret            
   jr nc,begin

   .db "Simple Engine Demo",0   
begin:

mainLoop:
   call processInput            ; process input
   call updateObjects         ; update objects
   call drawBackground         ; draw simple background
   call drawObjects            ; draw objects
   call ionFastCopy

   jr mainLoop

;------------------------------------------------------------
; processInput
;------------------------------------------------------------
;
processInput:
   ld a,(activeObject)         ; active object
   ld l,a
   ld h,0
   ld e,l
   ld d,h
   add hl,hl
   add hl,hl               ; * 4
   ex de,hl
   ld ix,objectTable+1
   add ix,de               ; ix points to current object

   ld a,Group2
   out (1), a
   nop \ nop
   in a,(1)
   cp KClear
   jp z,Quit
   ld a,Group1
   out (1), a
   nop \ nop
   in a,(1)
   cp KUp
   jp z,Up
   cp KDown
   jp z,Down
   cp KLeft
   jp z,Left
   cp KRight
   jp z,Right
   ret

Quit:
   pop af               ; clear call
   ret                  ; return

Up:
   ld a,(ix + OBJECTY + 0)
   add a,-1
   ret nc               ; only checking screen bounds
   ld (ix + OBJECTY + 0),a         ; really should be checking against
   ret                  ; object size!
Down:
   ld a,(ix + OBJECTY + 0)
   add a,1
   cp 64-8+1
   ret z
   ld (ix + OBJECTY + 0),a
   ret
Left:
   ld a,(ix + OBJECTX + 0)
   add a,-1
   ret nc
   ld (ix + OBJECTX + 0),a
   ret
Right:
   ld a,(ix + OBJECTX + 0)
   add a,1
   cp 96-8+1
   ret z
   ld (ix + OBJECTX + 0),a
   ret
   ret

;------------------------------------------------------------
; updateObjects
;------------------------------------------------------------
;
updateObjects:
   ld ix,objectTable
   ld b,(ix + 0)
   inc ix
updateObjectsLoop:
   push bc
   push ix
   ld a,(ix + OBJECTTYPE + 0)
   add a,a               ; 2 bytes per table entry
   ld e,a
   ld d,0
   ld hl,objectAnimationTable
   add hl,de               ; offset animation table
   ld e,(hl)
   inc hl
   ld d,(hl)               ; de points to animation
   ld a,(de)
   inc de
   ld b,a               ; b = frames in animation
   ld a,(ix + OBJECTANIMFRAME + 0)
   add a,a               ; each frame is 2 bytes
   ld l,a
   ld h,0
   add hl,de               ; hl points to animation frame data
   ld a,(ix + OBJECTX + 0)
   add a,(hl)
   ld (ix + OBJECTX + 0),a
   inc hl
   ld a,(ix + OBJECTY + 0)
   add a,(hl)
   ld (ix + OBJECTY + 0),a
   ld a,(ix + OBJECTANIMFRAME + 0)
   inc a
   cp b
   jr nz,$+3
   xor a                  ; reset frame if end is reached
   ld (ix + OBJECTANIMFRAME + 0),a   ; update animation frame
   pop ix
   ld de,OBJECTSIZE
   add ix,de               ; ix points to next object
   pop bc
   djnz updateObjectsLoop
   ret

;------------------------------------------------------------
; drawBackground
;------------------------------------------------------------
;
drawBackground:
   bcall(_grBufClr)            ; clear buffer
   ld hl,plotsScreen
   ld a,%10000000
   ld bc,(6*256)+32
drawBackgroundLoop:
   ld (hl),a               ; draw some dots as the background :X
   inc hl
   inc hl
   djnz drawBackgroundLoop
   xor %10000001
   ld de,32
   add hl,de
   ld b,6
   dec c                  ; yes i know but its easier to read :)
   jr nz,drawBackgroundLoop
   ret
;------------------------------------------------------------
; drawObjects
;------------------------------------------------------------
;
drawObjects:
   ld ix,objectTable
   ld b,(ix + 0)            ; b = total number of objects
   inc ix
drawObjectsLoop:
   push bc
   push ix
   ld a,(ix + OBJECTTYPE + 0)      ; use object type as table index
   add a,a               ; 2 bytes per table entry
   ld e,a
   ld d,0
   ld hl,objectSpriteSizeTable
   add hl,de
   ld c,(hl)               ; sprite width
   inc hl
   ld b,(hl)               ; sprite height
   ld hl,objectSpriteTable
   add hl,de
   ld e,(hl)
   inc hl
   ld d,(hl)               ; de = sprite pointer
   ld a,(ix + OBJECTX + 0)         ; a = x
   ld l,(ix + OBJECTY + 0)         ; l = y
   push de
   pop ix
   call ionLargeSprite         ; draw sprite
   pop ix
   ld de,OBJECTSIZE
   add ix,de               ; ix points to next object
   pop bc
   djnz drawObjectsLoop
   ret

;------------------------------------------------------------
; variables, tables & data
;------------------------------------------------------------
;
activeObject:
   .db 0                  ; player controlled object

objectTable:               ; list of in-game objects
   .db 3                  ; total number of objects
   ; object 0
   .db 48-4               ; x pos
   .db 32-4               ; y pos
   .db 0                  ; object type
   .db 0                  ; animation frame
   ; object 1
   .db 48-4-28               ; x pos
   .db 32-4               ; y pos
   .db 1                  ; object type
   .db 0                  ; animation frame
   ; object 2
   .db 48-4+28               ; x pos
   .db 32-8               ; y pos
   .db 2                  ; object type
   .db 0                  ; animation frame

objectSpriteTable:
   .dw sprite0               ; object0 sprite pointer
   .dw sprite1               ; object1 sprite pointer
   .dw sprite2               ; object2 sprite pointer

objectSpriteSizeTable:
   .db (8/8),8               ; width/8, height - sprite0: 8 * 8
   .db (8/8),8               ; width/8, height - sprite0: 8 * 8
   .db (16/8),16            ; width/8, height - sprite0: 16 * 16

objectAnimationTable:
   .dw idle               ; object0 will idle
   .dw moveUpDown            ; object1 will move up and down
   .dw moveLeftRight            ; object2 will move left and right

idle:
   .db 1                  ; number of frames
   .db 0,0               ; +x0,+y0,+x1,+y1,+x2,+y2,+x3,+y3 ...
moveUpDown:
   .db 24               ; number of frames
   .db 0,-1,0,-1,0,-1,0,-1         ; +x0,+y0,+x1,+y1,+x2,+y2,+x3,+y3 ...
   .db 0,-1,0,-1,0,-1,0,-1
   .db 0,-1,0,-1,0,-1,0,-1
   .db 0,1,0,1,0,1,0,1
   .db 0,1,0,1,0,1,0,1
   .db 0,1,0,1,0,1,0,1
moveLeftRight:
   .db 16               ; number of frames
   .db -1,0,-1,0,-1,0,-1,0         ; +x0,+y0,+x1,+y1,+x2,+y2,+x3,+y3 ...
   .db -1,0,-1,0,-1,0,-1,0
   .db 1,0,1,0,1,0,1,0
   .db 1,0,1,0,1,0,1,0

sprite0:                  ; sprite0 data
   .db %10101010
   .db %01010101
   .db %10101010
   .db %01010101
   .db %10101010
   .db %01010101
   .db %10101010
   .db %01010101
sprite1:                  ; sprite1 date
   .db %11111111
   .db %10000001
   .db %10000001
   .db %10000001
   .db %10000001
   .db %10000001
   .db %10000001
   .db %11111111
sprite2:                  ; sprite2 data
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111
   .db %11111111,%11111111

.end
END



I know your looking at IX thinking O_o, but it makes things easier to understand Smile.

You can add/remove objects by adding an entry to 'objectTable', then changing the total, which is currently '.db 3':
You can reuse existing object types 0,1,2 or if you want to create your own you would:
create a new entry to objectSpriteTable, objectSpriteSizeTable and objectAnimationTable

Alternatively you could reserve another variable for each object which denotes what animation each object should have. That way any object can perform any animation you wish, and it can even be changed at runtime Smile.


Last edited by Guest on 17 Mar 2010 02:06:22 am; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement