Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Tetra

Pages: [1] 2
Challenges & Competitions / [2BUTTON] - Earthbound
« on: January 29, 2008 »
Heres a game I managed to finally rush together  ;D

Its not complete, and is missing the part where you actually get to earth and fly through the atmosphere ;D

So I just made it into a simpler point system game. There is no interface or options. Just use up and down arrow.

Sorry about the big download, but I made it in blitz because I didnt have time to implement it in ogl using FB as I originally intended.

I only got as much as a starfield in this unfortunately, I wanted to make some fire effect too for the atmosphere stuff, but didnt have time.

Source / Exe : Download

Post your scores!

Java,JS & Flash / Flash - 3D Test
« on: July 21, 2007 »
I've been looking at some ActionScript programming recently, having wanting to make a simple 3D app viewable on the web.

Initially it confused the hell out of me, but eventually I got to understand how it works, and itas actually really cool ;D

What makes it cool is its ability to draw things in a really nice way and it takes care of a lot of things. These include app timing, antialiazing, ability to draw complex polygons, and then being able to color them in in various ways and draw outlines and alpha blend everything, even blen them in different ways. Its all object orientated too.

But I must say it quite a strange the way everything is connected / related, and how you create Object() and its variables. Once you get round that the potential for this language hits you, especially when u get your first app working :)

Heres a simple spinning cube. Just press and hold the left mouse button to rotate. I've included the source code for those who are interested, ans if you have any questions about it or wanted to try stuff out but some things confuse you ask here i'm sure I'll be able to help. I'm no expert, but i've tackled the hardest part of learning the relationships of variables and layers. The swf file you should be able to double click and if you got flash 8 installed it will run. The swf file is only 1.6kb :D

Lets get this compo off to a start :)

While watching a winamp plugin I was awed by the effects and shear speed, so I thought, hmm maybe blitz3D can do something similar at highres. Although it didnt quite workout as I intended, its turned out ok, and I'll probably have a go at making my original intention soon.

Its a simple program and the sourcecode is included, along with a png of the
as a long strip 242x95x(8 frames) with the mask FF00FF for transparency.;dl=item57

Freebasic / Floor Ceil ?
« on: June 03, 2007 »
I cant seem to find the functions to do this.

Could someone tell me how to floor and ceil in FB pls?

I've been working ma ass off on this project!

But its not quite finished, but I'll enter as it is. Theres no music, and a couple other stuff.

Instead of trying to make one of the following, I decided to make a compilation and my own take on them.

Its my first c++ app, an the first time I've used the engine I developed in blitz.
I've included the source as download too. But its not in a project, as soon as i can figure how to make it work in a new solution for VC i'll add that too, but all the code it there.

The engine is really ineficient and is all double based, and the code is fairly messy and uncomented, but it shows how far i've gotten with c++ :)

Hope you like it!

Updated the app, it was crashing, sorry about that.


I've updated the exe to a more finished state, still got no music though.;topic=1915.0;attach=1638

Wondered if anyone has come across this problem before.

I'm using matricies for rotating meshes and the camera in my engine. Yaw and Pitch work great, but when I try to roll the camera, it rolls along the x axis and is locked to that axis whatever the pitch and yaw is. Added to this, if I roll a mesh say to 45deg when I then move that mesh along the Z axis it moves up and down in a sin fashion along the y axis.

I've recalculated the matrix from the 3 basic rotation matricies for xyz incase I got it wrong so long ago, but it does exactly the same.

And to roll the camera, going along the z axiz is fine, but then trifing the camera laft and right gets screwed up.

Code: [Select]
Sin->x = sin( rotation->x );
Sin->y = sin( rotation->y );
Sin->z = sin( rotation->z );

Cos->x = cos( rotation->x );
Cos->y = cos( rotation->y );
Cos->z = cos( rotation->z );

rMatrix[0] =   Cos->y *  Cos->z;
rMatrix[1] =  -Sin->x * -Sin->y *  Cos->z + Cos->x * Sin->z;
rMatrix[2] =   Cos->x * -Sin->y *  Cos->z + Sin->x * Sin->z;

rMatrix[3] =   Cos->y * -Sin->z;
rMatrix[4] =  -Sin->x * -Sin->y * -Sin->z + Cos->x * Cos->z;
rMatrix[5] =   Cos->x * -Sin->y * -Sin->z + Sin->x * Cos->z;

rMatrix[6] =   Sin->y;
rMatrix[7] =  -Sin->x *  Cos->y;
rMatrix[8] =   Cos->x *  Cos->y;

any ideas?

C / C++ /C# / Pointer to an array of pointers :S
« on: April 19, 2007 »
I'm trying to effectively make a dynamically resizable array of pointers. But I think i'm being silly.

My problem is i'm not sure how to write it out.

Code: [Select]
typedef struct
double x,y,z;
} Vertex3D;

typedef struct
Vertex3D *v0;
Vertex3D *v1;
Vertex3D *v2;

unsigned int color;
float alpha;
bool use_alpha;

} TTriangle;

class mesh

void addVertex( Vertex3D *Vertex );



these are my basic structures. What I want to do is define an empty variable thats a pointer to an array of pointers. then, as I add verticies, I want to create a new array of pointers, copy the old pointers into the new array, add the new pointer to the end, delete the old array then update the array pointer to point to the new array of pointers.

The array of pointers would point to different verticies. So something along the lines of: -

int *VerticiesArrayPointer; // pointers to arrays are ints?

int *Verticies[vertexCount] = malloc(sizof(int)*vertexCount); // I dont know how to do this?

copy  &VerticiesArrayPointer to Verticies; // copy old array of pointers to new array of pointers
delete *VerticiesArrayPointer; // free old array of pointers memory
Verticies[vertexCount] = *newVertex; // add the new Vertex3D pointer to the end of the new array of pointers
*VerticiesArrayPointer = *Verticies; // set the pointer to the array to the new array

but I dont know how to do any of the above, or even what to search for on how to do it. I dont even know if thats just dumb :S

The reason I want to do it this way is because I dont know how big the array of verticies is going to be. Should I scrap this idea and just create a large array and not worry about memory usage?

Thnx for any help or direction.

I noticed that creating a window with CreateWindowEx, the width and height you specify is infact the actual window width and height. That means that the actual drawing area is the width and height minus the title bar height and border of the application.

So i tired to measure the border and title bar and add it to the width and height, but it didnt work :(

Is there any way to make it so that the width and height you specify is the actual drawing area?

C / C++ /C# / Dont leave me behind :P
« on: March 28, 2007 »
So a lot have been playing about with c++ and I thought its about time I have a go too  ;D

Thanx to Jims framework, and Stonemonkeys SetDIBitsToDevice method i've managed to make a simple app.

All its does is draw triangles onto the screen. But more so i've been messing with pointers and arrays.

I've no idea if what i've done is the best or most efficient way of doing things, so please cricise it   :||

This seems overall pretty slow to me (on my computer), is that because its all cpu based?

Anyhow all suggestions and corrections would be much appreciated  :cheers:

exe and code

Code: [Select]

#include <windows.h>

#include <stdlib.h>
#include <stdio.h>

#include <time.h>
#include <math.h>

Buffered window stuff

typedef struct{
HWND window;
unsigned int width,height;
unsigned int bufferSize;
unsigned int *argb;

int quit = FALSE;

void createBufferedWindow( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow, int width, int height, TCHAR title[] );
void cleanGarbage();
void render();

bufferedWindow* buffWindow;

const int GFX_Width = 640;
const int GFX_Height = 480;

int FPS;
int FPScnt;
int ttime;


Vertex Triangle defs and globals

typedef struct{
int x,y;

typedef struct{
T2DVertex *v0;
T2DVertex *v1;
T2DVertex *v2;
unsigned int color;

// Vertex array
T2DVertex *baseVertex = NULL;
int vertexCount = 0;

// Triangle array
TTriangle *baseTriangle = NULL;
int triangleCount = 0;

// Triangle fill edge temps
int Edge[GFX_Height][2];

void processEdge( T2DVertex *v0, T2DVertex *v1 );

T2DVertex &newVertex( int x, int y );
TTriangle &newTriangle( T2DVertex *v0, T2DVertex *v1, T2DVertex *v2, unsigned int color );
void createTriangle( int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color );
void initObject();
void renderTriangle();

void drawScanLine( int x1, int x2, int y, unsigned int color );
void drawLine( int x1, int y1, int x2, int y2, unsigned int color );


switch (uMsg)
case WM_PAINT:
PAINTSTRUCT paint={0};
paint.hdc = (HDC)wParam;
GetUpdateRect(hwnd, &paint.rcPaint,TRUE);
BeginPaint(hwnd, &paint);
EndPaint(hwnd, &paint);

quit = TRUE;

// Get keystrokes sent to the app
switch (wParam)
quit = TRUE;

default : break;
default : return DefWindowProc(hwnd, uMsg, wParam, lParam);
return 0;

void createBufferedWindow(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow, int width, int height, TCHAR title[] )
buffWindow = (bufferedWindow*)malloc( sizeof(bufferedWindow) );

buffWindow->width = width;
buffWindow->height = height;
buffWindow->bufferSize = width * height * sizeof(unsigned int);
buffWindow->argb = (unsigned int*)malloc( sizeof(unsigned int) * width * height );

buffWindow->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
buffWindow->bmi.bmiHeader.biWidth = width;
buffWindow->bmi.bmiHeader.biHeight = -height; // Make the buffer upright
buffWindow->bmi.bmiHeader.biPlanes = 1;
buffWindow->bmi.bmiHeader.biBitCount = 32;
buffWindow->bmi.bmiHeader.biCompression = BI_RGB;
buffWindow->bmi.bmiHeader.biSizeImage = 0;
buffWindow->bmi.bmiHeader.biXPelsPerMeter = 72;
buffWindow->bmi.bmiHeader.biYPelsPerMeter = 72;
buffWindow->bmi.bmiHeader.biClrUsed = 0;
buffWindow->bmi.bmiHeader.biClrImportant = 0;


TCHAR graphics_class[] = "gfxClass";
clas.cbSize = sizeof(WNDCLASSEX); = CS_HREDRAW | CS_VREDRAW;
clas.lpfnWndProc = WindowProc;
clas.cbClsExtra = 0;
clas.cbWndExtra = 0;
clas.hInstance = hInstance;
clas.hIcon = NULL;
clas.hCursor = NULL;
clas.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
clas.lpszMenuName = NULL;
clas.lpszClassName = graphics_class;
clas.hIconSm = 0;

RECT rect={0,0,width,height};
AdjustWindowRectEx(&rect, style, FALSE, WS_EX_TOPMOST);
buffWindow->window = CreateWindowEx(0, graphics_class, title, style, CW_USEDEFAULT, CW_USEDEFAULT, rect.right-rect.left,, NULL, NULL, hInstance, 0);

ShowWindow( buffWindow->window, nCmdShow );
UpdateWindow( buffWindow->window );

void cleanGarbage()
free( buffWindow->argb );
free( buffWindow );
free( baseVertex );
free( baseTriangle );

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
MSG msg;

createBufferedWindow( hInstance,hPrevInstance,lpCmdLine,nCmdShow,GFX_Width,GFX_Height,"First Basic Cpp");


HDC hdc;
int time = GetTickCount();;

while (!quit)
while (PeekMessage(&msg, buffWindow->window, 0, 0, PM_NOREMOVE))
if ( !GetMessage(&msg, buffWindow->window, 0, 0) )

// Draw stuff to the screen buffer

// Draw the buffer to screen
hdc = GetDC( buffWindow->window );
SetDIBitsToDevice(hdc, 0,0, buffWindow->width,buffWindow->height, 0,0, 0,buffWindow->height, buffWindow->argb, &buffWindow->bmi,  DIB_RGB_COLORS);
ReleaseDC( buffWindow->window, hdc );

// FPS stuff
ttime += GetTickCount() - time;
time = GetTickCount();

if ( ttime >= 1000 )
FPS = FPScnt;
FPScnt = 0;
ttime = 0;
char cbuffer[20];
int cbsize = sprintf_s( cbuffer, "FPS: %i", FPS );
SetWindowText( buffWindow->window, (LPCSTR)cbuffer );


return 0;

void render()
memset(buffWindow->argb, 0x000000, buffWindow->bufferSize );

void drawScanLine( int x1, int x2, int y, unsigned int color )
y = buffWindow->width * y;

for ( int x=x1; x<x2; x++ )
*(buffWindow->argb+x+y) = color;

void drawLine( int x1, int y1, int x2, int y2, unsigned int color )
float dx;
float dy;
int len;
int xLen;
int yLen;

xLen = x2 - x1;
yLen = y2 - y1;

len = (int)ceil( sqrt( (double)(xLen * xLen + yLen * yLen) ) );

dx = (float)xLen / (float)len;
dy = (float)yLen / (float)len;

for ( int i=0; i<len; i++ )
*(buffWindow->argb+x1+(int)(i*dx)+buffWindow->width*(y1+(int)( i * dy ))) = color;

void processEdge( T2DVertex *v0, T2DVertex *v1 )
int yLen;
int xRat;
int dx;

if ( v0->y < v1->y )
yLen = v1->y - v0->y;
xRat = (( v1->x - v0->x ) << 8) / yLen;
dx = v0->x << 8;

for ( int y=(v0->y); y<=(v1->y); y++ )
Edge[y][1] = dx >> 8;
dx += xRat;
yLen = v0->y - v1->y;
xRat = (( v0->x - v1->x ) << 8) / yLen;
dx = v1->x << 8;

for ( int y=(v1->y); y<=(v0->y); y++ )
Edge[y][0] = dx >> 8;
dx += xRat;

int minimum( int a, int b, int c )
int min = a;
if (b<a) min = b;
if (c<a) min = c;
return min;

int maximum( int a, int b, int c )
int max = a;
if (b>a) max = b;
if (c>a) max = c;
return max;

void renderTriangle()
memset( Edge, 0, sizeof( Edge ) );

int yMin;
int yMax;

for ( int i=0; i<triangleCount; i++ )
processEdge( baseTriangle[i].v0, baseTriangle[i].v1 );
processEdge( baseTriangle[i].v1, baseTriangle[i].v2 );
processEdge( baseTriangle[i].v2, baseTriangle[i].v0 );

yMin = minimum( baseTriangle[i].v0->y, baseTriangle[i].v1->y, baseTriangle[i].v2->y );
yMax = maximum( baseTriangle[i].v0->y, baseTriangle[i].v1->y, baseTriangle[i].v2->y );

for ( int y=yMin; y<=yMax; y++ )
drawScanLine( Edge[y][0], Edge[y][1], y, baseTriangle[i].color );

T2DVertex &newVertex( int x, int y )
T2DVertex *Vertex = (T2DVertex*)malloc(sizeof(T2DVertex));

Vertex->x = x;
Vertex->y = y;

return *Vertex;

TTriangle &newTriangle( T2DVertex *v0, T2DVertex *v1, T2DVertex *v2, unsigned int color )
TTriangle *Triangle = (TTriangle*)malloc(sizeof(TTriangle));

Triangle->v0 = v0;
Triangle->v1 = v1;
Triangle->v2 = v2;
Triangle->color = color;

return *Triangle;

void createTriangle( int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color  )
int v0 = vertexCount;
int v1 = v0 + 1;
int v2 = v1 + 1;

baseVertex[v0] = newVertex( x0, y0 );
baseVertex[v1] = newVertex( x1, y1 );
baseVertex[v2] = newVertex( x2, y2 );

baseTriangle[triangleCount] = newTriangle( &baseVertex[v0],&baseVertex[v1],&baseVertex[v2], color );


void initObject()
baseVertex = new T2DVertex[ 9 ];
baseTriangle = new TTriangle[ 3 ];

createTriangle(  50,170, 160, 80, 250,210, 0xFF0000 );
createTriangle( 315,255, 575,340, 200,380, 0x00FF00 );
createTriangle( 330, 60, 580,120, 360,180, 0x0000FF );

Useful links / What a gorgeous looking game!
« on: March 15, 2007 »

This is really amazing to watch, really really nice looking game.

Because I couldnt get my head around the rigid body stuff, I decided to make a game for the compo!

The game is simple, kill as many ufos as you can in 20s
All you need to so is use the mouse to aim, and click to fire.
Its not as easy as it seams because you dont get a crosshair!

The game will output your score to the Score.txt file.
It will keep adding to this file the more times you play.

Your score is based on the number of kills and efficiency.
Your efficiency is based on the number of kills vs shoots fired.

Heres a sample of a bad score :P

--------------------- 13 Mar 2007 - 05:48:43
Ships Killed : 12
Shoots Fired : 20
  Efficiency : 60.0%
       Score : 1800

I wanted to spend more time on it but i've already spent pretty much the best part of 20hrs so I will leave as is for now. I want to make the explosions nicer, but mite do that again after some sleep X-)

I havent supplied the code this time because it looks worse than my bedroom ^^ but if someone really wants it or want to know about anything in it just let me know and I'll either clean it up or post the relevant stuff.

Hope you enjoy it.


General coding questions / More Physics
« on: March 12, 2007 »
I just cant get my head round the maths behind the rigid body, i'm just too thick when it somes to math and math symbols. Wonder if someone could perhaps explain or show me what it means cos I dont have a clue.

I'll start by explaining what I done so far and post some links to the definations, and then if someone wouldnt mind telling me how badly I done :D

These are the links i've been looking at:-

Rigid body dynamics

I have absolutely no idea what I am doing, I dont understand the equations for Rigid body dynamics at all.

Here is some code, i've cut it down to simplify it, if I ever get it working i'll post the full code to it.

Square\dx# and Square\dy# is the velocity vector ( from the center of the square )
Square\odx# and Square\ody# is the previous velocity vector ( from the center of the square )

Code: [Select]

; Assuming a collision is detected do the following
; fyi all the vectors origin is at the center of the square
; Square\timePassed# = Milliseconds passed so divide with 1000 to convert to seconds

; Force = Mass * Acceleration
; Acceleration is the rate of change in velocity over time  a = v/t
Square\velocity# = VectorLength#( Square\dx# - Square\odx#, Square\dy# - Square\ody# )
Square\acceleration# = Square\velocity# / ( Square\timePassed# / 1000.0 )
Square\force# = Square\mass# * Square\acceleration#

; Angle between the velocity vector and point of impact vector
angle# = -getAngle( impactX#,impactY#, Square\dx#, Square\dy#, 0,0 )

; torque = distance to center * Force * sin( angle )
distance# = VectorLength#( impactX#, impactY# )
Square\torque# = Square\force# * distance# * Sin( angle# )

; Convert torque to angular velocity
Dunno how to do this

; Returns the length of a 2d vector
Function VectorLength#( x#,y# )

Return Sqr#( x# * x# + y# * y# )

End Function

; gets the angle between two vectors
; x1,y1 vector 1, x2,y2 vector 2, ox,oy origin
Function getAngle#( x1#,y1#, x2#,y2#, ox# = 0,oy# = 0 )

Local tvAx# = x1# - ox#
Local tvAY# = y1# - oy#

Local tvBx# = x2# - ox#
Local tvBY# = y2# - oy#

Local d# = ATan2#( tvAy#, tvAx# )

Local tvCx# =  Cos#( d# ) * tvBx# + Sin#( d# ) * tvBy#
Local tvCy# = -Sin#( d# ) * tvBx# + Cos#( d# ) * tvBy#

Local newAngle# = ATan2#( tvCy#, tvCx# )

If ( newAngle# > 0.0 )
newAngle# = -(180.0 - newAngle#)
newAngle# = -(-180.0 - newAngle#)

Return newAngle#

End Function

Some insight would be much appreciated :)

General coding questions / Gravity
« on: March 11, 2007 »
I know this may seem like  silly question, but I can seem to get it right and wondered if anyone could make it cleare to me.

I know that on earth that gravity has an effect on an object close to the surface at about 9.807m/s2

In terms of actually applying gravity on something what does that mean, that every second that passes the falling object has gained the speed of 9.807 every second?

It seems pretty insane if an object is travelling at 220miles an hour (98.07m/s) just after 10s of free fall if there was no air resistance.

That can only lead me to beleive I just dont get it :D I've forgotten all that I did at school, so if anyone would be able to remind me of the correct way to do it that would be great :)

Projects / Rigid Body Experiment
« on: March 09, 2007 »
I got a new :inspired: for the 20s Compo.

Without giving anything away I thought i'd give out a taser. I actually quite enjoyed throwing this square about and thought some my appreciate the same I did.

I've spent the whole day looking at different explinations, all unfortunately math heavy, which i'm not to great on. So I gave up a drew a picture of the problem and came up with this.
Its a bit buggy at the moment and the box seems to have an amazing ability to balance its self on its edge. But I think this is mainly down to the collision detection as I havent yet interpolated ( is that a word :? ) one frame to another to detect the actual time of collision. Also my torque calculations are not entierly exactly what they shuold be. But that doesnt matter :)

My final release will have the full sorce included but for now here an exe


Challenges & Competitions / 20SECONDS - 20sTimer
« on: March 06, 2007 »
Heres my first entry for the 20SECONDS compo!

Its written in Blitz3D and using blitz own collision system. Its a bit slow, and will take longer than 20 seconds on any PC thats older than mine ( 6 years :P )

I mite have a go at making my own collision system for it, so I can have more sand particles! and have it last 20s on any system :)

Its not a great simulation, and some of the collisions and accel is wrong, but it achive the effect :)

A zip file of the models and code is available for download, you will need the models to run the code.

the compiled exe is available here Download

Here is my entry for the comp :D

Its based on Logo with a few extra commands to make it easier to animate.

Read the readme for details on how to make you own scripts!

Not much happens because the script took a long time to write, but its is something different :)

Exe and source code included:


General chat / Happy belated Birthday Shockwave
« on: November 01, 2006 »
Sorry I didnt post any sooner  :whack:

Happy Birthday m8 :)

Hope you had a good one and a merry old time


Challenges & Competitions / CCC: Gloom
« on: November 01, 2006 »
Well I started this on the 29th! but I didnt manage to finish it in time.

That was the soonest I could get anything together :(

Anyhow, I'll enter what i've done so far. I decided to make it in Blitz3D. Its a little enviroment that has some sites to see. Unfortunately none of the sites are complete. The idea was that you would visit each site in turn, and hopefully something would happen to make you jump or scream mwahahaha. but I didnt get that far :D It has a heart rate monitor that would have beat faster as you got close to something scary, but it just beat normally, you can pretend it works and scroll the middle mouse button :D

What I have done is create a dark gloomy enviroment, with a bit of sound, with a few models and some lightning.

Just follow the path down the hill, if u get lost hold down the E key and jet pack up in the air and move about as normal. Theres not much to see, and the gave has an open end. but theres a few lightning triggers in there and a bell trigger for the church bell.


   Move - Forward├é  W / Backward S
   Strife - Left A / Right D
   Look About - Mouse

Please read the readme for extra controls

It was going to be something out of the norm in that it would have been an interactive 3D enviroment demo, hope you can see the direction I was going with it.

General chat / Happy Birthday Clanky!
« on: September 25, 2006 »
Happy Birthday


Blitz / BlitzBasic - Raycaster[BB2D]
« on: September 24, 2006 »
Was revisiting some old snes games and came ascross Jurassic Park. When you go inside you got a Doom style raycasted enviroment, and I wanted to reproduce it.

So heres my first attempt, it looks ok, but there are a few bugs in it. Also its not the best way to do it, its very inaccurate and expensive, but the basic idea is there.

Next step will be to introduce textures.

Use arrow keys to move about and space bar to show the map and your position. Exe and code available as a download.

Code: [Select]
; Raycaster
; Created on the 24 Spetember 2006
; an attempt by Tetra

AppTitle "Raycaster v0.1"


Global XRES = 640
Global YRES = 480

Global        FOV = 90
Global  half_FOV# = Float(FOV) / 2.0
Global delta_FOV# = Float(FOV) / Float(XRES)

Dim level(64,64)

Global PlayerX# = 60
Global PlayerY# = 60
Global PlayerA# = 220

Global PlayerDX# =  0
Global PlayerDY# =  0

Global Background

Global Timer

Function Initialize()

Restore .levelData

For y = 0 To 63
For x = 0 To 63
Read level( x,y )


Timer = CreateTimer( 60 )

End Function

Function CreateBackground()

Local c
Local y

Background = CreateImage( 640,480 )
SetBuffer( ImageBuffer( Background ) )

For y = 0 To 150
c = ( 150 - y ) * ( 255.0 / 158.0 )
Color c,c,c
Rect 0,y,640,1

Rect 0,479 - y ,640,1

End Function

Function Render()

Local dx#
Local dy#

Local currA# = PlayerA# - half_FOV#

Local cx#
Local cy#

Local dist#

Local hit = False

For x = 0 To 639

dx# = Cos#( currA# ) / 50.0
dy# = Sin#( currA# ) / 50.0

cx# = PlayerX#
cy# = PlayerY#

hit = False
dist# = 0.0

; Send out a ray
While Not hit
If cx# > 63 Then cx# = 63
If cx# <  0 Then cx# =  0

If cy# > 63 Then cy# = 63
If cy# <  0 Then cy# =  0

If level( Int(cx#), Int(cy#) ) > 0
hit = True

dist# = dist# + 0.01
cx# = cx# + dx#
cy# = cy# + dy#

; hack for removing the distortion
dist = dist * Cos( (currA# - PlayerA#) )

; Wall height projection
Local wallHeight# = ( 64.0 / dist# ) * 8.0

col = wallHeight

If col > 255 Then col = 255

Select level( Int(cx#), Int(cy#) )
Case 1 Color col,col,col
Case 2 Color col,0,0
Case 3 Color 0,col,0
Case 4 Color 0,0,col
End Select

size = (wallHeight / 2)
Rect x,( YRES / 2 ) - size, 1, size * 2

currA# = currA# + delta_FOV#


End Function

Function DrawMap()

Color 255,0,255
For x = 0 To 63
For y = 0 To 63
If level( x,y ) > 0 Then Rect(x*2,y*2,2,2)

Color 255,0,0
Rect( PlayerX*2, PlayerY*2, 2, 2 )

Color 0,255,0
Line PlayerX * 2,PlayerY * 2, (PlayerX * 2)+(PlayerDX * 4),(PlayerY*2)+(PlayerDY * 4)

End Function

Function InputControl()

If KeyDown( 200 ) Then
tx# = PlayerX# + (PlayerDX# / 2.0)
ty# = PlayerY# + (PlayerDY# / 2.0)

If tx# < 0 Then tx# = 0
If tx# > 63 Then tx# = 63

If ty# < 0 Then ty# = 0
If ty# > 63 Then ty# = 63

If level( tx,ty ) = 0
PlayerX# = tx#
PlayerY# = ty#

If KeyDown( 208 ) Then
tx# = PlayerX# - (PlayerDX# / 2.0)
ty# = PlayerY# - (PlayerDY# / 2.0)

If tx# < 0 Then tx# = 0
If tx# > 63 Then tx# = 63

If ty# < 0 Then ty# = 0
If ty# > 63 Then ty# = 63

If level( tx,ty ) = 0
PlayerX# = tx#
PlayerY# = ty#

If KeyDown( 205 ) Then
PlayerA = ( PlayerA + 6 ) Mod 360

If KeyDown( 203 ) Then
PlayerA = PlayerA - 6
If PlayerA < 0 Then PlayerA = PlayerA + 360

PlayerDX# = Cos( PlayerA )
PlayerDY# = Sin( PlayerA )

End Function

Function Main()

DrawImage( Background, 0, 0 )


; Press Space to draw map
If KeyDown( 57 ) DrawMap()

Color 255,255,255
Text 10,10,MaxDist

End Function


Graphics XRES,YRES,32,2


SetBuffer( BackBuffer() )

While Not KeyDown(1)

WaitTimer( Timer )



Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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