A Flappy Bird clone made in Fjord
at master 1.1 kB view raw
1using System; 2using Fjord; 3using Fjord.Modules.Debug; 4using Fjord.Modules.Game; 5using Fjord.Modules.Graphics; 6using Fjord.Modules.Input; 7using Fjord.Modules.Mathf; 8using Fjord.Modules.Sound; 9 10namespace Flappy_Bord { 11 class bird_controller : component { 12 13 float velocity = 0; 14 float gravity = 1f; 15 float max = 30f; 16 17 public override void on_load() 18 { 19 parent.get<Sprite_Renderer>().sprite.set_texture("bird.png"); 20 parent.get<Transform>().position = new V2f(100, 101); 21 } 22 23 public override void update() { 24 velocity += gravity; 25 26 velocity = Math.Clamp(velocity, -max, max); 27 28 parent.get<Transform>().position.y += velocity * game.delta_time; 29 30 if(input.get_key_just_pressed(input.key_space)) { 31 velocity = -200; 32 33 Sound.play_sound("jump"); 34 } 35 } 36 37 public override void render() 38 { 39 base.render(); 40 } 41 } 42}