How to make a platform game in windows form and c# in visual studio
HTML-код
- Опубликовано: 24 авг 2024
- Written tutorial - www.mooict.com...
Note - This tutorial is slightly different than the written tutorial as I have added enemies and moving platforms to it.
In this tutorial we will make a platform game using windows form, c# in visual studio. this tutorial took me a while to figure out but it was worth it in the end. It has platforms you can stand on and jump to, it has horizontally and vertically moving platforms.
We are using labels, picture boxes and timer to make this game work. We haven't used any third party libraries or classes to run the game its plain simple windows form. We make use of the standard components by making something fun inside of it also we make use of the events inside of windows form to respond to the user inputs and we use the main timer event to work as a main game loop.
In this we will learn together how to make a simple platform game, where player can move left and jump up and down, move from the platform to platform, collect coins and finally complete the game. We make this so it give different end messages depending how you lose game for example it can give a end message if you got hit by the enemy or fell off the platform.
Download this project here github.com/mooict/Platform-Game-in-Windows-Form
this is one of the coolest things i've ever seen
well done sir
Very nice analytical explanation from scratch. Thank you.
Glad you liked it!
Very good beginner tutorial, thx. Simple and short, to the point, and ending up with a game that works.
Thank you the kind feedback. I'm glad you found it useful 😊
I've followed your tutorial out of curiosity as a C# beginner. I made a slightly smaller form. But, the jumping was a bit weird for me, because it's very easy to fly up out of form if I held the space key any longer. Similar to "Bomb Jack" game, back in the days :) Adjusting force a bit, I managed to refine it just enough to be able to jump over enemies. Also, you forgot to limit player to go left and right out of form. Other than that, for a 45 minute, this is a amazing tutorial! I've learned a lot! Thank you so much!
Thank you Mr Freeman, things in black Mesa all good? Lol I'm glad you found this one useful😊
@dothebrew2343 Greetings ! None of this is real, is it? :)
Thank you for this! You gave me the confidence to go ahead and try, and I've officially made my first game! I'm excited to check out the rest of your videos!!
I know replying to your own comment is odd, but I've noticed you actually replying to a few people and figured I'd ask: how would you program it so you can press a button near an enemy to "kill" them? If this is covered in another of your videos I'm sure I'll find out soon enough either way!
Glad I could help!
OMG thank you so much this helped me sooooo much , i cant thank you enough
I'm loving your tutorials. Thank you very much!!!
You're welcome glad you found it useful
@@mooict Very useful, indeed! Nice to see there are still people like you in this world, feel embraced!
Oh my god you're a legend, Thanks so much for this tutorial 🙌
Thanks a lot for this tutorial. It totally helped.
Thank you!
Great job! I will make something like your game. :)
Great tutorial,
Once you use "Collect all the coins", then "you fell to your death" no longer works.
can you please make a tutorial on how to proceed to a next level, i cant figure out how to make another form open automatically when the player reaches the exit
Make a new form (for example form2) and do:
Form2 level2 = new Form2();
level2.Show();
this.Hide();
@@tzooby ty
great job Sir
best tutorial ever
A very nice tutorial. Thank you.
easy way for the RestartGame() Function:
Application.Restart()
edit: Im using visual basic. i dont know if thats something in C#
Application.Restart(); also works in C#. To use it you might want to add the line Environment.Exit(0); under it so it closes the current version running and then restarts it. Much more memory efficient 😉 thanks for the heads up.
awesome thank for the tutorials
cool video)
Amazing tutorial, thx
Glad you liked it!
Done it. Thanks.
The dialogue that shows up beneath the score is not showing, even though I wrote it the way you did. Do you know why that might be?
Try turning auto size off on the label in the properties window and drag the height of the label and make it bigger to see the text when game ends.
@@mooict Auto size was already on false. When I turned it on, the default sub-message appeared, but now its flickering like crazy.
super
Would there be any way to remove the glitchy-ness from the player?
The only way is to write normal code instead of this junk shit
Hello when I do the player.Left it says that Left does not contain a definition and no accessible extension method :((
it's a great video but when I restart the game the player keeps falling down. Thanks
I love the video my man, but I have having one error. When I compute, my player is not showing up..like at all. What do you think the error could be?
my enemies and vertical platform are just spazzing out as well. Horizontal is not moving at all.. i'm stumped to what im doing wrong though, code is mirroring yours
Have you enabled the timer?
cool tutorial, but am still having problem understanding the jumping of the player , can you pls explain a bit further
Legend
Hi, when I jump under a platform, I will end up on top of the platform, is that how it is suppose to behave with the code ?
That's how it's programmed for this game.
A messy quick fix for this would be to write out an if statement for each platform such as:
if (player.Bottom < platform1.Top + 1 && player.Bounds.IntersectsWith(platform1.Bounds) && jumping == false)
{//*execute stick to platform and force/jumpSpeed reset*//}
This would replace the foreach loop that is sticking the player to a platform.
It's less efficient but would only land the player on a platform if they are above it and would stop the player from teleporting from the bottom to the top.
how do i get from the welcome page to create new project????? pls help
How would I make this for android tho?
Hey. The vertical and horizontal platforms are moving way too fast for me. Even on value 1 theyre incredibly fast. Why is that so and how can i adjust that? Should i change it to double or something like that?
I'm not sure what might cause this, are the player movements and enemy movements on normal speed?
@@mooict I just followed the instructions in the video. The speed values were the same as in the video. But that was way too fast so i set them on 1. But thats still pretty fast. Nowhere near as slow as shown in the video.
@@mooict I just did make the playerspeed higher so it got compensated with that. But another thing is that my player isnt moving with the horizontalPlatform when im standing on it. You can see that the player is slightly moving into the direction the platform is moving but its still falling off pretty quickly. Either way I appreciaty the video it did help me alot :)
Check the timer tick option in the properties window. It might be caused because how fast the timer is ticking.
great video
Hi, how can i load a next map, for ex if i make 2 separat scene and load one after Another, how could i do that?
Hi you can do this by adding a new form inside the solutions explorer. By default it will be named Form2 so when you want to go to that form you can do the following
Form2 levelTwo = new Form2(); // create a new instance of a new Form2 called levelTwo
levelTwo.Show(); // show the new form on display
this.Hide(); // hide the current form
When you reach a part where you want the player to move to a new game level you do run the code above.
Hope this helps 😊
@@mooict thx dude!
@@mooict I'm trying to do this, but when the second form loads, the code doesn't work on the form. I can't move the sprite and the platforms and enemies don't move. Is there something on the second form I need to include for it to work?
Also, your tutorial is great and thanks for making it!
@@stephaniefriddle6937 you'll have to do the same thing again like adding the keyboard events, timer events etc to the second form to animate it and move the player etc.
@@mooict Thanks for the reply! I've done all that for the second form, I've been trying to comb through all the code to try and figure out why it's not working, but haven't been able to figure it out.
I changed the events on the form to run the MainGameTimerEvent on load, and the KeyDown/Up as well.
I've tried messing around with isGameOver and gameTimer, but haven't been successful there either.
You have a great tutorial bud!
Thanks for sharing your knowledge.
I am a very beginner c# programmer and I was able to reproduce the game.
Did a few alterations such as adding images instead of the boxes itself, the question now is:
How do I update the PictureBox when the player moves to the left or right?
Thank you!
Hi, glad you found this helpful. Check out the save the eggs game tutorial where I've shown how to change picture box images when moving the player left or right with key down.
whenever I hold the jump button it goes up continuously
i tried to import photo to the game and i add them but when i run the game without the photo
Hi!
Thx for the tutorial but i have one problem.
When i touch the enemy(One or Two) and it shows me that im dead, i press the restart bottom and all the Platform are glitching and the Player isn't appearing.
I hopefully you understand what i'm talking about.
What you recommend to do next?
Thanks a lot!🤗
I'm not sure what could be causing this issue. The project is now on GitHub you can download it and see the source code from there github.com/mooict/Platform-Game-in-Windows-Form hope this helps.
I’m using the 2022 version but i don’t know how to do the windows form thing
why is bool not working for me and the int is interface
Great tutorial! But how would you fix the glitch? It dosen't have to be simple, but i am trying to create this for an assignment in a course at my university :) So i would rather have it not 'glitching' ;)
change the borderstyle. Sometimes that helps
@@ImusingX What borderstyle would you suggest? :)
i use Fixed3D but i dont know if that works in C# because i use Visual Basic
@@PirateFoxBox Try and turn double buffering on - for your pictureboxes
why aren't you using player.bottom = x.top?
Hi, because we are already using player.top to simulate gravity and jump. It's more efficient to modify one coordinate of the player object than 2.
My restart function does not work properly
Hi Logan!
Hey bbg, this dumbass code doesn't work
I have a little experience with Processing and Java. Would this be easy enough to follow? I've heard that C# and Java are similar.
I have a problem and is that when I start the project my player does not move and I don´t know why.
I am having an error c # system.drawing.size.width is inaccessible due to its protection level please tell me how to fix it
how do you get the toolkit
how can I get the enemies to flip when they change direction?
I'm using your project to make a game for my School final project, but i have some questions that i need to make first, this because i can go forward with it, and all because i don't know how to make it advance to a new level, you know how can i make levels and connect them ?
Jo i have a problem my Character is falling down when i will test the mini game
Check the tags on the platform picture boxes. It should be "platform" on each of them.
hey i have a question what assets to use from visual studio to have this popup
green door not working why? i did everything like you did in video
Hey! I've found a fix for the glitch: in the "if (player.Bounds.IntersectsWith(x.Bounds))" statement, just add jumpingSpeed = 0; . It works greatly for me!
Awesome. Thank you.
@@mooict no bro, thank you for all the awesome C# game tutorials, I'm currently working on my bachelor's and I am making a game using a lot of ideas from yours. Thank you for your great work!!
@@georgedemian3776 It makes me really happy that you're completing your education. All the best you to my friend.
@@mooict Thank you! All the best to you too!
how?
Where can i find the step by step written guide
hi! this was an amazing tutorial!
though i think i did something wrong: whenever i press enter after i had died it doesn't let me respawn and one of the enemies spawns literally near the vertical platform in the middle of the air. how can i fix that?
Oh k, I think check the game reset function and make sure it's the same values as this tutorial.
@@mooict okay, thank you!
I had almost made it but had to leavz before finishing it, saved everything and now the level is gone, code's still alright but won't run without the squares anymore
Any idea how to fix the Glitch? I want to share with my son and nephews :D
Unfortunately the glitch is standard in Windows form.
im not sure what i did wrong i just went threw the video again all seems good my player just doesnt fall on the platform it just stays in the air(startpoint)
can u remove the glitch from the player?
Very very good video! I watched your flappy bird tutorial and this and you're fantastic! I might steal this idea (and tweak it a bit) for my high school programing homework. :)
P.S. I have a problem and i was wondering if you could help me: my player doesnt move. I'm at the same point as you in the code i did the maingametimer code and the keyup keydown and your player is moving, but my player is not. Do you maybe know why?
Hi, Thanks for the lovely comment. Check if the timer is enabled in the project. May be that's why the player isn't moving.
@@mooict yes it was that thank you very much
I'm at 24:13 in the video and while the character in the video jumps normally, mine is flying straight into the air without stopping or ever coming down. I've checked three or four times now and can't find what I've done differently. Can anybody help?
I just found the error myself. It was because the player character was still tagged as platform. The Game basically thought that the player was always touching a platform, because it counted the player as a platform.
@@user-kr3ev5lr5h THANK YOU SO MUCH!!! 5 HOURS OF MY LIFE 😭
When you die by falling or running into enemies the death message doesn't show up, how do I fix this?
By the way nice tutorial, it was very helpful and I learned a lot!!
hey, this seems to be a vs error, i am having the same problem now, but 1 year ago it was working fine
Hey, i have finished this tutorial and added in another 2 levels, but for my level three, how would i create a projectile based enemies, for example, an enemy that stands still but shoots arrows in one direction periodically ?
You can use either my jet fighter tutorial or the helicopter shooter tutorial to find the solution you need. In both of them I have objects moving from one side of the screen to the other continuously. Hope that helps
@@mooict hey thanks man, i'll get straight on that :)
My Create new project thing looks different it just says like "New File." "Open File.." Open Folder" "Run a Command" and idk how to get the Windows Form App (.Net Framework) thing to select and use. PLS HELP
This tutorial is really helpful for me as a beginner but whenever i tag the platform the player takes the same tag
as the the platform.
Make sure that the player picture box is not selected when you are selecting all of the other picture boxes.
i have a question, i made my map different, and the text goes behind a platform, how do i make it go infront of the platform?
Right click on the text and click bring to front
@@mooict thank you! My game is almost finished i am at the part where you add the kill text, its very cool and very good for starters
15:29
It's a good tutorial but as complete beginner who barely knows anything only the basics 90% og what you do like the let's say "Control x in this. Controls" I don't know where to learn such commands so I only end up copying you by the letter although I don't understand what am actually copying (I only know the basics such as variables, if statements, I've only ever fiddle with simple console programs so I don't know how to make such transition without just 100% copying that anyone can do) any tips how to get better at this or any useful video or link would be appreciated
This should help ruclips.net/video/TZudVQnANpY/видео.html
Thank you bro i only go on this Video becuse i wannt to make a tool but i dont now how i add a Code in the Form.cs becuse when i add there a code a full code then is there 99+ Problems can you maby help me ?
I'm your new Subscriber☺️
I've had to fix way too many errors in this tutorial, I gave up when it said the horizontalPlatform and verticalPlatform code didn't work, "name does not exist in the current context". I've had this problem before with the TxtScore and I fixed it by naming it again through the properties window, but this time nothing fixed it (even tried it in the designer code). Also my left and right controls don't even work, tried everything. Guess it's just my fault for trying to make a game in C# instead of python lol.
Check the spelling also make sure there is space in the end of it. Or delete the current picturebox, add another and name it on that one. Don't give up on C# just yet.
Great Tutorial
but at 40:01 you put if goLeft is false or goRight is false so it only deactivates if you move both to the right and left at the same time but then your not moving anyways so kinda pointless
also you can do enemyOne.right insted of enemyOne.left + enemyOne.width
start with 2:30
Nice tutorial!
Still I have a problem, the thing is I dont know why that happened but from one moment to the other i couldn't control my player block anymore. The player block is unresponsive after 1 input of right or left. Jumping is working just fine, its just that i cant move the player block anymore after I pressed it one time. As soon as I let go of left or right I cant move the player block anymore besides up (jumping). Any solutions? I also tried to download your file and copy&pasted it into my project but there is also the problem that the player block gets unresponsive after I press left or right one time + for some reason the vertical platform starts to glitch when i paste your code in. And furthermore my restart of the level isnt working even though its the same code as you have.
For the movement we have rules for right and left arrow keys in the key down and up event. The actual movement happens in the timer event. In there we check if the goright or goleft Boolean is true then we move the player in that direction. If yours isn't moving after one input check the timer event and see if it's the same as the code in the tutorial. Keep an eye on the brackets from the loops and if statements it can cause issues of it's not closed properly.
@@mooict I checked multiple times and i even redid the steps from the video tutorial, but it still didnt work. And like i said your code that i copy and pasted didnt work either. Even if it is possible that my code has flaws, yours surely shouldnt have any. Thats why im so confused because even your code didnt work when i pasted it in and i made sure everything was according to the tutorial.
I think you made the same mistake I did, you used KeyPress instead of KeyUp when making KeyIsUp in Form properties.
Took me one entire day to figure that out and it's an easy mistake to make since they are one under another so go take a look at it if you still have this game code saved somewhere.
Would this code work with unity?
No it won’t work for unity as is.
How do you make it go to a 2nd level? Cause i need it to advance to the next level
You can make a new form and make that appear on screen when objectives been met for this one. That one can have its own platform timer, enemies etc same as this one.
I need help
i kinda removed Form1 [Designer]
can you please tell me how to get it back
i just needed to shut down my pc and when i got back i could only see the test/debug window
In your solutions explorer double click on Form1 it should open the designer
@@mooict
Thank you so much
Nice idea but my player keeps falling through the platforms :/
Check collision between the platform and the player section inside the timer event. You may have missed that code in your project.
@@mooict Couldn't fix it, but thanks for the support. I will keep programming. This was my first project.
@@marioko5142Hi Mario, that's the spirit, keep on programming. For this project see if you have tagged the platform picture boxes to "platform" in the properties windows.
my player just flew away
Hello mr. cow
Hello 👋
is it ok when the KeyIsUp is above the KeyIsDown???
Yes that's fine
@@mooict ahm sir can i ask you a question why is my player are going through the platform???
@@selrahcph check the tag on the platform in the properties window. Make sure it says platform all lower case and no spaces.
im gonna make tetris.
That will be awesome.
Can you plz told me how I can add new stage
Yes that tutorial is coming soon
For me gameTimer.Start(); isn't correct syntax.
Go back to the design view and name the timer to gameTimer it should fix that
@@mooict Or then I could use "Timer.Start();", I think.
Thank you.
galera de jogos digitais do ifba de lauro aproveitou viu
in my vistual studio sayes the txtscore it does not exist in the curent context
Change the label name in the properties window to txtscore.
@@mooict ok i fixed that but i have a nother problet with and now the text isn’t working after txtscore
@@sidrittoplica5423 are you using txtscore.Text = "Score:" + score; make sure the .Text is with a capital T.
@@mooict I tried but nothin happens it says error
@@sidrittoplica5423 can you tell me what's the error?
Sir please provide the code
Full project and source code is on the GitHub. Link is pinned as the top comment.
all the time my designer resets, back to default form
Ah, that happened to me a couple of times too. make sure to save after each change you make also restarting visual studio sometimes fixes this issue.
hey thank u for this awesome tutorial! for some reason my player can walk out the frame and cant reappear, is there a solution to this problem? ive compared the code to urs multiple times and still cant figure out whats wrong
he didn't account for that in the tutorial.
I'm using visual studio code
gmpx
he sounds a little like georgenotfound
N n n a j t i b k n n r t s k Elko jedno
ca pue la merde sah
cool video)