GDScript Code Golf

The final final final version of flappy bird (I know :slight_smile: ).

Removed reload_current_scene() call by putting initialization into _init() and just calling that. Also removed the gameover X. It doesn’t serve much purpose and ditching it removes the need to assign to text twice. Last two characters killed by turning a local variable into a dummy function argument.

Thanks to @ratrogue’s hint on assigning integers directly to Color I realized that negative integers can be assigned as well. In two’s complement -1 has all the bits set, resulting in opaque white which I assign to the bird rect, sacrificing one character for aesthetics (replacing g with -1)

I don’t think it can go much lower than this - 425 characters:

extends Label;var p;var y;var c;var v;var l;var g=450
func _init():p=150;y=300;c=Rect2(y,0,48,48);v=0;l=0;
func _draw(h=0):draw_rect(c,-1);for i in 8:seed(p/g-i%4);h=randi()%g;h=Rect2(p%g+i%4*g,i/4*(h+180),150,h*int(i<4)+i/4*g);draw_rect(h,99);if h.intersects(c)||y>600:y=0
func _input(e):if e.get("pressed"):v=-g;if!y:_init()
func _process(d):if y:p-=3;v+=21;y=abs(y+v*d);c.position.y=y;text="%d"%l;queue_redraw();if!(p-90)%g:l+=1
5 Likes