Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11.  
  12. namespace _3dEngine
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Point[] map = { new Point(-100, -100), new Point(-100, 100), new Point(-100, 100), new Point(100, 100),
  17.             new Point(100, 100), new Point(100, -100), new Point(100, -100), new Point(-100, -100) };
  18.         public Point playerPos = new Point(0, 0);
  19.         public float playerAngle = 32;
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void Form1_Load(object sender, EventArgs e)
  26.         {
  27.  
  28.         }
  29.  
  30.         private void Form1_Paint(object sender, PaintEventArgs e)
  31.         {
  32.             Point sc1 = new Point(400, 500);
  33.             Padding pad = new Padding(10, 10, 10, 10);
  34.             Pen bd = new Pen(Color.Blue, 3);
  35.             Pen[] pens = { new Pen(Color.Blue), new Pen(Color.Red), new Pen(Color.YellowGreen), new Pen(Color.Turquoise) };
  36.             int pi = 0;
  37.             Graphics gr = e.Graphics;
  38.  
  39.             gr.DrawLine(bd, 0, 0, sc1.X, 0);
  40.             gr.DrawLine(bd, sc1.X, 0, sc1.X, sc1.Y);
  41.             gr.DrawLine(bd, sc1.X, sc1.Y, 0, sc1.Y);
  42.             gr.DrawLine(bd, 0, sc1.Y, 0, 0);
  43.  
  44.             // basically just padding, centers the screen instead of it being to the top left.
  45.             gr.TranslateTransform(sc1.X / 2, sc1.Y / 2);
  46.  
  47.             // draw player, note 0, 0 as the player is 'truly' static
  48.             gr.DrawEllipse(new Pen(Color.Red), -5, -5, 10, 10);
  49.  
  50.             // translate the world around the player
  51.             gr.TranslateTransform(playerPos.X, playerPos.Y);
  52.             gr.RotateTransform(playerAngle);
  53.  
  54.             //draw the world
  55.             for (int i = 0; i + 1 < map.Length; i += 2)
  56.             {
  57.                 gr.DrawLine(pens[pi], map[i].X, map[i].Y, map[i + 1].X, map[i + 1].Y);
  58.                 pi++;
  59.                 pi %= pens.Length;
  60.             }
  61.         }
  62.  
  63.         private void Form1_KeyPress_1(object sender, KeyPressEventArgs e)
  64.         {
  65.             if (e.KeyChar == 'q') { playerAngle--; }
  66.             else if (e.KeyChar == 'e') { playerAngle++; }
  67.             else if (e.KeyChar == 'w') { playerPos.Y--; }
  68.             else if (e.KeyChar == 's') { playerPos.Y++; }
  69.             else if (e.KeyChar == 'a') { playerPos.X--; }
  70.             else if (e.KeyChar == 'd') { playerPos.X++; }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement