How to make a simple T Rex endless runner game in windows form and c#
Вставка
- Опубліковано 10 лют 2025
- Images and written tutorial here - www.mooict.com...
In this tutorial we are going to make a simple endless runner similar to the dinosaur game from chrome browser. This is a endless runner so the objective of this game is to jump over the obstacles and score as high as possible.
We are making this game in visual studio with windows form and c# programming language. In this game we will use label, picture boxes and timer. Download the images from the link above and you follow along the tutorial as we will make this game scratch. We will go over some of the core programming techniques such as resetting the game so you can play again, timer event, key down and key up event inside of windows form. Its a fun little game to practice programming with. I hope you find it useful.
Moo Out.
Download this project here github.com/mooict/T-Rex-Endless-Runner-Game-in-Windows-Form
Dude your tutorials are awsome. Others look like beautifully packed shit. But yours are straight coding. Thanks for all the things you do to us.
*Awesome
@@bojohannesen4352 u replied a little bit late...man
@@hfauyr And?
@@bojohannesen4352 andd it doesnt matter if he spelled something wrong he was just complimenting the man + who asked for a correction
@@hfauyr When did I ask for YOUR opinion? Exactly. I didn't. And you gave it anyway. That's how comments work.
Thank you
I've just coded my first game in c# following your guide.
First of many 👍
Bro your tutorials are always good! Tks for showing me straight code. Hope you'll be better and better day by day.
Thank you ☺️
Thank you so much for all the tutorials sir learn a lot compared to online class ❤️
Thank you for this tutorial you helped me pass my class
Bruh... I LOVE YOUR TUTORIALS!!!!
Keep doing this Tutorials, You are perfect for beginners :)
It was amazing help in my project
Useful!
Glad it was helpful!
Very helpful! Thank you very much :)
Thank u i really learned alot in this vid i think i would leave unity!
Hi thanks for the compliment, these tutorials mainly cover basics of programming. if you are interested in games development I would strongly recommend learn and master unity.
Thanks. Ive done it. Next stop will be your pacman.
thank you dude
Nice tutorials
hey please help iam stuck i reacherd to min 20:57 my trex is moving with the obstacles i reviewd the video step by step but i coundnt find any mismatch with my code what could be wrong?????
Check the t Tex tag in the properties, if there is a tag then remove it
@@mooict yesss exactly thank you so much ... i dont know how it writen there i didnt write it u saved me
Nise
thanks for the content. kind of wish you were better at explaining cos i had such a difficult time learning this or even understanding.
Interesting video but I can't quite get in 12:36 this foreach. What is "Control" and "this.Controls". I will be so thankful if you explain it. :)
This will help - www.liangshunet.com/en/202002/498218422.htm
@@mooict Thank you!
omg, thank you a lot
Hey bro your tutorials are georgeous, can u help me pls? I want to make a trex can double jump and i dont know how
I'm really interested to know how you learned C#?
What advice do you want to give to who is beginners ?
Hi, my advise would be to make as many projects as you can try different ones from games design to application development. I went through the process of making games and apps since university and I enjoyed making things that worked for me. I didn't do any commercial apps just made stuff that I wanted and see if I can do it. It's challenging but growth in any skill is always challenging.
Hello I have a problem where the obstacle arent appearing and it shows error in the x.Left = this.ClientSize.Width
So if I use another gif or png instead of the gif or png you use, will I get an error?
i got everything right but the only thing that wrong is my dino, when i run the game it appear to be a black box above near the score label and cant be moved and score still inscrease :(
Really good tutorial! But your voice is a little too low!
Can i write this code in jetbrains?or only visual studio
There is a bit of a problem where the obstacle's hitbox is slightly oversized, I think you can fix this by making the image's transparent
Thank you so much for this but is there a reason why the dinosaur is under floor while playing the game, can you please tell me what i did wrong
You can check the trex.top value from the tutorial. For my one trex.Top = 367; in the timer and in the restart game function. You can also check the GitHub link for the project to view the full source code. Hope it helps.
@@mooict Yes, I have corrected, thank You
Hi there. I encountered a problem while programming the game. I followed your tutorial very closely, but for some reason, the floor picture box doesn't shows up
Did you add a picture box called floor to the form? check if that picturebox has any tags on it. Sometimes adding tags to the floor can cause it to move away from the form.
@@mooict Thanks for your help. It seems like I accidentally added the obstacle tag to the floor. I fixed it now
My obstacles and Trex are nowhere near each other but the if (trex.Bounds.IntersectsWith(x.Bounds)) is constantly true when I start the game. I don't know why
It shouldn't be constantly true only when both picture boxes are overlapping with each other. Check the for each loop, you should be checking the tags and intersection between both objects to detect collision
Me too
Do you open the unity project as 2D or what?
No its WPF but i dont recommend you to make a game in wpf as a beginner
This is Windows Form Application in visual studio. It's a different format of app than unity games. It is in 2d but we are not using unity we are using the .net framework to manually make a game rather than using s games engine.
@@mooict Oh ok thanks, I'll leave a sub, cos this tutorial is epic (:
@@mooict Oh ok thanks, I'll leave a sub, cos this tutorial is epic (:
Thanks
bro, How come everytime i run the game, the trex is not showing? But ain't got no error?
Check the location for the T rex in the code. It’s located with trex.Left and trex.Top
@@mooict i fixed it, thank you so much
How do you get these images and Gif's for your projects?
Some I found online and some of them I animated myself 😊
Hello! The Trex simply doesnt appear when I run the code. It just vanishes. The obstacles are there. The dino isnt. Im 15 min into the video
How did you get that “obstaclespeed”
Its defined in the begining when we start programming in the project.
Moo ICT oh I see it. It works! Thank you for the amazing tutorials
it tried the code and test it but it showed me a blank screen is there a way to fix it?
the floor is not solid
Help, i have a problem! the first time the game works but if i die and reset the game the dino stops jumping (the cactus stills move) what can i do?
Could you check the game reset function and see if the Dino is resetting to the right position
@@mooict thank you! Now it works
It works, but whenever I tried pressing space bar it closes itself instantly. Help.
Hello sir , this is my first time that I am making a game. I don't know why but I having problem with my obstacle, when I run the game the trex work finely but those obstacle don't move, they stay in same place!
Do you have any idea how to fix it or where the problem is ?
Hi check if you've tagged the picture boxes for the obstacles in the properties window.
@@mooict i just fixed the problem now and thank you so much for helping me to solve the problem.
I always get the cs1656 error and cs0108 warning with these keydown & keyup events
@Moo ICT can you do it with the flying birds?
hey there. thank you so much for this cool tutorial. but for some reason the game isn't working even tho i have no erros. when I start the game nothing happens and when i press space also nothing happens. do you have any idea why this happens?
Check the timer if it's enabled in the properties window.
@@mooict The dino now moves. but for some reason he falls thru the floor. also thanks for the quick response.
@@wouter9895 inside the timer event there's a part that checks for collision between the floor and the player see of it matches with your one and this tutorial code.
@@mooict oke, now that works. but now my obstacles wont move xD. I'm sorry for all the questions.
@@wouter9895 not a problem, see if you have added the tags to the obstacles in their properties window.
im a beginner and i didnt understand anything, i appreciate the working but should've explained more
after 24h, finally i can understand whats happening, i used the website for more information. You are a true legend
Hello
Score isn’t working it remains zero after jumping over hurdles
Can you explain please
Hi, check if the score integer is being updated on the label. inside of the timer even you can see a line like txtScore.Text = "Score" + score; this line is updating the label as the score is being updated.
My dinosaur is in the wrong place when I run the code. It is in the right place in the design tho!
Check the location of the trex picurebox in the reset function see if it matches the tutorial
Hey! I have a problem. When I run the code an empty form without pictures appears, plz help me((((((((
Does your code has this Form constructor. If not add it to the code see if that helps.
public Form1()
{
InitializeComponent();
}
@@mooict so now everything is ok but my Trex image is not appears, when is bump into the obstacle image is appearing. Problem CS0117 "Resources" doesn't have description for "Running"
@@aleksandranedosekina8990 see if you've imported a image called running in the project.
@@mooict i need tag or call pictureBox with Trex "running"?
@@aleksandranedosekina8990 there should be an image called running for the t rex. Import that to the project and the resource error will go away.
I have almost finished making flappy bird using only the console as the display. Very inefficient
That’s amazing. The fact it can be done in console and YOU are doing is amazing all to itself.
can anyone help when i go to right trex.top it doesnt work
Game is Not restart by pressing R.
Guide me How to restart the game
Game restart parts starts on 25:09. From there we are adding the game over function to the timer and then adding the other instructions inside of key up event. Hope this helps.
dino rex was bottom in the black picture box what i do now
Hi I'm not sure what you mean, is the t rex not stopping on the ground after the jump?
how do i create a way to save players score and make a highscore ?
You can easily save them into the file in game directory (using streamwrite and streamread)
@@czhockeyfan leaderboard style
I got half way through and followed it exactly and have 70 errors already. plz help
What's the errors?
well there are a lot haha. But its pretty much saying that pretty much everything is an invalid token so i don't really know whats happening.
When I usually get errors like this I check if I missed any brackets. Sometimes missing the brackets cause cascading errors through out the code.
tengo el personaje T Rex pero no me sale el piso negro en donde tiene que pisar el T Rex le di iniciar pero cuando inicio el juego solamente sale el T Rex con la pantalla en blanco y no el piso negro
coud u talk louder thanks for ur tutorials
Hi sorry about the audio quality on this I will fix this issue for future videos. For now you can use the volume booster browser extension if that helps.
you sound depressed, you ok there fam?
leave the poor guy alone . no boolie pls
- Привет! У меня такая проблема - игра работает нормально, но игровые очки не считаются! сделали все так, как описано на сайте...
Hooray, I figured it out myself! Thank you for publishing such an interesting project!
Well done 👍 and I'm glad you enjoyed it
Can you pls help me?
Hi what's the issue?
@@mooict Hey, can you explain me the MainGameTimerEvent part? (What the MainGameTimerEvent is and for what all the ifs and elses stand for)
@@mooict Id really appreciate it. Tomorrow I have a presentation about this and I dont get the MainGameTimerEvent part.🙁
@@juicynews0 Hi, the main game timer event is the TICK event for the timer. For this game the timer interval is set to 20 milliseconds so this event is called every interval or tick. We control the main game logic from inside of it for example the jump, landing on the ground, obstacles moving and replacing and finally updating the score. The timer will need to be enabled for all of this to work. All the best with your presentation tomorrow.
@@mooict Thank you so much man. I have another question about the MainGameTimerEvent. Can you explain me, for what the first IF, second IF , the else and the last IF stand for? (What we check in the ifs and else)
would you mind giving me your mail address so that i can send you my code to help to check?
i have followed each step carefully, and have checked that there should be no problem, but when i execute the app, it's not what it supposed to be, the trex is beneath the black bar, when i press space, it just jumps out. in addition, it's weird that the obstacles don't do anything
thanks in advance if you can help me out
Hi, here is the GitHub Repo for this project, github.com/mooict/T-Rex-Endless-Runner-Game-in-Windows-Form you can download it all and open it in visual studio. Hope that helps.
@@mooict thanks, i did it, i execute your project, it's better that it can be played, but the trex still doesn't show up correctly in the initial position. i can just see its head, it's body is covered by the black bar. i didn't change anything, i don't know why it works like that
@@forever_6 see if you have the same line as this trex.Top = floor.Top - trex.Height; in your code.
He sounds like georgenotfound
Howto convert exe
You can find your exe file in the debug folder inside of the visual studio project folder.
Y is ur voice soooooooooo low?
its too laggy .....when i play game
Check the timer interval and set the interval to 20
Bei mir kommen imme rnur 2 kakteen, kann mir jemand helfen?
el dinosaurio se lo chupa la tierra
you don't explain properly
Dude, if he doesn't help you, GO DO IT YOURSELF!
Love your tutorials! I followed this one but I got a few issues:
1 ==> trex.Image = Propreties.Ressources.dead;
2 ==> trex.Image = Propreties.Ressources.running;
they both dont work and it says that the ressouces doesn't contain a defenition for the words running and dead.
Also ==> txtscore += " Press R to restart the game!";
it does not work and it says that it cannot implicitly convert type 'string' to 'System.Windows.Forms.Label'
I tried to run the game without those lines and it partially worked. The obstacles and score worked, but every time I lunched it the trex went down and disappeared from the form.
Hi, for the first two errors relating to the resources means your project doesn't have a image named running or dead imported to the project. If you downloaded and imported the images from the website that will solve that. The other error needs to state txtscore.Text += " Press Enter to restart". It's important to change the text property from the label not the label itself. If you try txtscore == "something" it will show an error because c# thinks you are trying to change the label itself to a string so you need add txtscore.Text to it and it should work. Hope this helps ☺️