I have managed to make it under 34 char!
exteands Node2D
func _s():
s()
I just need to code it in C++…
lol!
I have managed to make it under 34 char!
exteands Node2D
func _s():
s()
I just need to code it in C++…
lol!
Could you not skip initializing the color to a set value and instead use the default color?
You can replace the t.has(a) with a in t, saves 2 more characters
OMG! we solved the greatest and biggest problem xD
lol
a in t
I didn’t know it lol
That’s cool!
Thanks everyone! Glad you like it.
There was a suggestion that brings it 4 chars down.
I seriously think we’re very near the theoretical lower limit.
You devil!
I don’t think so. draw_rect doesn’t have the default value for the color argument and since there are 2 colors, they need to be differentiated somehow. The best I could do is to use Color() ( which initializes to default black) instead of “000000”.
Done! 4 more chars down.
Well, I already have the “engine” so here goes flappy bird in 696 686 chars. I was expecting it to be squeezable under 500 since it has less state than the snake, but nope.
extends Panel;var t=[300,200,100,250];var p=1100;var s=[]
var b=Vector2.ONE*300;var c=Rect2(0,0,48,48);var v=0;var l=""
func _draw():
for i in s:draw_rect(i,Color());if i.intersects(c)||b.y>552:set_process(0);if!"X"in l:l+=" X"
draw_rect(c,"ff8800");draw_string(get_theme_font(""),Vector2(8,20),l)
func _input(e):if e.get("pressed"):v=-450;if"X"in l:get_tree().reload_current_scene()
func a(i,y,h):s+=[Rect2(p+i*450,y,150,h)]
func _process(d):
get_viewport().size=Vector2(1100,600)
v+=1300*d;b.y+=v*d;b.y=max(b.y,0);d*=170;p-=d
if p<-150:p+=450;t.pop_front();t+=[randi()%380+20]
if p<100&&p+d>100:l=str(int(l)+1)
s=[];for i in len(t):a(i,0,t[i]);a(i,t[i]+180,450)
c.position=b;queue_redraw()
Here some of us are just beginning and trying to make any games, and in comes @normalized making a game in a forum post under 700 characters.
Hats off to you sir.
Simply amazing!
Is it the time to ask for GTA 6, or do you need a couple more warm-up rounds?
Lol. I think I’ve had enough for the time being. I’d like to see what other golfers come up with. Doing a sub-1K space invaders might be a good challenge.
One last push on the flappy bird, before I breeze out over the horizon in my pink golf cart.
Bringing it just below 600 chars, it presumes the default window size:
extends Panel;var p=900;var t=[300,200,99];var s=[]
var y=300;var c=Rect2(y,0,48,48);var v=0;var l=""
func _draw():
for i in s:draw_rect(i,Color());if i.intersects(c)||y>600:set_process(0);l+=" X";y=0
draw_rect(c,"ff8800");draw_string(get_theme_font(l),c.size/2,l)
func _input(e):if e.get("pressed"):v=-450;if!y:get_tree().reload_current_scene()
func a(i,y,h):s+=[Rect2(p+i*450,y,150,h)]
func _process(d):
v+=1300*d;y=max(1,y+v*d);d*=170;p-=d
if p<-150:p+=450;t=t.slice(1)+[randi()%400+20]
l=str(int(l)+int(p<99&&p+d>99))
s=[];for i in len(t):a(i,0,t[i]);a(i,t[i]+180,450)
c.position.y=y;queue_redraw()
I tried even further by packing the column array into a single integer, 4 bits per column, but all the required bit fiddling resulted in exactly one character longer code, still under 600 though:
extends Panel;var p=900;var t=2132;var s=[]
var y=300;var c=Rect2(y,0,48,48);var v=0;var l=""
func _draw():
for i in s:draw_rect(i,Color());if i.intersects(c)||y>600:set_process(0);l+=" X";y=0
draw_rect(c,"ff8800");draw_string(get_theme_font(l),c.size/2,l)
func _input(e):if e.get("pressed"):v=-450;if!y:get_tree().reload_current_scene()
func a(i,y,h):s+=[Rect2(p+(2-i)*450,y*30,150,h*30)]
func _process(d):
v+=1300*d;y=max(1,y+v*d);d*=170;p-=d
if p<-150:p+=450;t=t<<4|randi()%14+1
l=str(int(l)+int(p<99&&p+d>99))
s=[];t|=t<<12;for i in 3:a(i,0,t&15);a(i,(t&15)+6,20);t>>=4
c.position.y=y;queue_redraw()
If only godot api calls weren’t so darn verbose ![]()
Dang godot being so easy to read!
Okay, realized my flappy bird approach was a bit wasteful. The map state doesn’t really need to be maintained, as it can be regenerated on the fly by utilizing the deterministic nature of the rng. I completely eliminated it. Also, motion/timing integration multiplication is skipped under assumption we’re running at fixed 60 fps.
Flappy bird down to mere 520 chars:
extends Panel;var p=150;var y=300;var c=Rect2(y,0,48,48);var v=0;var l=""
func _draw():
for i in 8:
var a=i/4;i%=4;seed(p/450-i);var h=randi()%380+20;a=Rect2(p%450+i*450,(h+180)*a,150,h*int(!a)+999*a)
draw_rect(a,Color());if a.intersects(c)||y>600:set_process(0);l+=" X";y=0
draw_string(get_theme_font(l),c.size/2,l);draw_rect(c,"ff8800")
func _input(e):if e.get("pressed"):v=-450;if!y:get_tree().reload_current_scene()
func _process(d):p-=3;v+=21;y=abs(y+v*d);c.position.y=y;queue_redraw();if!(p-90)%450:l=str(int(l)+1)
Keep telling us you’re done, but we all know this is going sub 500 ![]()
Can’t help it. Code golfing is addictive
. I truly don’t see a way for this to go sub 500 though. Most of the code is just necessary api calls anyway, and those cannot be shortened. I hate the fact that it needs to call Rect2 constructor twice.
Instead of Color() you can write 255, or, if a bit of transparency is okay, even 99. And the player’s color could be written as "red" instead of "ff8800", which is the shortest color name (together with “tan”).
Oh, good ones. Thanks. Red is a bit too dark to make a good contrast against the default gray. It’ll have to be 255 and 99. Brining it down to 509 characters:
extends Panel;var p=150;var y=300;var c=Rect2(y,0,48,48);var v=0;var l=""
func _draw():
for i in 8:
var a=i/4;i%=4;seed(p/450-i);var h=randi()%380+20;a=Rect2(p%450+i*450,(h+180)*a,150,h*int(!a)+999*a)
draw_rect(a,99);if a.intersects(c)||y>600:set_process(0);l+=" X";y=0
draw_string(get_theme_font(l),c.size/2,l);draw_rect(c,255)
func _input(e):if e.get("pressed"):v=-450;if!y:get_tree().reload_current_scene()
func _process(d):p-=3;v+=21;y=abs(y+v*d);c.position.y=y;queue_redraw();if!(p-90)%450:l=str(int(l)+1)
Technically, 99 can work for the bird as well, but it makes it all look washed out. If push comes to shove though and there’s a way to take out another 9 characters - I could live with it ![]()
Those color tricks are applicable to the snake as well.
If it’s allowed to extend from Label instead of Panel, the char count is down to 467.
extends Label;var p=150;var y=300;var c=Rect2(y,0,48,48);var v=0
func _draw():
for i in 8:
var a=i/4;i%=4;seed(p/450-i);var h=randi()%380+20;a=Rect2(p%450+i*450,(h+180)*a,150,h*int(!a)+999*a)
draw_rect(a,99);if a.intersects(c)||y>600:set_process(0);text+=" X";y=0
draw_rect(c,255)
func _input(e):if e.get("pressed"):v=-450;if!y:get_tree().reload_current_scene()
func _process(d):p-=3;v+=21;y=abs(y+v*d);c.position.y=y;queue_redraw();if!(p-90)%450:text=str(int(text)+1)
Aw, it has a bug: the game over screen doesn’t show the “ X” part.
For those who would like to get good at shaders or are already the elite, I suggest Shadertoy golf, bonus points for complete games running on WebGL ![]()
Ha! Looks like @BFranse was right ![]()
Still an excellent idea as it shaves off that nasty font call. Changing text apparently triggers _draw() sending it into an endless loop. The label text is also drawn behind anything that _draw() produces but it’s tolerable as the alpha of the map is 99 from the last intervention.
I implemented it by setting text twice. Looks like it doesn’t break anything.
In addition; the literal 450 appears quite a lot. I stretched some other literals (including 255 for the bird color) to that value. This made declaring it as a var worthwhile. To go as far as possible, I removed the space character in gameover " X" string and eliminated all unnecessary tabs from that for loop.
I also realized that set_process(0) doesn’t need to be called as there is another variable already abused to record the gameover state. So it can be replaced by mere if y: at the start of _process()
Without further ado, may I present you - flappy bird in 450 characters:
extends Label;var p=150;var y=300;var c=Rect2(y,0,48,48);var v=0;var l=0;var g=450
func _draw():draw_rect(c,g);for i in 8:var a=i/4;i%=4;seed(p/g-i);var h=randi()%g;a=Rect2(p%g+i*g,(h+180)*a,150,h*int(!a)+g*a);draw_rect(a,99);if a.intersects(c)||y>600:y=0;text="%dX"%l
func _input(e):if e.get("pressed"):v=-g;if!y:get_tree().reload_current_scene()
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
Insane. And fun to follow along!
You can get below 400. Calling it now
. Bookmark this post for later ![]()
The final final final version of flappy bird (I know
).
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