Discord
Login
Community
DARK THEME

Gravity not working

I need help because the gravity in my game isn't working. When i die it works but when i reset the game by pressing "r" it starts making the gravity slower insted of faster. i wanted the gravity to go faster so it would get harder over time. I also want the players speed to get faster over time so its playable

Link to thing, https://microstudio.dev/projects/pumkin/code/

You need to make the project public to show the code.

Go to the project settings (at the left edge, at the very bottom), make the project public and provide us with a link to the project.

ok

i have to ask my freind to do it because im not the owner but i an put a link to the code in a txt file

Hi co dev hear hear is the working link https://microstudio.io/i/pgmz5/pumkin/

In your code, line 57 - you set gravity to 0

To increase the player's speed, you increase the value of the speed variable - every time a spawn occurs.

The code is difficult to understand - I changed it a bit. R - restart

Game = class
  constructor = function()    
    Quick.init()    
    map = Quick.addMap("map",0,0,400,400)
    myobj = Quick.addSprite('wall_one',170,-10,0,500)
    myobj2 = Quick.addSprite('wall_one',-170,-10,0,500)
    player = Quick.addSprite("player",0,-90,20,20)
    speer = Quick.addSprite('speer',0,100,17,70)
    reset()
  end
  
  reset = function()
    Quick.gravity = 9.8
    falling = 0 // 2 == not alive, 0 == alive  
    speed = 2
    player.x = 0    
    player.solid = 1
    player.fall = 0    
    
    myobj2.fixed = 1
    myobj2.solid = 0
    
    myobj.solid = 0
    myobj.fixed = 1

    speer.solid = 0
    speer.vy = 0
  end
  
  update = function()
    Quick.update()
    if Quick.spriteCollision(player,speer) then
        player.y += 500 //move player off screen like hideing it
        stop()
        falling = 2 // 2 == not alive, 0 == alive
    end
    if player.x > 150 then
      player.x = 150
    end
    if player.x < -150 then
      player.x = -150
    end
    if keyboard.LEFT then
      player.x -= speed
    end
    if keyboard.RIGHT then
      player.x += speed
    end
    if falling == 2 and keyboard.R then
      reset()
      //Quick.gravity = 0
    end
    
    if keyboard.I then
      speer.fixed = 1
    end
    if keyboard.P then
      speer.fixed = 0
    end
    if falling == 0 then // 2 == not alive, 0 == alive
      spawn()
    end
  end
  
  spawn = function()
    if speer.y <-150 then
      speer.y = 150
      speer.x = player.x
      Quick.gravity += 1
      speed += 1
      print("gravity = "+ Quick.gravity + " player speed = " + speed )
    end
  end
  
  stop = function()
    die = 2 // 2 == not alive, 0 == alive
  end  
  
end

init = function()
  game = new Game()
end

update = function()
  game.update()
end

draw = function()
  Quick.draw()
end

THX ALOT my bad caps lock

wait your, Loginus????? SOOO cool. i saw some of your projects and its soo cool to have you hep me with my first Microstudio project

TYSM

also its my first time useing microstudio and more importantly Quick Engine. so could explain what the code is doing and why my code would not work

You made the code too complicated.

class "spike" - is redundant, and you didn't use it as a class.

You set the variable Quick.gravity = 0

But nowhere did you restore the variable to 9.8 (it had to be done after the restart).

You need to compare the code you wrote and the one I wrote to understand which parts of the code were changed.

Post a reply

Progress

Status

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