Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:51 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : lcd animation games

Author Message
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 09:02pm 30 Oct 2023
Copy link to clipboard 
Print this post

Just trying different lcd graphics animation 16 sprites.
1st is erase and write each, the other is use frame layer l as cls and frame f and not erase the sprites just move them but the video shows fast sprites by erasing each then slower frame method.
https://www.youtube.com/watch?v=CmACkYcvMLA
I found blit back ground black works to erase but filled box was recommended. old fashioned animation for simple games seems faster. It depends on the game or animation you want and spi lcd is not vga.

OPTION BASE 0        ' 0 based arrays
option DEFAULT INTEGER
OPTION EXPLICIT
option autorun on
dim dx(15),dy(15),spx(15),spy(15)
dim cannon(119),missile(15),oldspx(15),oldspy(15)
dim ptr,hiscore,spw,spht,temp,frame_num,frame_count,spdata,sp1
hiscore=0
CONST bk = RGB(BLack)
const wh = rgb(white)
const bl = rgb(blue)
const gr = rgb(green)
const cy = rgb(cyan)
const re = rgb(red)
const ma = rgb(magenta)
const ye = rgb(yellow)
const br = rgb(brown)
'
restore

cls
udg1 'draws sprite1 on screen at 10,10
BLIT READ 1,10,10,16,16 'reads sprite1 from screen to blit buffer1
udg1 'draws sprite2 on screen at 10,10
blit read 2,10,10,16,16 'reads sprite2 from screen to blit buffer2
cls
'blit read 3,10,10,16,16 'reads 16x16 background to blit buffer3
'
for temp=0 to 15 'set up start sprite positions and directions
do
 dx(temp)=(int(rnd*4)+1)-(int(rnd*8)+1)
loop until dx(temp)<>0
do
 dy(temp)=(int(rnd*4)+1)-(int(rnd*8)+1)
loop until dy(temp)<>0
 spx(temp)=104+((rnd*32)+1)
 spy(temp)=144+((rnd*32)+1)    
next temp
'
do 'demo moving sprite
   for temp=0 to 15
'        if sprite_status(temp)=1 then 'is sprite active
           if spx(temp)> 220 then 'check right edge
             dx(temp)= 0-dx(temp)
           end if
           if spx(temp)<8 then 'check left edge
             dx(temp)= 0-dx(temp)
           end if
           if spy(temp)>300 then 'check bottom edge
             dy(temp)= 0-dy(temp)
           end if
           if spy(temp)<8 then 'check top edge
             dy(temp)= 0-dy(temp)
           end if
     '
           oldspx(temp)=spx(temp):oldspy(temp)=spy(temp) 'get last position for erase
           spx(temp)=spx(temp)+dx(temp):spy(temp)=spy(temp)+dy(temp) 'get new position for draw
     '
               if frame_num=0 then'which sprite to draw
                 'BLIT WRITE 3,oldspx(temp),oldspy(temp), 16, 16 'erase sprite at last position
                 box oldspx(temp),oldspy(temp),16,16,0,,bk
                 BLIT WRITE 1,spx(temp),spy(temp), 16, 16 'draw sprite1 at new position
               else
                 'BLIT WRITE 3,oldspx(temp),oldspy(temp), 16, 16 'erase sprite at last position
                 box oldspx(temp),oldspy(temp),16,16,0,,bk
                 BLIT WRITE 2,spx(temp),spy(temp), 16, 16 'draw sprite2 at new position
               end if
   next temp
 '
   frame_count=frame_count+1 'when to change sprite
   if frame_count=10 then
     frame_num=not frame_num
     frame_count=0
   end if
loop
'
sub udg1 'draws 16x16 data for blit to copy
 for spht=0 to 15
   for spw=0 to 15
     read sp1
     pixel spw+10,spht+10,sp1
   next spw
 next spht
end sub
'
'sprite1
data wh,bl,bl,bl,bl,bk,bk,bk,bk,bk,bk,bl,bl,bl,bl,wh
data bk,bl,re,re,re,bl,bl,bk,bk,bl,bl,re,re,re,bl,bk
data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk
data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk
data bk,bk,bk,bk,bl,wh,bl,bk,bk,bl,wh,bl,bk,bk,bk,bk
data bk,bk,bk,bk,bk,bl,bl,bk,bk,bl,bl,bk,bk,bk,bk,bk
data bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,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,bk,bk
data bk,bk,bk,ye,ye,bk,bk,bk,bk,bk,bk,ye,ye,bk,bk,bk
data bk,bk,bk,bk,ye,ye,bk,bk,bk,bk,ye,ye,bk,bk,bk,bk
data bk,bk,bk,bk,bk,ye,bk,bk,bk,bk,ye,bk,bk,bk,bk,bk
data bk,bk,bk,bk,bk,bk,ye,bk,bk,ye,bk,bk,bk,bk,bk,bk


OPTION BASE 0        ' 0 based arrays
option DEFAULT INTEGER
OPTION EXPLICIT
option autorun on
dim dx(15),dy(15),spx(15),spy(15)
dim cannon(119),missile(15),oldspx(15),oldspy(15)
dim ptr,hiscore,spw,spht,temp,frame_num,frame_count,spdata,sp1
hiscore=0
CONST bk = RGB(BLack)
const wh = rgb(white)
const bl = rgb(blue)
const gr = rgb(green)
const cy = rgb(cyan)
const re = rgb(red)
const ma = rgb(magenta)
const ye = rgb(yellow)
const br = rgb(brown)
'
restore

cls
udg1 'draws sprite1 on screen at 10,10
BLIT READ 1,10,10,16,16 'reads sprite1 from screen to blit buffer1
udg1 'draws sprite2 on screen at 10,10
blit read 2,10,10,16,16 'reads sprite2 from screen to blit buffer2
cls
'blit read 3,10,10,16,16 'reads 16x16 background to blit buffer3
'
for temp=0 to 15 'set up start sprite positions and directions
do
 dx(temp)=(int(rnd*4)+1)-(int(rnd*8)+1)
loop until dx(temp)<>0
do
 dy(temp)=(int(rnd*4)+1)-(int(rnd*8)+1)
loop until dy(temp)<>0
 spx(temp)=104+((rnd*32)+1)
 spy(temp)=144+((rnd*32)+1)    
next temp

FRAMEBUFFER CREATE F
FRAMEBUFFER LAYER L
FRAMEBUFFER WRITE L
cls
'
do 'demo moving sprite
FRAMEBUFFER COPY L,F
FRAMEBUFFER WRITE F

   for temp=0 to 15
'        if sprite_status(temp)=1 then 'is sprite active
           if spx(temp)> 220 then 'check right edge
             dx(temp)= 0-dx(temp)
           end if
           if spx(temp)<8 then 'check left edge
             dx(temp)= 0-dx(temp)
           end if
           if spy(temp)>300 then 'check bottom edge
             dy(temp)= 0-dy(temp)
           end if
           if spy(temp)<8 then 'check top edge
             dy(temp)= 0-dy(temp)
           end if
     '
           oldspx(temp)=spx(temp):oldspy(temp)=spy(temp) 'get last position for erase
           spx(temp)=spx(temp)+dx(temp):spy(temp)=spy(temp)+dy(temp) 'get new position for draw
     '
               if frame_num=0 then'which sprite to draw
                 'BLIT WRITE 3,oldspx(temp),oldspy(temp), 16, 16 'erase sprite at last position
                 'box oldspx(temp),oldspy(temp),16,16,0,,bk
                 BLIT WRITE 1,spx(temp),spy(temp), 16, 16 'draw sprite1 at new position
               else
                 'BLIT WRITE 3,oldspx(temp),oldspy(temp), 16, 16 'erase sprite at last position
                 'box oldspx(temp),oldspy(temp),16,16,0,,bk
                 BLIT WRITE 2,spx(temp),spy(temp), 16, 16 'draw sprite2 at new position
               end if
   next temp
FRAMEBUFFER COPY F,N
 '
   frame_count=frame_count+1 'when to change sprite
   if frame_count=10 then
     frame_num=not frame_num
     frame_count=0
   end if
loop
'
sub udg1 'draws 16x16 data for blit to copy
 for spht=0 to 15
   for spw=0 to 15
     read sp1
     pixel spw+10,spht+10,sp1
   next spw
 next spht
end sub
'
'sprite1
data wh,bl,bl,bl,bl,bk,bk,bk,bk,bk,bk,bl,bl,bl,bl,wh
data bk,bl,re,re,re,bl,bl,bk,bk,bl,bl,re,re,re,bl,bk
data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk
data bk,bk,bk,bl,re,wh,bl,bk,bk,bl,wh,re,bl,bk,bk,bk
data bk,bk,bk,bk,bl,wh,bl,bk,bk,bl,wh,bl,bk,bk,bk,bk
data bk,bk,bk,bk,bk,bl,bl,bk,bk,bl,bl,bk,bk,bk,bk,bk
data bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk,bk
data bk,bk,bk,bk,ye,ye,ye,bk,bk,ye,ye,ye,bk,bk,bk,bk
data bk,bk,bk,ye,bk,bk,bk,bk,bk,bk,bk,bk,ye,bk,bk,bk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k
data bk,bk,bk,bk,bk,ye,bk,bk,bk,bk,ye,bk,bk,bk,bk,bk
data bk,bk,bk,bk,bk,bk,ye,bk,bk,ye,bk,bk,bk,bk,bk,bk
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024