Click here to Skip to main content
15,902,846 members
Home / Discussions / C#
   

C#

 
GeneralRe: linking up project Pin
skyeddie31-Jul-06 16:59
skyeddie31-Jul-06 16:59 
QuestionConnect to a central db server Pin
GizmoC30-Jul-06 18:34
GizmoC30-Jul-06 18:34 
AnswerRe: Connect to a central db server Pin
LongRange.Shooter31-Jul-06 5:56
LongRange.Shooter31-Jul-06 5:56 
QuestionHow to create a setup in C#? Pin
Mithun Acharya30-Jul-06 18:09
Mithun Acharya30-Jul-06 18:09 
AnswerRe: How to create a setup in C#? Pin
AnnnS30-Jul-06 19:50
AnnnS30-Jul-06 19:50 
QuestionFlickering problem! help! :( Pin
janita30-Jul-06 18:01
janita30-Jul-06 18:01 
AnswerRe: Flickering problem! help! :( Pin
Vipin Venugopal30-Jul-06 20:35
Vipin Venugopal30-Jul-06 20:35 
AnswerRe: Flickering problem! help! :( Pin
janita30-Jul-06 21:10
janita30-Jul-06 21:10 
Here the code

The Form, the timer and the onpaint
<br />
        protected override void OnPaint(PaintEventArgs pea)<br />
        {<br />
            game.onPaint(pea.Graphics);<br />
            this.Invalidate();<br />
        }<br />
<br />
        private void gameTimer_Tick(object sender, EventArgs e)<br />
        {<br />
            game.tick();<br />
            this.Refresh();<br />
        }<br />


I have a Game class, which is pasted below, i remove the other non-important code and pasted tick and paint only.
<br />
    class Game<br />
    {<br />
        Bitmap bufferImage;<br />
        public int tile_size;<br />
        public Game(Form1 parent_)<br />
        {<br />
            parent = parent_;<br />
            height = parent_.Height;<br />
            width = parent_.Width;<br />
            int zW = width / 3;<br />
            int zH = height / 3;<br />
            tile_size = zH>zW?zW:zH;<br />
            offsetX = (width - (tile_size * 3)) / 2;<br />
            offsetY = (height - (tile_size * 3)) / 2;<br />
            bufferImage = new Bitmap(width, height);<br />
<br />
            loadImage();<br />
            startGame(ARCADE);<br />
        }<br />
<br />
        public void tick()<br />
        {<br />
            DateTime currentTime = System.DateTime.Now;<br />
            TimeSpan duration = currentTime - timeTick;<br />
            //Console.WriteLine("milliseconds:" + duration.TotalMilliseconds);<br />
            //if (duration.TotalMilliseconds < 30)<br />
            //    return;<br />
<br />
            if (state == PLAY && gameType == ARCADE)<br />
            {<br />
                for (int i = 0; i < 3; i++)<br />
                {<br />
                    bool toLevelup = true;<br />
                    if ((arcadeLevel[0,0] != -1 && arcadeLevel[0,1] != arcadeLevel[0,2]) ||<br />
                      (arcadeLevel[1,0] != -1 && arcadeLevel[1,1] != arcadeLevel[1,2]) ||<br />
                      (arcadeLevel[2,0] != -1 && arcadeLevel[2,1] != arcadeLevel[2,2]))<br />
                    {<br />
                        toLevelup = false;<br />
                    }<br />
<br />
                    if (toLevelup)<br />
                    {<br />
                        level++;<br />
                        init(ARCADE);<br />
                    }<br />
                }<br />
            }<br />
            else if (state == PLAY && gameType == SURVIVAL)<br />
            {<br />
                duration = currentTime - timerSpeed;<br />
                if (duration.TotalMilliseconds >= 60000 && spawn_time > 0)<br />
                {<br />
                    spawn_time -= 50;<br />
                    timerSpeed = currentTime;<br />
                    level++;<br />
                }<br />
            }<br />
<br />
            //randomizer<br />
            int position, character;<br />
            duration = currentTime - timerGame;<br />
            if (duration.TotalMilliseconds >= spawn_time)<br />
            {<br />
                int count = 0;<br />
                bool generated = false;<br />
                while (!generated && count < 10)<br />
                {<br />
                    position = Math.Abs(random.Next() % (9));<br />
<br />
                    if (checkPlaceable(position))<br />
                    {<br />
                        generated = true;<br />
                        // DEBUG<br />
                        /*<br />
                        character = Math.Abs(random.Next() % (CHAR_MAX));<br />
                        /*/<br />
                        character = CHAR_PUTSU;<br />
                        //*/<br />
                        addCharacter(character, position);<br />
                    }<br />
                    count++;<br />
                }<br />
                timerGame = currentTime;<br />
            }<br />
<br />
            Tile tile;<br />
            for (int i = 0; i < landMap.GetLength(0); i++)<br />
                for (int j = 0; j < landMap.GetLength(1); j++)<br />
                {<br />
                    tile = landMap[i,j];<br />
                    if (tile.isHole && tile.character != CHAR_EMPTY)<br />
                    {<br />
                        duration = currentTime - tile.timerAnimate;<br />
                        if (duration.TotalMilliseconds >= ANIMATION_SPEED)<br />
                        {<br />
                            tile.charImgIdx++;<br />
                            tile.timerAnimate = currentTime;<br />
                        }<br />
                    }<br />
                }<br />
<br />
            if (life <= 0 && state == PLAY)<br />
            {<br />
                highscorePos = processHighscore();<br />
                if (0 < highscorePos)<br />
                {<br />
                    state = OVER;<br />
                    //showGameOver();<br />
                }<br />
                else<br />
                {<br />
                    state = END;<br />
                }<br />
            }<br />
            timeTick = currentTime;<br />
            DateTime currentTime2 = System.DateTime.Now;<br />
            duration = currentTime2 - currentTime;            <br />
        }<br />
        Graphics g = null;<br />
        public void onPaint(System.Drawing.Graphics g_)<br />
        {<br />
            if(g == null)<br />
                g = Graphics.FromImage(bufferImage);            <br />
<br />
            Tile tile;<br />
            for(int i=0; i<landMap.GetLength(0); i++)<br />
                for (int j = 0; j < landMap.GetLength(1); j++)<br />
                {<br />
                    tile = landMap[i,j];<br />
                    if(tile.isHole == true)<br />
                        g.DrawImage(imgTile[1], tile.pixelX, tile.pixelY);<br />
                    else<br />
                        paintClipImage(g, imgTile[0], tile.pixelX, tile.pixelY, tile.landImgIdx * tile_size, 0, tile_size, tile_size);                            <br />
<br />
                    if (tile.character != CHAR_EMPTY && !tile.isWacked && tile.isHole)<br />
                    {<br />
                        if(tile.charImgIdx >= ANIMATION_SEQUENCE.GetLength(0))<br />
                        {<br />
                            tile.character = CHAR_EMPTY;<br />
                        }<br />
                        else<br />
                        {<br />
                            tile.repaint = true;<br />
                            paintClipImage(g, imgCharacters[tile.character], tile.pixelX, tile.pixelY, ANIMATION_SEQUENCE[tile.charImgIdx] * tile_size, 0, tile_size, tile_size);                        <br />
                        }<br />
                    }<br />
<br />
                    if (tile.character != CHAR_EMPTY && tile.isWacked && tile.isHole)<br />
                    {<br />
                        if (tile.charImgIdx > 1)<br />
                        {<br />
                            tile.character = CHAR_EMPTY;<br />
                            tile.isWacked = false;<br />
                        }<br />
                        else<br />
                        {<br />
                            tile.repaint = true;<br />
                            paintClipImage(g, imgCharacters[tile.character], tile.pixelX, tile.pixelY, (ANIMATION_WACKED + tile.charImgIdx) * tile_size, 0, tile_size, tile_size);<br />
                            if (tile.hammerIdx < HAMMER_IDX_MAX)<br />
                            {<br />
                                int spaced = CHAR_WIDTH - HAMMER_WIDTH;<br />
                                paintClipImage(g, imgHammer, tile.pixelX + spaced, tile.pixelY, tile.hammerIdx * HAMMER_WIDTH, 0, HAMMER_WIDTH, HAMMER_WIDTH);<br />
                                tile.hammerIdx++;<br />
                            }<br />
<br />
                            if ((tile.character == CHAR_MONG || tile.character == CHAR_PUTSU || tile.character == CHAR_PIPKOW) && tile.hitAble && tile.powerCycle > 0)<br />
                            {<br />
                                int powerY = tile.pixelY + (CHAR_WIDTH / 6) * tile.powerCycle;<br />
                                g.DrawImage(imgPow, tile.pixelX, powerY);<br />
                                tile.powerCycle--;<br />
                            }<br />
                            else if ((tile.character == CHAR_MOTERO || tile.character == CHAR_MONG) && !tile.hitAble && tile.powerCycle > 0)<br />
                            {<br />
                                int powerY = tile.pixelY + (CHAR_WIDTH / 6) * tile.powerCycle;<br />
                                g.DrawImage(imgMinusHeart, offsetX + tile.pixelX, offsetY + powerY);<br />
                                tile.powerCycle--;<br />
                            }<br />
                        }<br />
                    }<br />
                }<br />
<br />
            g_.DrawImage(bufferImage, 0, 0);<br />
        }        <br />
<br />
    }<br />



Please help Smile | :)


Thanks,
Jan
AnswerRe: Flickering problem! help! :( Pin
janita1-Aug-06 15:41
janita1-Aug-06 15:41 
Questionconnection for excel Pin
Mohammed Elkholy30-Jul-06 11:35
Mohammed Elkholy30-Jul-06 11:35 
AnswerRe: connection for excel Pin
Guffa30-Jul-06 11:53
Guffa30-Jul-06 11:53 
Questionnew process information ? Pin
raol duke30-Jul-06 9:47
raol duke30-Jul-06 9:47 
QuestionIs there any packer for .NET? Pin
xkx3230-Jul-06 7:13
xkx3230-Jul-06 7:13 
AnswerRe: Is there any packer for .NET? Pin
leppie30-Jul-06 15:31
leppie30-Jul-06 15:31 
QuestionShould I use Dispose in this situation Pin
xkx3230-Jul-06 7:01
xkx3230-Jul-06 7:01 
AnswerRe: Should I use Dispose in this situation Pin
Colin Angus Mackay30-Jul-06 11:14
Colin Angus Mackay30-Jul-06 11:14 
AnswerRe: Should I use Dispose in this situation Pin
Guffa30-Jul-06 11:51
Guffa30-Jul-06 11:51 
AnswerRe: Should I use Dispose in this situation Pin
LongRange.Shooter31-Jul-06 5:59
LongRange.Shooter31-Jul-06 5:59 
QuestionHow to get Text control value into a numeric data type? Pin
Amol Ravatale30-Jul-06 5:39
Amol Ravatale30-Jul-06 5:39 
AnswerRe: How to get Text control value into a numeric data type? [modified] Pin
Shy Agam30-Jul-06 5:53
Shy Agam30-Jul-06 5:53 
AnswerRe: How to get Text control value into a numeric data type? Pin
User 665830-Jul-06 6:15
User 665830-Jul-06 6:15 
GeneralRe: How to get Text control value into a numeric data type? [modified] Pin
Shy Agam30-Jul-06 6:44
Shy Agam30-Jul-06 6:44 
GeneralRe: How to get Text control value into a numeric data type? Pin
User 665830-Jul-06 8:27
User 665830-Jul-06 8:27 
GeneralMy dear friends.... Thanks both of you Pin
Amol Ravatale30-Jul-06 21:14
Amol Ravatale30-Jul-06 21:14 
QuestionHow to generate combo box in a datagrid in windows forms( .Net 1.1) Pin
Rocky#30-Jul-06 0:52
Rocky#30-Jul-06 0:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.