Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- bool right;
- bool left;
- bool up;
- bool down;
- bool fire;
- public Form1()
- {
- InitializeComponent();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- /* move */
- if (right == true) { player.Left += 5; }
- if (left == true) { player.Left -= 5; }
- if (up == true) { player.Top -= 5; }
- if (down == true) { player.Top += 5; }
- /* boards */
- if (player.Top + player.Height >= screen.Height) { player.Top = screen.Height - player.Height; }
- if (player.Top <= 0) { player.Top = 0; }
- if (player.Width + player.Left >= screen.Width) { player.Left = screen.Width - player.Width; }
- if (player.Left <= 0) { player.Left = 0; }
- /* fire*/
- if (fire == true)
- {
- bullet1.Location = new Point(player.Location.X + 18, player.Location.Y - 10);
- bullet1.Visible = true;
- int i = 0;
- do
- {
- bullet1.Top -= 1;
- i++;
- System.Threading.Thread.Sleep(1);
- } while (i < 400);
- }
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Right) { right = true; }
- if (e.KeyCode == Keys.Left) { left = true; }
- if (e.KeyCode == Keys.Up) { up = true; }
- if (e.KeyCode == Keys.Down) { down = true; }
- //move
- /* fire*/
- if (e.KeyCode == Keys.Z) { fire = true; }
- }
- private void Form1_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Right) { right = false; }
- if (e.KeyCode == Keys.Left) { left = false; }
- if (e.KeyCode == Keys.Up) { up = false; }
- if (e.KeyCode == Keys.Down) { down = false; }
- //move
- /* fire*/
- if (e.KeyCode == Keys.Z) { fire = false; }
- }
- private void screen_Paint(object sender, PaintEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement