Aaron Raine

Aaron Raine

  • NA
  • 2
  • 2.2k

make my goblin appear and move after 5 seconds

Apr 25 2014 5:19 PM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Bounce
{
public partial class Form1 : Form
{

int horiz, vert, step;

public Form1()
{
InitializeComponent();
}

private void timer1_Tick_1(object sender, EventArgs e)
{
//image is moved at each interval of the timer

goblin.Left = goblin.Left + (horiz * step);
goblin.Top = goblin.Top + (vert * step);


// if goblin has hit the RHS edge, if so change direction left
 
if ((goblin.Left + goblin.Width) >= (Form1.ActiveForm.Width - step))
horiz = -1;

// if goblin has hit the LHS edge, if so change direction right
 
if (goblin.Left <= step)
horiz = 1;

// if goblin has hit the bottom edge, if so change direction upwards
 
if ((goblin.Top + goblin.Height) >= (Form1.ActiveForm.Height - step))
vert = -1;

// if goblin has hit the top edge, if so change direction downwards
 
if (goblin.Top < step)
vert = 1;
}


private void Form1_Load_1(object sender, EventArgs e)
{
//Soon as the forms loads activate the goblin to start moving
//set the intial direction
 
horiz = 1; //start going right
vert = 1; //start going down
step = 5;
timer1.Enabled = true;

}

}
}

Please someone tell me how i would get this goblin to appear after 5 seconds and move around the screen instead of it already being there and already bouncing around the screen.

Answers (1)