DIV ARENA FORUMS

Challenge #1 - Falling Rock

MikeDX - 15-3-2016 at 05:26 PM

Make a falling rock game in the fewest bytes of code:

requires:

- player spaceship (controlled via mouse OR keys) which is destroyed when rocks hit it.
- bullets fired from player
- rocks / enemies falling from top of screen - destroyed when hit by player bullets


whitespace (spaces, carriage returns) and comments do not count, so no need to minify your code)

you can use any graphics you like, but if you made them in the div editor, thats best ;)

Smallest code wins.. I'll submit my entry in a few days :)

RKSoft - 15-3-2016 at 06:16 PM

When is closing? I mean when should i finished my minigame?

MikeDX - 15-3-2016 at 06:19 PM

Let's leave this open for a while, maybe a week or so?

iWizard - 15-3-2016 at 07:32 PM

>> Smallest code wins.. I'll submit my entry in a few days :)

Should all the entries be revealed at the same time?

And considering code minimification; aren't variable names going to matter? :autism:

MikeDX - 15-3-2016 at 07:34 PM

The variable names will matter yes! :)

I don't think it's too bad to show entries as they are created...

If this format doesn't work, we'll change it to an "upload" method.

RKSoft - 16-3-2016 at 02:57 PM

uh, only a week? i haven't many time -.-

MikeDX - 16-3-2016 at 03:08 PM

ok well i'll leave it open until we have a few entries :)

RKSoft - 16-3-2016 at 06:16 PM

sounds better :) thx

Dennis - 16-3-2016 at 09:03 PM

I don't want to sound stupid but... where do I upload my entry ? :O

MikeDX - 16-3-2016 at 09:07 PM

you could attach a zip of it here and paste the code in [ code ] blocks

Score: 237 (confirmed by Mike)

Dennis - 16-3-2016 at 09:19 PM

Ok. I may even inspire others with my code. It's not very enjoyable to play but it seems to work :P

Code:
program a; begin load_fpg("a.fpg"); p(1,1,1,180); loop p(9,3,rand(0,320),0); frame; end end process p(t,graph,x,y) begin repeat if (t==1) x=mouse.x; if (mouse.left) p(-5,2,x,y-9); end else y+=t; end frame; until((collision(type p) and (t==1 or t==9)) or y>220 or y<-9) end


Attachment: a.zip (2kB)
This file has been downloaded 4098 times

MikeDX - 16-3-2016 at 09:24 PM

Nicely done dennis. i should have added that rocks should stop once player is dead though.


BreadCaster - 17-3-2016 at 05:12 AM

Does it have to be both a falling rock game, and also good/engaging? If so then this is a game design challenge, if not it's a programming one :p


iWizard - 17-3-2016 at 06:38 AM

Quote: Originally posted by BreadCaster  
Does it have to be both a falling rock game, and also good/engaging? If so then this is a game design challenge, if not it's a programming one :p

The definition for good/engaging in this case is fewest bytes of code. :smilegrin:

Then again, it might be nice to be able to say "whatever, it's still much better to play than that thing Dennis did. Dennis' thing is just small." :ninja:

MikeDX - 17-3-2016 at 08:59 AM

Quote: Originally posted by BreadCaster  
Does it have to be both a falling rock game, and also good/engaging? If so then this is a game design challenge, if not it's a programming one :p



No I already did the design

Anyway Dennis is winning :P

Score: 204 (Confirmed by Mike)

iWizard - 17-3-2016 at 10:39 AM

I thought I'll give it a go and whoa! It compiled! ...apart from parameters for signal() and I may have checked mouse stuff from the manual before compiling. BUT it was 320 chars and on top of that less optimized performance wise than Dennis'. :') I hate your genius Dennis.

So, I optimized Dennis' code somewhat further and it's now at 203.
Code:
program a; begin load_fpg("f.fpg"); p(1,1,1,200); end process p(t,graph,x,y) begin repeat if (t==1) x=mouse.x; if (mouse.left) p(-5,2,x,y-9); end p(9,3,rand(0,320),0); else y+=t; end frame; until(collision(type p) | y>240 | y<0) end

Maybe someone can skim it even further? If you were to go evil and take the off screen optimization out, which is not needed per rules, the score would be at 194.

MikeDX - 17-3-2016 at 02:04 PM

Quote: Originally posted by iWizard  
If you were to go evil and take the off screen optimization out, which is not needed per rules, the score would be at 194.


Well, you could but then div would (eventually) crash and then you'd probably be disqualified.

I can see a couple ways to trim a few bytes off even this implementation so there's still room for improvement with some hacking.

You should post your 320.

iWizard - 17-3-2016 at 03:00 PM

Quote: Originally posted by MikeDX  
I can see a couple ways to trim a few bytes off even this implementation so there's still room for improvement with some hacking.

Yay, so we will see yet another implementation. What could it be? Did DIV allow one line IFs, ie without an END? Maybe something with the choise of loop? Or maybe bit shifting? Nobody but asm-autists know about bit shifting! And in DIV? D:
Quote: Originally posted by MikeDX  

You should post your 320.

The mystery 320 is pretty much that with own processes for bullet and rock. And I noobisly initialised video mode. But even my fpg used the same graph codes :3 Yeah, I didn't put much thought on to the challenge itself - just happy that it ran and enjoyed how simple the code seemed.

MikeDX - 17-3-2016 at 04:02 PM

I've got this down to 198, using a new fpg and some dirty tricks.



Code:
program a; begin load_fpg("f"); p(1,1,180); end process p(t,x,y) begin graph=abs(t); repeat if(t) x=mouse.x; if(mouse.left) p(-8,x,y-9); end p(6,rand(0,320),0); else y+=t; end frame; until(collision(type p)|y>240|y<0) end




Attachment: a198.zip (2kB)
This file has been downloaded 4108 times

Score: 1 million (disqualified)

Sandman - 17-3-2016 at 05:34 PM

Nice tricks done here. Awesome start, Dennis!

Code:
program a; begin load_fpg("f"); p(1,1,9); // 180 can be 9, makes it rather unplayable though... end process p(t,x,y) begin graph=t*t; // you need to update the fpg with the new code here repeat if(t) x=mouse.x; if(mouse.left) p(-8,x,y-9); end p(6,timer%99,0); // Don't like this, one, but as per rules, rocks don't NEED to be spread out when falling end y+=t-1; // shaved off the else frame; until(collision(type p)) // like iWizard said, the y comparisons can go as per rules. Not a big fan of it either. end


Try that. :)

iWizard - 17-3-2016 at 05:52 PM

I think BreadCaster's note is soon starting to become rather relevant.

And on that bombshell it's time to conclude that the mystery 320 char code wins.

MikeDX - 17-3-2016 at 05:55 PM

Quote: Originally posted by Sandman  
Nice tricks done here. Awesome start, Dennis!

Code:
program a; begin load_fpg("f"); p(1,1,9); // 180 can be 9, makes it rather unplayable though... end process p(t,x,y) begin graph=t*t; // you need to update the fpg with the new code here repeat if(t) x=mouse.x; if(mouse.left) p(-8,x,y-9); end p(6,timer%99,0); // Don't like this, one, but as per rules, rocks don't NEED to be spread out when falling end y+=t-1; // shaved off the else frame; until(collision(type p)) // like iWizard said, the y comparisons can go as per rules. Not a big fan of it either. end


Try that. :)


DIV Crashed after a while.. and you didnt supply the fpg, also unplayable. disqualified :P

Score:189 (Confirmed by Mike)

Sandman - 17-3-2016 at 06:34 PM

Unplayable games are still games, though. Also don't play it so long, you have better things to do! Here's a cut down version anyway:

Code:
program a; begin load_fpg("f"); p(1,1,99); // 180 can be 99 end process p(t,x,y) begin graph=t*t; // smaller way of abs repeat if(t) x=mouse.x; if(mouse.left) p(-8,x,y-9); end p(6,timer%99,0); // Don't like this, one, but as per rules, rocks don't NEED to be spread out when falling end y+=t-1; // shaved off the else frame; until(collision(type p)|y>240|y<0) end



Attachment: bla.zip (2kB)
This file has been downloaded 4044 times

MikeDX - 17-3-2016 at 07:07 PM

Quote: Originally posted by Sandman  
Unplayable games are still games, though. Also don't play it so long, you have better things to do! Here's a cut down version anyway:


I dunno, unplayable games are just animations.

Liked this version better. Some good hacks there


BreadCaster - 17-3-2016 at 09:12 PM

also uh, why have people not just made the shapes/graphics using the draw commands? :S I mean this is a totally uninteresting sort of topic to me because i'm not logically minded enough to program much, let alone program things efficiently, but is there some reason everyone is using an fpg or am i just missing something here

MikeDX - 17-3-2016 at 09:13 PM

Basically using draw primitives would use a lot more code

BreadCaster - 17-3-2016 at 09:37 PM

ah, and the size of the lines of code would be more than the size of the .fpg? or does the .fpg not count :p

MikeDX - 17-3-2016 at 09:42 PM

The fpg doesnt count. just the bytes of code :)

Score: 172 (Confirmed by Mike)

Dennis - 18-3-2016 at 08:10 PM

Impressive code hacks here. Technically I am stuck making it shorter so I FOUND A LOOPHOLE in the game rules!


Code:
program a; begin load_fpg("f"); p(1,1,99); // 180 can be 99 end process p(t,x,y) begin graph=t*t; // smaller way of abs repeat if(t) x=mouse.x; p(-8,x,y-9); // OMG a ship with an AUTO TURRET! XD p(6,timer%99,0); // Don't like this, one, but as per rules, rocks don't NEED to be spread out when falling end y+=t-1; // shaved off the else frame; until(collision(type p)|y>240|y<0) end

MikeDX - 18-3-2016 at 08:51 PM

Nicely done Dennis

Score: 163 (but no real game)

MikeDX - 19-3-2016 at 02:48 AM

New winner: (not really).




Code:
program a; begin load_fpg("f"); p(1,1,99); // 180 can be 99 end process p(t,x,y) begin graph=t*t; // smaller way of abs repeat if(t) x=mouse; // x is the first element of mouse, no need for .x ;) p(-8,x,y-9); // OMG a ship with an AUTO TURRET! XD p(6,x,0); // nothing in rules saying where rocks start end y+=t-1; // shaved off the else frame; until(collision(type p)|y>240|y<0) end




Attachment: bla.zip (2kB)
This file has been downloaded 6129 times

Sandman - 19-3-2016 at 02:54 AM

Code:
p(6,x,0);

I actually had a constant for the x at some point, but I changed that to the timer, because it won't work since rocks will spawn over themselves and get destroyed immediately. In your case, only if you move your mouse fast enough will they actually fall down. I don't think this qualifies as a falling rocks game!

EDIT: though using x is a much better idea than a constant :kiss:

Score: 160 (but no real game)

Sandman - 19-3-2016 at 02:59 AM

But!

Code:
program a; begin load_fpg("f"); p(1,1,98); // 180 can be 99 end process p(t,x,y) begin graph=t*t; // smaller way of abs while(!collision(type p)&y<99&y>0) if(t) x=mouse; // x is the first element of mouse, no need for .x ;) p(-8,x,y-9); // OMG a ship with an AUTO TURRET! XD p(6,x,1); // nothing in rules saying where rocks start end y+=t-1; // shaved off the else frame; end end




Attachment: bla.zip (2kB)
This file has been downloaded 6133 times

Score: 170

MikeDX - 19-3-2016 at 03:02 AM

Agreed. I'll have to go for this instead



Code:
program a; begin load_fpg("f"); p(1,1,99); // 180 can be 99 end process p(t,x,y) begin graph=t*t; // smaller way of abs repeat if(t) x=mouse; // x is the first element of mouse, no need for .x ;) p(-8,x,y-9); // OMG a ship with an AUTO TURRET! XD p(6,timer%99,0); // Don't like this, one, but as per rules, rocks don't NEED to be spread out when falling end y+=t-1; // shaved off the else frame; until(collision(type p)|y>240|y<0) end




Attachment: bla.zip (2kB)
This file has been downloaded 6146 times

MikeDX - 19-3-2016 at 03:18 AM

Your 160 is nice. But I reckon I can keep 160 and make more of a game out of it ;)

Sandman - 19-3-2016 at 05:13 AM

I'll add the one without x for me as well for completeness:
Code:
program a; begin load_fpg("f"); p(1,1,98); // 180 can be 99 end process p(t,x,y) begin graph=t*t; // smaller way of abs while(!collision(type p)&y<99&y>0) if(t) x=mouse; // x is the first element of mouse, no need for .x ;) p(-8,x,y-9); // OMG a ship with an AUTO TURRET! XD p(6,timer%99,1); // nothing in rules saying where rocks start end y+=t-1; // shaved off the else frame; end end

Score: 158

MikeDX - 21-3-2016 at 02:50 AM

Utter filth, 158 chars, AND a playable game




Code:
program a; begin load_fpg("f"); p(1,1,98); // 180 can be 99 end process p(t,x,y) begin graph=t*t; // smaller way of abs while(!collision(type p)&y<99&y>0) if(t) x=mouse; // x is the first element of mouse, no need for .x ;) p(-6,x,y); // OMG a ship with an AUTO TURRET! XD p(8,x,1); // nothing in rules saying where rocks start end y+=t-1; // shaved off the else frame; end end




Attachment: bla.zip (2kB)
This file has been downloaded 6179 times

Sandman - 21-3-2016 at 03:02 AM

Good offset use!

I also made improvements:
Code:
program a; begin load_fpg("f"); p(0,1,97); // 180 can be 99 end process p(t,x,y) begin graph=t+9; // smaller way of abs while(!collision(type p)&y%99) //y<99&y>0) if(t==0) x=mouse; // x is the first element of mouse, no need for .x ;) //p(-8,x,y-8); // OMG a ship with an AUTO TURRET! XD p(6,p(-8,x,y-8)%y,1); // nothing in rules saying where rocks start end y+=t; // shaved off the else frame; end end


157 chars :)

Attachment: rocks157.zip (2kB)
This file has been downloaded 6427 times


MikeDX - 21-3-2016 at 03:51 AM

using the returned id of p() with %y is a genius faux random. very nicely done indeed!

Sandman - 21-3-2016 at 05:51 AM

The y-check is even more devious: all objects start at an odd y value, meaning y&99 is true, but when they reach >99 or <-99, y%99 becomes an even number.

Score: 153 (Confirmed by Mike)

Sandman - 24-3-2016 at 10:28 PM

OK, the final one:



Code:
program a; begin load_fpg("f"); p(9,1,97); // 180 can be 99 end process p(t,x,y) begin graph=t+9; // smaller way of abs while(collision(type p)^y%99) //y<99&y>0) if(t) x=mouse; // x is the first element of mouse, no need for .x ;) //p(-8,x,y-8); // OMG a ship with an AUTO TURRET! XD p(6,p(-8,x,y)%y,1); // nothing in rules saying where rocks start end y+=t%9; // shaved off the else frame; end end


153 chars

Attachment: rocks153.zip (2kB)
This file has been downloaded 6180 times

MikeDX - 24-3-2016 at 10:39 PM

I think we may have a winner. Very very nicely done. and a good group effort ;)

Dennis - 25-3-2016 at 11:56 AM

Kudos Sandman! Wow, I never thought the code would get this short! I already gave up under 172 chars.

I think I deserve some credit for some of the awesome graphics though.

MikeDX - 25-3-2016 at 03:02 PM

Dennis this is definitely a group effort. Some awesome tricks in there.

Sandman - 25-3-2016 at 07:40 PM

Dennis, of course! Your initial idea of using only a single process type did the most, in fact.

Dennis - 1-4-2016 at 09:36 PM

Why thank you! I was just kidding about the credit though. :)

iWizard - 4-4-2016 at 05:46 AM

You forgot to copyright it to hell and back DDD:

Dennis - 5-4-2016 at 11:15 AM

Copyright it, put micro trandsactions in it, put it on Google Play Story aaaand good to go by the norm!!!1!1

Sandman - 6-4-2016 at 10:17 PM

Get it to <150, Dennis, you can do it! Or maybe we need a new code golf challenge.