Jawa Trading Company's Forum Posts

  • I just now realized from your comment that an example of this exists and I didn't have to do it all by hand. I feel silly, Thank you for taking the time to point out my problem.

    edit: I see from your bookmark where I went wrong. Somehow I missed that part from the tutorial. Thanks. Problem fixed.

  • do I need to be more specific?

  • I've managed to piece this thing together pretty good I think. I think it all works pretty good if you are the peer. Laser shows up, can hit host/other peers, hosts/other peers health goes down, host/other peers can die --

    But for some reason the HOST's firing (bit 4) is not being translated locally or remotely. In other words, while all the peers see the host moving around and rotating properly - and its AimSpot. Left Mouse Clicking doesn't register on either side. I'd appreciate some input on where I went wrong.

  • link works now

  • Think you could bias certain terrain areas to create stuff like biomes and other terrain features?

    I could.

  • PHP script (and eventually Construct 2) that generates fractal terrain using Diamond Square Algorithm. The three links below show (in order), implementation inside Construct 2, Fractal Terrain with Gradient, Raw Fractal

    In Action Inside Construct

    Terrain Example

    Raw Example

    <?
    
    $DATA_SIZE = 513;
    $SEED = 0.0;
    $data = array();
    $maxY = -1E32;
    $minY = 1E32;
    mt_srand($DATA_SIZE);
    $RAND_MAX = mt_getrandmax();
    $data[0][0] = $data[0][$DATA_SIZE-1] = $data[$DATA_SIZE-1][0] = $data[$DATA_SIZE-1][$DATA_SIZE-1] = $SEED;
    $h = 200.0;
    
    for ($sideLength = $DATA_SIZE-1; $sideLength >= 2; $sideLength /= 2, $h /= 2.0)     {
              $halfSide = $sideLength/2;
              for($x=0; $x<$DATA_SIZE-1;$x+=$sideLength) {
                  ?for($y=0; $y<$DATA_SIZE-1; $y+=$sideLength) {
    
                        //x,y is upper left corner of the square
                        //calculate average of existing corners
                        $avg = $data[$x][$y] +                     //top left
                        $data[$x+$sideLength][$y]   +                    //top right
                        $data[$x][$y+$sideLength]   +                     //lower left
                        $data[$x+$sideLength][$y+$sideLength];      //lower right
              
                        $avg = $avg / 4.0;
    
                        //center is average plus random offset in the range (-h, h)
                        $offset = (-$h) + rand() * ($h - (-$h)) / $RAND_MAX;
                        $data[$x+$halfSide][$y+$halfSide] = $avg + $offset;
    
                  ?} //for y
              } // for x
              
              //Generate the diamond values
              //Since diamonds are staggered, we only move x by half side
              //NOTE: if the data shouldn't wrap the x < DATA_SIZE and y < DATA_SIZE
              for ($x=0; $x<$DATA_SIZE; $x+=$halfSide) {
                        for ($y=($x+$halfSide)%$sideLength; $y<$DATA_SIZE; $y+=$sideLength) {
         
                             //x,y is center of diamond
                             //we must use mod and add DATA_SIZE for subtraction 
                             //so that we can wrap around the array to find the corners
         
                             $avg = 
                             $data[($x-$halfSide+$DATA_SIZE)%$DATA_SIZE][$y] +     //left of center
                             $data[($x+$halfSide)%$DATA_SIZE][$y]                    +     //right of center
                             $data[$x][($y+$halfSide)%$DATA_SIZE]                    +     //below center
                             $data[$x][($y-$halfSide+$DATA_SIZE)%$DATA_SIZE];     //above center
         
                             $avg = $avg / 4.0;
         
                             //new value = average plus random offset
                             //calc random value in the range (-h,+h)
                             $offset = (-$h) + rand() * ($h - (-$h)) / $RAND_MAX;
                             $avg = $avg + $offset;
                        
                             //update value for center of diamond
                             $data[$x][$y] = $avg;
         
                             //wrap values on the edges
                             //remove this and adjust loop condition above
                             //for non-wrapping values
                             //if ($x == 0) $data[$DATA_SIZE-1][$y] = $avg;
                             //if ($y == 0) $data[$x][$DATA_SIZE-1] = $avg;
                        } //for y
                  ?} //for x
              } //for sideLength
         
         
              //Calculate minY and maxY values
         for ($i = 0; $i<$DATA_SIZE-1; $i++){
              for($j=0; $j<$DATA_SIZE-1; $j++) {
                  ?if ($data[$i][$j] > $maxY){
                        $maxY = $data[$i][$j];
                  ?}
                  ?if ($data[$i][$j] < $minY){
                        $minY = $data[$i][$j];
                  ?}
              }
         }
         
         createTerrain();
         
         // start of functions
         function createTerrain(){
            global $DATA_SIZE, $data, $maxY, $minY;
              $px = 0;
              $py = 0;
              $pz = 0;
              $pallete = array();
              // I use a 256px wide image gradient here to represent the colors for elevation
              $im = imagecreatefrompng("map.png");
              for($a = 0;$a<= 256;$a++){
                  ?$rgb = imagecolorat($im, $a+1, 1);
                  ?$r = ($rgb >> 16) & 0xFF;
                  ?$g = ($rgb >> 8) & 0xFF;
                  ?$b = $rgb & 0xFF;
                  ?$pallete[$a][r] =  $r;
                  ?$pallete[$a][g] =  $g;
                  ?$pallete[$a][b] =  $b;
              }
              $gd = imagecreatetruecolor($DATA_SIZE, $DATA_SIZE);
              for($x=0; $x < $DATA_SIZE-1; $x++){
                    for($y=0; $y < $DATA_SIZE-1; $y++){
                                ??//populate the point struct
                            $px = $x;
                            $py = $data[$x][$y]; // color || height
                            $pz = $y;
                                ??//change range to 0..1
                                ??$py = ($py - $minY) / ($maxY - $minY);
                                ??$py  = floor($py * 255);
                                       $c[0] = $pallete[$py][r];
                                       $c[1] = $pallete[$py][g];
                                       $c[2] = $pallete[$py][b];
                                ??$color = imagecolorallocate($gd, $c[0], $c[1], $c[2]);
                                ??imagesetpixel($gd, round($y),round($x), $color);
                         }
              }
              header('Content-Type: image/png');
              imagepng($gd);
              imagedestroy($gd);
          
    
    }
    
    function html2rgb($color){
        if ($color[0] == '#')
            $color = substr($color, 1);
    
        if (strlen($color) == 6)
            list($r, $g, $b) = array($color[0].$color[1],
                                     $color[2].$color[3],
                                     $color[4].$color[5]);
        elseif (strlen($color) == 3)
            list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
        else
            return false;
    
        $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
    
        return array($r, $g, $b);
    }
    
    ?>
  • Thanks a lot. I will give it a try.

  • I don't have Classic Construct. But try moving your mouse release event to after the mouse button event. and on your mouse button down sub event (power > 200) Try setting power to 200 instead of decrementing it. You might also want to change DOWN to pressed. Holding a key down will poll it every tick. You can literally get a very large number in a small amount of time.

    For example: If a tick occurs 20 times in 1 second. Your power variable will increment 100 every second. When you are checking the range (Power > 200), I assume you want to set a max Power. Decrementing it every tick will give you random results depending on the event/tick relationship.

    Try:

    + Left Mouse Button down

       - Power > 200 : Set power 200

    + Left Mouse Button Released

    ....

  • Awesome. Thanks. That did the trick.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I know there is a Perlin Noise plugin for Classic Construct. My question is is there something similar or a procedure I can use to emulate it in C2?

  • I am fidgeting around with the touch controls. The angry birds-esque genre seemed perfect to experiment getting this done.

    Problem is that occasionally when I release, the object just falls to the ground as if the angle and force were not applied. This happens intermittently.

    Any one have an ideas?

    Here is the capx [r99]

    http://dl.dropbox.com/u/53052693/ABC.capx

  • This is the first time I've shared anything. This example utilizes Ajax, XML, and 8Direction.

    The script I'm about to share [r98] consists of loading an XML file loaded with mapping data. In this specific example, nodes with 'W' represent a wall. Once the XML file loads via AJAX it stores the nodes in an array.

    Screenshot Map Editor

    As you can see in this screenshot. The W represents the walls. H represents hollow spaces. S represents where the 8Direction will start.

    http://dl.dropbox.com/u/53052693/mapping%20Array.capx

    The main loop destroys every wall block every tick. Then tests the X and Y limits of the viewport based off the scrollx and scrolly, and window height and width. If the conditions are met, the wall block is rendered. Otherwise it is ignored.

    The overall size of this map (XML) is 50x50 nodes. Thats 2500 array index. With 32px tiles, this comes out to a 1600x1600 px map. Since performance degrades sharply at 1000 objects (if not before), rendering 2500 objects is a big no-no. This script allows you to only render what is needed.

    Enjoy.

  • The expressions window says F4 to hide or show. Did you try that?

  • Correct, you will need to add the AJAX object to your project.

    Then use the objects Request URL (http://yourdomain.com/somepage.php?request=user which will return what ever data you are looking for.

    Then use the AJAX objects 'On Completed' to store the response in a variable via AJAX.LastData.