Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:24 07 Jul 2025 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 : MM+: Sprites on the SSD1963

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10215
Posted: 08:12am 08 Sep 2016
Copy link to clipboard 
Print this post

I've developed a Sprite infrastructure for the MX470 Micromite+ (64 or 100 pin). It has been tested on my 64-pin backpack but I would appreciate it if someone could test the attached version on the Explore-100.

The prerequisite for the code to work is that the RD pin on the display must be connected to a Micromite output pin and this should be pulled high by a resistor (1-10K is suitable). On the Explore-100 I believe RD is connected to pin-6.

the code uses the SDcard so MAKE SURE "OPTION TOUCH" IS CORRECTLY CONFIGURED OR THE TOUCH CONTROLLER WILL INTERFERE WITH THE SD CARD

There are 3 global constants that drive the code:
  Quote  const maxsprites=7 ' must be 2^n-1
const spritewidth=16
const spriteheight=16


maxsprites is critical as it defines the number of least-significant bits in the images that are used to code the sprite number. It must be one of 3, 7, 15, 31 etc. i.e. 2, 3, 4, 5-bits

The code works using .PPM images (binary mode) stored on the SDcard to define the background and the sprites

There are just 4 user-routines:

displaybackground "tiger-3.ppm",0,0

says display the image file "tiger-3.ppm" on the display with the top left hand corner at coordinate 0,0 and maxsprites as defined above.

loadsprite 1,"pac_man.ppm"


says load the image file "pac_man.ppm" as sprite instance number 1. NB sprite numbering starts at 1 and goes up to maxsprites. The same image can be loaded as multiple sprite instances.

collision% = ShowSprite(1,200,140)

says display the #1 sprite instance with the top left hand corner at coordinates 200,140. If successful it returns 0. If the sprite would have overlapped one or more existing sprites it is not displayed and the function returns a bitmap which indicates all the sprites that it would have overlapped. It is then up to the programmer to decide what to do when a collision is seen.
When the sprite is displayed the background is left intact where the sprite "colour" was black (i.e. RGB(0,0,0) ). However the complete sprite area is considered for collision detection.

if RemoveSprite(1) then

removes the sprite instance #1 from the display and replaces the original background. It returns 0 if successful and -1 if the sprite was not being displayed when the remove routine was called.

The functionality of the 4 calls is demonstrated simply in the demo program

displaybackground "tiger-3.ppm",0,0
loadsprite 1,"pac_man.ppm"
loadsprite 2,"blinky.ppm"
loadsprite 3,"blinky.ppm"
'
collision% = ShowSprite(1,200,140)
if collision% then print "Program Bug"
collision% = ShowSprite(1,400,140) 'should get a report that it is already displayed
if collision%<>-1 then print "Program Bug"
collision% = ShowSprite(2,220,140)
if collision% then print "Program Bug"
collision% = ShowSprite(3,210,140)
If collision% then
for i%=1 to maxsprites
if (collision%>>i%) and 1 then print "collision with sprite number ",i%
next i%
endif
pause 4000
if RemoveSprite(1) then print "Program Bug"
IF RemoveSprite(2) then print "Program Bug"
IF RemoveSprite(3)<>-1 then print "Program Bug" 'should get a report that it is not displayed


which returns the console text:
  Quote  > RUN
Error: Sprite 1 is already displayed
collision with sprite number 1
collision with sprite number 2
Error: Sprite 3 is not currently displayed
>

The test program with the required image files is attached:
2016-09-08_180741_spritetest100.zip

Like Geoff I am not an expert on games programming so all constructive comment is appreciated.








 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 09:55am 08 Sep 2016
Copy link to clipboard 
Print this post

Hi Peter,

Tiger is 480x272, so not full screen on my 5" display.

2 items appear to the left of the tigers chin.

Console output:-

[Code]
RUN
Error: Sprite 1 is already displayed
collision with sprite number 1
collision with sprite number 2
Error: Sprite 3 is not currently displayed
>
[/code]

Phil
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10215
Posted: 11:05am 08 Sep 2016
Copy link to clipboard 
Print this post

Phil

Thanks. That is working exactly as it should. Now it would be good if someone programmed up a real application. I couldn't include a 800x480 background image as it exceeds the ZIP attachment limitEdited by matherp 2016-09-09
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025