Advertisement

c# drawing sprites

Started by March 16, 2019 12:23 AM
55 comments, last by phil67rpg 5 years, 11 months ago

try? I thought you said it was real close to what you wanted, can't you just tweak it and march on? What's wrong Phil? What have you tried? What situation do you prefer to be in? How do  you want it? And what are you going to do with it once you get it? 

If you browse the last code I gave you, you'd realize its a neat little circle circle collision thing with arrays (which you were studying at the time) that I though might be fun-phil, but you chose to ignore it.(maybe wise, idk) I'm sorry, what are you trying to remedy?

Dev careful. Pixel on board.
Buckle up. Everything will be revealed.

I have tried tweaking it but just cant come up with a viable solution. I am so close, I have got it to blink off and on.


        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.Black);
            e.Graphics.DrawImage(ship, 350 + x, 530);
            e.Graphics.DrawImage(bullet, 375 + x, 520 + y);
            e.Graphics.DrawImage(bug_one, 350, 0);
            if (draw_flag == false && y <= -510)
            {
                e.Graphics.DrawImage(coll, 350, 0);
            }
            else 
            {
                e.Graphics.DrawImage(bug_one, 350, 0);
            }
            if (draw_flag==true)
            {
                e.Graphics.DrawImage(black, 350, 0);
            }
        }
        int count = 0;
        private void timer2_Tick(object sender, EventArgs e)
        {
            draw_flag = false;
            int stop = 4;
            if (count > stop)
            {
                draw_flag = true;
                count = 0;
            }
            count++;
        }
    }

 

Advertisement

you have to reason this out my friend. Keep throwing bools at it, what ever it takes. I want to start talking about a common object wrapper and self management but if you can't get this mechanic down to some simple logic, I fear all may be lost.

In effect, what you have done since your last code sample was replace the toggle in the tick callback with a different toggle and a delay, so it blinks slower. Did you sense that?   

Dev careful. Pixel on board.
Buckle up. Everything will be revealed.

I will work on it some more and will use more bools. I am not giving up.

well I am thinking about making a game called scorched earth, it has a tank that shoots a bullet in a parabola and tries to hit another tank. I think might a little simpler plus it has some math which I like, I am going to stick with windows forms and also I am still going to work on my bug invaders game, maybe I am going to solve my problem. should I start a new game or should I stick with my current game?

Fundamentally they are the same in my opinion. It really doesn't matter at this point what shapes or images you use to represent your on screen entities. Doesn't matter if it's a tank or a bug. Could be anything, because under the hood they are built from the same pieces. What we care about right now is learning code flow, filling our tool box with routines that we discover along the way to reuse and make better. Problem solving is why we turn the machine on in the first place.  

This will actually be the cool part phil. Once you get this sequence figured out, you will be shooting bugs, having tanks shooting bullets in cool shapes at other tanks, you dream it, you'll be lighting that sprite up with it. Don't get distracted.

Have you tried perhaps to work it out on paper? You'd be surprised what you can come up with or potentially realize when you change up your approach.

Keep notes of your new ideas though. Return to them when the time is right. 

How did the reading on arrays go?

Dev careful. Pixel on board.
Buckle up. Everything will be revealed.

Advertisement

 so these game are similar?

under the hood, sure. In both games you need to handle bullet behavior, both games need to check if they were hit by the bullet. You need to render them, that will be similar, etc... So right now it doesn't matter what game you make, but instead focus on all the little pieces of code in a slightly generic fashion. Build your methods so that later you can copy and paste your own code. 

Dev careful. Pixel on board.
Buckle up. Everything will be revealed.

On 3/19/2019 at 5:04 PM, phil67rpg said:

I have tried tweaking it but just cant come up with a viable solution. I am so close, I have got it to blink off and on.



        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.Black);
            e.Graphics.DrawImage(ship, 350 + x, 530);
            e.Graphics.DrawImage(bullet, 375 + x, 520 + y);
            e.Graphics.DrawImage(bug_one, 350, 0);
            if (draw_flag == false && y <= -510)
            {
                e.Graphics.DrawImage(coll, 350, 0);
            }
            else 
            {
                e.Graphics.DrawImage(bug_one, 350, 0);
            }
            if (draw_flag==true)
            {
                e.Graphics.DrawImage(black, 350, 0);
            }
        }
        int count = 0;
        private void timer2_Tick(object sender, EventArgs e)
        {
            draw_flag = false;
            int stop = 4;
            if (count > stop)
            {
                draw_flag = true;
                count = 0;
            }
            count++;
        }
    }

 

Dude just look at your logic... You draw when draw_flag is true... and it's only true every fourth tick... That is, right now, it will be off, off, off, on, off, off, off, on, etc.  You are forcing it to blink. I'm not sure if you're having trouble with understanding how basic animation works or if you don't understand basic coding, but this thread is painful to read...  Maybe Google how to make a flip book... If you only draw on every fourth page, it's going to look like it's blinking...

But, look man... Just remove the code that you put that makes it blink... replace the entire timer code with "draw_flag = true;"  -- and then it will just be true every frame (i.e. If you don't want it to blink, draw it on every page of your flip book, stop skipping pages!).

Also you're totally murdering c# casing conventions.  In simplified terms, you should be using TitleCase for class level variables, and camelCase for method level variables... (It's not going to make your code work any different, it's just a matter of established conventions... You don't have to change it, it's just annoying to see.) 

well brianslugs38 I have replaced my timer with draw_flag=true only. however it blacks out the bug sprite.


        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.Black);
            e.Graphics.DrawImage(ship, 350 + x, 530);
            e.Graphics.DrawImage(bullet, 375 + x, 520 + y);
            e.Graphics.DrawImage(bug_one, 350, 0);
            if (draw_flag == false && y <= -510)
            {
                e.Graphics.DrawImage(coll, 350, 0);
            }
            else 
            {
                e.Graphics.DrawImage(bug_one, 350, 0);
            }
            if (draw_flag==true)
            {
                e.Graphics.DrawImage(black, 350, 0);
            }
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
                draw_flag = true;
        }

 

This topic is closed to new replies.

Advertisement