Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-17-2016, 04:36 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Raycasting V2 - Progress!!!

Okay! So I have sort of made some progress with my efforts in raycasting using GS2, it's still very buggy and still doesn't look quite right...



PHP Code:
//#CLIENTSIDE
function onCreated(){
  
this.maxlooplimit 100000;
  
sleep(0.5);
  
this.map = {
    {
1,1,1,1,1,1,1,1,1,1,1,1,1},
    {
1,0,0,0,0,0,0,0,0,0,2,0,1},
    {
1,0,0,0,0,0,0,0,0,0,2,0,1},
    {
1,0,0,0,0,0,0,0,0,0,0,0,1},
    {
1,0,0,0,0,1,1,0,0,0,0,0,2},
    {
1,0,0,0,0,1,1,0,0,0,0,0,2},
    {
2,0,0,0,0,0,0,0,0,0,0,0,1},
    {
2,0,0,0,0,0,0,0,0,0,0,0,1},
    {
2,0,0,0,0,0,0,0,0,0,0,0,1},
    {
2,0,0,0,0,2,2,0,0,0,0,0,1},
    {
2,0,0,0,0,2,2,0,0,0,0,0,1},
    {
1,0,0,0,0,0,0,0,0,0,0,0,1},
    {
1,1,1,1,1,1,2,2,2,1,1,1,1},
  };
  
this.600;
  
this.400;
  
this.off = {screenwidth/this.w/2screenheight/this.h/2};
  
this.off = {5050};
  
this.mapwidth this.map[0].size();
  
this.mapheight this.map.size();
  
this.posx 2;
  
this.posy 2;
  
this.dirx = -1;
  
this.diry 0;
  
this.planex 0;
  
this.planey 0.66;
  
this.time 0;
  
this.oldtime 0;
  for(
temp.0temp.2000temp.++){
    if(
isobject((@"3D_R_"@temp.i))){
      (@
"3D_R_"@temp.i).destroy();
    } 
  }
  
onTimeout();
}
function 
sqrt(n) { 
  return 
n^0.5
}
function 
onTimeout(){
  for(
temp.0temp.this.wtemp.++){
    
temp.camerax temp.x/this.-1;
    
temp.rayposx this.posx;
    
temp.rayposy this.posy;
    
temp.raydirx this.dirx this.planex temp.camerax;
    
temp.raydiry this.diry this.planey temp.camerax;
    
temp.mapx int(temp.rayposx);
    
temp.mapy int(temp.rayposy);
    
temp.sidedistx 0;
    
temp.sidedisty 0;
    
temp.deltadistx sqrt(+ (temp.raydiry temp.raydiry)/(temp.raydirx temp.raydirx));
    
temp.deltadisty sqrt(+ (temp.raydirx temp.raydirx)/(temp.raydiry temp.raydiry));
    
temp.perpwalldist 0;
    
temp.stepx 0;
    
temp.stepy 0;
    
temp.hit 0;
    
temp.side 0;
    if(
temp.raydirx 0){
      
temp.stepx = -1;
      
temp.sidedistx = (temp.rayposx temp.mapx)*temp.deltadistx;
    }else{
      
temp.stepx 1;
      
temp.sidedistx = (temp.mapx temp.rayposx) * temp.deltadistx;
    }
    if(
temp.raydiry 0){
      
temp.stepy = -1;
      
temp.sidedisty = (temp.rayposy temp.mapy) * temp.deltadisty;
    }else{
      
tmep.stepy 1;
      
temp.sidedisty = (temp.mapy temp.rayposy) * temp.deltadisty;
    }
    
temp.count 0;
    while(
temp.hit == 0){
      
temp.count ++;
      if(
temp.sidedistx temp.sidedisty){
        
temp.sidedistx += temp.deltadistx;
        
temp.mapx += temp.stepx;
        
temp.side 0;
      }else{
        
temp.sidedisty += temp.deltadisty;
        
temp.mapy += temp.stepy;
        
temp.side 1;
      }
      if(
this.map[temp.mapx][temp.mapy] > 0){
        
temp.hit 1;
      }
      if(
temp.count == 9999){
        
temp.hit 1;
        
//maxlooplimit..?
      
}
    }
    if(
temp.side == 0){
      
temp.perpwalldist = (temp.mapx temp.rayposx + (temp.stepx)/2)/temp.raydirx;
    }else{
      
temp.perpwalldist = (temp.mapy temp.rayposy + (temp.stepy)/2)/temp.raydiry;
    }
    
temp.lineheight this.h/temp.perpwalldist;
    
temp.drawstart = -temp.lineheight/this./2;
    if(
temp.drawstart 0){
      
temp.drawstart 0;
    }
    
temp.drawend temp.lineheight/2  this.h/2;
    if(
temp.drawend >= this.h){
       
temp.drawend this.1;
    }
    
temp.this.map[temp.mapx][temp.mapy];
    
temp.= {000};
    if(
temp.== 1){
      
temp.= {100}; //Red for outside walls
    
}
    if(
temp.== 2){
      
temp.= {010}; //Blue for 2
    
}
    
temp.alp 1;
    if(
temp.side == 1){
      
temp.alp 0.5;
    }
    
//DRAWWWW
    
new GuiBitmapCtrl("3D_R_"@temp.x) {
      
thiso.off[0] + temp.x;
      
thiso.off[1] + temp.drawstart;
      
width 1;
      
height temp.drawend;
      
bitmap "block.png";
      
alpha temp.alp;
      
red temp.c[0];
      
blue temp.c[1];
      
green temp.c[2];
    }
  }
  
temp.rot 0;
  
temp.ms 0.1;
  if(
keydown(1)) temp.rot = -0.1;
  if(
keydown(3)) temp.rot 0.1;
  if(
keydown(2)){
    if(
this.map[int(this.posx this.dirx temp.ms)][int(this.posy)] == 0){
       
this.posx -= this.dirx temp.ms;
    }
    if(
this.map[int(this.posx)][int(this.posy this.diry temp.ms)] == 0){
      
this.posy -= this.diry temp.ms;
    }
  }
  if(
keydown(0)){
    if(
this.map[int(this.posx this.dirx temp.ms)][int(this.posy)] == 0){
       
this.posx += this.dirx temp.ms;
    }
    if(
this.map[int(this.posx)][int(this.posy this.diry temp.ms)] == 0){
      
this.posy += this.diry temp.ms;
    }
  }
  
temp.olddirx this.dirx;
  
this.dirx this.dirx cos(-temp.rot) - this.diry sin(-temp.rot);
  
this.diry temp.olddirx sin(-temp.rot) + this.diry cos(-temp.rot);
  
temp.oldplanex this.planex;
  
this.planex this.planex cos(-temp.rot) - this.planey sin(-temp.rot);
  
this.planey temp.oldplanex sin(-temp.rot) + this.planey cos(-temp.rot);
  
settimer(0.05);

Would anyone have any ideas on how to make it look more realistic, maybe even texture/shading etc?

If I remove
PHP Code:
      if(temp.count == 9999){
        
temp.hit 1;
        
//maxlooplimit..?
      

I get: Script: Loop limit exceeded in function onTimeout in script of Weapon -Gunderak/3D

So guessing something isn't 100%..

EDIT: I was using this as a base and trying to convert it to GS2
http://lodev.org/cgtutor/files/raycaster_flat.cpp
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 08-17-2016 at 06:01 AM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.