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 _3dEngine
- {
- public partial class Form1 : Form
- {
- public Point[] map = { new Point(-100, -100), new Point(-100, 100), new Point(-100, 100), new Point(100, 100),
- new Point(100, 100), new Point(100, -100), new Point(100, -100), new Point(-100, -100) };
- public Point playerPos = new Point(0, 0);
- public float playerAngle = 32;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- Point sc1 = new Point(400, 500);
- Padding pad = new Padding(10, 10, 10, 10);
- Pen bd = new Pen(Color.Blue, 3);
- Pen[] pens = { new Pen(Color.Blue), new Pen(Color.Red), new Pen(Color.YellowGreen), new Pen(Color.Turquoise) };
- int pi = 0;
- Graphics gr = e.Graphics;
- gr.DrawLine(bd, 0, 0, sc1.X, 0);
- gr.DrawLine(bd, sc1.X, 0, sc1.X, sc1.Y);
- gr.DrawLine(bd, sc1.X, sc1.Y, 0, sc1.Y);
- gr.DrawLine(bd, 0, sc1.Y, 0, 0);
- // basically just padding, centers the screen instead of it being to the top left.
- gr.TranslateTransform(sc1.X / 2, sc1.Y / 2);
- // draw player, note 0, 0 as the player is 'truly' static
- gr.DrawEllipse(new Pen(Color.Red), -5, -5, 10, 10);
- // translate the world around the player
- gr.TranslateTransform(playerPos.X, playerPos.Y);
- gr.RotateTransform(playerAngle);
- //draw the world
- for (int i = 0; i + 1 < map.Length; i += 2)
- {
- gr.DrawLine(pens[pi], map[i].X, map[i].Y, map[i + 1].X, map[i + 1].Y);
- pi++;
- pi %= pens.Length;
- }
- }
- private void Form1_KeyPress_1(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == 'q') { playerAngle--; }
- else if (e.KeyChar == 'e') { playerAngle++; }
- else if (e.KeyChar == 'w') { playerPos.Y--; }
- else if (e.KeyChar == 's') { playerPos.Y++; }
- else if (e.KeyChar == 'a') { playerPos.X--; }
- else if (e.KeyChar == 'd') { playerPos.X++; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement