snake-game3.md

从零开始设计一个类贪吃蛇的框架(三) 从零开始设计一个类贪吃蛇的框架(一) 从零开始设计一个类贪吃蛇的框架(二) 我们的蛇不能老是傻傻地瞎转悠 为了让蛇显得聪明些,我们增加一些相关的效果 比如停、撞墙、躲避墙 让蛇停下来 function SnakeGameController:stopSnake() print("stopping snake!") for i=1,snake["nodes"] do snake["x"][i] = display.cx snake["y"][i] = display.cy end self:drawSnakeNode(BLUE) end 如果点击或触摸,让蛇转向 转向要首先判断方向,我们把他单独实现出来 function SnakeGameController:needChangeDirection(x,y) print("Detected touch!!!!!") x = x - display.width/2 y = y - display.height/2 curDirection = snake["direction"] snakeHead = snake["nodes"] if curDirection<3 and y > snake["y"][snakeHead] then newDirection = 3 elseif curDirection<3 and y < snake["y"][snakeHead] then newDirection = 4 elseif curDirection>2 and x > snake["x"][snakeHead] then newDirection = 1 elseif curDirection>2 and x < snake["x"][snakeHead] then newDirection = 2 end return newDirection end 触摸事件,按方向移动 function SnakeGameController:onTouch(event, x, y) newDirection = self:needChangeDirection(x,y) print("Direction is ".
Read more →

socketio.md

Learning socket.io combine socket.io with express is easy var app = require('express')(); var server = require('http').createServer(app); var io = require('socket.io').listen(server); setting route of express app.get('/', function(req, res){ res.sendfile(__dirname + '/index.html'); }); setting socket.io on server side io.sockets.on('connection',function(socket){ io.sockets.emit('sayhello',{hello:'world'}); io.sockets.emit('news','All done!'); // receive the socket from client socket.on('feedback',function(data){ console.log("your feedback recevied",data.msg) io.sockets.emit('feedback',data.msg); }); socket.on('login',function(data){ console.log('Got your name:', data); var msg = data.name + ' just logged in'; //broadcast to client io.sockets.emit('news',msg); //save data to a file }); }); Note: io.
Read more →

virtual_machines.md

Read more →

virtualbox.md

Read more →

vmc.md

Read more →