Discord
Login
Community
DARK THEME

pls help add aniation script

hi i am the dev of a 16 bit dungun crawler that i just started to make could some one add a animtion where when he jumps the jetpack sprite is show insted here is the code https://microstudio.io/i/pgmz5/ogmz5s/

You need to implement a state machine. You won't be able to create a game without it.


Player = class
  constructor = function()
    this.walk = Quick.addSprite("bob",0,100,50,50)
    this.walk.display = 1

    this.fly = Quick.addSprite("sprite",0,0,50,50)
    this.fly.display = 0
    this.fly.solid = 0

    this.current = this.walk
  end
  
  state = function( mode )
    if this.current == this.walk and mode then 
        this.walk.display = 0
        this.fly.display = 1
        this.fly.solid = 1
        this.fly.x = this.walk.x
        this.fly.y = this.walk.y
        this.fly.vx = this.walk.vx
        this.fly.vy = this.walk.vy 
        this.walk.solid = 0
        this.current = this.fly
        print("d")
    else
      if not mode and this.current == this.fly then 
        this.walk.display = 1
        this.fly.display = 0
        this.fly.solid = 0
        this.walk.solid = 1
        this.walk.x = this.fly.x
        this.walk.y = this.fly.y
        this.walk.vx = this.fly.vx
        this.walk.vy = this.fly.vy
        this.current = this.walk
      end
    end
    if mode then 
       this.current.ay = 600  
    end
  end

end

init = function()
  Quick.init()
  player = new Player()
  mymap = Quick.addMap("map",0,0,500,50)
end

update = function()

  if keyboard.LEFT then
      player.current.vx -= 5
  end
  if keyboard.RIGHT then
    player.current.vx += 5
  end

  player.state( keyboard.SPACE )
  Quick.camera.move( player.current.x, player.current.y )
  
  print( "x = "+player.current.x+" y = "+ player.current.y+ "  vy = " + player.current.vy)
  
  Quick.update()
end
draw = function()
  Quick.draw() 
  CRT(1000, 0.5,5) 
  //CRT(no of lines,intensity,speed)
end

Why cant we make a game without it. it seems like too much work for something so simple. BTW im co-dev for the game he is talking out that we need help with

If you have a player character who can

  • stand
  • to go
  • run
  • fly
  • to sleep
  • eat

Then you need to change its state to the one you want it to be now.

During some states, e.g. you cannot perform certain activities

  • you have to lie down while you sleep and you can't eat.
  • you can't sleep or eat while running
  • you can eat while standing still. All of this requires being encoded in a state machine. Otherwise your code will be difficult to develop.

https://medium.com/al-game-code/state-machine-for-games-summarizing-and-simplifying-d08d64705258

Here's a simple solution to changing the graphics. You simply change the name of the graphic you want the player character to have now.

Player = class
  constructor = function()
    this.sprite = Quick.addSprite("bob",0,100,50,50)
  end
  
  state = function( mode )
    if this.sprite.name == "bob" and mode then 
        this.sprite.name = "sprite"
    else
      if not mode and this.sprite.name == "sprite" then 
        this.sprite.name = "bob"
      end
    end
    if mode then 
       this.sprite.ay = 600  
    end
  end

end

init = function()
  Quick.init()
  player = new Player()
  mymap = Quick.addMap("map",0,0,500,50)
end

update = function()
  if keyboard.LEFT then
      player.sprite.vx -= 5
  end
  if keyboard.RIGHT then
    player.sprite.vx += 5
  end

  player.state( keyboard.SPACE )
  Quick.camera.move( player.sprite.x, player.sprite.y )
  
  print( "x = "+player.sprite.x+" y = "+ player.sprite.y+ "  vy = " + player.sprite.vy)
  
  Quick.update()
end
draw = function()
  Quick.draw() 
  CRT(1000, 0.5,5) 
  //CRT(no of lines,intensity,speed)
end

can you @Loginus join the dev team

@pgmz5

I'm trying to create my own game.

I won't have time for one more project.

However, you can always ask for help with a problem you encounter.

ok thx tho

Post a reply

Progress

Status

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