C
C#

I'm stuck,visual studio 22, I need help making my invaders/enemies move left to right then down

I'm stuck,visual studio 22, I need help making my invaders/enemies move left to right then down

SSpirant0411/20/2023
I’m trying to get my invaders/enemies to move left to right then down like in the game space invaders. but I can’t for the life of me figure it out. Invader class https://pastebin.com/a14y0aHS Program class https://pastebin.com/aLHFM9ZW Not needed to change but here is the player class https://pastebin.com/CygjmEYr If there’s a better way to post my code her please let me know
TTheRanger11/20/2023
i do not recommend the way you set the locations of your objects along with how you print them its very complicated, there's actually a better and an easier way
SSpirant0411/20/2023
I just updated the pastebin links with the additions I added is it still bit messy! Like 3ish minutes ago
TTheRanger11/20/2023
first, an object's location should not be an int alone in any 2d game, an object has a horizontal, and a vertical location we always represent them as x and y variables you either define an int X and an int Y for your player and invader class or make your own Struct that has X and Y fields and this is the recommended way we usually call the struct Vector2 second, the way where ur trying to print the objects is too complicated its actually simpler than that there is a method called Console.SetCursorPosition basically you use it to specify where in the command prompt window to print a string your invaders doesnt need to be stored in a 2d array, just a 1d array is enough, or a list
SSpirant0411/20/2023
How would you go about making them come down after hitting the right side I also added the SetCursorPosition works great!
TTheRanger11/20/2023
thats simple, iterate through each invader if one of them is on the right side, increment all the Y of all invaders by 1 seems your Location variable is still an int which isnt recommended and ur invaders field is still a 2d array
SSpirant0411/20/2023
I see thank you I’ll try to figure that but I have one question how come when I run my code it closes after like 6 seconds is there a way for it to last longer?
TTheRanger11/20/2023
did u update ur code?
SSpirant0411/20/2023
Not yet but it always closes when the invaders hit the middle of the screen
TTheRanger11/20/2023
well update and let me see
SSpirant0411/20/2023
Or when I move left or right immediately then it closes faster than that Fix it on program class line 62 I just put 8 instead of 5 that fixed that issue now to figure out to move down with out destroying everything I also need figure what I did do to make my player put in the middle I wanted it to be on left side like when I started where the invaders are Also I updated the links with additions
TTheRanger11/20/2023
thats easy just increment y of each invader, or currentLine as u call it
SSpirant0411/20/2023
If I couldn’t change the code I have now (example the invader class) how can I use the increment without the x and y solution 😦
TTheRanger11/20/2023
No description
SSpirant0411/20/2023
I would use this!? Interesting
TTheRanger11/20/2023
well, in ur code, Location represents the x and CurrentLine represents the y
SSpirant0411/20/2023
I didn’t add the x and y in current line in the invader class that what I mean how to implement the downwards without changing it I know it’s not the ideal method to go about the invader class
TTheRanger11/20/2023
ur not making any sense y represents the vertical position we just call it y your variable CurrentLine represents the vertical position you want the invaders to move down, ud have to change the value of CurrentLine
SSpirant0411/20/2023
Ohhhh I’m sorry i got confused my bad but thank you for clarifying

Looking for more? Join the community!

C
C#

I'm stuck,visual studio 22, I need help making my invaders/enemies move left to right then down

Join Server
Want results from more Discord servers?
Add your server
Recommended Posts
✅ Where should I store all the sensitive file on .NET project?Hello everyone, May I know where should I store all the credential files that needs to be used by .Unity CodeI have been trying to get my C# code to work in unity for about a week and I am officially lost. I'vHelp! Reporting service in dotnet Core?please don't mind my english, it is not that good. i have created 2 projects one is server -dotnetCatAPI Json deserialization issue.I'm having trouble getting my code to deserialize my json correctly. When I run my Program.cs I get ✅ Any idea why I cant use sendkey?Authorization in microservices archHello everyone, I'm quite new to the NET microservices arhitecture and right now I'm implementing a.✅ I can't get my runButton button to work on a windows form app```cs if (e.KeyCode == Keys.Enter || (e.Modifiers == Keys.None && sender == runButton)) ``` I can sGit and Google Drivenew git user.. it seems to have your local repositories in a google drive controlled file structure ASP.NET CRUD MODALI created a MVC controller with actions (CRUD) and I would like to know, how to modify this pre geneError✅ using from another csprojCurrently i have 2 projects, an api app and a worker service app And both use the same models. Is thJavascript not working on my MVC projectI'm learning front end tutorials at the moment so I'm totally new to designing websites. _Layout.csis there a way to get the colocation center connected to with C# ?I wanna get information about the colocation center exactly how Cloudflare warp gets it in the prefexaml and x:Class - issue (CS1061)I got a project wich some of you helped me with allready, tho there is still one issue I coudn't resCan't fire click blazor ui button```cs @page "/members" @namespace Blazor.Web @attribute [StreamRendering] <PageTitle>Members</PageTHelp Minecraft Console Client scripting(https://github.com/MCCTeam/Minecraft-Console-Client Link to MCC) is there a way to make a C# scrip✅ Bypass ASP.NET Required authenticatorIm trying to return Forbid (403) to the user if a resource already exists it all works fine but the Issues trying to create new error typesHello everyone. I'm trying to create my own extensible error type, based on the RFC 7807. ```c# puI have a Visual-Studio Proj. in .NET Framework and need help fixing the "CS0120" error it throws up.Basically I want to make an App which you just run and it will automatically, by pressing just one bplease help!!! (winforms c#)Does anyone know how can i make the user move the last drawn shape on a picturebox (the picture box