Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 0e77bba279395d1c9e1f98c452d3b010 > files > 57

edje-devel-1.0.0-2.fc15.i686.rpm

<html>
<head>
    <title>Edje: embryo_pong.edc</title>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
    <meta name="author" content="Andres Blanc" >
    
    <link rel="icon" href="img/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="img/favicon.png" type="image/x-icon">
    <link rel="icon" href="img/favicon.png" type="image/ico">
    <link rel="shortcut icon" href="img/favicon.png" type="image/ico">

    <link rel="stylesheet" type="text/css" href="e.css">
    <link rel="stylesheet" type="text/css" href="edoxy.css">
</head>

<body>

<div id="container">

<div id="header">
<div class="layout">
    
    <h1><span>Enlightenment</span></h1>
    <h2><span>Beauty at your fingertips</span></h2>

    <table cellspacing="0" cellpadding="0" width="100%"><tr>
      <td id="header_logo">
        <a href="http://www.enlightenment.org"></a>
      </td>
      <td id="header_menu">
        <table cellspacing="0" cellpadding="0" align="right"><tr>
          <td class="nav_passive"><a class="nav_passive" href="http://www.enlightenment.org/p.php?p=home">Home</a></td> 
          <td class="nav_passive"><a class="nav_passive" href="http://www.enlightenment.org/p.php?p=news">News</a></td> 
          <td class="nav_passive"><a class="nav_passive" href="http://www.enlightenment.org/p.php?p=about">About</a></td> 
          <td class="nav_passive"><a class="nav_passive" href="http://www.enlightenment.org/p.php?p=download">Download</a></td> 
          <td class="nav_passive"><a class="nav_passive" href="http://www.enlightenment.org/p.php?p=support">Support</a></td> 
          <td class="nav_passive"><a class="nav_passive" href="http://www.enlightenment.org/p.php?p=contribute">Contribute</a></td> 
          <td class="nav_passive"><a class="nav_passive" href="http://www.enlightenment.org/p.php?p=contact">Contact</a></td> 
          <td class="nav_passive"><a class="nav_passive" href="http://trac.enlightenment.org/e">Tracker</a></td>
          <td class="nav_passive"><a class="nav_passive" href="http://www.enlightenment.org/p.php?p=docs">Docs</a></td> 
        </tr></table>          
      </td>
      <td id="header_last"></td>
    </tr></table>

    <div class="doxytitle">
        Edje Documentation <small>at Tue Feb 8 2011</small>
    </div>

    <div class="menu-container">
        <div class="submenu">
            <ul class="current">
                <li><a href="files.html">Files</a></li>
                <li><a href="Edje__Edit_8h.html">Edje Edit API</a></li>
                <li><a href="examples.html">Examples</a></li>
                <li><a href="luaref.html">LUA scripting</a></li>
                <li><a href="Edje_8h.html">Edje API</a></li>
                <li><a href="edcref.html">EDC Reference</a></li>
                <li class="current"><a  href="index.html">Main Page</a></li>
            </ul>
        </div>
    </div>


    <div class="clear"></div>
</div>
</div>

<div id="content">
<div class="layout">
<!-- Generated by Doxygen 1.7.3 -->
</div>
<div class="header">
  <div class="headertitle">
<h1>embryo_pong.edc</h1>  </div>
</div>
<div class="contents">
<p>Super-simple Pong implementation in pure embryo.</p>
<div class="fragment"><pre class="fragment">
<span class="preprocessor">#define DEBUG_ENABLE 0</span>
<span class="preprocessor"></span><span class="preprocessor">#define FPS 30</span>
<span class="preprocessor"></span><span class="preprocessor">#define COLOR_BG 50 50 50 255</span>
<span class="preprocessor"></span><span class="preprocessor">#define COLOR_FG 222 222 222 255</span>
<span class="preprocessor"></span><span class="preprocessor">#define PAD_SIZE 60</span>
<span class="preprocessor"></span><span class="preprocessor">#define PAD_DISTANCE 20</span>
<span class="preprocessor"></span><span class="preprocessor">#define BALL_SPEED 5.0</span>
<span class="preprocessor"></span><span class="preprocessor">#define BALL_SPEEDUP 0.1</span>
<span class="preprocessor"></span><span class="preprocessor">#define BALL_SIZE 10</span>
<span class="preprocessor"></span>
<span class="preprocessor">#if DEBUG_ENABLE</span>
<span class="preprocessor"></span><span class="preprocessor">#define DBG(...) { \</span>
<span class="preprocessor">   new _buf[128]; \</span>
<span class="preprocessor">   snprintf(_buf, sizeof(_buf), __VA_ARGS__); \</span>
<span class="preprocessor">   set_text(PART:&quot;dbg&quot;, _buf); }</span>
<span class="preprocessor"></span><span class="preprocessor">#else</span>
<span class="preprocessor"></span><span class="preprocessor">#define DBG(...)</span>
<span class="preprocessor"></span><span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
collections {
   group { <a name="a0"></a><a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;main&quot;</span>;
      min: 500 300;
      script {
         <span class="keyword">public</span> ballx, bally;
         <span class="keyword">public</span> ballspeedx, ballspeedy;
         <span class="keyword">public</span> player_score, ai_score;

         <span class="keyword">public</span> game_reset() {
            set_int(ai_score, 0);
            set_int(player_score, 0);
            set_text(PART:<span class="stringliteral">&quot;score1&quot;</span>, <span class="stringliteral">&quot;0&quot;</span>);
            set_text(PART:<span class="stringliteral">&quot;score2&quot;</span>, <span class="stringliteral">&quot;0&quot;</span>);
            game_init();
         }
         
         <span class="keyword">public</span> game_init() {
            set_float(ballspeedx, 0.0);
            set_float(ballspeedy, 0.0);
            set_float(ballx, 100);
            set_float(bally, 100);
         }
         
         <span class="keyword">public</span> start_game() {
            set_float(ballspeedx, BALL_SPEED);
            set_float(ballspeedy, BALL_SPEED * randf());
         }

         <span class="keyword">public</span> player_wins() {
            <span class="keyword">new</span> buf[16]
            set_int(player_score, get_int(player_score) + 1);
            snprintf(buf, <span class="keyword">sizeof</span>(buf), <span class="stringliteral">&quot;%d&quot;</span>, get_int(player_score));
            set_text(PART:<span class="stringliteral">&quot;score1&quot;</span>, buf);
            game_init();
         }

         <span class="keyword">public</span> ai_wins() {
            <span class="keyword">new</span> buf[16]
            set_int(ai_score, get_int(ai_score) + 1);
            snprintf(buf, <span class="keyword">sizeof</span>(buf), <span class="stringliteral">&quot;%d&quot;</span>, get_int(ai_score));
            set_text(PART:<span class="stringliteral">&quot;score2&quot;</span>, buf);
            game_init();
         }

         <span class="keyword">public</span> game_loop(count) {
            count++;

            <span class="comment">/* get field geometry */</span>
            <span class="keyword">new</span> fx, fy, fw, fh;
            get_geometry(PART:<span class="stringliteral">&quot;bg&quot;</span>, fx, fy, fw, fh);

            <span class="comment">/* get mouse coords */</span>
            <span class="keyword">new</span> mx, my;
            get_mouse(mx, my);

            <span class="comment">/* get the ball info */</span>
            <span class="keyword">new</span> Float:bx = get_float(ballx);
            <span class="keyword">new</span> Float:by = get_float(bally);
            <span class="keyword">new</span> Float:speedx = get_float(ballspeedx);
            <span class="keyword">new</span> Float:speedy = get_float(ballspeedy);

            <span class="comment">/* move the player pad */</span>
            <span class="keyword">new</span> pady = my - PAD_SIZE / 2;
            <span class="keywordflow">if</span> (pady &lt; 0) pady = 0;
            <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pady + PAD_SIZE &gt; fh) pady = fh - PAD_SIZE;
            custom_state(PART:<span class="stringliteral">&quot;pad1&quot;</span>, <span class="stringliteral">&quot;default&quot;</span>, 0.0);
            set_state_val(PART:<span class="stringliteral">&quot;pad1&quot;</span>, STATE_REL1_OFFSET, 20, pady);
            set_state(PART:<span class="stringliteral">&quot;pad1&quot;</span>, <span class="stringliteral">&quot;custom&quot;</span>, 0.0);

            <span class="comment">/* move the AI pad */</span>
            <span class="keyword">new</span> pad2y = round(by) - PAD_SIZE / 2 - BALL_SIZE / 2;
            <span class="keywordflow">if</span> (pad2y &lt; 0) pad2y = 0;
            <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pad2y + PAD_SIZE &gt; fh) pad2y = fh - PAD_SIZE;
            custom_state(PART:<span class="stringliteral">&quot;pad2&quot;</span>, <span class="stringliteral">&quot;default&quot;</span>, 0.0);
            set_state_val(PART:<span class="stringliteral">&quot;pad2&quot;</span>, STATE_REL1_OFFSET, 20, pad2y);
            set_state(PART:<span class="stringliteral">&quot;pad2&quot;</span>, <span class="stringliteral">&quot;custom&quot;</span>, 0.0);
         
            <span class="comment">/* calc new ball position */</span>
            bx += speedx;
            by += speedy;

            <span class="comment">/* check walls collision */</span>
            <span class="keywordflow">if</span> (by &lt; 0)
            {
               speedy = -speedy;
               by = 0;
            }
            <span class="keywordflow">else</span> <span class="keywordflow">if</span> (by + BALL_SIZE &gt; fh)
            {
               speedy = -speedy;
               by = fh - BALL_SIZE - 1;
            }

            <span class="comment">/* check player pad collision */</span>
            <span class="keywordflow">if</span> ((speedx &lt; 0) &amp;&amp;
                (bx &lt; PAD_DISTANCE + 10) &amp;&amp; (bx &gt; 0) &amp;&amp;
                (by + BALL_SIZE &gt; pady) &amp;&amp; (by &lt; pady + PAD_SIZE))
            {
               <span class="keyword">new</span> Float:dy = by - pady - PAD_SIZE / 2;
               speedy += dy / 10;
               speedx = -speedx + BALL_SPEEDUP;
            }

            <span class="comment">/* check AI pad collision */</span>
            <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((bx + BALL_SIZE &gt; fw - PAD_DISTANCE - 10) &amp;&amp;
                     (bx + BALL_SIZE &lt; fw) &amp;&amp;
                     (by + BALL_SIZE &gt; pad2y) &amp;&amp; (by &lt; pad2y + PAD_SIZE))
            {
               <span class="keyword">new</span> Float:dy = by - pad2y - PAD_SIZE / 2;
               speedy += dy / 10;
               speedx = -speedx - BALL_SPEEDUP;
            }
            
            <span class="comment">/* apply the new ball position */</span>
            custom_state(PART:<span class="stringliteral">&quot;ball&quot;</span>, <span class="stringliteral">&quot;default&quot;</span>, 0.0);
            set_state_val(PART:<span class="stringliteral">&quot;ball&quot;</span>, STATE_REL1_OFFSET, round(bx), round(by));
            set_state(PART:<span class="stringliteral">&quot;ball&quot;</span>, <span class="stringliteral">&quot;custom&quot;</span>, 0.0);

            <span class="comment">/* update global vars */</span>
            set_float(ballx, bx);
            set_float(bally, by);
            set_float(ballspeedx, speedx);
            set_float(ballspeedy, speedy);

            <span class="comment">/* AI score a point */</span>
            <span class="keywordflow">if</span> (bx &lt; 0) ai_wins();
            <span class="comment">/* player score a point */</span>
            <span class="keywordflow">if</span> (bx + BALL_SIZE &gt; fw) player_wins();

            <span class="comment">/* show debug info (if debug enabled) */</span>
            DBG(<span class="stringliteral">&quot;loop:%d  [speed %f  %f] [mouse: %d %d] [ball: %f %f]&quot;</span>,
                count, speedx, speedy, mx, my, bx, by)

            <span class="comment">/* recall the loop in n seconds */</span>
            timer(1.0 / FPS, <span class="stringliteral">&quot;game_loop&quot;</span>, count);
         }
      }
      parts {
         part { <a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;bg&quot;</span>;
            <a name="a1"></a><a class="code" href="edje__data_8c.html#a0dae2edc8bfd2bedabfa38415c35f3ec">type</a>: RECT;
            description { state: <span class="stringliteral">&quot;default&quot;</span> 0.0;
               color: COLOR_BG;
            }
         }
         part { <a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;net&quot;</span>;
            <a class="code" href="edje__data_8c.html#a0dae2edc8bfd2bedabfa38415c35f3ec">type</a>: RECT;
            description { state: <span class="stringliteral">&quot;default&quot;</span> 0.0;
               color: COLOR_FG;
               max: 10 9999;
            }
         }
         part { <a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;score1&quot;</span>;
            <a class="code" href="edje__data_8c.html#a0dae2edc8bfd2bedabfa38415c35f3ec">type</a>: TEXT;
            description { state: <span class="stringliteral">&quot;default&quot;</span> 0.0;
               color: COLOR_FG;
               rel2.relative: 0.5 0.5;
               rel2.offset: -20 0;
               text {
                  text: <span class="stringliteral">&quot;0&quot;</span>;
                  font: <span class="stringliteral">&quot;Sans&quot;</span>;
                  size: 50;
                  align: 1.0 0.0;
               } 
            }
         }
         part { <a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;score2&quot;</span>;
            <a class="code" href="edje__data_8c.html#a0dae2edc8bfd2bedabfa38415c35f3ec">type</a>: TEXT;
            description { state: <span class="stringliteral">&quot;default&quot;</span> 0.0;
               color: COLOR_FG;
               rel1.relative: 0.5 0.0;
               rel1.offset: 20 0;
               text {
                  text: <span class="stringliteral">&quot;0&quot;</span>;
                  font: <span class="stringliteral">&quot;Sans&quot;</span>;
                  size: 50;
                  align: 0.0 0.0;
               } 
            }
         }
         part { <a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;pad1&quot;</span>;
            <a class="code" href="edje__data_8c.html#a0dae2edc8bfd2bedabfa38415c35f3ec">type</a>: RECT;
            description { state: <span class="stringliteral">&quot;default&quot;</span> 0.0;
               color: COLOR_FG;
               max: 10 PAD_SIZE;
               fixed: 1 1;
               align: 0.0 0.0;
               rel1.offset: PAD_DISTANCE 0;
            }
         }
         part { <a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;pad2&quot;</span>;
            <a class="code" href="edje__data_8c.html#a0dae2edc8bfd2bedabfa38415c35f3ec">type</a>: RECT;
            description { state: <span class="stringliteral">&quot;default&quot;</span> 0.0;
               color: COLOR_FG;
               max: 10 PAD_SIZE;
               fixed: 1 1;
               align: 1.0 0.0;
               rel2.offset: -PAD_DISTANCE 0;
            }
         }
         part { <a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;ball&quot;</span>;
            <a class="code" href="edje__data_8c.html#a0dae2edc8bfd2bedabfa38415c35f3ec">type</a>: RECT;
            description { state: <span class="stringliteral">&quot;default&quot;</span> 0.0;
               color: COLOR_FG;
               max: BALL_SIZE BALL_SIZE;
               fixed: 1 1;
               align: 0.0 0.0;
               rel1.offset: 100 100;
            }
         }
<span class="preprocessor">         #if DEBUG_ENABLE</span>
<span class="preprocessor"></span>         part { <a class="code" href="edje__data_8c.html#a8f8f80d37794cde9472343e4487ba3eb">name</a>: <span class="stringliteral">&quot;dbg&quot;</span>;
            <a class="code" href="edje__data_8c.html#a0dae2edc8bfd2bedabfa38415c35f3ec">type</a>: TEXT;
            description { state: <span class="stringliteral">&quot;default&quot;</span> 0.0;
               color: 255 255 255 200;
               text {
                  font: <span class="stringliteral">&quot;Sans&quot;</span>;
                  size: 12;
                  align: 1.0 1.0;
               }
            }
         }
<span class="preprocessor">         #endif</span>
<span class="preprocessor"></span>      }
      programs {
         <span class="comment">/* on load: reset the game and start the game loop */</span>
         program {
            signal: <span class="stringliteral">&quot;load&quot;</span>;
            source: <span class="stringliteral">&quot;&quot;</span>;
            script {
               game_reset();
               timer(0.1 , <span class="stringliteral">&quot;game_loop&quot;</span>, 0);
            }
         }
         <span class="comment">/* mouse left click: start the game, if not yet started */</span>
         program {
            signal: <span class="stringliteral">&quot;mouse,down,1&quot;</span>;
            source: <span class="stringliteral">&quot;bg&quot;</span>;
            script {
               <span class="keywordflow">if</span> (get_float(ballspeedx) == 0.0)
                  start_game();
            }
         }
         <span class="comment">/* mouse right click: restart the game*/</span>
         program {
            signal: <span class="stringliteral">&quot;mouse,down,3&quot;</span>;
            source: <span class="stringliteral">&quot;bg&quot;</span>;
            script {
               game_reset();
            }
         }
      }
   }
}
</pre></div> </div>
</div>
 
 <div id="push"></div>
 </div> <!-- #content -->
  </div> <!-- .layout -->
 
 </div> <!-- #container -->
 
 
  <div id="footer">
    <table><tr>
      <td class="copyright">Copyright &copy;2011 Enlightenment</td>
      <td class="generated">Docs generated Tue Feb 8 2011 17:28:42</td>
    </tr></table>
  </div>


</body>
</html>