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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Felipe RamosPosted May 19, 2011, 3:27 PM
Felipe RamosPosted May 19, 2011, 3:44 PM
albert albertPosted May 19, 2011, 3:40 PM
albert albertPosted May 19, 2011, 3:12 PM
but if u press "S" then on the FormMenu it doesnt work.
What is the effect?
Thx.
Felipe RamosPosted May 19, 2011, 3:06 PM
albert albertPosted May 19, 2011, 2:56 PM
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 RamosPosted May 19, 2011, 2:42 PM
albert albertPosted May 19, 2011, 2:40 PM
THX!!
Felipe RamosPosted May 19, 2011, 1:52 PM
[STAThread]
albert albertPosted May 19, 2011, 1:23 PM
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 RamosPosted May 19, 2011, 1:11 PM
Felipe RamosPosted May 19, 2011, 1:10 PM
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 RamosPosted May 19, 2011, 12:44 PM
I'll see what I find for the other issue.
albert albertPosted May 19, 2011, 12:31 PM
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.
albert albertPosted May 19, 2011, 11:43 AM
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]
Felipe RamosPosted May 19, 2011, 11:00 AM
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();
}
Dorababu MekaPosted May 19, 2011, 10:48 AM