I am reading a book on C# called Visual C# 2017 and doing the exercises in the back of the chapters. this might help me. also I am going to look up timers and c#
c# bug invaders
cool, lets talk about it when you're ready.
I'm looking at these two classes in your environment.
https://docs.microsoft.com/en-us/dotnet/api/system.timers.timer?view=netframework-4.7.2
and something a little more high performance you have built in.
Make life easier, go straight to the source. Try them both.
And consider this. https://gafferongames.com/post/fix_your_timestep/
Dev careful. Pixel on board.
goliath do you have any more input on my problem? also I have looked at your links.
9 minutes ago, phil67rpg said:goliath do you have any more input on my problem? also I have looked at your links.
Great, write us up a brief summary of what your learned and how it will help your code. Saying you looked at the links doesn't mean anything. Prove to us you're learning something, or at least trying. At this point it almost seems you want us to write this for you and to solve all your problems. You'll never learn anything this way.
"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin
yes. but I think we've overstayed our welcome in this thread. There was a call for self re-examination or a push toward doing some interesting tests with timing to realize a logical visual sequence. Please start a new topic so that we try to follow the rules of the forum.
Dev careful. Pixel on board.
well I have got my code to draw a bug and then shoot a bullet at the bug. when the bullet hits the bug it draws a collision sprite. I want it to only draw the collision sprite for a short period of time and then draw a black sprite which erases the collision sprite. I have condensed my code. this post is for crazycdn
public void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 20;
timer1.Start();
timer2.Interval = 20;
timer2.Tick += new EventHandler(RunEvent);
timer2.Start();
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
}
bool draw_flag = true;
private void RunEvent(object sender, EventArgs e)
{
draw_flag = false;
}
int x = 0, y = 0;
Bitmap bug_one = new Bitmap("bug_one.bmp", true);
Bitmap ship = new Bitmap("ship.bmp", true);
Bitmap bullet = new Bitmap("bullet.bmp", true);
Bitmap coll = new Bitmap("coll.bmp", true);
Bitmap black = new Bitmap("black.bmp", true);
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
{
x-=5;
if(x<=-350)
{
x = -350;
}
}
if(e.KeyCode == Keys.Right)
{
x+=5;
if(x>=375)
{
x = 375;
}
}
if (e.KeyCode == Keys.Space)
{
if (y <= -530)
{
y = 0;
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
y -= 5;
Invalidate();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
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);
}
}
@GoliathForge, I seem to recall other people here trying to send Phil down the route of using a high precision timer. It didn't go well. To be bluntly honest, I don't know why people keep insisting on sending Phil down a path of greater complexity when clearly there's issues with simpler things.
@phil67rpg, to show a sprite for "a short period of time" you need to know when to start and stop displaying the sprite.
It looks like you already have a 2nd timer but I'm not 100% sure it's setup correctly. Assuming it is, you still need the event function for it. Add the following into your code.
private void timer2_Tick(object sender, EventArgs e)
{
}
Also change the timer interval to the following in your Form1_Load function
//Interval is in milliseconds. 1000 milliseconds = 1 second
timer2.Interval = 1000;
Now you have a timer that ticks every second. Add a global variable (maybe called totalSeconds) that increases by 1 when the tick function is called. When you have that working, you then have a way of seeing how many seconds have passed since your program has started.
When a collision occurs between a bullet and a bug, you could then have another variable (maybe called collidedAt) set to totalSeconds + 2000. When totalSeconds is more than collidedAt then stop painting your collision sprite.
It's not a perfect solution but it might help get an idea of what you can do with the timers.
Again, I'm not 100% sure you have Timer2 setup correctly. It would depend on how you added the additional timer control to your project.
Good luck.
1 hour ago, phil67rpg said:this post is for crazycdn
No, no it is not for me. I asked you to summarize what you learned from reading those links, not post your code that doesn't show anything timer related other then a generic timer function that does nothing timer related. As @GoliathForge stated, start a new thread. Stop posting all of your code and not asking any questions. Start showing what research you've conducted to solve your own problems. Start answering questions asked by those you seek help from. You've been asked and told to do this for about a decade now @phil67rpg and learning disability or not, it's not a tall order honestly. Try sticking with one project, not changing projects every couple weeks also.
"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin
LOL..oh my goodness. I think we're doing better. A little more every time. The question becomes, will we retain, refine and conform.
1, 2, 3..Not it.
Keep trying. If we just do it for you, it may actually be hurtful to the learning process. Best from us should be a second opinion or better approach. Unless that is what you need, how to structure or manage group boolean tests. I really don't know sorry. Your game is yours. Your world is yours.
I'd love to see you turn this around and start showing finished working blog announcements. Bug Splatter....
Dev careful. Pixel on board.