It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

By Guy W. Lecky-Thompson
Gamasutra
September 17, 1999

Letters to the Editor:
Write a letter
View all letters


Features

Contents

Introduction

Predictably Random Numbers

Name Generation Techniques

Generating Random Terrain

Plot Sequencing

Code Listings

Listing 1

Listing 2

Listing 3

Listing 4

Listing 5

Listing 3:
Unigen.cpp

// Class Implementation File for the Universe Class

// (c) 1999 Guy W. Lecky-Thompson

// All Rights Reserved

Universe::Universe(unsigned long ulXDimension,

unsigned long ulYDimension)

{

// Set the parameters for this universe

this->ulXDimension = ulXDimension;

this->ulYDimension = ulYDimension;

// Initialise the randomizer

this->prRandomizer = new PseudoRandomizer(ulXDimension,

ulYDimension,

ulXDimension * ulYDimension);

}

int Universe::StarAt(unsigned long ulXPosition,

unsigned long ulYPosition,

unsigned long ulSerialNumber)

{

unsigned long ulRandomValue;

// Set up the serial number for this grid reference

ulSerialNumber = ((ulYPosition + 1) * this->ulXDimension) + ulXPosition);

for (unsigned long ulCounter = 0; ulCounter < ulSerialNumber; ulCounter++)

{

ulRandomValue = this->prRandomizer->PseudoRandom();

}

// If ulRandomValue falls in the lower 1%, there is a star here

if (ulRandomValue <= ((this->ulXDimension * this->ulYDimension) / 100))

return 1;

return 0;

}

Unigen.h

// Class Header File for the Universe Class

// (c) 1999 Guy W. Lecky-Thompson

// All Rights Reserved

#include "prand.h" // The Class Definition for the random number generation

class Universe

{

private:

unsigned long ulXDimension, ulYDimension; // The 'size' of the Universe

unsigned long ulUniverseSerialNumber;

PseudoRandomizer * prRandomizer;

public:

Universe(unsigned long ulXDimension,

unsigned long ulYDimension);

int StarAt(unsigned long ulXPosition,

unsigned long ulYPosition,

unsigned long ulSerialNumber);

};


 

Listing 4


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service