How to make a simple space invaders style game in windows form with C# coding
HTML-код
- Опубликовано: 25 авг 2024
- Written tutorial - www.mooict.com...
In this tutorial we will make a simple and fun space invaders style game called sad invaders. Yea let that sink in for a second. OK we're good now. Basically I just changed a few things around for the game tutorial and change the player character to a high definition triangle and the invaders to a super sophisticated sad face image i made in power point.
In the initial tutorial, we manually add the invaders to the form, tag them and then use a for each loop to animate and interact with them in the game. This version of the game is made through the code mainly, we are setting up the variables, adding time, key down and key up events. We create few different custom classes that create the invaders for the game, make bullets that shoot from the player and shoot down towards the player also we are spawning the and animating the invaders.
What we are doing in this project is that we are taking the existing tutorial from MOO ICT website links above and more functionality to it and making it more interactive.
It was a lot of fun making this game, I hope you enjoy it. As always keep programming, stay well, stay safe and Moo Out.
Download this project here github.com/mooict/Space-Invaders-Style-Game-Tutorial-Windows-Form
Cheers for the videos, it's been a great help in giving ideas. I've been looking all around for some tutorials for games as I'm trying to make a connect 4 from windows form.
Thanks a lot for this tutorial, your channel looks very nice :)
Thank you 😊
Nice video again !
Thank you 😊
Well, after watching a 4hr C# basics video, and then following this video, my code at least has no errors, but the enemy bullets never appear, the player bullet is static and shows, but doesn't move, and for some reason I only ever get 2 enemies on screen at a time, but what did i expect, I took a C, and an x86 asm (if you can believe it) programming course 15 years ago and that's my only experience with programming so what did I expect LOL. In any case, it was fun and I learned some things. Thanks!
Hey Brian glad you liked the tutorial. I'm working on making better ones it's still very much work in progress. I did learn C when I was at uni haven't used it since but it's a real beast . I find C# comfortable to use and learn.
@@mooict Good to know! I'll be looking out for more tutorials. :) Also, I fixed my code. It was a couple mistakes within the long for loop (fair enough, that was the hard bit). Now I'm working on trying to get the enemy bullets to spawn from random enemies rather than the top of the screen. Not sure yet how I will accomplish that but it will be a fun puzzle for me. :)
I LOVE YOU
Done it. Thanks.
Thanks buddy :-)
Can you show instructions on how to add sounds, please? 👍
Will do
This is great thanks! I'm trying to make a board game in C# (I'll probably try Draughts first), do you have any suggestions?
If you are interested in board games then check out the battleship tutorial you can probably make your game similar to that framework.
Why my bullet are invisible?
solo disparan los enemigos pero no se ven en la pantalla solo disparan cuando yo disparo a los enemigos cuando inicio el juego
Excellent video! How do I script enemies to shoot?
Hi, one of the way you can do this is pick a random enemy when the game is running and spawn the bullet from location of that enemy. There are lots of different ways to do this I think have a go at it see what it works out
why are you all creating projects in wf and not in wpf ???
Some are in Windows form and some in wpf. I have labelled all of them so you see which is made with wpf ones if needed.
can anyone tell me ... my "player" doesnt stop on the end of screen, it goes out and out of the screen it will be shoot by sadbullets. ???
Yes because the bullet is aimed at the player so even outside the scope of this level the bullet will follow the player picture box.
@@mooict thanks, and how can i stop my player running outsite? only with canvas? or is there something easier
Hello ! How can I change the image of the enemy bullets? I want to put meteorites instead.
Hi, you can make the bullet picture box bigger by adding to the height and width of the picture box and add your picture to it same way we have done for the invaders picture boxes.
@@mooict so.. I managed to add the meteorites but I don't know how to remove the enemy's bullets. Right now If I'm trying to play, both meteorites and bullets are coming to kill me. Do you have any idea how could I change my code so I'm attacked just by meteorites and my player would fire bullets? I will let the code below, maybe will help
private void makeBullet(string bulletTag)
{
PictureBox bullet = new PictureBox();
bullet.Image = Properties.Resources.bullet;
bullet.SizeMode = PictureBoxSizeMode.StretchImage;
bullet.Size = new Size(5, 20);
bullet.Tag = bulletTag;
bullet.Left = player.Left + player.Width / 2;
PictureBox meteor = new PictureBox();
meteor.Size = new Size(30, 50);
meteor.Image = Properties.Resources.meteor;
meteor.Tag = "meteor";
meteor.SizeMode = PictureBoxSizeMode.StretchImage;
meteor.Left=player.Left + player.Width / 2;
this.Controls.Add(meteor);
if ((string)bullet.Tag == "bullet")
{
bullet.Top = player.Top - 20;
}
else if((string)bullet.Tag == "meteor")
{
bullet.Top = -100;
}
this.Controls.Add(bullet);
bullet.BringToFront();
}
@@cristis.3724 this is the make bullet function it will create a bullet when we press the space bar. So having both meteor and bullet created in this method will make both when the place presses space. You need to make a separate function for the meteor and you can make like a countdown integer in the game for example if the meteor countdown goes below 0 then run the meteor function. The reset that integer to 10 or sometime. Have a go at this and see how it works for you.
Also you wrote bullet.top -=100 instead of meteor.top on the else if statement.