Porting small game from Java to .NET CF?

  • Thread starter Thread starter Rene Ruppert
  • Start date Start date
R

Rene Ruppert

Hi,

Recently I wrote a small Boulder Dash game which runs as a Java applet.
Now I've ported the whole thing to my PDA and it would work, but the game
screen won't show as soon as I include my main loop.
In the Java applet this was something like

while(true)
{
Thread.Sleep(GAME_DELAY);

// Move sprites...
// Read key input...

Invalidate();
Update();
}

In .NET the App won't start if I leave the while() loop in the game. If I
take it out, the game appears. Where does this difference come from and what
is the right way to port it?

Regards,

René
 
You're giving us very little info to go on, but try adding
Application.DoEvents() after the call to Update().

-Chris
 
Okay, here a little bit more detailed. I have already added DoEvents(). The
screen is drawn correctly the first time after calling refreshScreen() in
the constructor. But it will never be redrawn while the game is in the
while() loop, although the display keeps changing...what the hell is going
on there?
btw: both, OnPaint() and OnPaintBackground() are overridden and empty.

public class GameWindow
{
private static Graphics graphics;

public GameWindow()
{
this.ClientSize = new Size(Screen.PrimaryScreen.WorkingArea.Width,
Screen.PrimaryScreen.WorkingArea.Height);
this.Text = "FleckiDash.NET";
this.Visible = true;

graphics = this.CreateGraphics();

graphics.FillRectangle(new SolidBrush(Color.Black),
0, 0, Screen.PrimaryScreen.WorkingArea.Width,
Screen.PrimaryScreen.WorkingArea.Height);

init();
refreshScreen();
}

public void run()
{
while (true)
{
Application.DoEvents();
Thread.Sleep(GAME_DELAY);

// Move all objects...

refreshScreen();
}
}

private void refreshScreen()
{
graphics.DrawRectangle(new Pen(Color.Black), 0, 0, PIXELWIDTH,
PIXELHEIGHT);

// Spielfeld zeichnen.
for (byte y = 0; y < FIELDHEIGHT; ++y)
{
for (byte x = 0; x < FIELDWIDTH; ++x)
{
drawSprite(ref graphics, x, y);
}
}

int statusY = PIXELHEIGHT - 13;
graphics.DrawRectangle(new Pen(Color.Black), 0, statusY,
PIXELWIDTH - 1, 13);
graphics.DrawRectangle(new Pen(Color.Black), 1, statusY + 1,
PIXELWIDTH - 3, 11);
graphics.DrawString("Level: " + level,
new Font("Arial", 8, FontStyle.Regular),
new SolidBrush(Color.White), 3,
statusY);
graphics.DrawString("M"use: " +
player.actGems + " von " + player.gemsToWin,
new Font("Arial", 8, FontStyle.Regular),
new SolidBrush(Color.White),
70, statusY);
}
}
 
DOH!

How damn stupid can one be? I didn't call the run() method which contains
the main loop...

René
 
Back
Top