C# example to load Doom WAD file

using System;
using System.IO;
namespace waddy
{
class Program
{
static string GetString(byte[] arr)
{
return System.Text.ASCIIEncoding.ASCII.GetString(arr);
}
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
if (File.Exists("DOOM.WAD"))
{
using (BinaryReader reader = new BinaryReader(File.Open("DOOM.WAD", FileMode.Open)))
{
string name = GetString(reader.ReadBytes(4));
int numberOfLumps = reader.ReadInt32();
int folderPosition = reader.ReadInt32();
reader.BaseStream.Seek(folderPosition, SeekOrigin.Begin);
Console.WriteLine(name);
Console.WriteLine("Contains " + numberOfLumps + " lumps");
int count = 0;
while (reader.BaseStream.Position < reader.BaseStream.Length)
{
reader.BaseStream.Seek(folderPosition + (16 * count), SeekOrigin.Begin);
int filePos = reader.ReadInt32();
int fileSize = reader.ReadInt32();
string lumpName = GetString(reader.ReadBytes(8));
//Console.WriteLine("Next lump pos is " + filePos);
//Console.WriteLine("Next lump size is " + fileSize);
Console.WriteLine("Next lump name is " + lumpName);
//reader.BaseStream.Seek(filePos + 12, SeekOrigin.Begin);
count++;
}
}
}
}
}
}
view raw WadReader.cs hosted with ❤ by GitHub

Example of bouncing ball

var gameScreen = document.getElementById("gameScreen");
var context = gameScreen.getContext("2d");
context.fillStyle = "#FFFFFF";
context.font = "8px Sans-Serif";
context.fillText("Pong!", 10, 10);
var ball = {
x : 50,
y : 50,
width : 5,
height : 5,
x_direction : 1,
y_direction : 1
};
var previousBall = ball;
var boundary = {
x1: 20,
x2: 200,
y1: 20,
y2: 120
};
context.fillStyle = "#FF00FF";
context.strokeStyle = "#FF00FF";
context.strokeRect(boundary.x1, boundary.y1, boundary.x2 boundary.x1, boundary.y2 boundary.y1);
var timer = setInterval(updateGameScreen, 10);
function updateGameScreen() {
context.clearRect(previousBall.x, previousBall.y, previousBall.width, previousBall.height);
previousBall = ball;
if (ball.x_direction === 1) {
ball.x += 2;
if (ball.x_direction === 1 && ball.x > boundary.x2 10) {
ball.x_direction = 1;
}
}
if (ball.x_direction === 1){
ball.x -= 2;
if (ball.x_direction === 1 && ball.x < boundary.x1 + 10) {
ball.x_direction = 1;
}
}
if (ball.y_direction === 1) {
ball.y++;
if (ball.y_direction === 1 && ball.y > boundary.y2 7) {
ball.y_direction = 1;
}
}
if (ball.y_direction === 1){
ball.y;
if (ball.y_direction === 1 && ball.y < boundary.y1 + 7) {
ball.y_direction = 1;
}
}
context.fillRect(ball.x, ball.y, ball.width, ball.height);
}