|
Post by johnno56 on Dec 16, 2018 20:23:15 GMT -6
As per your suggestion. This is a VERY basic Lander. You know the drill. Up arrow to apply vertical thrust. Left and right arrows to apply horizontal thrust. Touch the "Moon" - Boom! Land faster than 3.0 - Boom! Land safely - Next level. Only 3 levels. As I said this is very basic. Just to see if I can do it or not. Appreciate any constructive criticism. If this is ok then I have some alternate levels... J Attachments:lunarlander.zip (172.67 KB)
|
|
|
Post by tbird on Dec 16, 2018 23:46:35 GMT -6
Sweet! I will check out in the morning.
|
|
|
Post by johnno56 on Dec 17, 2018 0:03:02 GMT -6
Morning? It's 5pm... lol
J
|
|
|
Post by tbird on Dec 17, 2018 8:54:57 GMT -6
Well that is nice clean looking code, but it wont run lol, on my lappy anyway. Looking into it.
|
|
|
Post by tbird on Dec 17, 2018 9:00:42 GMT -6
Well after a quick debug it crashes on shipcontrol()....but I have to go to work so I can't really dive in right now, bummer...hoping to play it, till tonight I guess, or maybe morning for you lol.
|
|
|
Post by tbird on Dec 17, 2018 9:05:34 GMT -6
Oh never mind, I was in Windows. Last night, I had to fix a huge issue with the collision editor...so yeah disregard my stupidity.
|
|
|
Post by johnno56 on Dec 17, 2018 12:29:47 GMT -6
It's almost 5am here in Melbourne and that could be the reason for my train, or lack of train, of thought..
You said it wouldn't run on your laptop? Is it the odd "window/canvas" size? Sometimes I will 'prototype' a game using "Scratch" and then copy my assets to use elsewhere. A Scratch screen is 480 x 360, but for some strange reason, the dimensions of the graphics assets double in size when copied. Hence the weird "window/canvas" parameters. I can re-jig everything to fit a 800 x 600 or 640 x 480 if you wish?
I use Geany as my editor. It's no better than the RC Editor except in one area. The Linux version of the RC Editor does not display error messages whereas linking Geany to the RC Editor it does. I just paused my posting to test the game using the RC Editor directly and it ran just fine.
Now my brain hurts... Confusion is setting in... caffeine levels are way too low...
I had spent many, many, many minutes keying in all that code only to be told... Wait! You said you ran it on Windows? As a dedicated Linux user, I am obligated to inform you that, this could be your problem... or it could be that I am incredibly biased... lol
But, in the interest of 'standardisation', I will re-code for for a smaller display...
just out of curiosity, what is the resolution of you laptop?
Oh. Before I forget... Many moons ago (no pun intended) I was working on a crude lunar landscape generator using SDLBasic. If I can convert it, I will attempt to incorporate it into the next version... (or just post it as a 'snippet') after standardisation is completed of course... lol
As Homer Simpson would say, "Oh. That's just perfect!". I just realised that I did not wash my coffee cup after using it last night... Now I have to wait longer for my coffee...
J
ps: Have a good day/night... Great! There goes yet another brain ache...
|
|
|
Post by n00b on Dec 17, 2018 19:36:59 GMT -6
It crashed on Windows for me as well. I found the issue. The issue was that when you use GetPixel() and the x or y position was less than zero then it was causing a crash. Internally this function dumps all the screens pixels in a 2 dimensional array and then checks the color at screen_pixel[x][y]. If you have a negative value for either then it starts trying to check for the value in memory it does not have access to so it crashes.
I made some modifications to your code to keep it from crashing.
' ' Lander '
WindowOpen(0,"LUNAR LANDER",windowpos_centered,windowpos_centered,960,720,0) CanvasOpen(0,960,720,0,0,960,720,0) window(0) Canvas(0) hideMouse()
bg1 = 1 loadImage(bg1,"assets/level1.png") bg2 = 2 loadImage(bg2,"assets/level2.png") bg3 = 3 loadImage(bg3,"assets/level3.png") ship = 10 loadImage(ship,"assets/ship.png") boom = 11 loadImage(boom,"assets/boom.png")
loadFont(1,"assets/impact.ttf",24) loadFont(2,"assets/impact.ttf",100)
font(1)
randomize(timer)
level = 1 maxLevel = 3 xvel = 0 yvel = 0 shipx = 50 + rand(800) shipy = 50 alive = 1 fuel = 500 speed = abs(yvel) burnrate = 0.5
moon = rgb(255,255,220) pad = rgb(128,0,255)
sub updateLevel() select case level case 1 DrawImage(bg1,0,0) case 2 DrawImage(bg2,0,0) case 3 DrawImage(bg3,0,0) end select end sub
sub hud() font(1) setColor(rgb(255,255,255)) DrawText("FUEL: " + str$(fuel),15,0) DrawText("SPEED: " + str$(yvel),0,30) end sub
sub landed() font(2) setColor(rgb(0,255,0)) DrawText("LANDED!", 300,20) if level < maxLevel then font(1) setColor(rgb(255,255,0)) DrawText("NEXT LEVEL...",400,150) end if if level = maxLevel then font(1) setColor(rgb(255,255,255)) DrawText("GAME OVER!!",400,150) end if update() end sub
sub crashedMoon() font(2) setColor(rgb(255,0,0)) DrawText("CRASHED!!",250,20) font(1) setColor(rgb(255,128,0)) DrawText("Couldn't find the Pad?",350,150) update() end sub
sub crashedPad() font(2) setColor(rgb(255,0,0)) DrawText("CRASHED!!",250,20) font(1) setColor(rgb(255,128,0)) DrawText("You landed too fast!!",350,150) update() end sub
sub shipControl() DrawImage(ship,shipx,shipy) yvel = yvel + 0.05 shipx = shipx + xvel oldy = shipy shipy = shipy + yvel yvel = shipy - oldy if key(k_up) and fuel > 0 then yvel = yvel - 0.1 fuel = fuel - burnrate end if if key(k_left) and fuel > 0 then xvel = xvel - 0.1 fuel = fuel - burnrate end if if key(k_right) and fuel > 0 then xvel = xvel + 0.1 fuel = fuel - burnrate end if if shipx < 0 or shipy < 0 then 'do nothing elseif getPixel(shipx,shipy+42) = moon or getPixel(shipx+25,shipy+42) = moon then DrawImage(boom,shipx - 37,shipy - 29) ' Insert "CRASHED" notice here <================================= crashedMoon wait(5000) end end if if shipx < 0 or shipy < 0 then 'do nothing elseif getPixel(shipx,shipy+41) = pad and getPixel(shipx+25,shipy+41) = pad and yvel < 3 then ' insert "Landed" notice here <================================ landed wait(2000) level = level + 1 shipx = 50 + rand(800) shipy = -50 if fuel < 100 then fuel = fuel + 100 end if if level > 3 then wait(2000) end end if end if if shipx < 0 or shipy < 0 then 'do nothing elseif getPixel(shipx,shipy+41) = pad and getPixel(shipx+25,shipy+41) = pad and yvel >=3 then DrawImage(boom,shipx - 37,shipy - 29) crashedPad update() wait(5000) end end if
update() end sub
do ClearCanvas updateLevel hud shipControl loop until key(k_escape)
|
|
|
Post by johnno56 on Dec 17, 2018 20:14:41 GMT -6
My apologies for that. In my haste I had left out the screen limit checks. Normally with these kind of games, I usually 'screen wrap' or stop, when the ship reaches the screen edge...
I will make sure that the corrections are made to my current version. I have added a few sounds and a new 'ship'. Two types of crashes. (No. Not the dead program type... lol) If there is still available fuel. Boom! If no full then Thud. I am also working on some better 'screens' and possibly a better HUD. Not too sure about the latter... lol
I have a quick question about the sounds. I have sounds for the main engine (up) and the thrusters (left and right). Whenever a key is pressed the appropriate sound is played. But sounds like a 'machine gun' because it plays the sound over and over so fast... Is there any way to control this? ie: play the sound until finished before it plays again... I hope I'm making sense.
|
|
|
Post by tbird on Dec 17, 2018 20:35:05 GMT -6
Use of a timer would be helpful, play the sound for the length of the sound then loop (if required).....n00b better chime in I actually have not used a single sound yet except the gun shot sound from that example....so I have little to add.
|
|
|
Post by johnno56 on Dec 17, 2018 21:01:26 GMT -6
This is my current version. Standardised screen to 800 x 600. New ship. Few sounds. Limited x-axis movement. I have included a crumpled ship image for when it crashes without fuel but cannot get it to display. I have tried the 'DeleteImage()' command followed by the 'DrawImage()' of the crumpled ship... but did't work. It's not a big deal if it doesn't end up working... I am open to any suggested improvements... I don't want to take this too far, after all, it's meant to be a 'simple' lander... lol J Attachments:lunarlander.zip (724.28 KB)
|
|
|
Post by n00b on Dec 18, 2018 7:23:30 GMT -6
I think the timer idea for the sound is a good one. You could create a variable that keeps track of the time since the sound last played and then play it after a set period.
I tried it in your code and it had some good results. I do think that you also may need to trim the noise at the beginning and end of the wav files as well.
I created a variable at the top called sound_timer and set it equal to timer(). Then I put this every where you needed to play a sound.
if (timer - sound_timer) > 300 then sound_timer = timer playSound(thrust,4,0) end if
As far as your issue with the crumbled ship look at the following:
sub shipControl() if shipx <= 5 then shipx = 5 xvel = 0 end if if shipx >= 750 then shipx = 750 xvel = 0 end if DrawImage(ship,shipx,shipy) 'THE MAIN SHIP SPRITE IS ALWAYS DRAWN EVEN IF YOU DECIDE TO DRAW THE CRUMBLED SHIP LATER ON yvel = yvel + 0.05 shipx = shipx + xvel oldy = shipy shipy = shipy + yvel yvel = shipy - oldy
If you move the line where you draw the ship to the end of your shipControl sub then it should work the way you want it to.
Hope that helps.
|
|
|
Post by tbird on Dec 18, 2018 8:37:17 GMT -6
I moved over to linux and played, you need some difficulty levels got em all on the first try lol. But I liked it nonetheless, great job johnno.
|
|
|
Post by tbird on Dec 18, 2018 9:54:00 GMT -6
Well I guess it wasn't too easy, my wife tried and died 12 times to finish the 3 levels lol, but it's all good.
|
|
|
Post by johnno56 on Dec 18, 2018 13:51:44 GMT -6
Noob: Your 'sound' modifications worked like a charm. I see what you mean by 'trimming'. A consistent faint 'click' as the sound plays. I found and online (and downloadable) sound effect generator (bfxr.net) and hopefully create a 'seamless' effect. (not sure I can apply 'seamless' to sound but I think you might get the meaning. Wonderful... I now have a 'crumpled' ship... Thank you. Again, thank you for the sound mod. Much appreciated. TBird: The current levels were meant to be easy... The game was just a "see if I can" experiment. Once all (or pretty much all) of the 'bugs' are ironed out, I plan to include difficulty... but not too much... lol For example: As the levels progress the size of the "pad" will reduce. Then perhaps reduce the maximum landing speed... I have some 'carverns' to 'fly' through but find pixel perfect collision problematic at best... Oh well, looks like I just have to get creative... Please tell your wife, "Only 12 times?". I wrote this thing and I can assure her that I crashed many more times. lol 12 times? She's doing fine... It's almost 7am here in Melbourne and my brain is running on fumes... This much coding BEFORE my caffeine fix is not healthy... lol Once my caffeine levels are "back to norm", I plan to edit some sounds and breakout the graphics editor, then look at some 'difficulty'... Moo Ha Ha.... Have a great day, guys. J
|
|