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 Defender Clone
Page 1 of 2 | |||||
Author | Message | ||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
Well, for better or for worse, here's my first program for the Maximite. Defender. To be honest it just started out as me playing around (up until yesterday the file was still called "test.bas"). I don't claim that it's well programmed, it was very much just me screwing around. I knew I wanted to play with parallax scrolling, and before I knew it I had a passable defender clone (a testament to the CMM2's ease of use - not my programming prowess). Buoyed by encouragement from the Maximite Facebook Page guys, I'm publishing it here - warts and all. I did go through and comment some of the code - but it was really a great learning experience for me. The main thing I learned was that the first line I should have typed was "option explicit". I was having a great old time using undefined variables with gay abandon like an absolute maniac, however that came back to bite me during debugging. I will also plan my sprite/bitmap management better next time. Next time I will also impose a proper naming convention. I started using the one I use for C/C#, but quickly realised that it didn't fit, so then I tried another convention and finally a third. I would argue by the time you have three different naming conventions in the one program.... you technically do not have any naming convention. I also need to learn how to do proper sound effects (this one just has simple waves), but like I say it was never intended for public publishing - just for me to learn. But for all of that, it's here. I hope you enjoy it. I'm going to move on from it, I feel this code has done it's job for me, which is to highlight the mistakes I made, and also teach me what "I don't know" yet. To that end, I'm going to program another tech demo next, and use it to fill in the massive blanks in my knowledge. Once that is done, then hopefully I'll be ready to start writing a "proper" game. One that I won't be ashamed to show you guys the source code for :-D The Defender source code can be downloaded from here, Defender.zip or from my OneDrive here: https://1drv.ms/u/s!AnkZn9N9Pt1fp7cb52Ygsl0E8RJYWg?e=zWLTdJ Edited 2020-09-06 04:51 by PeteCotton |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1108 |
Nicely done! Now I need to spend a while studying how you make it work so well! Visit Vegipete's *Mite Library for cool programs. |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
Thank you very much. Your kind words are appreciated. * I will answer any questions I can about the code, but be aware, some of it might not be great programming. Edited 2020-09-06 06:21 by PeteCotton |
||||
Sasquatch Guru Joined: 08/05/2020 Location: United StatesPosts: 355 |
WOW This is fantastic. I love the graphics! Defender/Stargate was always one of my favorites! I'm gonna need to spend a lot more time testing this... strictly for quality control purposes, of course -Carl |
||||
RetroJoe Senior Member Joined: 06/08/2020 Location: CanadaPosts: 290 |
Awesome !! The parallax horizon is terrific - very “Battle Zone”-esque. If I’m not mistaken, the CMM2 will soon have a tidy collection of loving homages to favourite 8-bit games. MAME is great to play those (and a great resource to get the game play and A/V elements in the right ballpark), but it’s amazing the CMM2 enables you to do stuff like this entirely in BASIC. I am working on my own “port” and you have demonstrated some excellent techniques I can learn from (the hit detection and explosion in particular) - thanks very much! Joe P. Montreal P.S. There also seems to be a growing “Kanadian Korner” of The Back Shed - the long Canadian winters should produce lots of great results :) Happy Maximiting ! Enjoy Every Sandwich / Joe P. |
||||
TweakerRay Senior Member Joined: 01/08/2020 Location: GermanyPosts: 138 |
Wow ! Fantastic ! If you need some music for your game and can include mp3s let me know ;-) I am musician and I have done some retro-style music already as well as some more other tracks you might like ;-) check this: Example Music This was for my own small videogame... Or something like this ? Example Music I have done for a contest More music of course at my page: www.tweakerray.de http://tweakerray.bandcamp.com |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
I know. +30C degrees here in Alberta today, +12C tomorrow with a chance of snow..... I suspect that's summer over for us. I am genuinely getting more fun out of this box that I have had programming in decades. I can't explain it, but you are right, this thing is going to keep me amused through the long winter. Thank you very much. I might well take you up on this. Sound is definitely one of the areas where I am still incredibly weak. Like I mentioned above, I think for the next project I will try and teach myself about all of the areas I am lacking (which is a lot). |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
Thank you very much. I was worried about posting this. But your positive feedback has put my mind at rest. Thank you so much. |
||||
retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 131 |
Is there a YT video of it running? Gen1 Honda Insights. |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
Here you go. https://youtu.be/jgUyCZoqWgA Unfortunately my camera didn't pick up the sound, but you're not missing much there - it's definitely the weak spot of the game. I was really trying to get a good parallax going. I am very happy with the way the vertical parallax looks. It kicks in when the player is in the top half of the screen, I wanted to give the impression of rising up high over the mountains. The player has three lives and I originally had it so that the game paused and restarted for a few seconds after each death, but this slowed down the game play. So I made it that the screen flashes each time the player collides with something, and on the third hit they explode. That caused issues if the player ran through a bunch of aliens and lost all three lives straight away, so the player now gets a 3 second shield of invulnerability each time they lose a life. The 3 mountain ranges are drawn on one buffer screen. Each range is 1600 pixels wide and 100 pixels high. So mountain range 1 is on rows 0-100 and 101-200. Range 2 is on 201 to 300 and 301 to 400. And range 3 is on 401 to 500 and 501 to 600. These are blitted on to the screen and stitched together to repeat indefinitely. I drew the mountains in the program using a sin/cosine calculation - the type you would use for a 3d plot. And instead of drawing it in 3d, I plotted it sideways on. This took about 20 seconds during startup, so once I was happy with them I saved the bitmap to disk and removed the code (so now it just loads the screen on startup). If you noticed I plotted the mountains at different brightnesses to help with the depth illusion (further away = duller colours). I also plotted the foreground mountains with filled in polgons (filled with a dark green) so that they would do "hidden line removal" on the mountains ranges behind them. Finally, for the 3d effect of the ground I again wrote a little plot function that would draw a 3D grid at 20 evenly spaced angles, and then depending on where the player is on the X-axis, I plot the appropriate one of these 20 steps, which gives the effect of the 3d scrolling ground. I know it's hard to see with all of the images stuck together, so it might be clearer if I show a couple of them split out. If I can answer any other questions, I would be more than happy to. Thank you for all of the positive feedback. It is appreciated. P.S. Despite the video, I can actually play the game better than that, but I was balancing the keyboard on one knee while peering around the back of the camera :-D Edited 2020-09-07 03:11 by PeteCotton |
||||
irich2 Newbie Joined: 21/07/2020 Location: United StatesPosts: 4 |
Would you mind posting the code you used to draw the mountains and the ground? I would love to see that!! |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
No problem. I'll dig it out tomorrow. Pete |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
As promised, here's the code to draw the mountains, and the code to draw the foreground scroll. DrawBackground.zip Here are the relevant code modules. The first one is for the mountains mode 1,8 cls dim float height(100,100) dim integer xarray (3) dim integer yarray (3) page write 0 DrawMountains(1) DrawMountains(2) DrawMountains(3) sub DrawMountains(formula) ' Calculate the grid of values for x=-50 to 50 for y=-50 to 50 distance = sqr(x*x+y*y) distance2 = sqr ((X-10) * (x-10) + (y-10) * (y-10)) distance3 = sqr(abs ((x+22) * (x+12) + (y+11) * (y+3))) if formula=1 then height(x+50, y+50) =cos(distance2/3) * sin(distance/4)* sin(distance3) * (50-distance)* 2.4 if formula=2 then height(x+50, y+50) = sin(distance2/10) * cos(distance/4) * cos(distance3/2) * (30-distance)*1.6 if formula=3 then height(x+50, y+50) = sin(x/10) * cos(distance/4) * cos(distance3/2) * (30-distance)*0.8 if height(x+50,y+50)<1 then height (x+50, y+50)=1 'Make the last height equal to the first so that it is seamless if x=50 then height(x+50,y+50) = height(0,y+50) next y next x ' Plot each rectangle as a filled polygon for x=1 to 100 for y=1 to 100 ' Is this the second (wrapped) line? tempx = GetOnScreenX(x,y) yoffset=(formula-1)*200 xoffset=0 if (tempx>799) then xoffset=-800 yoffset=(formula-1)*200 + 100 end if xarray(0)=GetOnScreenX(x-1,y-1) + xoffset yarray(0)=GetOnScreenY(x-1, y-1) + yoffset xarray(1)=GetOnScreenX(x,y-1) + xoffset yarray(1)=GetOnScreenY(x,y-1) + yoffset xarray(2)=GetOnscreenX(x,y) + xoffset yarray(2)=GetOnScreenY(x,y) + yoffset xarray(3)=GetOnScreenX(x-1,y) + xoffset yarray(3)=GetOnScreenY(x-1,y) + yoffset r = abs(height(x,y))*6 if r>255 then r=255 if (formula=1) then polygon 4, xarray(), yarray(), RGB(0,80,0), RGB(0,0,0) if (formula=2) then polygon 4, xarray(), yarray(), RGB(0,128,0), RGB(0,40,0) if (formula=3) then polygon 4, xarray(), yarray(), RGB(0,255,0), RGB(0,80,0) next y next x end sub function GetOnscreenX (x,y) GetOnScreenX = y*2 + (x*16) rem if GetOnscreenx > 800 then GetOnscreenX = GetOnScreenX-800 end function function GetOnScreenY (x,y) rem GetOnScreenY = 500 - (y*2) - height(x,y) GetOnScreenY = 100 - height(x,y) rem if GetOnScreenX(x,y) > 800 then GetOncreenY = GetOnScreenY + 200 end function and for the foreground/ground level mode 1,8 cls for animation=1 to 20 yoffset= 200+(animation-1)*10 line 0,yoffset,800,yoffset,1,rgb(0,255,0) line 0,yoffset+4, 800, yoffset+4,1,rgb(0,255,0) line 0,yoffset+9, 800, yoffset+9,1,rgb(0,255,0) for verticals = 1 to 10 xoffset = animation*4 x1 = xoffset+ (80*verticals) x2 = 400 + ((x1-400)*1.2) line x1,yoffset, x2, yoffset+9,1,rgb(0,255,0) next verticals next animation Edited 2020-09-09 10:26 by PeteCotton |
||||
irich2 Newbie Joined: 21/07/2020 Location: United StatesPosts: 4 |
Thank you Pete for sharing your code. Greatly appreciated!! Keep up your great work!! |
||||
TweakerRay Senior Member Joined: 01/08/2020 Location: GermanyPosts: 138 |
Defender.zip Could not resist to put the new music in the game ;-) My only question would be... is it possible to have it play in the background ? I was not able to do that with this code since It's not my programm... I just put my new composed music to this... hope you like it ;-) You need to install this in the Folder Defender on your sd Card So on my CMM2 it sits all on a:\Defender\ Hope it works... http://tweakerray.bandcamp.com |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
Fantastic. I look forward to trying it out tomorrow. Thanks! :-D |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4019 |
@TweakerRay, love the soundtrack, very appropriate. It's a damn shame that using PLAY MP3 to play in the background and PLAY SOUND for FX in the foreground seems to be incompatible: Error in line xx: Sound output in use @matherp, any advice ? @PeteCotton, for the "Welcome Tape" is there any chance you could redo the logo with the name "Guardian" or some other non (c) infringing title of your choice? Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 393 |
Very well done! -Bill |
||||
TweakerRay Senior Member Joined: 01/08/2020 Location: GermanyPosts: 138 |
@Tom, thanks... Yeah If the soundtrack is only on the titlescreen most people only would hear the first bars and play the game and get the same 4 bars of the beginning... and i hoped that the score could be played in the background... that would be neat. But I guess because mp3 will eat up a lot of cpu power it's not possible ? Maybe @matherp could tell if it's possible... otherwise mp3 playback is not really usefull if it eats so much cpupower that you can't play other sounds... http://tweakerray.bandcamp.com |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 355 |
Absolutely. No problem. It's Canadian Thanksgiving today though, so probably won't get around to it until I sober up! |
||||
Page 1 of 2 |
Print this page |