Skip to content

Instantly share code, notes, and snippets.

View EncodeTheCode's full-sized avatar
💭
Coding useful tools for workflow.

EncodeTheCode

💭
Coding useful tools for workflow.
View GitHub Profile
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
from numpy import *
vertices = array([
[-1, -1, -1],
[1, -1, -1],
[1, 1, -1],
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import random
import numpy as np
# Define the cube vertices
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
import random
pygame.init()
clock = pygame.time.Clock()
local clock=os.clock
function sleep(n)
local t=clock()
while clock()-t<=n do end
end
function sleep_for(t)
local t = t or 0
sleep(t) -- Sleep server connection for 1 entire second.
end
while true do
local keyPress = io.read(1)
if keyPress == "w" or keyPress == "W" then
print("You just pressed W")
elseif keyPress == "a" or keyPress == "A" then
print("You just pressed A")
elseif keyPress == "s" or keyPress == "S" then
print("You just pressed S")
elseif keyPress == "d" or keyPress == "D" then
print("You just pressed D")
local socket = require("socket")
-- create a TCP server and bind it to port 12345
local server = socket.tcp()
server:bind("*", 12345)
server:listen()
-- set the server to non-blocking mode
server:settimeout(0)
addbind("W")
addbind("A")
addbind("S")
addbind("D")
function onPlayerKeyPress(id,key,state)
if(key=="W" and state==1) then
msg("W is pressed!")
elseif(key=="A" and state==1) then
msg("A is pressed!")
function onPlayerKeyPress(id,key,state)
if(key=="W" and state==1) then
print("W is pressed!")
elseif(key=="A" and state==1) then
print("A is pressed!")
elseif(key=="S" and state==1) then
print("S is pressed!")
elseif(key=="D" and state==1) then
print("D is pressed!")
end
function onPlayerKey(player, key, state)
if state == 1 then
if key == 87 then -- W key
-- do something when W is pressed
elseif key == 65 then -- A key
-- do something when A is pressed
elseif key == 83 then -- S key
-- do something when S is pressed
elseif key == 68 then -- D key
-- do something when D is pressed
function c_msg(p,r,g,b,m,c)
r,g,b,c=r or '0',g or '0',b or '0',c or ''
local k = string.format("%s%s%s%s", string.char(169), r, g, b)
-- k=string.sub(k,1,-1)
-- k=string.gsub(k,"%s+","")
msg2(p, k .. m .. c);
end
function onPlayerKeyPress(id,key,state)
if(state==1)then