How to Make a Mario Style Side Scrolling Game in Windows Form and C# in Visual Studio

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ม.ค. 2025
  • Download images here - www.mooict.com...
    The written tutorial is also online on the MOO ICT website, you can check it out to learn more about the game development process. You can check the code there too. We will cover everything for the game in this video.
    Welcome to this new tutorial from MOO ICT, I am very excited to show you my new project and this one was quiet an accomplishment from my point of view, because it took me forever to figure it out all the while trying to keep the core concept as simple as possible for beginner programmers. In this project we will make a side scrolling platform game similar to mario and sonic but not to those legendary scales.
    In this project you will learn how to make a simple side scrolling game using windows and C# programming only using Visual Studio and the system default components.
    We will make this game using picture boxes, label and timer. We will make out functions inside the C# and make the level move left and right with the character.
    To demonstrate this method, this game requires the player to go the end of the level to collect and key and then come back to the beginning of the level and open a door to complete the game, during the game play you can jump on platforms, collect various coins. There are also pitfalls, if you fall off the platforms then you will end the game, luckily we will code a game restart function inside of it too so when that happens you can start the game again and try to complete it.
    I hope this small project comes handy for your own, happy programming and moo out.

ความคิดเห็น • 127

  • @mooict
    @mooict  3 ปีที่แล้ว +5

    Download the project here github.com/mooict/Side-Scrolling-Platform-game-in-Windows-Form

  • @cherylklimack325
    @cherylklimack325 2 ปีที่แล้ว +1

    Thanks!

  • @aking6033
    @aking6033 2 ปีที่แล้ว +1

    32:23 Spicy nope PictureBox.. :D Thank you for the video!

  • @matthewmarse829
    @matthewmarse829 2 ปีที่แล้ว +2

    Thank you for the tutorial. loved it

  • @Zakaria_TheWolf
    @Zakaria_TheWolf ปีที่แล้ว +1

    Amazing Lesson Thanks Brother

    • @mooict
      @mooict  ปีที่แล้ว +1

      My pleasure!

  • @Imagoodplayer
    @Imagoodplayer ปีที่แล้ว +1

    i have a problem. at 26:44 everytime i move my character the coins is still following me. any help for that? thanks

    • @mooict
      @mooict  ปีที่แล้ว

      Hi, do the coins have their tags set up in the properties?

    • @Imagoodplayer
      @Imagoodplayer ปีที่แล้ว

      @@mooict yeah, im sorry it's not the only coin that following me. even the the platform is following me when i moving . at 26:44

    • @Imagoodplayer
      @Imagoodplayer ปีที่แล้ว

      @@mooict i copy correctly your code but i don't know what is the solution to this problem.

    • @Imagoodplayer
      @Imagoodplayer ปีที่แล้ว

      @@mooict pls help

    • @mooict
      @mooict  ปีที่แล้ว

      The idea is platforms, coins background should move on the opposite direction to the player. If you have tagged all the elements properly then you might want to check MoveGameElements function and make sure the + and - is in the right spot as the tutorial

  • @MpNeMo-xi9dt
    @MpNeMo-xi9dt 2 หลายเดือนก่อน +1

    ur the goat bro

  • @bryantimothyevangelista6761
    @bryantimothyevangelista6761 2 ปีที่แล้ว

    Hi, could you please help me? The background isn't moving just like 21:51 even though I followed your steps.

    • @lukechantrell2117
      @lukechantrell2117 2 ปีที่แล้ว +1

      I know this was 2 months ago but I had the same problem. The fact is that his website and videos are both different in small ways. You have changed the forms background to the image, what you need to do is make a picture box and put the background into that. Make it the right size etc and then right click it and send it to the back. No need to delete all the other images to add it.

  • @pje_
    @pje_ 2 ปีที่แล้ว +1

    You could set force to 0 when player bounds intersects with bounds of platform and else force is setting to 8 it would remove glitching maybe.

    • @mooict
      @mooict  2 ปีที่แล้ว +1

      It didn’t work like that for me unfortunately. The timer ticks kept glitching the picture boxes. There is another way force redraw of the form components to stop it from glitching as much.

    • @sirgouki6207
      @sirgouki6207 ปีที่แล้ว

      @@mooict Don't use picture boxes - draw directly into the form and stuff like this wont happen. Also, enable double buffering in the form properties to prevent flickering.

    • @mooict
      @mooict  ปีที่แล้ว

      @@sirgouki6207 Yea I agree, I have been moving more towards the paint events and drawing the graphics directly to the form now. You can do a lot more this way and have way more control of the components than just using picture boxes. 👍

  • @skyechapman6595
    @skyechapman6595 4 ปีที่แล้ว +2

    I would like to follow along with this tutorial for a project for college. How would I go about changing the background and sprite image?

    • @mooict
      @mooict  4 ปีที่แล้ว

      You can find all of the images on the website. Simply create your own images with the same size as these and you will have re-skinned this game. Although if it's for an assignment I would suggest you add your own functions and features to this tutorial so it won't be plagiarised directly and it will be something that you would have created.

    • @skyechapman6595
      @skyechapman6595 4 ปีที่แล้ว +1

      @@mooict Awesome, thanks for the heads up. Could you maybe help describe different functionalities I should look into? Maybe a certain color coin could trigger a power-up or trigger a sound playback format? I'm only week 1 into my programming class at full sail. Thanks for all the help!

    • @mooict
      @mooict  4 ปีที่แล้ว +1

      I suppose you can mix and match some of the tutorials together. There are couple of tutorials I've done where you have enemies in the games so take what you need from them and you can add them to the final game. It will be a fun challenge for you to do and may be the final one may even surprise you.

  • @TVMaryam
    @TVMaryam 4 ปีที่แล้ว +2

    I would like to upload the game online. Is it possible to do so? Is it developed for a .net or .net core platform?

  • @audreyarellano3709
    @audreyarellano3709 9 หลายเดือนก่อน

    My background doesn't go back to the start it just keeps going to the right, how do I fix it?

  • @cherylklimack325
    @cherylklimack325 2 ปีที่แล้ว

    Great! Thank you!

  • @ahmadnaser8172
    @ahmadnaser8172 8 หลายเดือนก่อน

    good stuff i know iam late but please how can you make some spikes or stuff that will result in taking life away

  • @ThrillNet
    @ThrillNet 4 ปีที่แล้ว +3

    Plz could you do some tutorials on getting started with unity. They don't have to be too complex because really I'm just using games development as a way to learn programming in general and am not necessarily going to go into the gaming field but I think it would be good to at least give unity a go. Also some mobile app development stuff would be useful.

    • @mooict
      @mooict  4 ปีที่แล้ว +5

      I will try definitely. There are some great channels like brackeys that do nice and simple unity tutorials.

  • @htttpswww9971
    @htttpswww9971 ปีที่แล้ว

    How to download the archive of this project?

  • @Petra_Christalbert
    @Petra_Christalbert 2 ปีที่แล้ว

    @Moo ICT
    I got a big problem on placing Picture box above Picture Box here... When I add a Picture box as Background and then add new Picture box as Player over it, then empty area of Player Picture box will shown blank color instead of showing the background... So it's like I can't stack Picture box over Picture box (That will make it looks bad), Ima using PNG picture with erased background for the Player that I hope the picture box behind Player will shown up...
    (Ugh idk how to explain it, my English is bad...)

    • @mooict
      @mooict  2 ปีที่แล้ว

      Hi Sultan, unfortunately the picture box doesn't support transparency natively you have the do a slight work around to get it working. This is why I am using square platform and square player. I will cover how to work with transparent images in the future.

    • @Petra_Christalbert
      @Petra_Christalbert 2 ปีที่แล้ว +1

      @@mooict Thank you ~~~ You answered my Question so clear... I thought that My Visual Studies version isn't Up To Date or My device doesn't support for it... Thanks dude...

  • @mrilusion1103
    @mrilusion1103 2 ปีที่แล้ว

    I have a problem, I hope you can answer me because I need it, the problem is that, when I run the program, the monitor (player) crashes, and I checked the code again and found no errors, what could it be? please answer

    • @mooict
      @mooict  2 ปีที่แล้ว

      I have uploaded this source code GitHub did you get a chance to see the project from there? Hopefully that could help to see what’s causing the crash.

  • @arvsnacs422
    @arvsnacs422 4 ปีที่แล้ว +1

    Done it. Thanks.

  • @44dxni21
    @44dxni21 4 หลายเดือนก่อน

    Im new to visual studio and i was told to copy a game tutorial to learn C# but when i made the project, there was no form that automatically appeared

    • @44dxni21
      @44dxni21 4 หลายเดือนก่อน

      Can someone please help me, my toolbox also has nothing in it and idk what to do 😢

    • @mooict
      @mooict  4 หลายเดือนก่อน

      Did you make a Windows Forms Project in visual studio? Double check the project type and then you will see the form pop up when the project is created.

  • @lukehope4484
    @lukehope4484 4 ปีที่แล้ว +1

    txtScore does not work for me and has a redline underneath saying does not exist did I miss something?

    • @mooict
      @mooict  4 ปีที่แล้ว +2

      Yea you need to name the label to txtScore in the properties window

    • @lukehope4484
      @lukehope4484 4 ปีที่แล้ว +1

      Moo ICT ah thx gonna rewatch it to find it tbf pal you're helping me get through this coding quite easily appericate the timely response to

    • @mooict
      @mooict  4 ปีที่แล้ว +1

      No problem Luke, happy programming 👍

  • @mehmeterenortak
    @mehmeterenortak 3 ปีที่แล้ว +1

    I have a question. I hope you can understand my english :) when I press on the jump button which is space it jumps little or too much according to time I'm pressing on space button.
    Therefore character goes too high or too low It's hard to adjust it. as I see from your videos you don't have this problem. same problem also happened on flappy bird game that you made.
    I checked my codes and everything seems same as yours. I hope you see my comment and help me with that .

    • @jetarinpattanajirarutchago5606
      @jetarinpattanajirarutchago5606 3 ปีที่แล้ว

      Me too. same issue as you.

    • @mehmeterenortak
      @mehmeterenortak 3 ปีที่แล้ว

      @@jetarinpattanajirarutchago5606 hit me back if you find an answer bro. For the last 5 application I made it is still same. I believe it is because we're using c# form it is not a game engine I thing that is why tihs problem occurs.

    • @sunnybhoite6634
      @sunnybhoite6634 ปีที่แล้ว

      im also having same problem need to submit my coursework in next 2 hrs
      will be glad if anyone can tell the solution quickly

  • @mrdummy_nl
    @mrdummy_nl 3 ปีที่แล้ว +1

    With last Visual Studio 2019 (ver 16.10.2) i noticed the coords are changed from "," to ";" (so its not more 640,520 but now 640;520)
    And you choose for easy game reset way with
    Form1 newWindow = new Form1();
    newWindow.Show();
    this.Hide();
    causes very different result: new window popped up, old window didn't hide - and - the MessageBox where i fell off showed up again. This causes forever loop with endless MessageBox messages and more windows are opened. I cannot get out the mess and so i must force close whole process. The function this.Hide(); seems not work.
    Also function CloseGame has no result: there is nothing linked in the game. It was not clearly told in the tutorial.
    It means this tutorial end not very well with latest Visual Studio 2019. (it's now 1 year later from video)
    I recommend check the problem with last Studio and might need updated tutorial. Also, video code is different from text in your mooict website. That is actually not so great with different, it can confuse little new students why video is going different.
    Try match tutorial on website with this video, please. They are now not very equal, there are some codes added and RestartGame is missing on website.

    • @mooict
      @mooict  3 ปีที่แล้ว

      Hi, Yes indeed the website needs updating. I have included this tutorial on github with the video version. hopefully you can use that on your project.

  • @IXSICNESS
    @IXSICNESS 2 ปีที่แล้ว

    Absolutely brilliant tutorial. i have had a single problem which is that all my objects are shifted to the left when i run the application so they dont line up with their placement in design view. not a clue what caused it. if anyone can offer any assistance it would be greatly appreciated.

  • @skyechapman6595
    @skyechapman6595 3 ปีที่แล้ว

    for some reason, every time I start the program it just automatically flashes a black screen and goes back to the code

  • @anamulchowdhury8005
    @anamulchowdhury8005 4 ปีที่แล้ว +1

    Hi ,
    The width size become 1386 from 2000 . I try to type 2000.480 but after I typed 2000.480 it becomes 1386.480.
    In this case what should I do ??

    • @mooict
      @mooict  4 ปีที่แล้ว +1

      Is it the width of the form or the picture box

    • @anamulchowdhury8005
      @anamulchowdhury8005 4 ปีที่แล้ว

      @@mooict it's the widht of the form.

    • @anamulchowdhury8005
      @anamulchowdhury8005 4 ปีที่แล้ว

      In few words, i can't make it that much bigger that show all the the background . What I should do in this case ??

    • @sloap
      @sloap 4 ปีที่แล้ว +1

      @@anamulchowdhury8005 it must be your screen resolution

    • @shore7069
      @shore7069 2 ปีที่แล้ว +1

      I had the same issue 😢

  • @Infi1Hayat
    @Infi1Hayat ปีที่แล้ว

    Why my Visual Studio 2022 app the form just stuck at 1900. ? 🥺

  • @fishwishpishpish9165
    @fishwishpishpish9165 4 ปีที่แล้ว

    hey, do you know how to step through code in visual studio while also inputting key presses? I'm trying to debug my code but cant seem to input anything like key presses while the code is being stepped through except f11 which I'm using to step through the program

  • @cristiandendiu6609
    @cristiandendiu6609 2 ปีที่แล้ว

    door and key doesn't exist in the current context... What can i do ?

    • @mooict
      @mooict  2 ปีที่แล้ว

      I think you didn't name those picture boxes to door and key. Check the names of them in the properties window.

  • @kirstynoble3982
    @kirstynoble3982 2 ปีที่แล้ว

    Is there a way to prevent going through the platform?

    • @sirgouki6207
      @sirgouki6207 ปีที่แล้ว +1

      You need to perform collision detection against the sides and bottoms of the platforms, and stop the player's speed in the appropriate direction to prevent phasing through objects like that. Code to do so would be too complex to type out in TH-cam's crappy comments section, but you can use the code (it may need minor changes but it should nearly be 1:1) that is used in the Game Maker tutorials for making a Zelda clone by CodeWorkshop, even though the language is different the way its accomplished in C# is nearly identical.
      Note: I say collision detection against the sides and bottom, but you actually just need collision detection against the entire rectangle the platforms exist in, and to handle it properly, which the code I mentioned will do. I suspect this tutorial is just using an if against the top of the rectangles, something like "if(player.y > platform.y)" as opposed to what a normal game would be doing.

  • @fishwishpishpish9165
    @fishwishpishpish9165 4 ปีที่แล้ว

    hey im not really sure i understand what the variable "force" does, could you help please? thanks

    • @mooict
      @mooict  4 ปีที่แล้ว

      Its length of the jump, as long as we have value in force player will move up with the jump and when it's below 0 jumping will be set to false.

  • @fishwishpishpish9165
    @fishwishpishpish9165 4 ปีที่แล้ว

    hi do you have a plain text version of the code from your website? I'm asking as id like to be able to search for specific things in the code, such as "PictureBox" to see how many times it appears and where it appears, but i try to do that on your website and it doesn't work. thanks

    • @mooict
      @mooict  4 ปีที่แล้ว

      I'm working on making them text friendly, will be updating soon.

    • @fishwishpishpish9165
      @fishwishpishpish9165 4 ปีที่แล้ว

      Moo ICT thank you :))

  • @hristinanikolova7641
    @hristinanikolova7641 4 ปีที่แล้ว

    Hey, When I run it the form is shrinked and my game elements( platform, key and door) are not where I put them. I had the same problem with the breakout game, altough I set the size in the properties. Do you have any ideas what is the problem?

    • @mooict
      @mooict  4 ปีที่แล้ว +3

      I'm not sure what can cause this problem. You can make a new project and see if it does the same thing.

  • @fishwishpishpish9165
    @fishwishpishpish9165 4 ปีที่แล้ว

    is the player actually moving? theres a variable called playerspeed, but earlier in the tutorial you said that the player doesnt move and only the background moves to meet the player. thanks

    • @mooict
      @mooict  4 ปีที่แล้ว

      Hi yes, the player moves slightly forward and backwards in the game. This is why we using the playerSpeed integer. Once the player makes to the edge on the right or left then the background moves. This gives the game a little more depth to it's usability.

    • @fishwishpishpish9165
      @fishwishpishpish9165 4 ปีที่แล้ว

      @@mooict ahhhh thanks

  • @Gioele5924
    @Gioele5924 3 ปีที่แล้ว +1

    hi, could you do the side scrolling with the form instead of with the image as background? thanks, u are the best :D

    • @mooict
      @mooict  3 ปีที่แล้ว +2

      It's not possible to side scroll the form. It's the base of the game you can only scroll components inside of it.

    • @pje_
      @pje_ 2 ปีที่แล้ว

      @@mooict you could make a panel and it will scroll and put in there some platforms and items that you want to scroll except player and score text and then that panel has background image and size the same size as the bi and then transparency may work :)

    • @pje_
      @pje_ 2 ปีที่แล้ว +1

      you could make a panel and it will scroll and put in there some platforms and items that you want to scroll except player and score text and then that panel has background image and size the same size as the bi and then transparency may work :) try it maybe it works I'm just imagining shshshhhhshshsh

    • @mooict
      @mooict  2 ปีที่แล้ว +1

      That seems like a neat idea 💡 haven’t tried it yet, I will tho thanks 😊

    • @sirgouki6207
      @sirgouki6207 ปีที่แล้ว

      @@mooict You can use GDI+ on the form itself, it has been possible since at least Visual Studio Community 2017.

  • @florissmulders3973
    @florissmulders3973 4 ปีที่แล้ว

    hey, so when you jump at the bottom of the platform, the game teleports you to the top of the platform. Is there a way to fix this?

    • @mooict
      @mooict  4 ปีที่แล้ว

      That's actually what the code is doing at the moment. It's using the intersect with method to check if the player hits another picture box called platform then it will place the player on top of the platform.

    • @florissmulders3973
      @florissmulders3973 4 ปีที่แล้ว

      Yes, but because of that, if the player hits the bottom of the picture box he will teleport to the top of it. The player should bounce back if he hits the bottom of the picture box, not go through it.

    • @mooict
      @mooict  4 ปีที่แล้ว

      Hi I haven't figured out how to do that with a platform game such as this in Windows form yet but you can check out the WPF PAC Man game tutorial that uses wall collision where the player stops when it touches the wall.

    • @xthiccc3562
      @xthiccc3562 3 ปีที่แล้ว

      @@florissmulders3973 I don't know if you're still interested but basically what you need to do is that in the line of code that makes the player stand on the ground, you need to make it so it only works if you're touching the top part of the platform. I know my explanation is a bit weird but if you're still up to it I could show you in detail how it's done

  • @riemerdijkstra5974
    @riemerdijkstra5974 4 ปีที่แล้ว +1

    nice tutorial. wall collision sucks a little tho

  • @number2709
    @number2709 2 ปีที่แล้ว

    The score label no longer works properly. The label scrolls with the rest of the level. This is from the source code I downloaded from github btw. I copied the code into my own project and the same issue occurred

    • @mooict
      @mooict  2 ปีที่แล้ว

      Hi, you can comment out or delete the txtScore.Parent line inside of the Form1() constructor to make it stick to the top right corner of the screen. See the example blow.
      public Form1()
      {
      InitializeComponent();
      //txtScore.Parent = background;
      }
      This will fix the problem of the label scrolling with rest of the level. I've also updated the GitHub Repo with the changes. Thanks for letting me know. :)

  • @ivansanchez2989
    @ivansanchez2989 8 หลายเดือนก่อน

    Bro it keeps flickering for me plsss helpp everything works but the screen keeps flickering

    • @mooict
      @mooict  8 หลายเดือนก่อน

      The flickering is part of the game in this tutorial. I will be releasing a fix for it soon on the channel stay tuned 👍🏽

  • @Lakate91
    @Lakate91 3 ปีที่แล้ว

    I did this project but my player keeps falling through the platform. I am thinking somehting is wrong with the code?

    • @mooict
      @mooict  3 ปีที่แล้ว

      Check the timer event code again. Inside of the timer event it's checking if the player has landed on a platform and so on.

    • @Lakate91
      @Lakate91 3 ปีที่แล้ว

      @@mooict Thank you I will check it

    • @htttpswww9971
      @htttpswww9971 ปีที่แล้ว

      @@mooict How to download the archive of this project?

  • @Motivational-mindset-l7w
    @Motivational-mindset-l7w ปีที่แล้ว

    bro only problem with your videos is very less sound otherwise very nice videos i like them

  • @OLDbespreDEL
    @OLDbespreDEL 4 ปีที่แล้ว

    Why aren't you using Monogame or Unity?

    • @mooict
      @mooict  4 ปีที่แล้ว +4

      I love working in unity, but also like to make these games the non conventional way it's fun to do and I think it helps with teaching some of the component programming in C#.

  • @Kollegah9997
    @Kollegah9997 3 ปีที่แล้ว

    How about using a Game Engine?

    • @mooict
      @mooict  3 ปีที่แล้ว +1

      I whole heartedly support using a games engine like Godot, or unity or even game maker. The aim for this project was to make it ourselves from scratch without using game engines to learn how to control components using C# in Windows forms.

  • @shubhamsvlog97
    @shubhamsvlog97 4 ปีที่แล้ว

    x variable shows some error

    • @mooict
      @mooict  4 ปีที่แล้ว

      What's the error?

  • @tygr120killer3
    @tygr120killer3 3 ปีที่แล้ว

    hello thanks you pls help me :( no grafick

  • @bestgamerz8093
    @bestgamerz8093 ปีที่แล้ว

    One criticism about this video is that your voice is very low and sometimes you are mumbling. NOTE: My Headphone volume is maxed.

  • @mvk658
    @mvk658 3 ปีที่แล้ว

    Insane

  • @laszlobarnaludescher7847
    @laszlobarnaludescher7847 8 หลายเดือนก่อน

    thx

  • @thewanderingidiot2642
    @thewanderingidiot2642 3 ปีที่แล้ว

    thanks

  • @aj_art8058
    @aj_art8058 3 ปีที่แล้ว

    how would you publish this on google app store? or would you need to convert it to xamarin?

  • @guijarry
    @guijarry 4 ปีที่แล้ว

    goRight == true ?

    • @guijarry
      @guijarry 4 ปีที่แล้ว

      That seem illegal

    • @mooict
      @mooict  4 ปีที่แล้ว

      How do you mean?

  • @xxxiies
    @xxxiies ปีที่แล้ว

    how to make it like that by using VB programming language?

  • @crisbueno3802
    @crisbueno3802 3 ปีที่แล้ว

    can you send me the code?

  • @TVMaryam
    @TVMaryam 4 ปีที่แล้ว

    The door keeps on moving along the player although it's a picturebox and I've followed your video tutorial. Please see the following pictures of "MainTimerEvent" and "MoveGamesElement": ibb.co/Jt8p2Kh
    and ibb.co/k8vLcR4

    • @mooict
      @mooict  4 ปีที่แล้ว

      Did you put a door tag on the door picture box?

    • @TVMaryam
      @TVMaryam 4 ปีที่แล้ว

      @@mooict yes, on the tag as well as the name.

    • @TVMaryam
      @TVMaryam 4 ปีที่แล้ว

      @@mooict Any idea?

    • @mooict
      @mooict  4 ปีที่แล้ว

      @@TVMaryam the code posted on there is correct. I can't seem to figure out what could be wrong here. Can you check if there is any space left in the door picture boxes name or tag?

  • @urosbaljak2749
    @urosbaljak2749 3 ปีที่แล้ว

    5.01 how u strach wtf ???????????????????

  • @josezambrana5596
    @josezambrana5596 4 ปีที่แล้ว +1

    supreme :)

  • @dkracingfan2503
    @dkracingfan2503 4 ปีที่แล้ว +2

    That white boarder on the coins tho. 🤢🤢🤢

    • @mooict
      @mooict  4 ปีที่แล้ว

      Having a scroll able picturebox as they background doesn't allow for transparency at all. One way to remedy this would be to change the back colour of the coins to dark blue so it kind of matches up with the background.

  • @soundrogue4472
    @soundrogue4472 3 ปีที่แล้ว

    Okay please get to the coding aspects right away; I came to learn the code not see the map set up.

  • @matthewmarse829
    @matthewmarse829 2 ปีที่แล้ว +1

    Transparent background for the coins
    public Form1()
    {
    InitializeComponent();
    foreach (Control x in this.Controls)
    {
    if (x is PictureBox && (string)x.Tag == "Coin")
    {
    BackGround.Controls.Add(x);
    x.BackColor = Color.Transparent;
    }
    }
    }