how do i pass a variable in flex


i've been looking on google how pass variable yet

i've come empty handed

i have c code , as3

 

i've never been able c program compile on own, tutorial im trying understand raycasting

from can gather think variables passed threw this

 

#######raycaster.c##########
as3_val loop( void* self, as3_val args )
{
    as3_arrayvalue(args,"inttype,inttype,inttype,inttype",&k_up,&k_down,&k_left,&k_right);
    castray();
    int opos,j,i,jpos;
    for(j=0; j < resy; j++ ){
        jpos = resx*j;
        for(i=0; < resx; i++ ){
            opos = (jpos+i);
            tbuffer[opos] = buffer[i][j];
        }//end of for
    }//end of
    return 0;
}//end of loop

however not 1 of values inside of as3_arrayvalue found on main.as

this function comunicates c code, wrong

####main.as######
        private function enterframe(event:event):void {
            alcrclib.loop(upkey,downkey,leftkey,rightkey);
            alchemymemory.position=alcscreenbufferpointer;
            screenbitmapdata.setpixels(screenbitmapdata.rect,alchemymemory);
           
            }

 

the reason want this, other know how, because useful above else, i've written as3 comunicates php

to array of images  topdown game, , wouldn't know how load these variables c http request if can flash tell c every thing worked out

 

 

 

 

 

 

 

 

 

 

heres both codes in full

 

#####main.as####

/**
*alchemy ray caster
*april 6, 2010
*bruce jawn
*http://bruce-lab.blogspot.com
 
*copyright (c) <2010> <bruce jawn>
*this software released under mit license
*<http://www.opensource.org/licenses/mit-license.php>
**/
package {

 

//    import cmodule.ray_caster._worldmap;
//    import cmodule.ray_caster._worldmap;
    import cmodule.ray_caster.clibinit;
//    import cmodule.ray_caster.textfieldi;
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.engine.textblock;
    import flash.text.engine.textline;
    import flash.text.textfield;
    import flash.utils.*;
    import flash.ui.*;

 

    [swf(width="840", height="880")]
    public class main extends sprite {

 

        [embed(source="../wolftex/barrel.png")]
        public static var barrelclass:class;

 

        [embed(source="../wolftex/bluestone.png")]
        public static var bluestoneclass:class;

 

        [embed(source="../wolftex/colorstone.png")]
        public static var colorstoneclass:class;

 

        [embed(source="../wolftex/eagle.png")]
        public static var eagleclass:class;

 

        [embed(source="../wolftex/greenlight.png")]
        public static var greenlightclass:class;

 

        [embed(source="../wolftex/greystone.png")]
        public static var greystoneclass:class;

 

        [embed(source="../wolftex/mossy.png")]
        public static var mossyclass:class;

 

        [embed(source="../wolftex/pillar.png")]
        public static var pillarclass:class;

 

        [embed(source="../wolftex/purplestone.png")]
        public static var purplestoneclass:class;

 

        [embed(source="../wolftex/redbrick.png")]
        public static var redbrickclass:class;

 

        [embed(source="../wolftex/wood.png")]
        public static var woodclass:class;

 

        //array hold textures
        private var texs:array=[];
        private var worldmap:array = [];
        //private var worldmap[1]:array=[];
        private static const screen_width:int=640;
        private static const screen_height:int=480;
        private var screenbitmapdata:bitmapdata;
        private var screenbitmap:bitmap;

 

        private var alchemymemory:bytearray;
        private var alcrclib:object;
        private var clibinit:clibinit;
        private var alcscreenbufferpointer:uint;
        private var alctexpointer:uint;

 

        private var upkey:int=0;
        private var downkey:int=0;
        private var leftkey:int=0;
        private var rightkey:int=0;
        private var a:flash.text.textfield;
        public function main() {
            stage.framerate=60;
            stage.align=stagealign.top_left;
            stage.scalemode=stagescalemode.no_scale;
            stage.fullscreensourcerect=new rectangle(0,0,screen_width,screen_height);
            init();
           
            }//end of function main

 

        private function init():void {
            initbitmaps();
            initalchemy();
            initrendering();
        }//end of function init

 

        private function initbitmaps():void {
            texs.push(preparebitmapdata(new eagleclass().bitmapdata  ));
            texs.push(preparebitmapdata(new redbrickclass().bitmapdata  ));
            texs.push(preparebitmapdata(new purplestoneclass().bitmapdata  ));
            texs.push(preparebitmapdata(new greystoneclass().bitmapdata  ));
            texs.push(preparebitmapdata(new bluestoneclass().bitmapdata  ));
            texs.push(preparebitmapdata(new mossyclass().bitmapdata  ));
            texs.push(preparebitmapdata(new woodclass().bitmapdata  ));
            texs.push(preparebitmapdata(new colorstoneclass().bitmapdata  ));
            texs.push(preparebitmapdata(new barrelclass().bitmapdata  ));
            texs.push(preparebitmapdata(new pillarclass().bitmapdata  ));
            texs.push(preparebitmapdata(new greenlightclass().bitmapdata  ));

 

            screenbitmapdata=new bitmapdata(screen_width,screen_height,false,0);
            screenbitmap=new bitmap(screenbitmapdata);
            addchild(screenbitmap);
   
            worldmap[1] = (1,2,3,4);
            worldmap[2] = (1,2,3,4);
            worldmap[3] = (1,2,3,4);
            worldmap[4] = (1,2,3,4);
            worldmap[5] = (1,2,3,4);
            worldmap[6] = (1,2,3,4);
            worldmap[7] = (1,2,3,4);
           
           
           
           
           
           
           
           
           
           
            }//end of function initbitmaps

 

        //prepare bitmap once take account lower-endianess of alchemy code.
        private function preparebitmapdata(sourcemap:bitmapdata):bitmapdata {
            var outbitmapdata:bitmapdata=sourcemap.clone();
            outbitmapdata=new bitmapdata(outbitmapdata.width,outbitmapdata.height,true,0xff000000);
            outbitmapdata.copychannel(sourcemap,outbitmapdata.rect,outbitmapdata.rect.topleft,bitmapd atachannel.alpha,bitmapdatachannel.blue);
            outbitmapdata.copychannel(sourcemap,outbitmapdata.rect,outbitmapdata.rect.topleft,bitmapd atachannel.red,bitmapdatachannel.green);
            outbitmapdata.copychannel(sourcemap,outbitmapdata.rect,outbitmapdata.rect.topleft,bitmapd atachannel.green,bitmapdatachannel.red);
            outbitmapdata.copychannel(sourcemap,outbitmapdata.rect,outbitmapdata.rect.topleft,bitmapd atachannel.blue,bitmapdatachannel.alpha);
            return outbitmapdata;
        }//end of function preparebitmapdata

 

        private function initalchemy():void {
            clibinit=new clibinit  ;
            alcrclib=clibinit.init();

 

            //retrieve "alchemy memory".
            var ns:namespace=new namespace("cmodule.ray_caster");
            alchemymemory=ns::gstate.ds;

 

            //allocate buffers in alchemy.
            alcscreenbufferpointer=alcrclib.initializescreenbuffer(screen_width,screen_height);//setu p screenbuffer of size x,y;

 

            //copy textures alchemy memory.
            (var i:int=0; i<11; i++) {
                var ba:bytearray=texs[i].getpixels(texs[i].rect);
                alctexpointer=alcrclib.initializetexbuffer(i);
                alchemymemory.position=alctexpointer;
                alchemymemory.writebytes(ba,0,ba.length);
            }//end of for
        }//end of function initalchemy

 

        private function initrendering():void {
            stage.addeventlistener(keyboardevent.key_down,key_pressed);
            stage.addeventlistener(keyboardevent.key_up,key_released);
            addeventlistener(event.enter_frame,enterframe);
        }//end of function initrendering

 

        private function enterframe(event:event):void {
            alcrclib.loop(upkey,downkey,leftkey,rightkey);
            alchemymemory.position=alcscreenbufferpointer;
            screenbitmapdata.setpixels(screenbitmapdata.rect,alchemymemory);
           
            }//end of function enterframe

 

        private function key_pressed(e:keyboardevent):void {
           
            switch (e.keycode) {
                case keyboard.up :
                    upkey=1;
                    break;
                case keyboard.down :
                    downkey=1;
                    break;
                case keyboard.left :
                    leftkey=1;
                    break;
                case keyboard.right :
                    rightkey=1;
                    break;
            }//end of switch
       
            }//end of function key_pressed

 

        private function key_released(e:keyboardevent):void {
            switch (e.keycode) {
                case keyboard.up :
                    upkey=0;
                    break;
                case keyboard.down :
                    downkey=0;
                    break;
                case keyboard.left :
                    leftkey=0;
                    break;
                case keyboard.right :
                    rightkey=0;
                    break;               
                    }//end of switch
            }//end of function key_released

 

           
            }//end of class
}//end of package

 

 

 

 

###raycaster####

//raycasting engine lode's computer graphics tutorial
//http://www.student.kuleuven.be/~m0216922/cg/raycasting.html
//modified alchemy bruce jawn
//http://bruce-lab.blogspot.com
#include "as3.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//============================================================
//============================================================
enum bool {false=0,true=!false};

 

#define screenwidth 1640
#define screenheight 1480
#define texwidth 64
#define texheight 64
#define mapwidth 24
#define mapheight 24

 

//1d screen buffer
int* tbuffer;
int resx = 0;
int resy = 0;
//2d screen buffer
int buffer[screenwidth][screenheight];
//1d zbuffer
double zbuffer[screenwidth];
//============================================================
//============================================================
//textures
int texture[11][texwidth*texheight];

 

#define numsprites 19
//arrays used sort sprites
int spriteorder[numsprites];
double spritedistance[numsprites];

 

struct ssprite
{
  double x;
  double y;
  int texture;
};

 

struct ssprite sprite[numsprites]=
{
  //green light in front of playerstart
  {20.5, 11.5, 10},
  //green lights in every room
  {18.5,4.5, 10},
  {10.0,4.5, 10},
  {10.0,12.5,10},
  {3.5, 6.5, 10},
  {3.5, 20.5,10},
  {3.5, 14.5,10},
  {14.5,20.5,10},
 
  //row of pillars in front of wall: fisheye test
  {18.5, 10.5, 9},
  {18.5, 11.5, 9},
  {18.5, 12.5, 9},
 
  //some barrels around map
  {21.5, 1.5, 8},
  {15.5, 1.5, 8},
  {16.0, 1.8, 8},
  {16.2, 1.2, 8},
  {3.5,  2.5, 8},
  {9.5, 15.5, 8},
  {10.0, 15.1,8},
  {10.5, 15.8,8},
};
//============================================================
//============================================================
//map
int worldmap[mapwidth][mapheight] =
{
  {8,8,8,8,8,8,8,8,8,8,8,4,4,6,4,4,6,4,6,4,4,4,6,4},
  {8,0,0,0,0,0,0,0,0,0,8,4,0,0,0,0,0,0,0,0,0,0,0,4},
  {8,0,3,3,0,0,0,0,0,8,8,4,0,0,0,0,0,0,0,0,0,0,0,6},
  {8,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6},
  {8,0,3,3,0,0,0,0,0,8,8,4,0,0,0,0,0,0,0,0,0,0,0,4},
  {8,0,0,0,0,0,0,0,0,0,8,4,0,0,0,0,0,6,6,6,0,6,4,6},
  {8,8,8,8,0,8,8,8,8,8,8,4,4,4,4,4,4,6,0,0,0,0,0,6},
  {7,7,7,7,0,7,7,7,7,0,8,0,8,0,8,0,8,4,0,4,0,6,0,6},
  {7,7,0,0,0,0,0,0,7,8,0,8,0,8,0,8,8,6,0,0,0,0,0,6},
  {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,6,0,0,0,0,0,4},
  {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,6,0,6,0,6,0,6},
  {7,7,0,0,0,0,0,0,7,8,0,8,0,8,0,8,8,6,4,6,0,6,6,6},
  {7,7,7,7,0,7,7,7,7,8,8,4,0,6,8,4,8,3,3,3,0,3,3,3},
  {2,2,2,2,0,2,2,2,2,4,6,4,0,0,6,0,6,3,0,0,0,0,0,3},
  {2,2,0,0,0,0,0,2,2,4,0,0,0,0,0,0,4,3,0,0,0,0,0,3},
  {2,0,0,0,0,0,0,0,2,4,0,0,0,0,0,0,4,3,0,0,0,0,0,3},
  {1,0,0,0,0,0,0,0,1,4,4,4,4,4,6,0,6,3,3,0,0,0,3,3},
  {2,0,0,0,0,0,0,0,2,2,2,1,2,2,2,6,6,0,0,5,0,5,0,5},
  {2,2,0,0,0,0,0,2,2,2,0,0,0,2,2,0,5,0,5,0,0,0,5,5},
  {2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,5,0,5,0,5,0,5,0,5},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5},
  {2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,5,0,5,0,5,0,5,0,5},
  {2,2,0,0,0,0,0,2,2,2,0,0,0,2,2,0,5,0,5,0,0,0,5,5},
  {2,2,2,2,1,2,2,2,2,2,2,1,2,2,2,5,5,5,5,5,5,5,5,5}

 

  };
//============================================================
//============================================================
double posx = 22.0, posy = 11.5; //x , y start position
double dirx = -1.0, diry = 0.0; //initial direction vector
double planex = 0.0, planey = 0.66; //the 2d raycaster version of camera plane
int k_left=0;
int k_right=0;
int k_up=0;
int k_down=0;
//speed modifiers
double movespeed =  .30; //the constant value in squares/second
double rotspeed =   .20; //the constant value in radians/second
//============================================================
//============================================================
as3_val initializescreenbuffer(void* self, as3_val args)
{
    as3_arrayvalue(args, "inttype, inttype", &resx, &resy);
    tbuffer = malloc( resx * resy * sizeof(int) );
    return as3_ptr( tbuffer );
}//end of initializescreenbuffer

 

//used load textures & sprite textures
as3_val initializetexbuffer(void* self, as3_val args)
{
    int index;
    as3_arrayvalue(args, "inttype", &index);
    return as3_ptr( texture[index] );
}//end of initializetexbuffer

 

//start main loop
as3_val loop( void* self, as3_val args )
{
    as3_arrayvalue(args,"inttype,inttype,inttype,inttype",&k_up,&k_down,&k_left,&k_right);
    castray();
    int opos,j,i,jpos;
    for(j=0; j < resy; j++ ){
        jpos = resx*j;
        for(i=0; < resx; i++ ){
            opos = (jpos+i);
            tbuffer[opos] = buffer[i][j];
        }//end of for
    }//end of
    return 0;
}//end of loop

int main()
{
    as3_val initializescreenbuffermethod = as3_function( null,initializescreenbuffer );
    as3_val loopmethod = as3_function( null,loop );
    as3_val initializetexbuffermethod = as3_function( null,initializetexbuffer );
    as3_val result = as3_object("initializescreenbuffer:as3valtype,loop:as3valtype,initializetexbuffer:as3valt ype"
                                ,initializescreenbuffermethod,loopmethod,initializetexbuffermethod);
    as3_release( initializescreenbuffermethod );
    as3_release( loopmethod );
    as3_release( initializetexbuffermethod );
    as3_libinit( result );
   
    return 0;
}//end of main
//================================================================
//================================================================
void castray()
{
    printf ("hello world!\n");
    int x;
    int y;
    int w=screenwidth;
    int h=screenheight;
    for( x = 0; x < screenwidth; x++) for( y = 0; y < screenheight; y++) {buffer[x][y] = 0;} //clear buffer instead of cls()
    for(x = 0; x < w; x++)
    {
      //calculate ray position , direction
      double camerax = 2 * x / (double)(w) - 1; //x-coordinate in camera space    
      double rayposx = posx;
      double rayposy = posy;
      double raydirx = dirx + planex * camerax;
      double raydiry = diry + planey * camerax;
    
      //which box of map we're in 
      int mapx = (int)(rayposx);
      int mapy = (int)(rayposy);
      
      //length of ray current position next x or y-side
      double sidedistx;
      double sidedisty;
      
      //length of ray 1 x or y-side next x or y-side
      double deltadistx = sqrt(1 + (raydiry * raydiry) / (raydirx * raydirx));
      double deltadisty = sqrt(1 + (raydirx * raydirx) / (raydiry * raydiry));
      double perpwalldist;
      
      //what direction step in x or y-direction (either +1 or -1)
      int stepx;
      int stepy;
           
      int hit = 0; //was there wall hit?
      int side; //was ns or ew wall hit?

 

      //calculate step , initial sidedist
      if (raydirx < 0)
      {
        stepx = -1;
        sidedistx = (rayposx - mapx) * deltadistx;
      }//end of if (raydirx < 0)
      else
      {
        stepx = 1;
        sidedistx = (mapx + 1.0 - rayposx) * deltadistx;
      }//end of else
      if (raydiry < 0)
      {
        stepy = -1;
        sidedisty = (rayposy - mapy) * deltadisty;
      }//end of if (raydiry < 0)
      else
      {
        stepy = 1;
        sidedisty = (mapy + 1.0 - rayposy) * deltadisty;
      }//end of else
      //perform dda
      while (hit == 0)
      {
        //jump next map square, or in x-direction, or in y-direction
        if (sidedistx < sidedisty)
        {
          sidedistx += deltadistx;
          mapx += stepx;
          side = 0;
        }//end of if (sidedistx < sidedisty)
        else
        {
          sidedisty += deltadisty;
          mapy += stepy;
          side = 1;
        }//end of else
        //check if ray has hit wall      
        if (worldmap[mapx][mapy] > 0) hit = 1;
      }//end of while (hit == 0)
     
      //calculate distance of perpendicular ray (oblique distance give fisheye effect!)   
      if (side == 0) perpwalldist = fabs((mapx - rayposx + (1 - stepx) / 2) / raydirx);
      else       perpwalldist = fabs((mapy - rayposy + (1 - stepy) / 2) / raydiry);
     
      //calculate height of line draw on screen      
      int lineheight = abs((int)(h / perpwalldist));
     
      //calculate lowest , highest pixel fill in current stripe
      int drawstart = -lineheight / 2 + h / 2;
      if(drawstart < 0) drawstart = 0;
      int drawend = lineheight / 2 + h / 2;
      if(drawend >= h) drawend = h - 1;
      //texturing calculations
      int texnum = worldmap[mapx][mapy] - 1; //1 subtracted texture 0 can used!
     
      //calculate value of wallx
      double wallx; //where wall hit
      if (side == 1) wallx = rayposx + ((mapy - rayposy + (1 - stepy) / 2) / raydiry) * raydirx;
      else       wallx = rayposy + ((mapx - rayposx + (1 - stepx) / 2) / raydirx) * raydiry;
      wallx -= floor((wallx));
      
      //x coordinate on texture
      int texx = (int)(wallx * (double)(texwidth));
      if(side == 0 && raydirx > 0) texx = texwidth - texx - 1;
      if(side == 1 && raydiry < 0) texx = texwidth - texx - 1;
      int y;
      for(y = drawstart; y < drawend; y++)
      {
        int d = y * 256 - h * 128 + lineheight * 128; //256 , 128 factors avoid floats
        int texy = ((d * texheight) / lineheight) / 256;
        int color = texture[texnum][texwidth * texy + texx];
        //make color darker y-sides: r, g , b byte each divided through 2 "shift" , "and"
        if(side == 1) color = (color >> 1) & 8355711;
        buffer[x][y] = color;
      }//end of for(y = drawstart; y < drawend; y++)
     
      //set zbuffer sprite casting
      zbuffer[x] = perpwalldist; //perpendicular distance used
     
      //floor casting
      double floorxwall, floorywall; //x, y position of floor texel @ bottom of wall

 

      //4 different wall directions possible
      if(side == 0 && raydirx > 0)
      {
        floorxwall = mapx;
        floorywall = mapy + wallx;
      }//end of if(side == 0 && raydirx > 0)
      else if(side == 0 && raydirx < 0)
      {
        floorxwall = mapx + 1.0;
        floorywall = mapy + wallx;
      }//end of else if(side == 0 && raydirx < 0)
      else if(side == 1 && raydiry > 0)
      {
        floorxwall = mapx + wallx;
        floorywall = mapy;
      }//end of else if(side == 1 && raydiry > 0)
      else
      {
        floorxwall = mapx + wallx;
        floorywall = mapy + 1.0;
      }//end of else
     
      double distwall, distplayer, currentdist;

 

      distwall = perpwalldist;
      distplayer = 0.0;
      if (drawend < 0) drawend = h; //becomes < 0 when integer overflows
      //draw floor drawend bottom of screen
      for(y = drawend + 1; y < h; y++)
      {
        currentdist = h / (2.0 * y - h); //you make small lookup table instead

 

        double weight = (currentdist - distplayer) / (distwall - distplayer);
        
        double currentfloorx = weight * floorxwall + (1.0 - weight) * posx;
        double currentfloory = weight * floorywall + (1.0 - weight) * posy;
       
        int floortexx, floortexy;
        floortexx = (int)(currentfloorx * texwidth) % texwidth;
        floortexy = (int)(currentfloory * texheight) % texheight;
       
        //floor
        buffer[x][y] = (texture[3][texwidth * floortexy + floortexx] >> 1) & 8355711;
        //ceiling (symmetrical!)
        buffer[x][h - y] = texture[6][texwidth * floortexy + floortexx];
      }//end of for(y = drawend + 1; y < h; y++)
    }//end of for(x = 0; x < w; x++)
   
    //sprite casting
    //sort sprites far close
    int i;
    for(i = 0; < numsprites; i++)
    {
      spriteorder[i] = i;
      spritedistance[i] = ((posx - sprite[i].x) * (posx - sprite[i].x) + (posy - sprite[i].y) * (posy - sprite[i].y)); //sqrt not taken, unneeded
    }//end of for(i = 0; < numsprites; i++)
    combsort(spriteorder, spritedistance, numsprites);
    
    //after sorting sprites, projection , draw them
    for(i = 0; < numsprites; i++)
    {
      //translate sprite position relative camera
      double spritex = sprite[spriteorder[i]].x - posx;
      double spritey = sprite[spriteorder[i]].y - posy;
        
      //transform sprite inverse camera matrix
      // [ planex   dirx ] -1                                       [ diry      -dirx ]
      // [               ]       =  1/(planex*diry-dirx*planey) *   [                 ]
      // [ planey   diry ]                                          [ -planey  planex ]
     
      double invdet = 1.0 / (planex * diry - dirx * planey); //required correct matrix multiplication
     
      double transformx = invdet * (diry * spritex - dirx * spritey);
      double transformy = invdet * (-planey * spritex + planex * spritey); //this depth inside screen, z in 3d      
           
      int spritescreenx = (int)((w / 2) * (1 + transformx / transformy));
     
      //parameters scaling , moving sprites
      #define udiv 1
      #define vdiv 1
      #define vmove 0.0
      int vmovescreen = (int)(vmove / transformy);
     
      //calculate height of sprite on screen
      int spriteheight = abs((int)(h / (transformy))) / vdiv; //using "transformy" instead of real distance prevents fisheye
      //calculate lowest , highest pixel fill in current stripe
      int drawstarty = -spriteheight / 2 + h / 2 + vmovescreen;
      if(drawstarty < 0) drawstarty = 0;
      int drawendy = spriteheight / 2 + h / 2 + vmovescreen;
      if(drawendy >= h) drawendy = h - 1;
     
      //calculate width of sprite
      int spritewidth = abs( (int) (h / (transformy))) / udiv;
      int drawstartx = -spritewidth / 2 + spritescreenx;
      if(drawstartx < 0) drawstartx = 0;
      int drawendx = spritewidth / 2 + spritescreenx;
      if(drawendx >= w) drawendx = w - 1;
     
      //loop through every vertical stripe of sprite on screen
      int stripe;
      for(stripe = drawstartx; stripe < drawendx; stripe++)
      {
        int texx = (int)(256 * (stripe - (-spritewidth / 2 + spritescreenx)) * texwidth / spritewidth) / 256;
        //the conditions in if are:
        //1) it's in front of camera plane don't see things behind you
        //2) it's on screen (left)
        //3) it's on screen (right)
        //4) zbuffer, perpendicular distance
        int y;
        if(transformy > 0 && stripe > 0 && stripe < w && transformy < zbuffer[stripe])
        for(y = drawstarty; y < drawendy; y++) //for every pixel of current stripe
        {
          int d = (y-vmovescreen) * 256 - h * 128 + spriteheight * 128; //256 , 128 factors avoid floats
          int texy = ((d * texheight) / spriteheight) / 256;
          unsigned int color = texture[sprite[spriteorder[i]].texture][texwidth * texy + texx]; //get current color texture//??????????????????
          if((color & 0x00ffffff) != 0) buffer[stripe][y] = color; //paint pixel if isn't black, black invisible color
        }//end of for(y = drawstarty; y < drawendy; y++)
      }//end of for(stripe = drawstartx; stripe < drawendx; stripe++)
    }//end of for(i = 0; < numsprites; i++)
  
   
    //readkeys
    //move forward if no wall in front of you
    if (k_up)
    {
      if(worldmap[(int)(posx + dirx * movespeed)][(int)(posy)] == false) posx += dirx * movespeed;
      if(worldmap[(int)(posx)][(int)(posy + diry * movespeed)] == false) posy += diry * movespeed;
    }//end of if (k_up)
    //move backwards if no wall behind you
    if (k_down)
    {
      if(worldmap[(int)(posx - dirx * movespeed)][(int)(posy)] == false) posx -= dirx * movespeed;
      if(worldmap[(int)(posx)][(int)(posy - diry * movespeed)] == false) posy -= diry * movespeed;
    }//end of if (k_down)
    //rotate right
    if (k_right)
    {
      //both camera direction , camera plane must rotated
      double olddirx = dirx;
      dirx = dirx * cos(-rotspeed) - diry * sin(-rotspeed);
      diry = olddirx * sin(-rotspeed) + diry * cos(-rotspeed);
      double oldplanex = planex;
      planex = planex * cos(-rotspeed) - planey * sin(-rotspeed);
      planey = oldplanex * sin(-rotspeed) + planey * cos(-rotspeed);
    }//end of if (k_right)
    //rotate left
    if (k_left)
    {
      //both camera direction , camera plane must rotated
      double olddirx = dirx;
      dirx = dirx * cos(rotspeed) - diry * sin(rotspeed);
      diry = olddirx * sin(rotspeed) + diry * cos(rotspeed);
      double oldplanex = planex;
      planex = planex * cos(rotspeed) - planey * sin(rotspeed);
      planey = oldplanex * sin(rotspeed) + planey * cos(rotspeed);
    }//end of if (k_left)

 


}//end of castray

 

//sort algorithm
void combsort(int* order, double* dist, int amount)
{
  int gap = amount;
  enum bool swapped = false;
  while(gap > 1 || swapped)
  {
    //shrink factor 1.3
    gap = (gap * 10) / 13;
    if(gap == 9 || gap == 10) gap = 11;
    if (gap < 1) gap = 1;
    swapped = false;
    int i;
    (i = 0; < amount - gap; i++)
    {
      int j = + gap;
      if (dist[i] < dist[j])
      {
        double disttemp=dist[i];
        dist[i]=dist[j];
        dist[j]=disttemp;
        int ordertemp=order[i];
        order[i]=order[j];
        order[j]=ordertemp;
        swapped = true;
      }//end of if (dist[i] < dist[j])
    }//end of (i = 0; < amount - gap; i++)
  }//end of while(gap > 1 || swapped)
}//end of combsort

the sorce file can found here http://bruce-lab.blogspot.com/2010/04/alchemy-ray-casting-engine-source-code.html

i looked @ website , of source files.  , there more issues merely passing avariable.



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Blank pages again for IE7 and IE6

How to update nested ListCollectionViews?

cf_sql_integer vs cf_sql_bigint vs cf_sql_int??