Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 08-17-2016, 05:47 AM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
seems cool
__________________
Reply With Quote
  #3  
Old 08-17-2016, 05:58 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Quote:
Originally Posted by Crono View Post
seems cool
Thanksss <3

I just can't get it to look right though
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 08-18-2016, 03:19 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Such improvements, much wow!
The walls still bug out when you are close, not sure why o.o

Just using the wolfenstein graphics as a placeholder for now.
__________________

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-18-2016 at 07:19 AM..
Reply With Quote
  #5  
Old 08-19-2016, 03:36 AM
Xerath Xerath is offline
Registered User
Join Date: Jul 2016
Location: Sydney, Australia
Posts: 5
Xerath is on a distinguished road
What a beauty
Reply With Quote
  #6  
Old 08-19-2016, 03:56 AM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
time to make graalenstein eh?
__________________
Reply With Quote
  #7  
Old 08-19-2016, 07:15 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road


Managed to implement the way the floors are done in Doom etc but since I can't access the image buffer it's wayyyyyy too slow to actually render a 1x1 pixel graphic for the floor and ceiling data, so for now just using a solid image.


Here is my floor logic if anyone has any ideas on how to make it not laggy, maybe I'm doing it a dumb way, not sure:

PHP Code:
    temp.floorxwall 0;
    
temp.floorywall 0;
    if(
temp.side == && temp.raydirx 0){
      
temp.floorxwall temp.mapx;
      
temp.floorywall temp.mapy temp.wallx;
    }else if(
temp.side == && temp.raydirx 0){
      
temp.floorxwall temp.mapx 1;
      
temp.floorywall temp.mapy temp.wallx;
    }else if(
temp.side == && temp.raydiry 0){
      
temp.floorxwall temp.mapx temp.wallx;
      
temp.floorywall temp.mapy;
    }else{
      
temp.floorxwall temp.mapx temp.wallx;
      
temp.floorywall temp.mapy 1;
    }
    
temp.distwall temp.perpwalldist;
    
temp.distplayer 0;
    if(
temp.drawend 0){
      
temp.drawend this.h;
    }
    for(
temp.temp.drawendtemp.this.htemp.++){
      
temp.currentdist this.h/(temp.this.h);
      
temp.weight = (temp.currentdist)/(temp.distwall);
      
temp.currentfloorx temp.weight*temp.floorxwall + (temp.weight) * this.posx;
      
temp.currentfloory temp.weight*temp.floorywall + (temp.weight) * this.posy;
      
temp.floortexx int(temp.currentfloorx*this.texturewidth)%this.texturewidth;
      
temp.floortexy int(temp.currentfloory*this.texturewidth)%this.texturewidth;
      
Gunderak_3D.drawimagestretched(temp.xtemp.y11"wolftextures.png"temp.floortexx+(64*6), temp.floortexy11);
    } 

I mean, it works, but like 0.00005 FPS lol.
__________________

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-19-2016 at 10:35 AM..
Reply With Quote
  #8  
Old 08-23-2016, 04:46 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Nice! I think Dusty made something similar but for like a mario kart style minigame
__________________
http://i.imgur.com/OOJbW.jpg

Last edited by BlueMelon; 08-24-2016 at 04:03 PM.. Reason: like -> think
Reply With Quote
  #9  
Old 08-24-2016, 02:51 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Quote:
Originally Posted by BlueMelon View Post
Nice! I like Dusty made something similar but for like a mario kart style minigame
Thanks! I was thinking just a minigame where you could see other players in the 3D world etc and kill them for fun, not sure where I am taking it at this stage, having issues with rendering sprites, the ZBuffer thing is confusing me.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #10  
Old 08-24-2016, 04:14 PM
swimdude swimdude is offline
SWIMGHOSTPURRP
swimdude's Avatar
Join Date: Mar 2011
Posts: 135
swimdude will become famous soon enough
Quote:
Originally Posted by Gunderak View Post
Thanks! I was thinking just a minigame where you could see other players in the 3D world etc and kill them for fun, not sure where I am taking it at this stage, having issues with rendering sprites, the ZBuffer thing is confusing me.
would LOOOOVE for this to be its own thing on my server, maybe you can expand on it if you want, a small DOOM MMO via graal haha.

im a huge DOOM fan , hit me back. ill let you work on that project w my server.
Reply With Quote
  #11  
Old 08-24-2016, 07:47 PM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
any projects or is this more of an experiment?
__________________
Reply With Quote
  #12  
Old 08-24-2016, 11:28 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Quote:
Originally Posted by swimdude View Post
would LOOOOVE for this to be its own thing on my server, maybe you can expand on it if you want, a small DOOM MMO via graal haha.

im a huge DOOM fan , hit me back. ill let you work on that project w my server.
I'm not sure if at this stage I'll disclose the full source, because it may get used still, and sorry no time, too busy working on Zone iPhone


Quote:
Originally Posted by Crono View Post
any projects or is this more of an experiment?
It started as an experiment but not I'm thinking of taking it further, improving it etc and possibly making it into a minigame!
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #13  
Old 08-25-2016, 07:04 AM
swimdude swimdude is offline
SWIMGHOSTPURRP
swimdude's Avatar
Join Date: Mar 2011
Posts: 135
swimdude will become famous soon enough
Quote:
Originally Posted by Gunderak View Post
I'm not sure if at this stage I'll disclose the full source, because it may get used still, and sorry no time, too busy working on Zone iPhone




It started as an experiment but not I'm thinking of taking it further, improving it etc and possibly making it into a minigame!
yea ill pay you if they arent, if they arent then thats def a nono
Reply With Quote
  #14  
Old 08-25-2016, 07:57 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Quote:
Originally Posted by swimdude View Post
yea ill pay you if they arent, if they arent then thats def a nono
Bahaha, maybe one day, but tbh doesn't bother me, I work full time anyway so I get money from that.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #15  
Old 08-26-2016, 07:27 AM
swimdude swimdude is offline
SWIMGHOSTPURRP
swimdude's Avatar
Join Date: Mar 2011
Posts: 135
swimdude will become famous soon enough
Quote:
Originally Posted by Gunderak View Post
Bahaha, maybe one day, but tbh doesn't bother me, I work full time anyway so I get money from that.
so humble i love it

nice to see ppl still with some talent running around doing something different. keep us updated w this
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 09:06 PM.


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