Prikaz jedne poruke
Stara 15.6.2015, 13:07   #1
Borisav Živanović
Član
 
Član od: 11.5.2014.
Lokacija: Grocka
Poruke: 40
Zahvalnice: 12
Zahvaljeno 5 puta na 4 poruka
Slanje poruke preko Skypea korisniku Borisav Živanović
Određen forumom Objekat ubrzava umesto da se kreće stalnom brzinom

Pozdrav! Počeo sam da pravim jednostavnu igru u C#. Kockice se random pojavljuju na ekranu i vi trebate da ih upucate. Još nisam ni stigao do dela sa upucavanjem i skorom zato što je baklja koju ispaljuje igrač svaki put sve brža i brža (sve dok ne dostigne brzinu svetlosti). Evo koda:
Kod:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Begaj
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Cursor.Hide();
            FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            TopMost = true;
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A)
            {
                pictureBox1.Location = new Point(pictureBox1.Location.X - 5, pictureBox1.Location.Y);
            }
            if (e.KeyCode == Keys.S)
            {
                pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + 5);
            }
            if (e.KeyCode == Keys.D)
            {
                pictureBox1.Location = new Point(pictureBox1.Location.X + 5, pictureBox1.Location.Y);
            }
            if (e.KeyCode == Keys.W)
            {
                pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 5);   
            }
        }
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                const string message = "OCES DIZADJES";
                const string caption = "IZLAZ";
                var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    Application.Exit();
                }
            }
            if (e.KeyCode == Keys.Space)
            {
                pictureBox7.Visible = true;
                Timer tajmer = new Timer();
                pictureBox7.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 30);
                tajmer.Interval = 100;
                tajmer.Tick += new EventHandler(tajmer_Tick);
                tajmer.Start();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           pictureBox2.Location = new Point((int)(new Random().Next(0, 1000)), (int)(new Random().Next(0, 600)));
           pictureBox3.Location = new Point((int)(new Random().Next(0, 600)), (int)(new Random().Next(0, 100)));
           pictureBox4.Location = new Point((int)(new Random().Next(0, 100)), (int)(new Random().Next(0, 60)));
           pictureBox5.Location = new Point((int)(new Random().Next(0, 1300)), (int)(new Random().Next(0, 500)));
           pictureBox6.Location = new Point((int)(new Random().Next(0, 400)), (int)(new Random().Next(0, 780)));
        }
        private void tajmer_Tick(object sender, EventArgs e)
        {
            pictureBox7.Location = new Point(pictureBox7.Location.X, pictureBox7.Location.Y - 30);
        }
    }
    public static class GlobalVariables
    {
        public static int a = 0;
    }
}
Borisav Živanović je offline   Odgovor sa citatom ove poruke