Discord
Login
Community
DARK THEME

I code a Platformer with Quick engine

I code a Platformer with Quick engine and i need help after i coded the jump code i see that i can spam jump and thats the bad

my movementcode:

; playermovement = function() if keyboard.RIGHT then player.vx = 100 player.name = "player_right" else player.vx = 0 player.name = "player_idle" end if keyboard.LEFT then player.vx = -100 player.name = "player_left" end if keyboard.UP then player.vy = 100 end if not player.grounded then player.name = "player_jump"

  end
end

my main code ; init = function() Quick.init() player = Quick.addSprite("player_idle",0,0,20,20) Quick.addMap("map",0,-51,300,200)

Quick.Gravity = 40 end

update = function() Quick.update() playermovement()

Quick.camera.move(player.x,player.y)

if player.y<-85 then gameover = 1

end

end

draw = function() if gameover then screen.clear screen.drawText("GAMEOVER",0,0,50,"rgb(255,255,255)") else Quick.draw() end

end

use the Quick Engine function which tells you that you are in contact with the ground ( solid ).

In your case it will look like this

if keyboard.UP and player.grounded then jump() end;

I highlighted the places where I added the code

//movementcode:

playermovement = function()
  if keyboard.RIGHT then
    player.vx = 100 
    player.name = "player_right" 
  else 
    player.vx = 0 
    player.name = "player_idle" 
  end 
  if keyboard.LEFT then 
    player.vx = -100 
    player.name = "player_left" 
  end 
//----------------------------------------------  
  if keyboard.UP and player.grounded then 
    player.vy = 100 
  end 
//-----------------------------------------------  
  if not player.grounded then 
    player.name = "player_jump"
  end
end

//my main code ; 

init = function() 
  Quick.init() 
  player = Quick.addSprite("player_idle",0,0,20,20) 
  Quick.addMap("map",0,-51,300,200)
  Quick.Gravity = 40 
end

update = function() 
  Quick.update() 
  playermovement()

  Quick.camera.move(player.x,player.y)

  if player.y<-85 then 
    gameover = 1
//----------------------------------------------------
  end
  print( "touches the block = " + player.grounded )
//---------------------------------------------------  
end

draw = function() 
  if gameover then 
    screen.clear()
    screen.drawText("GAMEOVER",0,0,50,"rgb(255,255,255)") 
  else 
    Quick.draw() 
  end
end

thanks

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community