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.Windows.Forms;
- namespace Game_deel1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- bool hoogte = true;
- bool breedte = true;
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- this.Text = (e.KeyCode.ToString());
- int x = pbPlayer.Location.X;
- int y = pbPlayer.Location.Y;
- switch (e.KeyCode.ToString())
- {
- case "A":
- x -= 10;
- if (x < 0)
- {
- x = 0;
- }
- break;
- case "S":
- y += 10;
- if (y > 300 - pbPlayer.Height)
- {
- y = 300 - pbPlayer.Height;
- }
- break;
- case "D":
- x += 10;
- if (x > 600 - pbPlayer.Width - 16)
- {
- x = 600 - pbPlayer.Width - 16;
- }
- break;
- case "W":
- y -= 10;
- if (y < 0)
- {
- y = 0;
- }
- break;
- default:
- break;
- }
- pbPlayer.Location = new System.Drawing.Point(x, y);
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (breedte == true && hoogte == true)
- {
- pbBal.Location = new Point(pbBal.Location.X +1, pbBal.Location.Y +1);
- if (pbBal.Location.Y > 350 - pbBal.Height - 40)
- {
- hoogte = false;
- this.Text = "Dood";
- }
- if (pbBal.Location.X > 600 - pbBal.Width - 16)
- {
- breedte = false;
- }
- }
- if (breedte == true && hoogte == false)
- {
- pbBal.Location = new Point(pbBal.Location.X +1, pbBal.Location.Y -1);
- if (pbBal.Location.Y < 0)
- {
- hoogte = true;
- }
- if (pbBal.Location.X > 600 - pbBal.Width - 16)
- {
- breedte = false;
- }
- }
- if (breedte == false && hoogte == true)
- {
- pbBal.Location = new Point(pbBal.Location.X -1, pbBal.Location.Y +1);
- if (pbBal.Location.Y > 350 - pbBal.Height - 40)
- {
- hoogte = false;
- this.Text = "Dood";
- }
- if (pbBal.Location.X <0)
- {
- breedte = true;
- }
- }
- if (breedte == false && hoogte == false)
- {
- pbBal.Location = new Point(pbBal.Location.X -1, pbBal.Location.Y -1);
- if (pbBal.Location.Y < 0)
- {
- hoogte = true;
- }
- if (pbBal.Location.X < 0)
- {
- breedte = true;
- }
- }
- if ((pbBal.Location.Y + pbBal.Height == pbPlayer.Location.Y) &&
- (pbBal.Location.X + pbBal.Width > pbPlayer.Location.X) &&
- (pbBal.Location.X + pbBal.Width < pbPlayer.Location.X + pbPlayer.Width))
- {
- hoogte = false;
- }
- // if ()
- }
- }
- }
Add Comment
Please, Sign In to add comment