Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:40 01 Aug 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 : CMM2 - Sprite Interrupt Help

     Page 1 of 2    
Author Message
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 07:09pm 26 Sep 2020
Copy link to clipboard 
Print this post

Hi Everyone,

I successfully used sprite interrupt in my program, but it only works for the first instance of collision even though it's in a loop.  It doesn't recognize the new sprite on the screen in which I collided with using keyboard keys.

Can anyone help ?

Thanks a Bunch !  
If what you are doing is bringing out the worst in you than stop doing it.
 
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 10:18pm 26 Sep 2020
Copy link to clipboard 
Print this post

When I use SPRITE(S) it always returns a -1 for all of my sprites.  Why ?
My Sprites are numbered 1-7.

I have 7 sprites.  They are all png files 32x32 and 64x64.  The one sprite I want to collide with is on layer 0 and all other sprites are on a different layer so they won't collide with each other.
Edited 2020-09-27 08:19 by shaputer
If what you are doing is bringing out the worst in you than stop doing it.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 07:41am 27 Sep 2020
Copy link to clipboard 
Print this post

Need more info to try and help. Can you post a simple demo of the issue?

Test program attached. This works exactly how I would expect.

box 0,0,32,32,5,rgb(red),rgb(green)
sprite read 1,0,0,32,32
sprite copy 1,3,1
box 0,0,64,64,10,rgb(blue),rgb(yellow)
sprite read 2,0,0,64,64
cls
sprite interrupt myint
sprite show 1,100,100,0
sprite show 3,150,150,2
do
 for i=0 to 200
   sprite show 2,i,i,1
   pause 100
 next i
 for i=200 to 0 step -1
   sprite show 2,i,i,1
   pause 100
 next i
loop
sub myint
 ? i,sprite(s)
end sub

Edited 2020-09-27 18:53 by matherp
 
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 12:59pm 27 Sep 2020
Copy link to clipboard 
Print this post

Here is the code.  I'm not sure why you used Sprite read and Sprite copy.

SPRITE LOADPNG 1, "CarL.png"  'CAR FACING LEFT SPRITE
SPRITE LOADPNG 2, "CarR.png"  'CAR FACING RIGHT SPRITE
SPRITE LOADPNG 3, "CarU.png"  'CAR FACING UP SPRITE
SPRITE LOADPNG 4, "CarD.png"  'CAR FACING DOWN SPRITE
SPRITE LOADPNG 5, "ManL.png"  'MAN FACING LEFT SPRITE
SPRITE LOADPNG 6, "ManR.png"  'MAN FACING RIGHT SPRITE
SPRITE LOADPNG 7, "TStone.png" 'TOMB STONE SPRITE


XR = MM.INFO(HPOS) + 52
YR = MM.INFO(VPOS) + 65

X = MM.HRES-100 'SIZE TO MOVE ON X AXIS
Y = MM.VRES-50  'SIZE TO MOVE ON Y AXIS

XM = X - 100
YM = Y - 100

SPRITE SHOW 2, XR, YR, 1  'SHOW THE CAR FACING RIGHT SPRITE
SPRITE SHOW 6, RND * XM, RND * YM, 0'SHOW MAN BASED RANDOMLY ON SCREEN

START:
DO
 IF KEYDOWN(0) THEN 'AT LEAST 1 KEY PRESSED
   IF TIMER > 200 THEN  'OPTIONAL-CHANGE TO ALTER RESPONSE TO KEY PRESSES
    TIMER = 0
    FOR I = 1 TO KEYDOWN(0) ' CHECK FOR ARROW KEYS AND ESC KEY
     

      IF KEYDOWN(I) = 27 THEN EXIT DO  'ESCAPE KEY TO EXIT
      IF KEYDOWN(I) = 130 THEN LEFT
      IF KEYDOWN(I) = 131 THEN RIGHT
      IF KEYDOWN(I) = 128 THEN UP
      IF KEYDOWN(I) = 129 THEN DOWN
    NEXT I

  END IF
 END IF  
LOOP

SUB LEFT

S = SPRITE(S)
PRINT SPRITE(S)

IF XR < 65 THEN GOTO START 'HITTING LEFT EDGE

DO
 IF XR < 65 THEN SPRITE SWAP 1, 2 : GOTO START

 XR = XR - SP
   
 IF KEYDOWN(1) = 130 THEN  
   SPRITE SHOW 1, XR, YR, 2          
   PAUSE 200
   SPRITE INTERRUPT CRASH
 END IF

LOOP UNTIL KEYDOWN(1) <> 130

SPRITE HIDE 1
END SUB



SUB CRASH
IF SPRITE(S) <> 0 THEN
 SPRITE SWAP 6, 7 'TURN MAN INTO TOMBSTONE

 PAUSE 200

 PLAY STOP
 PLAY MP3 "CRASH.mp3", ENGINE
 
 SPRITE SHOW 6, RND * XM, RND * YM, 0 'RANDOMLY SHOW MAN ON SCREEN
END IF  
END SUB


Edited 2020-09-27 23:01 by shaputer
If what you are doing is bringing out the worst in you than stop doing it.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 01:31pm 27 Sep 2020
Copy link to clipboard 
Print this post

Don't understand what you are doing and can't test without the various png files. You have the sprite interrupt command inside a do loop inside a subroutine which seems very strange. Normally it should be called once at the top of the main program once initialisation is complete - see my example
 
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 04:24pm 27 Sep 2020
Copy link to clipboard 
Print this post

OK, that's one thing I'm doing wrong.  I knew I was not using the Sprite Interrupt correctly.  Didn't quite understand that it only needed to be used once.  There is probably other things wrong.

Here is a link to the whole program with everything. Don't laugh too hard at my meager programming skills.  Never had a chance to learn properly back in the day.  That's why I am revisiting it.  Hopefully I will learn

My program is my take on an old game back in the 70s called Death Race.  
You got a car that you run into a man and he turns into a tombstone.  Then another man appears............repeat.  If I could accomplish that much then maybe I will expand the functionality a bit..........wishful thinking  

I am aware I don't need that S=SPRITE(S) line.  Was planning on deleting that.

https://www.dropbox.com/s/8ekg4685p3uxfar/TakeOut.zip?dl=0
Edited 2020-09-28 03:39 by shaputer
If what you are doing is bringing out the worst in you than stop doing it.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 05:43pm 27 Sep 2020
Copy link to clipboard 
Print this post

If you haven't coded before then it is a really good effort. HOWEVER......

You are using GOTO which results in spaghetti code that is very difficult to debug.
In particular GOTO commands from within a subroutine that leave the subroutine are seriously bad and will result in the program going wrong. Even worse is that the GOTO in the subroutine causes the main program to exit a DO loop without any proper termination. Together these will corrupt the stack in the machine and it will eventually run out and crash.

Pretend that the GOTO command doesn't exist and think about how to write the code without it. It is probably best to start with a simple bit of the code. Place the car and the man such that a single direction will cause a collision. Then move the car until the collision. Once you have the simplest case working then slowly build up complexity.

Get rid of all the SPRITE INTERRUPT calls except one at the top.
The value of -1 is correct until the two sprites overlap at which point the CRASH routine is called. If the crash routine stops the sprites overlapping then any SPRITE(S) call outside of the interrupt routine will give -1 as there is no longer a collision. There is not normally a reason to use SPRITE(S) except in the interrupt routine.

Keep experimenting and you will get there but do start simple and build up.
 
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 06:06pm 27 Sep 2020
Copy link to clipboard 
Print this post

Thanks a BUNCH !!!  

I have coded before.  I have several VisualBasic Programs that work that I use often.  I know how to write Arduino Sketches.  I control my CNC with a shell script program to send gcode files to operate it.............I just have never done any graphics programming.

Back in the 80s they taught BASIC as a business skill.........creating menus, arrays to store text data etc.  Programming for games was considered a hobby you had to learn on your own.  I never did.

I'm going to review all you've said and straighten it out.  Thank you soooo much for taking the time to tell me what you did.  I appreciate it.  I know no one that I can ask any questions because no one I know can write a computer program.    
If what you are doing is bringing out the worst in you than stop doing it.
 
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 02:13pm 02 Oct 2020
Copy link to clipboard 
Print this post

Well, programming any game, even the simplest is not a beginner's task on Color Maximite 2.  Documentation on poke, peek, blits, sprites, is very limited with out of context examples which make it hard to understand how they should be used for someone who has never programmmed any graphics applications.

There are no books I can find on BASIC programming anymore.  Shame.......the board is a good idea though. Maybe one day more proper documentation will come out.  
If what you are doing is bringing out the worst in you than stop doing it.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 02:22pm 02 Oct 2020
Copy link to clipboard 
Print this post

Have you read "Graphics programming on the Colour Maximite 2"?

Available here
 
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 05:13pm 02 Oct 2020
Copy link to clipboard 
Print this post

Yes, I have.   Pages 39, 41 and 42 are close to what I want to do.  Everything is so cumbersome and confusing that it's hard to keep my concentration.

1.  There are too many pdf documentation files.  I have now combined them.
2.  Sample code is hard to read with all the comments  mixed with the commands.  
   Easy to miss something.
3.  zip files like ghost.zip don't have the program file. So I have to stop and copy paste from a pdf file just to get a .bas program.

4.  I downloaded the code library for Color Maximite and so many programs didn't run that I didn't even try the remainder.

It's all so painful unfortunately.......It's much easier to create my simple little program in Scratch within Ubuntu then use Color Maximite.  Plus I can't use my MOD file with WAV sound effects because I created my file from combining 2 WAV files in an audio editing program.  Now all I get is 41000hz errors.  Just not fun anymore.

I still don't quite understand SPRITE layers in conjunction with the PAGE WRITE, PAGE COPY.......I don't understand what I'm doing just trying to copy sample code and alter it.  That doesn't work well.  Sample code filenames are confusing.......background image named "part02" in ghost.bas is not very descriptive.  

The Ghost program sample is what I want to do except let's say there were 2 ghosts.
One facing side ways for left and right and one showing an overhead view for up and down.  That's all I want to do besides collide with one other sprite whenever I encounter it.  Way too easy to take so long.....

Thanks anyway
Edited 2020-10-03 03:16 by shaputer
If what you are doing is bringing out the worst in you than stop doing it.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 05:39pm 02 Oct 2020
Copy link to clipboard 
Print this post

Won't Scratch do all those things you want?

John
Edited 2020-10-03 03:39 by JohnS
 
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 05:53pm 02 Oct 2020
Copy link to clipboard 
Print this post

Yup, my point exactly.  Will stick to that.  Just thought I could do it on Maximite since I bought it and it said it was for beginners.  Not so.  

Will program other things on it instead.
If what you are doing is bringing out the worst in you than stop doing it.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 06:04pm 02 Oct 2020
Copy link to clipboard 
Print this post

Peter,

I had forgotten about the "Ghost demo". Could I include it with on the "Welcome Tape" as I am short of simple sprite demos?

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 06:06pm 02 Oct 2020
Copy link to clipboard 
Print this post

Yes, of course, use mode 3,12 and lose the IMAGE RESIZE - looks better that way
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 06:39pm 02 Oct 2020
Copy link to clipboard 
Print this post

  shaputer said  Yup, my point exactly.  Will stick to that.  Just thought I could do it on Maximite since I bought it and it said it was for beginners.  Not so.  

Will program other things on it instead.

It's suitable for beginners but you may need to put more effort in and learn more yourself.

John
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 06:57pm 02 Oct 2020
Copy link to clipboard 
Print this post

  JohnS said  
  shaputer said  Yup, my point exactly.  Will stick to that.  Just thought I could do it on Maximite since I bought it and it said it was for beginners.  Not so.  

Will program other things on it instead.

It's suitable for beginners but you may need to put more effort in and learn more yourself.


What is missing compared with the 80's is:

1) the inch-thick manuals that with the benefit of hindsight were actually comprehensive BASIC programming courses.

2) the magazines and books full of type-ins.

We have the new 80's hardware but not the supporting material ... the internet is very much a different beast, better in some ways than manuals, but spoon feeding answers and requiring less of the thinking that will set you in good stead when the answers aren't immediately available. Plus copy & paste teaches you infinitely less than typing in a program and then fixing all the bugs that both you and the original author / typesetter introduced.

Feeling nostalgic for his childhood,

Tom
Edited 2020-10-03 05:00 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 07:17pm 02 Oct 2020
Copy link to clipboard 
Print this post

Yes, and it costs about a fifth or tenth as much, allowing for inflation.  It can also do more and as with other multi-purpose tools more means more learning.

Sticking with Scratch may be what some choose (are there jobs in what's learned with it though?).

John
 
shaputer
Newbie

Joined: 25/07/2020
Location: United States
Posts: 38
Posted: 07:58pm 02 Oct 2020
Copy link to clipboard 
Print this post

Yeah, I'm already half through my lifetime.  I've taken weeks reading MMBasic pdfs and writing and rewriting this tiny program.  I will leave this for the young folks and those my age (59) who are way more experienced cause actually I like playing video games way more than making them.

Scratch is very useful in getting the whole graphics manipulation process understood.  
Scratch has great videos on how to do this step by step.  Haven't seen that for Maximite.

It's ok cause I wasn't learning much in this area from MMBasic.

Searching for examples you can understand takes forever also.

Just thought I would try something simple that was similar to a game I played years ago in a n arcade.

Haven't seen any jobs for BASIC programming
Edited 2020-10-03 06:00 by shaputer
If what you are doing is bringing out the worst in you than stop doing it.
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 490
Posted: 09:49pm 02 Oct 2020
Copy link to clipboard 
Print this post

  shaputer said  OK, that's one thing I'm doing wrong.  I knew I was not using the Sprite Interrupt correctly.  Didn't quite understand that it only needed to be used once.  There is probably other things wrong.

Here is a link to the whole program with everything. Don't laugh too hard at my meager programming skills.  Never had a chance to learn properly back in the day.  That's why I am revisiting it.  Hopefully I will learn

My program is my take on an old game back in the 70s called Death Race.  
You got a car that you run into a man and he turns into a tombstone.  Then another man appears............repeat.  If I could accomplish that much then maybe I will expand the functionality a bit..........wishful thinking  

I am aware I don't need that S=SPRITE(S) line.  Was planning on deleting that.

https://www.dropbox.com/s/8ekg4685p3uxfar/TakeOut.zip?dl=0


Your file link is dead link.  It says deleted. I would like to see the code.
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025