Making a Game With 10 Lines of Code Only (Challenge)
HTML-код
- Опубликовано: 12 июн 2024
- ➤ Download GameMaker for free: opr.as/JonasGM
Thanks to GameMaker for sponsoring the video!
In this game development challenge I tried to make games with just 10 lines of code.
0:00 - Intro
0:44 - Game 1: Flappy Duck
1:06 - Game 2: Breakup
3:59 - Game 3: Fishy Chase
6:57 - Challenge Rules
7:32 - Game 4: Driveover
10:38 - Game 5: Ville Cellule
➤ Try out GameMaker for free: opr.as/JonasGM
➤ Get my game Will You Snail on Steam: store.steampowered.com/app/11...
➤ Join the Will You Snail Discord: / discord
➤ Join our creative game dev community on Discord: / discord
Hope you enjoy. :)
#gamedev #indiedev #gamemaker - Развлечения
➤ Download GameMaker for free (sponsored): opr.as/JonasGM
I never thought I'd be able to fit 5 entire games into a RUclips comment. Feel free to use the code below as you please. :)
GAME 1 SOURCE CODE:
// In the step event of the duck:
vspeed += 1.3
if keyboard_check_pressed(vk_space)
vspeed = -24
image_angle = -vspeed * 2
if position_meeting(x, y, obj_floor)
room_restart()
with obj_gate do
{
x -= 5
}
GAME 2 SOURCE CODE:
// In the step event of the mat:
x = mouse_x
with obj_ball do { vspeed += 0.4
if place_meeting(x, y, obj_mat) { vspeed = -25
hspeed = (x-obj_mat.x) / 8 }
move_bounce_solid(false) }
with obj_destructable_block do { if place_meeting(x, y, obj_ball) { instance_destroy()
with instance_nearest(x, y, obj_ball) do vspeed *= -1
if (sprite_index == spr_multiball_block) instance_create_layer(x, y, "Ball", obj_ball)}}
if (instance_number(obj_destructable_block) == 0) room_goto_next()
if (instance_nearest(960, -100000, obj_ball).y > 2000) room_restart()
GAME 3 SOURCE CODE:
// In the step event of the fish parent (enemies and player obj are children):
if (instance_number(obj_fish) 0) { motion_add((sprite_index == spr_fish_red) ? point_direction(x, y, instance_nearest(x, y, obj_fish).x, instance_nearest(x, y, obj_fish).y) + sin(x/50+color_get_red(image_blend)*79157)*30 + sin(y/50+color_get_green(image_blend)*79157)*30 : (point_direction(x, y, mouse_x, mouse_y) + sin(x/50+color_get_red(image_blend)*79157)*30 + sin(y/50+color_get_green(image_blend)*79157)*30 + mouse_check_button(mb_right)*180), (sprite_index == spr_fish_red) ? (255/450) : (mouse_check_button(mb_left) and !mouse_check_button(mb_right))*0.2 + clamp(mouse_check_button(mb_right)*(color_get_blue(image_blend)*1.25-point_distance(x, y, mouse_x, mouse_y))/100, -0.25, 1)*0.25)
image_angle -= angle_difference(image_angle, direction + sin(x/30)*10 + sin(y/30)*10) * 0.1
image_speed = speed/5+0.5
speed = max(0.2, speed * ((object_index == obj_evil_fish) ? 0.93 : 0.97)) + (random(1) < 0.01)*0.5
if (object_index == obj_fish) and (place_meeting(x, y, obj_evil_fish)) {instance_create_layer(x, y,"Fx", obj_fish_death).image_angle = image_angle
instance_destroy()}
if (random(1) < ((0.001 + (object_index == obj_evil_fish)) * ((object_index == obj_fish) or (instance_number(obj_evil_fish) < instance_number(obj_fish)/40)))) instance_create_layer(x, y, "Instances", object_index).image_blend = make_color_rgb(200+random(55), 200+random(55), 200+random(55)) }}
with obj_evil_fish do {if (instance_number(obj_evil_fish) > (instance_number(obj_fish)/40+1.5)) instance_destroy()}}
GAME 4 SOURCE CODE:
// In the step event of the car:
if ((speed > 0.01) and (!position_meeting(x, y, obj_rocks))) for(dist = 0; dist < 1; dist += 1/point_distance(x, y, x-hspeed, y-vspeed))instance_create_layer(lerp(x-hspeed, x, dist), lerp(y-vspeed, y, dist), "CarTracks", obj_car_track).image_angle = image_angle
motion_add(image_angle+keyboard_check(vk_down)*180, (keyboard_check(vk_up) or keyboard_check(vk_down)) * (position_meeting(x, y, obj_rocks) ? 0.2 : (position_meeting(x, y, obj_ice) ? 0.1 : 0.5)))
speed *= position_meeting(x, y, obj_rocks) ? 0.9 : (position_meeting(x, y, obj_ice) ? 0.998 : max(0.95, position_meeting(x, y, obj_road) * 0.97))
image_angle += (keyboard_check(vk_left) - keyboard_check(vk_right)) * speed * 0.3 * ((abs(angle_difference(image_angle, direction)) < 90) ? 1 : -1)
direction += angle_difference(round((direction-image_angle) / 180) * 180 + image_angle, direction) * (position_meeting(x, y, obj_ice) ? 0 : (0.005 + position_meeting(x, y, obj_road) * 0.05))
with obj_car_track do { if (image_alpha < 0.005) instance_destroy() else image_alpha *= 0.99}
with obj_collectible do {if place_meeting(x, y, obj_car) instance_destroy()}
// In the Draw GUI event of the car:
draw_healthbar(10, 10, 1910, 30, 100-instance_number(obj_collectible)/22*100, c_black, c_yellow, c_yellow, 0, true, true)
draw_healthbar(10, 40, 1910, 60, score/50, c_black, c_red, c_red, 0, true, true)
if (score++ == 5000) {score = -2} else if (score < 0) {if (instance_number(obj_collectible) > 0) room_restart()}
GAME 5 SOURCE CODE:
// In the draw event of the building manager:
if mouse_check_button_pressed(mb_left) { if !position_meeting(floor(mouse_x/80)*80+40, ceil(mouse_y/40)*40-20, obj_building) { instance_create_depth(floor(mouse_x/80)*80+40, ceil(mouse_y/40)*40, -2000-ceil(mouse_y/40)*40, obj_building).sprite_index = sprite_index
sprite_index = choose(spr_building_house, spr_building_road, spr_building_flowers, spr_building_water, spr_building_tree, spr_building_flowers, spr_building_water, spr_building_tree)
for(xxx = 40; xxx < room_width; xxx+=80){for(yyy = 20; yyy < room_height; yyy+=40){if (random(1) < 0.1) for(dir=0; dir
Now make a game in 1 line of code
Game 3s code with text wrap is an interesting sight to see
Finally a convenient way to do source control: The RUclips comment section.
Awesome!
Wow that's so cool that you are finally being sponsored by GM
Loved the video. Was great to work with you Jonas! I wonder if anyone else will take the 10 lines of code challenge 😎
I'd be curious to see that!! 😎
@@JonasTyroller 1 scripter vs 1 master
can you make gms2 back in to a single purchase instead of a subscription based service.
i'm thinking of downloading game maker, publish a game, would that be for free?
@@arandomguythatdoesntpost nope. if you want to publish your game, you have to pay at least 42€ per year
a few years later, he finaly, has mastered the fine art of coding, recreating minecraft with only 4 lines of godly code...
4 long lines of code
Minecraft is coded in Java, and technically you can write in a single line of code every java program, using different class file, but that's a detail.
@@Tombo22 thanks.
i feel much smarter now
Jonas: _"I made a game with 10 lines of code."_
*Me: My function that moves the player left and right is 8 lines with NO indentation* 😂
Let's see what I can do with 2 lines of code 🤔
Me: Only ten lines? Cool! Let's do it!
Then I realized...
Python: It takes ten lines to make a window because you don't have a game engine.
most things in python you can do in 1 line with list comprehension, ternary operators, tuple unpacking, lambda functions and stringing everything together
average calculator:
print((lambda a:sum(a)/len(a))([int(x)for x in input().split(" ")]))
leap year finder (in dutch):
print((lambda a: f"{a} is {['g',''][a%4==0 and (a%100!=0 or a%400==0)]}een schrikkeljaar")(int(input())))
real quadratic equasion solver (also in dutch):
print((lambda a,b,c:[["geen wortels",f"een wortel
{(-b+(b*b-4*a*c)**0.5)/(2*a)}"][b*b-4*a*c==0],f'twee wortels
{f"{chr(10)}".join(sorted([str((-b+(b*b-4*a*c)**0.5)/(2*a)),str((-b-(b*b-4*a*c)**0.5)/(2*a))]))}'][(b*b-4*a*c)>0])(float(input()),float(input()),float(input())))
cartesian coordinates to polar coordinates:
print("
".join((lambda a,b: [str(((a**2)+(b**2))**0.5), str(atan2(b,a))])(float(input()), float(input()))))
and I've made so many more oneliners, so yea my point, if y ou try hard enough, you could probably reduce the linecount by a lot
but 10 lines of Perl, buahahahahaaa :)
@@maxpoppe OK, I admit it was an exaggeration. However, because I work with pygame a lot, I would need 1 line to import pygame, 1 line to make a window, 1 line to set a "run" variable to True, 1 line to start a while loop, 3 lines to check to see if the window should close, and 1 line to update the screen. So, in order to make and constantly update a window that can be closed by the "x" in the corner, I would need 8 lines. There is probably a more efficient way to do this, but I only started learning a few months ago and am almost completely self-taught (thanks reddit/stackoverflow), so a master could probably do that in fewer lines.
@@BeneathTheBrightSky you can still do all that in one line :p
(globals().__setitem__("setvar",lambda k,v:globals().__setitem__(k,v)),setvar("pg",__import__("pygame")),setvar("random",__import__("random")),setvar("sys", __import__("sys")),setvar("locals", __import__("pygame.locals")),setvar("newfood",lambda:setvar("food",pg.Vector2(random.randint(3, 57)*10,random.randint(3, 57)*10))),newfood(),setvar("snakepos", pg.Vector2(30,30)),setvar("snakedir", pg.Vector2(10,0)),setvar("snakebody", []),setvar("clock", pg.time.Clock()),pg.display.set_caption("snake"),setvar("screen",pg.display.set_mode((600,600))),setvar("x",[0]),[(x.append(0),screen.fill((0,0,0)),pg.draw.rect(screen,(255, 0, 0),pg.Rect(food,(10, 10))),[(pg.draw.rect(screen,(255,255,255),pg.Rect(part,(10,10))))for part in snakebody+[snakepos]],snakebody.append(pg.Vector2(snakepos)),snakebody.remove(snakebody[0]),snakepos.__iadd__(snakedir),(setvar("snakepos", pg.Vector2(30, 30)),setvar("snakedir", pg.Vector2(10, 0)))if(snakepos in snakebody or snakepos.x == -10 or snakepos.x == 600 or snakepos.y == -10 or snakepos.y == 600)else None,(snakebody.append(pg.Vector2(snakepos)),newfood(),)if food == snakepos else None,[((pg.quit(),sys.exit(1))if event.type==locals.QUIT else((((setvar("snakedir",pg.Vector2(0,-10)))if event.key==locals.K_w else None,(setvar("snakedir",pg.Vector2(0,10)))if event.key==locals.K_s else None)if snakedir.x!=0 else((setvar("snakedir",pg.Vector2(-10,0)))if event.key==locals.K_a else None,(setvar("snakedir",pg.Vector2(10,0)))if event.key==locals.K_d else None))if event.type==locals.KEYDOWN else None))for event in pg.event.get()],pg.display.update(),clock.tick(10))for _ in x])
In my opinion and sry for my bad english
Pygame is good for learning codes .
But if you really want to make money from coding a game .
You should run away from it.
Native python code is very slow compared to other languages .
Maybe you consider others language or game engine if you want to code a game .
But if you really like python or did want to learn new language yet.
After you done with pygame you can explore some new stuffs
e.g. Data Sci, A.I. or Website,Back End api etc.
You will find out much more potential of python 💪💪💪
technically you can have all of this in 1 line. the syntax doesn't require any newlines. awesome games though
Yeah, that's true. That's why I specified the rules a bit more clearly at 7:00.
@@JonasTyroller yeah I was about to say I'm pretty sure he already mentioned the rules
@@JonasTyrollerJonas, I don't know about game maker, but you can do something like this using just one line (pseudo):
If (1==1 OR function1() OR function2() OR x = 1 + 2) function3(y = function4(), z = function5(), function6())
Or many many many many!!! other variants of this style. Endless code in one line.
@@jussivalter With js you can have like
if (function1() && function2() && function3() ... && true) {}
with that all functions give as return value true.
Html chicken out
Glad you're back enjoying making new games. Also about the last game, I'm gonna yoink it for upcoming jams.😅
Sure, give it a go! :)
0:46 We need a game with jonas's *POING* *POING* sound effects
POING
What a cool concept! I got GameMaker Studio 2 back in 2019 and loved it, but as school took over and I focused more on music in my spare time and didn't really touch the program too much. Maybe I should pick up coding again, I feel really inspired after watching this video!
Making these mini 10 line games in GameMaker was surprisingly fun. Pretty satisfying as they are so fast to make and you can make 2-3 of them each day if you want. Haha. :D
@@JonasTyroller I've got some spare time this weekend, I'll give it a shot!
@@maxbradymusic This... or Godot ;-)
Both are fun!
Really love the concept for the self building city builder at the end. You should look into fleshing it out, maybe making different terrain expand differently and turning it into a full game! I think it has a ton of potential!
I was expecting to see very long lines, but I was surprised how little code you actually needed to make the first 2 games. Since these are "clones" of some very well-known games, it proves that you could technically become a famous game developer by writing just 10 lines of code. 😝
Haha, lol. Never thought about it this way but there is probably a bit of truth to it. Simple but well polished games can do quite well. Or maybe it's just making the correct game at the correct time? Hitting the zeitgeist?
This simple well-known games was made without any game engines, and they needed a huge amount of optimization for old consoles. Now game development became easier, but games became harder (except for hyper-casuals, IDLEs, etc). What a good balance!
I know you might not mean that very seriously, but just for fun, I'm going to debunk that theory. Games like those primarily rose to fame because there weren't that many options in the past, while the game market is unbelievably saturated today. Also Jonas managed to fit it in 10 lines because the engine carried, which wouldn't have happened back then, since they didn't have game maker or unity or any other cool engine.
*Puts the entire code into 1 line*
"OK now that was the longest line of code l probably wrote" - Jonas Tyroller 2022
Will you Snail in 5 lines of Code when?
Ehhhh....
These car sounds are so realistic. Thought I'm watching a Formula 1 race 😂🤣😂
ten lines of codes with the curly brackets on seperate lines, damnn
The ultimate flex.
I think it would've been cool to know how many lines of code there would have been if you formatted your code like you usually do.
Oh my goodness, very entertaining as usual. I physically reacted to the idea of adding even MORE road types for Driveover just imagining the nested turnery operators!
I made a game using 1 line and debuging was a mess. Nice video
Oh, you did. Great job!
@@JonasTyroller yeah it took me 1 week and I also made a video about it. It wasn't long only 2 mins. Please make a video on how to make a good devlog.
Wow, this was both very impressive (these games look like really fun minigames) and giving me nightmares from horrible code structure. :D
The fish, driving and builder game looked especially nice. I don't think I have seen a game using a cellular automaton like that before. Very creative.
6:37 best asmr ever lol
"Aggressive Mouth Sounds for Sleep" Hmm.. Time to start a 3rd channel.
Finally! I've been searching for videos like this showing how to create quality graphical games and art with no more than 2000 bytes (which to me is sort of 10 lines of code).
Great video Jonas! I also started out with game maker, I love seeing how it's evolved and still used.
Well this looked like a lot of fun whilst still being absolutely chaotic, nice work!
honestly one liners are my favorite pieces of code, they’re so satisfying and in js you can literally completely change the structure of a dataset using one line
That's insane how much you could do in 10 lines of code. I might give it a try in Godot and see what I can do.
awesome video, I learn a coupple of thing that I dont know in game maker, thanks for the video!
Man, GameMaker is criminally underrated for how simple yet powerful it is, like just compare the code you need to e.x. rotate an object towards the mouse in GML vs Unity, you need like 3 times less code to do the same thing
Usually I don't like this type of idea (making a certain type of functionality much easier in one language/environment than under ordinary circumstances where you would have to figure it out yourself), but for GameMaker I'll let it slide because GM does a really good job at making small gamedev very easy and straightforward, whereas an engine like Unity requires a bit more work and therefore more understanding of, for example, rotating an object toward a specific point
@@SpringySpring04 yeah exactly. and it just got to the point when when I see how just the simplest things are done in Unity it just seems so unnecessarily complicated and bloated after you've seen what's possible (x = 10 instead of transform.position....blah) (I'm only talking about 2D)
And I love C#, it's just that it's ridiculous to me how people can call Unity beginner-friendly when GM exists and it allows you to make pretty much any game (except for something really bleeding-edge technology-wise) and it's like 10 times faster to implement the same things
That was actually really entertaining ;)
Your humor really reminds me to a friend of mine
Love the vid, would like to see more challenges like this!!!
Those do look like a lot of fun, especially the last one. Also amazing video
You know you did well when Game Maker Studio sponsors your video.
When Jonas uploads I know it's a good day
Your content is so amazing, I liked this vid!
Happy you enjoy it. Thanks! :)
This was super cool! I would love to see some other videos where maybe you break down the code of each one a bit more? Perhaps a secondary challenge where you try to flesh each game out to 100 lines of code, without using all the inception for/if loops?
This seems like a cool challenge! Might attempt it.
The car sounds really crank me up, and I don't laught too often for that kind of stuff, Thank You!!!
Btw, the city builder is an amazing game!
I would love to see this as a game jam. Fun video!
WOW 10 LINES! Good thing you were being carried by the 1000s of lines of code the is Game Maker.
As someone who has been attempting to learn game dev, (3 weeks in) this is actually insane
You're one of the best and funniest game devs jonas..
You are a legend, thank you for content.
the last game was really cool, nice video
I expected every line of code is gonna long as hell but the first game was shorter than I expected. great video btw
Really cool ideias man!
That builder game looks really fun! I would want to see a game like that as a full game.
It might be time to try a new challenge! This seems like a ton of fun and the games you've made are really solid for the 10 lines!
Very cool idea and the last game is my favourite one ❤❤❤
I started coding maybe a couple of days ago and now I finally understand some of the code in programmers videos xD
That’s incredible! This summer my friends and I are making one! And it’s going to be a horror game, based off of that Minecraft-like, underwater adventure, indie game, called Subnautica!
6:33
This would be a great game to (given more lines of code) turn into a sort of arcade game where you see how long you survive.
Edit: 10:13
This is a lot like GTA on the Game Boy Color.
i love your craze way to explane thing keep going !
I knew it! I was like is gonna be like flappy bird? 😆
I realize we're trying to market towards a younger audience that's getting into indie game development, and that they crave fast-paced, crazy, memey and animated (not that kind of animated) content creators, but as a 30+ programmer I'm more into watching the progress and results, and don't need all the craziness in between.
Maybe I'm wrong and this is just you being you, in which case I'm glad and I fully support it! But if it's not, I'd just like to say that at least I think your work and enthusiasm about it is enough; your channel *will* continue to grow, as long as you're having fun with it. 🙂
I hope this came off as supportive and constructive, and not the opposite. We all have different preferences, and I'm sure that running a successful channel is a lot of pressure when content is just getting faster and shorter these days.
Appreciate the feedback. I feel like I do have a bit of a crazy side in me and I'm slowly getting more comfortable with letting it out. I'm still trying to strike a good middleground between taking it seriously and letting the crazy out. Depending on the video idea and how I feel that day, the pendulum might swing more or less to either side. :)
@@JonasTyroller Your personality is unique, at first I thought you were a bit annoying but the more I watched your channel, the more I liked it and your personality, don't let anyone shut you down! :D
@@JonasTyroller I'm glad to hear that you're just being yourself! In that case I'm all for it. Carry on!
Great Video! :D
The city builder gameplay is genious!
I have an idea for the building/puzle game, like you could only place certain tiles on other certain tiles, like cacti can only be placed on sand or something.
Yo that's such a neat idea! Was really impressed with the city builder game.
Thank you! :)
Cool stuff! 👀
So it's 50,000 massive libraries combined
and a game engine which does basically everything you need to with premade code.
It is really cool seeing zlatan Ibrahimovic making youtube videos, it's good to see you man!
this was such a smart way to make an ad
this is actually really cool
Jonas:Can you make a game in 10 lines of code?
Blueprint developers:I have no such weaknesses.
@Barret Wallace No duh,node aren't really lines. That's what I meant.
You are totally awesome man, I am a unity developer and i played your will you snail game. I think now i should try game maker studio 2. I really love your videos and also played your game will you snail too. You are my motivation man ❤️❤️❤️❤️
Congrats on getting on Game Grumps !!!
Wait this is the guy who made
Will you snail
That's really cool
really cool video :D
"Puzzle games are easy to make" that made me laugh. 🤣
Now the question... How much lines of code would it be if the code was formated in an apropriate way?
Still not a lot, probably just 50 to 100 lines.
@@Brahvim yeah
Amazing concepts for sure! By the way, does the FUN button game thing from your older videos exist?
You should do a challenge where you have to use tons of lines of code for one small game so it ends up super over engineered
*10:20** May headphone users rest in peace* 🙂
The third game was actually stunning
Ten lines of code...
And an ENTIRE GAME ENGINE.
Java programmers are literally shaking in disbelief right now
Cool channel would love to see downloadable source code examples. Also would love to see a publish game to steam example but cool channel keep up the great work👍
As an intellectual I know that, for a fact, you can write a whole-ass library of functions in just a single line, using any of the "C" languages
"I like water. Who doesn't like water?"
I can hear the underwater track from "Will You Snail?". It haunts me
In theory, you can even make game in one line, but that would be very VERY hard to read, and some languages don't really like when you do do everything in one line
Great video! We should create a game jam with the restriction to only use X lines of code. You would have to post the actual code/YYP and maybe add some other restrictions.
Ville Cellule could've been perfect for that gamejam, out of control
When a game takes the same time to develop as the time you can have fun with it
I would love to see you do this with other game engines.
Next video: Make Will You Snail with 1000 lines, 100 lines and 10 lines
You could technically make a lot of games in a single line if you're insane enough ;P
7:00
@@diggitydingdong Yes I watched the video, thank you, lol
I mean if you're gonna format it weirdly, you can write pretty much any code in one line... even if it's supposed to be 2000 lines long...
"I can't juggle so many balls!"
-Jones Tyroller, 2022
Yay new video!
Yay! :)
This was a fun video to watch as always Jonas. I also use Game Maker Studio mostly you inspired me to use it and snagged my 1-year license on sale discount. Loving the journey of learning it and knowing it uses a similar language to python makes it easy for me to grasp. I am mega tempted to partake in this challenge. even though I'm only a newb so far but it could be good for practice.
Very interesting concept.
Alternative title: German developer rolls his head to make obfuscated code.
duuuuude, ccoool , thank you
I love gamemaker so much
You love to create games, I love to play games, let's make Valve #SaveTF2!!
Really impressive
A different engine I like is pico-8, which uses lua (tricky after so much practice with oop for me!). I enjoy it!
I will also be one to say, it IS very fast to get something up and running in GameMaker. I can go from nothing to a fully playable concept and a fairly complex one in a matter of an hour or two.
It feels really weird how Game Maker has changed over the years, I remember having to write extensions for GameMaker 7, 8, and 8.1 before to add more complex logic and features to games without having multiple page scripts. But now you can just do it in 10 lines.
The step logic would have looked identical back in GM 7 or even earlier. Barely anything has changed as far as I can tell and most of the work has been done on the rendering engine. vspeed, keyboard_check_pressed and image_angle have been around since the beginning, the only thing I don't recognize is position_meeting which seems to check if a point p is within a bounding box
Would be great if you could go into the mechanics of game 5 in a bit more detail. The use of cellular automata is very fascinating!
Jonas is one of those kids who fights imaginary aliens in his room