# GamesLunar Lander [WIP]

#### ilan

##### Expert
Longtime User
Hi b4x Gamers,

i am working on a new Gift for you! (b4x gamers community). I am creating a Lunar Lander game.
The first step is to create the Terrain but i want to make it randomized so i created my own algorithm.
Have a look and tell me if it is ok.

Full Game Source:

This is what i have until now:

Part1:

Part2:

Part3:

Part4 (Gameplay):

#### Attachments

• result.jar
500.5 KB · Views: 182
Last edited:

#### JordiCP

##### Expert
Longtime User
Looks nice!
I had to do something similar time ago (generate mountain terrain) with random samples from left to right in order to opt-in for a project which dealt with altimeter and other sensors samples.

Just uploaded the video to Youtube to be able to show it here

Just searched the old B4A project, here is how it was done
There can be 5 possible slopes: -2 (high negative), -1 (low negative), 0 (no slope), 1 (low positive) and 2 (high positive)

1. At start, the slope was set to 0 (null slope) and first point was set to an arbitrary Y value.
2. Then the next point was calculated (random from 0 to 11)
• If value was <= 5, current slope was not changed
• if value was 6 or 7, slope was increased by one
• if value was 8 or 9, slope was decreased by one
• if value was 10, slope was increased by two
• if value was 11, slope was decreased by two
3. After it, slope value was limited to be between -2 and 2
4. Based on it, the next point was calculated to be Y(n+1) = Y(n) + slope*10
5. Go back to (2) until finished

I guess the principle is similar. But instead of assigning a different probability to each slope (result was not nice), it was better to assign a different probability to each "change of slope", always with higher chances to keep with the current slope whichever it was.
I remember that the weights (grouping) assigned to the random generated value in order to decide how and when it changes direction are key to make the result more or less eye-catching.
Can share the generator code in case it is useful for you

#### ilan

##### Expert
Longtime User
Can share the generator code in case it is useful for you
You mean my code that creates the terrain as in the video?

yes sure will do that when i get home (now i am in supermarket buying toillet paper before lockdown )

ps. Your example Looks awesome @JordiCP , i am sure tour code is much more logical than mine

#### JordiCP

##### Expert
Longtime User
You mean my code that creates the terrain as in the video?
Nope, perhaps I expressed myself wrong, sorry . I meant that I can share mine, in case there is something in it that could be useful for your project

(now i am in supermarket buying toillet paper before lockdown )

#### ilan

##### Expert
Longtime User
Nope, perhaps I expressed myself wrong, sorry . I meant that I can share mine, in case there is something in it that could be useful for your project
Every code is always welcome. I enjoy seing how people solve problems and learn from it

#### 73Challenger

##### Member
I LOVE that game! There weren't many Lunar Lander games built so they were hard to find. The first time I played it, my family was on a trip to Disney World in 1980!!! We went to NASA for the day and they had it. My parents had to pry my fingers off the thruster throttle control to get me to leave. Fun fact, Lunar Lander was released before Asteroids. Atari used the same vector graphics engine for Asteroids but Lunar Lander got there first!

Nice work, look forward to crashing a few ships when it's done!

#### Jeffrey Cameron

##### Well-Known Member
Longtime User
First version of Lunar Lander I played was text-based on a teletype. You had to enter decimal values for the thrust and vector parameters, and it would print out the results. The first graphics-based "lander" game I really played was Oids on the Atari ST, I am ashamed to admit how many hours I spent playing that game

#### ilan

##### Expert
Longtime User
First version of Lunar Lander I played was text-based on a teletype. You had to enter decimal values for the thrust and vector parameters, and it would print out the results. The first graphics-based "lander" game I really played was Oids on the Atari ST, I am ashamed to admit how many hours I spent playing that game
i don't know this game. i know the classic lunar lander game. but his one looks really cool.

#### Jeffrey Cameron

##### Well-Known Member
Longtime User
i don't know this game. i know the classic lunar lander game. but his one looks really cool.
It is available as abandonware. But don't blame me for any reduction in your productivity

#### ilan

##### Expert
Longtime User
Yeah, I absolutely love lunar lander games, an love seeing WIP threads...
FYI, for the terrain I used @Informatix simplex noise library in my hill climb racing game, maybe you can take a look at it
A few years ago I started my own lunar lander...

i remember this thread. you are really good in game making. 1 of the best i know in this forum.
in my example i will not use box2d or any rendering library only core + math.
it should be simple and similar to the old good black&white lined lunar lander game

#### ilan

##### Expert
Longtime User
ok, i have uploaded a new video with some progress. i am now drawing the ship, moving it and check collision.
in the second half of the video i am drawing the collision lines with a green color and as soon as they touch another line from the terrain they are drawn red to show that there was a collision.

i am using the line2line collision from jeffrey thompson on this site: http://www.jeffreythompson.org/collision-detection/line-line.php

you really should check his site, there are really cool collision detection options you can use like point to point, point to line, line to line, and many more.

video in post #1

Last edited:

#### ilan

##### Expert
Longtime User
i completed a more challenging part. camera zooming when spaceship get near to terrain. this was something i had to think some time about how to solve it and needed several hand drawings

video in post #1

#### ilan

##### Expert
Longtime User
btw, i need to mention that i have not played this game on real console so i need your help. what is counted for a successful landing?
i need to take in account the angle, speedx, speedy and landing place.

when should i show a successful landing?

if angle < ?
if speedx < ?
if speedy < ?

thanx

#### 73Challenger

##### Member
@Jeffrey Cameron That is cool!

@ilan The main things I recall about the game is... there were 3 buttons for craft rotation, left right and Abort, plus an aircraft style throttle.

This guy has a video that explains most of the game play.

Another with no commentary

Successful landing
Vertical speed < 15 (there was a hard landing feature, maybe from 10-15 vertical speed)
Horizontal < 31
Lander must be centered

Landing gets you more fuel
Crashing takes away fuel
SuperBurn uses alot of fuel.

The landing speed determines the pad multiplier.

#### ilan

##### Expert
Longtime User
Game is playable. Uploaded a new video on post #1.
I must say it was a really fun project. Now i will see what i can do with it
i need to refactor the code before i can upload the project for you guys, so stay tuned

Staff member
Longtime User

#### 73Challenger

##### Member
WOW @ilan very nice! I look forward to playing it (and maybe borrowing some code )

#### ilan

##### Expert
Longtime User
I look forward to playing it
Jar file uploaded to post #1
to move the ship just use the LEFT|UP|RIGHT keys of your keyboard

Games Mobile Games
Replies
48
Views
7K
Replies
3
Views
1K
Replies
7
Views
2K
Replies
15
Views
3K
Replies
6
Views
3K