elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


  Mostrar Mensajes
Páginas: 1 ... 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 [32] 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 ... 53
311  Programación / Desarrollo Web / dibujar y borrar en: 15 Abril 2015, 18:28 pm
como podria dibujar una linea en canvas  y luego borrarla cuando deje de apretar una tecla ?

 este es mi  codigo

ya puedo dibujar la linea pero cuando dejo de presionar la tecla deberia borrarse la linea dibujada


bueno pretendo hacer este juego
https://www.youtube.com/watch?v=WuuO7aOrTwo

ayuda please!!!
Código
  1.  
  2. // Variables globales
  3.  
  4.  
  5. function main()
  6. {
  7. window.addEventListener('keydown', dirigir, true);
  8. var canvas  = document.getElementById("canvas2D");
  9. var cWidth  = document.getElementById("canvas2D").width;
  10. var cheight = document.getElementById("canvas2D").height;
  11.   var context = canvas.getContext("2d");
  12.   var player={direction:39, posX:20, posY:20, ancho:10, alto:10};
  13. var enemigo={posX:200, posY:200, ancho:50, alto:50};
  14. var lineaDibujada={X1:20, Y1:20, X2:player.posX, Y2:player.posY};
  15. //context.fillRect(20,20,50,50);
  16. function init(){
  17. if(typeof game_loop!="undefined"){
  18. clearInterval(game_loop);
  19. }
  20. game_loop=setInterval(main,200);
  21. }
  22.  
  23. function dibujarLinea(X1,Y1,X2,Y2){
  24. context.save();
  25. context.moveTo(X1,Y1);
  26. context.lineTo(X2,Y2);
  27. context.strokeStyle = "#f00";
  28. context.stroke();
  29. context.restore();
  30. }
  31.  
  32.      function dirigir(evt) {
  33.  
  34.       if(evt.keyCode!=null){
  35.       switch(evt.keyCode){
  36. case 39:
  37. if(player.posX<cWidth-4){
  38.  
  39. player.posX+=2;
  40.  
  41. }
  42. break;
  43. case 37:
  44.  
  45. if(player.posX>-1){
  46. //dibujarLinea(player.posX,player.posY,player.posX-2,player.posY);
  47. player.posX-=2;
  48. }
  49. break;
  50. case 38:
  51. if(player.posY>-1){
  52. // dibujarLinea(player.posX,player.posY,player.posX,player.posY-2);
  53. player.posY -=2;
  54. }
  55. break;
  56. case 40:
  57.   if(player.posY<cheight-4){
  58.  // dibujarLinea(player.posX,player.posY,player.posX,player.posY+2);
  59.   player.posY+=2;
  60.   }
  61.  
  62. break;
  63. default:
  64. player.posX=player.posX;
  65. player.posY=player.posY;
  66.        }
  67.       }else{
  68.       context.restore();
  69.       //context.clearRect(0,0,cWidth,cheight);
  70.  
  71.       }
  72.  
  73.      }
  74.  
  75. function main(){
  76. moverEnemigo();
  77. setBackground();
  78. drawPlayer();
  79. dibujarLinea(lineaDibujada.posX1,lineaDibujada.posY1,player.posX,player.posY);
  80. drawEnemigo();
  81. }
  82. function moverEnemigo(){
  83. var aleatorio =Math.random();
  84. aleatorio =aleatorio*100;
  85. if(aleatorio<25){
  86. if(enemigo.posX<cWidth-20){
  87. enemigo.posX+=10;
  88. }else{
  89. enemigo.posX-=10;
  90. }
  91.  
  92. }
  93. if(aleatorio>=25&& aleatorio<45){
  94. if (enemigo.posX>20){
  95. enemigo.posX-=10;
  96. }else{
  97. enemigo.posX+=10;
  98. }
  99. }
  100. if(aleatorio>=45 && aleatorio<70){
  101. if(enemigo.posY>20){
  102. enemigo.posY-=10;
  103. }
  104. else{
  105. enemigo.posY+=10;
  106. }
  107. }
  108. if(aleatorio>=70 && aleatorio<=100){
  109. if(enemigo.posY<cheight-20){
  110.   enemigo.posY+=10;
  111. }else{
  112. enemigo.posY-=10;
  113. }
  114. }
  115.  
  116.  
  117. //para que se acerque al jugador e imponga miedo
  118.  
  119. }
  120. function setBackground(){
  121. context.save();
  122. context.fillStyle="white";
  123. context.fillRect(0,0,cWidth,cheight);
  124. context.strokeStyle="black";
  125. context.strokeRect(0,0,cWidth,cheight);
  126. context.restore();
  127. }
  128. setBackground();
  129. function drawPlayer(){
  130. context.save();
  131. context.fillStyle="blue";
  132. context.fillRect(player.posX,player.posY, player.ancho,player.alto);
  133. context.restore();
  134. }
  135. function drawEnemigo(){
  136. context.save();
  137. context.fillStyle="Red";
  138. context.fillRect(enemigo.posX,enemigo.posY, enemigo.ancho,enemigo.alto);
  139. context.restore();
  140. }
  141.  
  142. init();
  143. }
  144.  



Código
  1. <!DOCTYPE HTML>
  2. <script src="animatorStix.js"></script>
  3. <link rel="stylesheet" type="text/css" href="style.css">
  4. <title>GOGOGO</title>
  5. </head>
  6.  
  7. <body onload="main()">
  8. <h1> GOGOGO </h1>
  9. <canvas id="canvas2D" width="500" height="400">Navegador no soportado</canvas>
  10.  
  11.  
  12. </body>
  13.  
  14. </html>
  15.  

Mod: Tema modificado, colocadas etiquetas GeSHi para mejor visualización del código
312  Programación / Java / Re: ¿Cómo ejecutar un programa de Java en el escritorio? en: 6 Marzo 2015, 04:21 am
ahora haz la prueba que tu programa tenga una bd !!! te daras cuenta que no funcionara!!!

saludos
313  Programación / Java / Re: Necesito configurar Sublime Text 2 para hacer debug de Java! en: 6 Marzo 2015, 04:04 am
Sublime no es IDE, es un editor de texto!!!

saludos
314  Programación / Java / Re: Implementar guardado de archivo en: 24 Febrero 2015, 03:05 am
tambien podrias usar la funcion exec y usar comandos del cmd como ser touch fileNew
abrir el archivo fileNew y escribir lo que desees



slds
315  Programación / Java / Re: Cómo redimensionar tamaño de los componentes al modificar tamaño de JFrame en: 24 Febrero 2015, 02:54 am
tendrias que trabajar con layouts!!!
creo que tambien con la funcion pack();

316  Programación / Java / websocket + netbeans + java + js en: 16 Febrero 2015, 03:46 am
hola estuve realizando pizarra virtual en tiempo real pero no logro que funcione
mi codigo html
Código:
<!DOCTYPE html>
<html>
    <head>
        <title>Start Page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body onload="comenzar()">
        <h1>    Wireframe   </h1>
            <canvas id="myCanvas" width="500" height="250" style="border:1px solid #000000;">  </canvas>
           
            <div id="output"></div>
        <script type="text/javascript" src="pizarra.js"></script>
        <script type="text/javascript" src="websoket.js"></script>
       
    </body>
</html>



codigo js

Código:
function comenzar(){ 
    lienzo = document.getElementById('myCanvas');

ctx = lienzo.getContext('2d');
//Dejamos todo preparado para escuchar los eventos
document.addEventListener('mousedown',pulsaRaton,false);
document.addEventListener('mousemove',mueveRaton,false);
document.addEventListener('mouseup',levantaRaton,false);
}

function pulsaRaton(capturo){ estoyDibujando = true;
    //Indico que vamos a dibujar
    ctx.beginPath(); //Averiguo las coordenadas X e Y por dónde va pasando el ratón
    ctx.moveTo(capturo.clientX-lienzo.offsetLeft,capturo.clientY-lienzo.offsetTop);
    sendData(capturo,"pulsaRaton");
}

function mueveRaton(capturo){
    if(estoyDibujando){
        //indicamos el color de la línea
        ctx.strokeStyle='#000'; //Por dónde vamos dibujando
        ctx.lineTo(capturo.clientX-lienzo.offsetLeft,capturo.clientY-lienzo.offsetTop); ctx.stroke();
    }
    sendData(capturo,"mueveRaton");
}

function levantaRaton(capturo){ //Indico que termino el dibujo
    ctx.closePath();
    estoyDibujando = false;
    sendData(capturo,"levantaRaton");
}
function sendData(evt,methodo){
    websocket.send(JSON.stringify(
            {
                coord:{
                    x:evt.clientX,
                    y:evt.clientX,
                },
                methodName: methodo
            }
            ));
}

Código:
var wsUri = "ws://" + document.location.host + document.location.pathname + "endpoint";
var websocket = new WebSocket(wsUri);
   
websocket.onerror = function(evt) { onError(evt) };

function onError(evt) {
    writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
// For testing purposes
var output = document.getElementById("output");
websocket.onopen = function(evt) { onOpen(evt) };

function writeToScreen(message) {
    output.innerHTML += message + "<br>";
}

function onOpen() {
   
    writeToScreen("Connected to " + wsUri);
}
// End test functions
websocket.onmessage=function (evt){
   
    console.log(evt.data);
    var json=JSON.parse(evt.data);
    if(json.methodName=="pulsaRaton"){
        pulsaRaton(evt);
    }
    if(json.methodName=="mueveRaton"){
        mueveRaton(evt);
    }
    if(json.methodName=="levantaRaton"){
        levantaRaton(evt);
    }
}



y este es serverEndPoint

Código:
package org.sample.pizarra;

import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.websocket.EncodeException;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;


@ServerEndpoint("/endpoint")
public class serverEndPoint {

private static Set<Session> peers = Collections.synchronizedSet(new HashSet<Session>());

    @OnMessage
    public String onMessage(String message,Session peer) throws IOException {
       
        for(Session s: peers){
            if(s!=peer){
                s.getBasicRemote().sendText(message);
            }
        }
        return null;
    }
 
     @OnOpen
    public void onOpen (Session peer) {
        peers.add(peer);
    }

    @OnClose
    public void onClose (Session peer) {
        peers.remove(peer);
    }
   
   
   
   
}




no puedo realizar la conexion
ayuda
317  Programación / PHP / grupo de desarrollo de software en: 15 Octubre 2014, 04:26 am
hola a toda la comunidad...

quisiera formar un equipo de desarrollo de software para implementar alguna idea de algun software para la web a forma de compartir conocimiento...y mucho mas

les interesa???
318  Programación / Java / Re: Juego de estilo Flappy Bird en: 14 Octubre 2014, 02:19 am
codigo?
319  Programación / Java / Re: Como es la creación de Personajes u objetos 2d y 3D? en: 14 Octubre 2014, 02:12 am
utiliza unity !!!
320  Programación / Java / Re: Duda Java (para noob) en: 14 Octubre 2014, 02:10 am
seria asi
Código
  1. package tp.Pr0;
  2.  
  3. public class FuncsMatematicas {
  4. /* public static int factorial (int n) {
  5. return n;
  6. }*/
  7. public static void combinatorio (int n, int k) {
  8. for (int i = 0; i < 6; ++i) {
  9. for (int j = 0; j <= i; ++j)
  10. System.out.print(FuncsMatematicas.combinatorio(i, j) + " ");
  11. System.out.println();
  12. }
  13. }
  14. public static void main (String args[]) {
  15. FuncsMatematicas.combinatorio(4, 2);
  16. }
  17. }
  18.  

investiga la diferencia entre funcion y procedimiento... suerte
Páginas: 1 ... 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 [32] 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 ... 53
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines