![]() |
Forum Index : Microcontroller and PC projects : Heart Attack (game)
Page 1 of 2 ![]() ![]() |
|||||
Author | Message | ||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Hi ! I have done a small game called "Heart Attack" Feedback is much appreciated... ![]() Heart Attack (by TweakerRay).zip http://tweakerray.bandcamp.com |
||||
Sasquatch![]() Guru ![]() Joined: 08/05/2020 Location: United StatesPosts: 377 |
Nice work TweakerRay! Like a "Blast from the Past" -Carl |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Thank you very much... I think I am not able for doing some more fancy stuff... but I am happy what I can do right now. It's just a small programm but I learn a lot and its so much fun to think of how things can be programmed... now I appreciate my other games on ps4 even more ;-) Because I see how hard it is to do something like that... I hope more people will check out this game ! Please do and tell me what you think about this... Here is the game --- > (Heart Attack by TweakerRay) Maybe have ideas how to improve this or add new stuff to it. Cheers TweakerRay http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
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. 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 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. 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". 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. 6) You can use ? for PRINT, but most people don't ![]() 7) If you want to print an empty line you can just do PRINT (or presumably ?) you don't need to do PRINT " " or ? " ". 8) Where you find yourself writing lists of mutually exclusive IF THEN statements look at using SELECT CASE instead. 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. Keep up the good work, Tom Edited 2020-10-14 22:15 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
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 ;-) 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... 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... 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 ... Don't understand what you mean... 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... 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 ;-) 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... 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 :-) Thank you very much ! Any input on the game itself ? (Not just my bad coding ? ) ;-) Cheers TweakerRay Edited 2020-10-14 23:00 by TweakerRay http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
END ends the definition of the FUNCTION or SUB, and that should only happen once. EXIT actually leaves it. In the absence of an explicit EXIT the FUNTION or SUB will exit when it reaches its END. 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... My experience is that this: If a = b Then statement1 statement2 statement3 EndIf is more readable than this for any non-trivial statements: If a = b Then statement1 : statement2 : statement3 YMMV. Commenting on code is one of the perils of my day job ![]() My main suggestion would be do switch to a lower-resolution MODE, it will make the game a bit easier (I found lining up to pickup a heart more difficult than it should have been) and be more in keeping with its retro simplicity/styling. Best wishes, Tom Edited 2020-10-14 23:08 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Okay so correct would be SUB subname bla bla code what the sub does more cool stuff even more cool stuff coders do... EXIT SUB END SUB would that be the correct form ? So I just missed the EXIT SUB to put in right ? Yeah It may be easier on a bigger resolution but also the screen would be smaller and all values would have to be changed... maybe I do that but I like the resolution... Maybe my next game uses a different resolution. Any advice which I should use which works better ? And may I ask what your dayjob is ? (if you don't want to answer that is okay) just interested. Thanks for the help. Cheers TweakerRay http://tweakerray.bandcamp.com |
||||
MauroXavier Guru ![]() Joined: 06/03/2016 Location: BrazilPosts: 303 |
My experience is that this: If a = b Then statement1 statement2 statement3 EndIf is more readable than this for any non-trivial statements: If a = b Then statement1 : statement2 : statement3 If you use too many statements on a loop, I believe that the "IF-THEN-ELSE" in one single line can be faster IN SOME SITUATIONS instead of beautifully separated statements for each line. But, of course, you right telling it's less readable. In some tests in my raycast engine, I saw some considerable speed gain when using hundreds of loops per second, but for common loops interactions, for sure is a better approach make an indented source code with separated statements as you suggested. Edited 2020-10-14 23:51 by MauroXavier |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
SUB subname bla bla code what the sub does more cool stuff even more cool stuff coders do... EXIT SUB END SUB would that be the correct form ? So I just missed the EXIT SUB to put in right ? "No", in that case you wouldn't bother since reaching the END automatically exits the sub. In your game you wrote this: sub moveup ' y=y-12:yr=12:xr=0 'Coursor up if y=25 then buffer$=chr$(129):ta$=buffer$:bouncesound2 : end sub yg=y/12 xg=x/8 if xygrid(xg,yg-1)=1 then buffer$=chr$(129):ta$=buffer$:bouncesound: end sub if xygrid(xg,yg-1)=3 then loselife: end sub 'scroll from 1 to 12 pixels for lv=1 to 12 color yellow ' Print Char ? @(x,y);chr$(135) pause smother ? @(x,y);chr$(32) y=y-1 next 'Last movement will also be stored to buffer2$ from buffer$ buffer2$=buffer$ end sub All those intermediate END SUBs should be EXIT SUBs - a SUB or FUNCTION should only ever have a single END. To be honest I'm surprised it works, but BASIC is a fairly lazy language and some implementations allow stuff that would be considered verboten in stricter languages. Maybe my next game uses a different resolution. Any advice which I should use which works better ? Perhaps MODE 3 ? Games are not really my thing, and there are others, e.g. Mauro, who could advise you better. One major advantage of the low-res modes is you have to push less pixels to fill the screen, which is important for performance if you've got a lot of heavy game logic or a lot of graphics to manipulate. I'm a Principal Software Engineer (though I prefer to just call myself a "Programmer") for a British subsiduary of a major German automation company that you will have heard of ![]() No worries, thanks for the Welcome Tape music. Best wishes, Tom Edited 2020-10-15 00:02 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
I thought the sub is declared like this... SUB genius subname bla bla awesome code bla bla END Sub so correct is: SUB genius subname bla bla more stuff even more stuff EXIT Sub right ? because the manual states: Page 86 SUB xxx (arg 1 [,arg2,...]) <statement> <statement> END Sub This is now where I get into trouble... the manual shows this example... the manual continues and says "The command EXIT Sub 'can' be used for an early exit but I did not want to early exit... for me it was okay when the sub is called ... excuted and ended when reached the end... Thats how I interpreted the manual... The manual also writes EVERY definition must have one END SUB so I thought my code was correct... So I am confused now that my code works and is wrong even when I get an error when I had forgotten the END SUB it explecit told me to put one in there... http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
"Yes", absolutely correct. However you wrote this (I've indented it and added some numbers to refer to): 1 sub moveup ' y=y-12:yr=12:xr=0 'Coursor up 2 if y=25 then buffer$=chr$(129):ta$=buffer$:bouncesound2 : end sub 3 yg=y/12 4 xg=x/8 5 if xygrid(xg,yg-1)=1 then buffer$=chr$(129):ta$=buffer$:bouncesound: end sub 6 if xygrid(xg,yg-1)=3 then loselife: end sub 7 8 'scroll from 1 to 12 pixels 9 for lv=1 to 12 10 color yellow ' Print Char 11 ? @(x,y);chr$(135) 12 pause smother 13 ? @(x,y);chr$(32) 14 y=y-1 15 next 16 'Last movement will also be stored to buffer2$ from buffer$ 17 buffer2$=buffer$ 18 end sub At lines 2, 5 and 6 you have early exits from the subroutine, so they should be EXIT SUB, not END SUB. As you said each SUB should have only one END SUB, line 18 in this case. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Ahhhh now I understand... okay I change that to exit sub then... understood... Thanks a lot... http://tweakerray.bandcamp.com |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Heart Attack (by TweakerRay).zip Update of Heart attack to V1.1 I corrected the wrong End sub mistakes to exit subs let the "?" be exchanged to Print and reduced the mp3 filesize to 160 kbit/s so its now only 4 MB ;-) Hope you enjoy this... http://tweakerray.bandcamp.com |
||||
MauroXavier Guru ![]() Joined: 06/03/2016 Location: BrazilPosts: 303 |
Maybe my next game uses a different resolution. Any advice which I should use which works better ? It completely depends on the type of game you intend to develop. If you wish to develop a faster action game and uses the main commands of MMBASIC without pushing too hard pixels manually, than 320x200 is very good, but if you don't use many video pages, 320x240 is very good to use better the screen space. If you need to develop a game that uses many effects on screen at the same time or use hundreds of loops per second, maybe 240x216 or 256x240 is a good bet, but you need to be aware of pixelation characteristics of these resolutions, and another thing to give consideration is that some monitors don't scale it very well. Another great resolution for games is 640x400, as you have some video pages and it has a great compromise between performance x good graphics, which you can make a smooth scroll with many objects on the screen with almost no trick. In 640x480 or 800x600 you have fewer video pages and the performance can be affected if you need to make a full scroll action game. 1024x768 definitively isn't a good choice for a game, but it doesn't mean you can't do it things like domino, chess, tetris and other puzzle game with some creativity. For comparisons of the resolutions that I had used in my programs: - Gauntlet: started at 320x200 at 16-bit color, after I changed to 320x240 at 8-bit color to have some speed up and for better use of the screen space. - Final Fight: started at 320x200 at 8-bit and now is 320x240, but I had to use framebuffer to store the images of the enemies as this mode has fewer video pages. - PSG Demo: 800x600 at 8-bit color. I wish to develop a demo of the power of the CMM2 to play chiptunes, then I focused to impress using a high resolution, but with this, I needed to make some sacrifice in the graphical bars of each music channel. - Wolfenstein 3D: I wish 320x240, but I needed to keep at 320x200 at 16-bit color, as the images became ugly in 8-bit, and as I needed to use all video pages. I tried 240x216 because any pixel count to gain some speed in the raycast, but I back to 320x200 because it make the game a little more ugly. - Demo X: I was forced to use 640x400 at 16-bit and this wasn't an easy task. In 8-bit the speed was fantastic, but the 16-bit mode, it makes the graphics much more pleasurable to see, and as it is a demoscene, beauty is key; - Into The Darkness: As it is based in the Wolf 3D raycast engine, I'm using now 320x200 at 16-bit, but have some chance to change to 256x240 to make the game a little faster. I hope this helps you to choose the resolution for your games. Edited 2020-10-15 02:43 by MauroXavier |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Thanks a lot for the input All your programms are ace... Just a joy to watch. I guess I will be fine with 320 X 240 I guess... I can't do such magic tricks you do... so not much effects ;-) Do you know how you could play music in background while a game is playing ? Or is that not possible ? I find it complicated with the mod files... And I would love to have backgroundmusic played by mp3... Thanks and keep up your magic... its fantastic ... can't wait to see your into the darkness... the grafix already look promising... If you need a title music in mp3 style check out my score I did for a ghost novel... Wie ein Schwarzer Spiegel - Score at Bandcamp Cheers TweakerRay http://tweakerray.bandcamp.com |
||||
MauroXavier Guru ![]() Joined: 06/03/2016 Location: BrazilPosts: 303 |
Unfortunately, you can't play any sound effect simultaneously with MP3 music (Not yet, but we never know when Peter goes to make a new magic trick). You have three alternatives: 1) - Play a MOD music and use the PLAY EFFECT command to play WAV files as a sound effect, but you must use WAV that is the same frequency as the MOD. A good middle term usage is to use all in 22050Hz, use this frequency to the WAV in mono, and play the mod forcing this: PLAY MODFILE "....", 22050 2) - Play a MOD file using some channels as sound effects. It's easier than you think! Get the OpenMPT program (it's free!), open the MOD on it, click on the Samples tab, change the number of the sample that doesn't have any data, or click on the left icon and create a new sample, then open your file browser, select your WAV at the same frequency that you will play the MOD and simply drag and drop it in the frequency wave. Look at the red circles to guide you: ![]() Save the music, and in your program, you can play your SFX sample at any frequency with this: PLAY MODSAMPLE number, channel, volume, frequency number = the number of the sample that you changed on the MOD file channel = 1 to 4 volume = 1 to 64 frequency = 22050 if your WAV is at the same frequency. The benefit of this is that you can go to 8000 to play it slower or 44100 to play it at doubled speed. In a game, it can be very useful (I used this in Gauntlet). 3) - Play two WAV sounds using DAC, like the game Max-E-Man. You can play the music on one channel and another channel to play SFX. With this approach, you can play any WAV music without limiting you to the MOD file format, but it can eat your RAM! I think that with the PLAY MODSAMPLE command you can do more things than the other ways. You can even use the PLAY EFFECT at the same time with PLAY MODSAMPLE, with this you can put your essential sound effects on the MOD file, and other sounds that you use sometimes keep it on WAV files. I hope this helps you in some manner. Edited 2020-10-15 04:54 by MauroXavier |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
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 ;-) I think the 3rd way might be the one I could imagine... I guess that's why people in the old school did mod tracker music because they were limited to the ram and just could use small samples as instruments... I actually started doing music on an amiga 500 with a tracker programm but I have to look if I can find a programm on pc with that you could load samples and do .mod songs maybe I get back to do tracker songs again ;-) This could be handled by the cmm2 easily than an mp3 i guess... I had in mind to play mp3 in background but I guess this won't happen that fast. But thank you so much for the detailed help here. I don't want to stop you so long of your cool projects. Thank you for this. And I hope i did not stop you so long with this. Again much appreciated and a big THANK YOU !!!! So if you ever need some sounds keep me in mind ;-) Cheers TweakerRay http://tweakerray.bandcamp.com |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
You have three alternatives: ...... THANK YOU! Thanks for this Mauro, I've been looking for a clear explenation on the best way to do music on the CMM2. This is incredibly helpful. |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 543 |
.... 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: .... All excellent points. Having said that I am going to break half of those with gay abandomnment in my next program ![]() I did set out with the best of intentions with my latest game.... then I started to cut corners and generally make a mess - but it didn't matter as I was having lots of fun! And like Mauro mentioned, sometimes the code gets dirty just so that I can squeeze an extra FPS or two out of it. In my professional life code clarity is everything - with the CMM2 I'm definitely feeling the hobbiest "make it work" vibe. Pushing the hardware as far as I can. Note: None of this is objecting to your points - I think everything you said is 100% right. I'm just pre-warning you that a hot mess of code is on it's way - and like a maniac I'm revelling in it ![]() |
||||
RetroJoe![]() Senior Member ![]() Joined: 06/08/2020 Location: CanadaPosts: 290 |
@Mauro, thanks as well. I’ve gotten pretty much this far already I.e. figuring out what the hell a MOD file is (apparently, it made its first appearance on the Amiga), acquired the samples I want, and fooled around with the various open-source MOD trackers. I even did a WAV to MIDI conversion to extract the melody and harmony data. On that note (pun intended :), one thing I keep missing is: 1) it’s the MOD player’s job to increase or decrease the sample’s playback rate to hit all the right notes, but 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! @Will, I too get an allergic reaction when I see ? instead of “print” - it’s like seeing graffiti on a church. I know Peter M. uses it in his examples, but it seems like such a violent “cognitive mode switch” and loss of clarity & elegance, for very little savings in typing effort (and pretty sure zero improvement in interpreter performance, right?) This is supposed to be BASIC, man, not Unix !! Edited 2020-10-15 06:34 by RetroJoe Enjoy Every Sandwich / Joe P. |
||||
Page 1 of 2 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |