Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:54 03 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 : Heart Attack (game)

     Page 2 of 2    
Author Message
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 08:36pm 14 Oct 2020
Copy link to clipboard 
Print this post

  TweakerRay said  Thanks a lot for this I think this is a post which should be pinned... it describes a lot good stuff for beginners and how sound is handled... unfortunatly when I read mono and 22000 hz I think this is not for me as a musician ;-)


Don't worry!! You can make very cristal clear music on the CMM2 using MOD files.

You can use samples at 44100Hz, including sound effects as samples at this frequency with WAV files played in stereo at this frequency too. Isn't a problem at all.

I use 22050Hz only to squeeze maximum performance because my games are more "performance-hungry" and I make all I can do to speed up the things a little.
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 08:54pm 14 Oct 2020
Copy link to clipboard 
Print this post

  RetroJoe said  2) where do you tell the tracker what the “natural” note of the raw sample is ?

For example, if I import a WAV file of a 440Hz square wave, how do I specify that is in fact the note of “A”?

If you would be so kind to point out where in OpenMPT you do that, that would be awesome!


Things work this way:

Look at the little screenshot that I posted ago.

When you import a sample, you need to set the main frequency in that screen (on the left side), and above you define the transpose note.

If you upload a 44100 Hz sample and set it as a note "A", then when you use upper notes it will play it faster or slower in lower notes. In the standard MOD file, the notes change the speed of the samples, and if you want to maintain the tempo in each note, you need to make a loop (look in the middle of the image), defining when to Start and to End the waveform.

Only for clarification, I'm not a musician and not a "MOD file expert", I'm only an enthusiast game developer. All the things that I do with MOD music I learned trying alone and reading some docs. Then I can't talk about real music notation because I don't even have good ears to distinguish some notes.
 
bar1010
Senior Member

Joined: 10/08/2020
Location: United States
Posts: 197
Posted: 10:33pm 14 Oct 2020
Copy link to clipboard 
Print this post

  TweakerRay said  
  thwill said  Hey "TweakerRay",

Fun little game and amazing music as always.

If I can be so bold (or rude) I have some suggestions to offer regarding your code, YMMV and no doubt other denizens may disagree with me on some points:

1) For any program of more than a few lines long the first non-comment line should be OPTION EXPLICIT, it will save you a lot of hurt in the long-run.



Hmmm okay... Understood... I come from C-64 where you don't have that I think ;-)
That's why I also am used to do ? instead of print... and for my reading I always used ?" " to be sure it is a new row ;-)

  thwill said  
2) Everyone else will find it much more readable if you indent the contents of all structures, i.e.
For i = 1 To 5
 ' Indent everything in here
Next i

If z Then
 ' And here
ElseIf y Then
 ' And here
Else
 ' And here
EndIf

Do
 ' And here
Loop

Sub a
 ' And here
End Sub

Function b
 ' And here
End Function




Yeah I know that is a good point... I think I am beeing a little lazy ;-)
I try to do that. Its better readable agreed...

  thwill said  

3) Don't use END {FUNCTION | SUB} for early returns from functions and subroutines, use EXIT {FUNCTION | SUB}. There is also an EXIT FOR and an EXIT DO for loops.



Well how I understood the subs for me was that they build small routines I just can recall... and if you don't do an end sub you will get an error
I am not familiar with EXIT... have to check how that works...

  thwill said  
4) Don't use GOTO. You can almost always rewrite in a more readable manner using a FOR NEXT or DO LOOP. And eliminating GOTO removes most use for labels. If you must use GOTO then don't use it to jump out of loops, functions or subroutines, I'm not sure you did it here, but you've done it in one of your other programs that I was looking at for the "Welcome Tape".


hmmm... I come also from amiga basic where you have lables to jump... so I am used to do gotos and lables...And this programm uses the subs just as small routines it will use and then continue with the main programm... at least I have intended the programm to do so ;-) or tried ...

  thwill said  
5) There is a time and place for multiple:statement:lines, but in most cases code is much more readable with each statement on a separate line.



Don't understand what you mean...

  thwill said  
6) You can use ? for PRINT, but most people don't .


aehm.... yes... but this game is inted for this machine... so if it can read a ? for PRINT I will rather do that instead of writing a PRINT every time...
As I said before... coming from c-64 and If I don't need a long command then i use
the short form. and a ? for PRINT is a common term I think...

  thwill said  
7) If you want to print an empty line you can just do PRINT (or presumably ?) you don't need to do PRINT " " or ? " ".


I don't know why I do that maybe to be sure it does not print a variable and just an empty string... But if I don't need to do that then I could try to relearn that ;-)

  thwill said  
8) Where you find yourself writing lists of mutually exclusive IF THEN statements look at using SELECT CASE instead.

uff... I did not know SELECT CASE (and a lot other commands) right now... so I have to take a look into that... The problem is that I miss some examples of the commands ... In the old C-64 book you had examples where you use some of the commands...
The manual here is great, but I miss a few examples which explain a little detail how you use some commands...

  thwill said  
9) Personally because it only works with a USB keyboard I would only use KEYDOWN if I needed to check for multiple keys, or "special" keys. If you use INKEY$ instead then it will work for anyone using a keyboard attached via a serial console.


This actually has a reason now ;-) I am used to inkey$ too but I figured out that that command is much slower than KEYDOWN... Also I snagged this code from another programm I wrote where I thought maybe I press two keys at the same time so diagonal movement would be possible... I skipped that later here because it already got complicated enough for my small brain ;-) hmmm... I wrote this programm for the cmm2 and not the serial console... and the cmm2 uses an usb keyboard.
you could argue why are you not using a nunchuck to control the figure... so it is what it is i guess ;-)

Thanks for the input, I have to check out the commands you mentioned and try to be a better coder ;-) bare with me... I am still happy I got this running at all :-)

  thwill said  
Keep up the good work,



Thank you very much ! Any input on the game itself ? (Not just my bad coding ? ) ;-)


Cheers TweakerRay


My advice is do what you are comfortable with, not what other people are comfortable with.
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 543
Posted: 11:31pm 14 Oct 2020
Copy link to clipboard 
Print this post

  TweakerRay said  Hi ! I have done a small game called "Heart Attack"

Feedback is much appreciated...


Heart Attack (by TweakerRay).zip


I just got a chance to play it. Very well done! Lots of fun. Thanks for sharing.
 
TweakerRay

Senior Member

Joined: 01/08/2020
Location: Germany
Posts: 138
Posted: 07:29am 15 Oct 2020
Copy link to clipboard 
Print this post

  bar1010 said  
My advice is do what you are comfortable with, not what other people are comfortable with.


True... But his advice has valid and good points and I am thankful for the advice from all people here so I get better in coding and it really helps to see the code better.
Also all help from Mauro is much appreciated - this cleared a lot of fog in my knowledge about the sound options here.

@Retro Joe: I see it as PeterCotton: This is for me a hobby and If I use a "?" for a "Print" , sure its not elegant but I would not say its a grafitti on a church...
I am beginner... I did not know better. This are workethics. (And this should be fun... But I get the point that a cleaner code is better)

I tided my code a little bit... so please download the latest version of the game.
And bare with me ;-) I am a beginner not a magician programmer.

Also maybe Important: the new version also has a smaller mp3 so the filesize in total is reduced. (I changed the mp3 from 320kbit to 160Kbit/s) - I found out that the CMM2 has problems playing MP3s which holds coverinformation in the file.


Download the game here:
HEART ATTACK V1-1  


Cheers TweakerRay
http://tweakerray.bandcamp.com
 
TweakerRay

Senior Member

Joined: 01/08/2020
Location: Germany
Posts: 138
Posted: 10:40pm 16 Oct 2020
Copy link to clipboard 
Print this post

I added WII Controller to the game ;-)
So you can now play it with the digital joypad and b for bombs on a controller or ona keyboard with the coursor keys and b

So you can now either use the keyboard or the WII Controller from the front

to avoid checking all the allowed keys and all the stuff that happens when you use your keyboard (For instance the little yellow sign moves in the same direction you last moved it if you dont press another key...) I simply changed the incoming buttons to strings which will be checked like it's keyboard presses...
with that I don't need to programm everythin again.

2 Questions for the more experienced programmers here:

Do anyone know if that will make a big lag ? Or can the cmm2 handle that ?
For me it's okay...

Because of getting a error message and abort of the programm when no controller is connected I had to use "ON ERROR IGNORE"...

So I check at beginning if that error code is there...

Is there a clever way how you can avoid to use this

"On Error Ignore"


Or is this how you have to do it ?


Download the new Version here:
Heart Attack (by TweakerRay)_v1-2 with controller support.zip


Cheers TweakerRay
http://tweakerray.bandcamp.com
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 11:00pm 16 Oct 2020
Copy link to clipboard 
Print this post

  TweakerRay said  Because of getting a error message and abort of the programm when no controller is connected I had to use "ON ERROR IGNORE"...

So I check at beginning if that error code is there...

Is there a clever way how you can avoid to use this

"On Error Ignore"


Or is this how you have to do it ?


Hi TR,

this is the correct way to do that (from Sasquatchs Mandelbrot code):
DIM TRUE =1
 On Error Skip 1
   Wii Nunchuk Open
 If MM.ERRNO = 0 Then HaveChuk = True

and later
If HaveChuk Then
    If Nunchuk(Z,3) = 1 Then K = 73 'Zoom in
    If Nunchuk(C,3) = 1 Then K = 67 'Re-Center

...

Gruß
Michael
causality ≠ correlation ≠ coincidence
 
TweakerRay

Senior Member

Joined: 01/08/2020
Location: Germany
Posts: 138
Posted: 03:26pm 17 Oct 2020
Copy link to clipboard 
Print this post

Danke Two Fingers ;-)

Do I need to close connection of the Classic Controller also somehow ?
Or if a controller is not connected is the errorcode check enough ?
Or for better coding close it ?

I have not done this before. So any advice would be appreciated.

Cheers TweakerRay
http://tweakerray.bandcamp.com
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 04:04pm 17 Oct 2020
Copy link to clipboard 
Print this post

Hi TR,
i'm not very familiar with this nunchuk thing.
I would think it doesn't matter if the nunchuk channel is open. But I assume that it is not open when an error message appears. I think it's just good style to close a nunchuk channel - no risk of data loss like with open files. I don't know for sure. A look at the source code might help (or Peter clarifies).
It can also help if you read working sample code.

Kind regards
Michael
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 04:34pm 17 Oct 2020
Copy link to clipboard 
Print this post

If the Wii open command fails with an error then the port will not be left open from V5.05.06RC3 onwards. Before that release it was left open in some cases by mistake but that would be benign and have no impact on the program.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 04:37pm 17 Oct 2020
Copy link to clipboard 
Print this post

@Peter, THANKS!
causality ≠ correlation ≠ coincidence
 
TweakerRay

Senior Member

Joined: 01/08/2020
Location: Germany
Posts: 138
Posted: 08:32am 19 Oct 2020
Copy link to clipboard 
Print this post

Thanks a lot ! @matherp.
http://tweakerray.bandcamp.com
 
TweakerRay

Senior Member

Joined: 01/08/2020
Location: Germany
Posts: 138
Posted: 07:10pm 02 Nov 2020
Copy link to clipboard 
Print this post

I just bump this up again... maybe someone else likes to play it ?

Heart Attack (Game) with WII Controller (or Keyboard) support



Cheers TweakerRay
http://tweakerray.bandcamp.com
 
     Page 2 of 2    
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