Hi everyone,
I want to run directly Form1 if the application starts.
I tried this:
startGame.PerformClick();
But now I have to press start on the form to start the game.
This is the hole project.
THX.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 11:27 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted May 19, 2011, 6:48 AM EDT
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 7:00 AM EDT
Add back initialSetup since in your code is commented out and call the function before the closing bracket of form_load.
public void startNewGame()
{
//MessageBox.Show("Hallo");
//Form1 form = new Form1();
gameStart = true;
animationTimer.Start();
_game.initialSetup();
_game.setupInvaders();
_game.setUpShields();
_game.setupInvaders();
_game.setUpLifeMarker();
this.Refresh();
}
private void Form1_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
Screen screen = Screen.PrimaryScreen;
int tempHeight = screen.Bounds.Height;
int tempWidth = screen.Bounds.Width;
// Resolution.
//Resolution.se
/*
switch (screen)
{
case "800*600":
fixHeight = 800;
fixWidth = 600;
Resolution.
break;
}
*/
Fm1 = this;
bttnFile.Enabled = false;
bttnMedium.Checked=true;
//creditTimer.Start();
_game.currentDirection = Game.direction.right;
picExplode.Visible = false; ;
_game.difficultySetting = "medium";
_game.invaderMaxbullets = 6;
lblLives.ForeColor = Color.Black;
lblScore.ForeColor = Color.Black;
lblLevel.Text = ("Level: 1");
lblLevel.ForeColor = Color.Black;
startNewGame();
}
albert albertRank #2,683 · 519 reputationPosted May 19, 2011, 7:43 AM EDT
THX.
I have it now like this: see attachment.
But there is 1 problem. If I shoot an invader out of the sky the invader will not be removed.
And I have a FormMenu and if the user presses "s" the have to begin.
Like this:
[code]
private void frmMenu_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.S)
Form1.Fm1.startGame.PerformClick();
//game.StartGame();
if (e.KeyCode == Keys.Q)
Application.Exit();
if(keysPressed.Contains( e.KeyCode))
{
keysPressed.Remove(e.KeyCode);
}
keysPressed.Add(e.KeyCode);
}
[/code]
albert albertRank #2,683 · 519 reputationPosted May 19, 2011, 8:31 AM EDT
an other question: Do u have a simple solution to get the game play faster?
I think u see it by urself that the movements are going very slowly. I already changed the Timers.
But that dont affect so mutch.
THX anyway.
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 8:44 AM EDT
I'll see what I find for the other issue.
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 9:10 AM EDT
Init
LoadContent
Loop
Update
Game Logic/Input/Etc
Draw
UnLoadContent
This following link is a great start point http://create.msdn.com/en-US/education/tutorial/2dgame/getting_started
If you are required to stay with GDI and the tmers, make sure you clean your code and avoid any checks you don't need. For example since your bullets are traveling along your y axis instead of checking every tick, check only after the bullet have cross a y value that approaches your first invader line and when you clear the first line update the y value further up.
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 9:11 AM EDT
albert albertRank #2,683 · 519 reputationPosted May 19, 2011, 9:23 AM EDT
I have it now like this.
There was just some duplicate code.
But how to start the game from The FormMenu?
this doesnt work:
[code]
private void frmMenu_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.S)
Form1.Fm1.startNewGame();
[/code]
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 9:52 AM EDT
[STAThread]
albert albertRank #2,683 · 519 reputationPosted May 19, 2011, 10:40 AM EDT
THX!!
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 10:42 AM EDT
albert albertRank #2,683 · 519 reputationPosted May 19, 2011, 10:56 AM EDT
1 more question. There is also a splash Screen.
I want that loaded first. And then u will see the FormMenu.
I had this:
[code]
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
bool newGame = false;
Application.Run(new SplashScreen());
FormMenu menu = new FormMenu();
menu.OnNewGame += () =>
{
newGame = true;
menu.Close();
};
Application.Run(menu);
if (newGame)
Application.Run(new Form1());
}
[/code]
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 11:06 AM EDT
albert albertRank #2,683 · 519 reputationPosted May 19, 2011, 11:12 AM EDT
but if u press "S" then on the FormMenu it doesnt work.
What is the effect?
Thx.
albert albertRank #2,683 · 519 reputationPosted May 19, 2011, 11:40 AM EDT
Felipe RamosRank #1,409 · 1.2K reputationPosted May 19, 2011, 11:44 AM EDT