Can I make a Lunar Lander?

I just saw @orkn post about ice and belts. It really helped me with was I trying to do last night. But my ship only does one hop and then hits the ground. I did not see any commands for the control pad. I want to "ignore" gravity (y++) when I hold the up direction.

Could you explain a little more what you are trying to do and maybe share the code that isn't working as you want it to?

I'm sure you can make a lunar lander, but as Pulp is made for top-down games anything that's side-on with gravity is going to be a bit trickier. I'm glad you found my post useful, but I suspect it wouldn't be the right approach for this!

As you mention "holding" the up direction, you might want to check out Pulp's configuration options config.inputRepeat, config.inputRepeatDelay and config.inputRepeatBetween in the documentation. Unless you change these (and I haven't tested this) you shouldn't expect to get an "up" input for every frame that the up button is held.

Here is the bit of code, it is yours.

on playerGravity do
	x = event.px
	y = event.py
	y++
	
	tileSolid = solid x,y
	if tileSolid==0 then
		ignore
		wait 0.2 then
			listen
			goto x,y
		end
	end

I saw some of the examples of other games (Dr. Panic, Pong, etc) that were more than just a top down game. So I thought it might be possible.

Here is an example of a lunar lander type game.

http://moonlander.seb.ly

I did see the config info, but thought it was only for the "A" and "B" buttons. I didn't try because I could see a way to get the keypress for the control pad.

Where is the playerGravity event being called from? I'm guessing in the game's loop?

If you think through what the code is doing, as soon as the player (the lunar lander) has a non-solid tile beneath it, the ignore is going to disable all player input, the game will wait 0.2 seconds, and then re-enable input with listen as the player is moved down a tile. That's why you can only hop one tile upwards then get moved back down. The ignore/listen pattern makes sense for sliding across a tile or being moved by a conveyor belt, but in your situation you want the player to be able to move while in the air.

For a simple, repeating downwards push you could instead only call playerGravity every some number of frames and have it immediately act like this:

on playerGravity do
  x = event.px
  y = event.py
  y++

  tileSolid = solid x,y
  if tileSolid==0 then
    goto x,y
  end
end

The problem is that's not really "gravity" as it's not an accelerative force. That lunar lander game doesn't implement movement as "press direction - move a unit in that direction". Instead movement is worked out from the player's velocity, which is changed by a downwards gravity and a thrust force from player input.

You could make a lunar lander like game with simple tile based movement, and this would certainly be easier in Pulp, or you could try and make velocity based movement with acceleration, but this is going to mean a lot more code.

1 Like