forked from pyrex/chameleonic
		
	catch up to latest developments #10
| @@ -117,22 +117,46 @@ end | ||||
| kbd={} | ||||
| add(real_modules,kbd) | ||||
| function kbd:init() | ||||
|  self.prev_real=btn() | ||||
|  self.real=btn() | ||||
|  self.down=0 | ||||
| end | ||||
|  | ||||
| function kbd:update() | ||||
|  local now=btn() | ||||
|  local pressed=now&~self.prev_real | ||||
|  self.down&=now | ||||
|  self.down|=pressed | ||||
|  self.prev_real=now | ||||
|  -- figure out what keys are _really_ pressed | ||||
|  local now_real=btn() | ||||
|  local was_real=self.real | ||||
|  self.real=now_real | ||||
|  | ||||
|  -- add keys that are really pressed  | ||||
|  -- if they weren't really pressed before | ||||
|  -- (they may have been force- | ||||
|  --  released by :release()) | ||||
|  local real_pressed=(~was_real)&now_real | ||||
|  | ||||
|  local now_down=(self.down&now_real)|real_pressed | ||||
|  local was_down=self.down | ||||
|  self.down=now_down | ||||
|  | ||||
|  -- deduce pressed/released by changes in down | ||||
|  local pressed=(~was_down)&now_down | ||||
|  local released=(~now_down)&was_down | ||||
|  | ||||
|  self.pressed=pressed | ||||
|  self.released=released | ||||
| end | ||||
|  | ||||
| function kbd:btn(i) | ||||
|  return self.down&(1<<i)!=0 | ||||
| end | ||||
|  | ||||
| function kbd:btnp(i) | ||||
|  return self.pressed&(1<<i)!=0 | ||||
| end | ||||
|  | ||||
| function kbd:btnr(i) | ||||
|  return self.released&(1<<i)!=0 | ||||
| end | ||||
|  | ||||
| function kbd:release(i) | ||||
|  self.down&=~(1<<i) | ||||
| end | ||||
| @@ -624,33 +648,41 @@ function player:update() | ||||
|   end | ||||
|  | ||||
|   if kbd:btn(0) then  | ||||
|    if level:can_move(true,self.x,self.y,-1,0,0,2) then | ||||
|     self.todo=f4({{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1}}) | ||||
|    else | ||||
|    self.orientx=-1 | ||||
|    self.orienty=0 | ||||
|   elseif kbd:btn(1) then | ||||
|    self.orientx=1 | ||||
|    self.orienty=0 | ||||
|   elseif kbd:btn(2) then | ||||
|    self.orienty=-1 | ||||
|   elseif kbd:btn(3) then | ||||
|    self.orienty=1 | ||||
|   end | ||||
|  | ||||
|   if kbd:btn(4) then | ||||
|    if kbd:btnp(4) and self.rope!=nil then  | ||||
|     self.rope:destroy() | ||||
|     kbd:release(4) | ||||
|    end | ||||
|    -- wait for user to release it | ||||
|   else | ||||
|    if kbd:btn(0) then  | ||||
|     if level:can_move(true,self.x,self.y,-1,0,0,2) then | ||||
|      self.todo=f4({{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1}}) | ||||
|     end | ||||
|    elseif kbd:btn(1) then | ||||
|     if level:can_move(true,self.x,self.y,1,0,0,2) then | ||||
|      self.todo=f4({{orientx=1,orienty=0,px=2},{px=7},{x=self.x+1}}) | ||||
|    else | ||||
|     self.orientx=1 | ||||
|     self.orienty=0 | ||||
|     end | ||||
|    elseif kbd:btn(2) then | ||||
|     if level:can_move(true,self.x,self.y,0,-1,0,2) then | ||||
|      self.todo=f4({{orienty=-1,py=-2},{py=-7},{y=self.y-1}}) | ||||
|    else | ||||
|     self.orienty=-1 | ||||
|     end | ||||
|    elseif kbd:btn(3) then | ||||
|     if level:can_move(true,self.x,self.y,0,1,0,2) then | ||||
|      self.todo=f4({{orienty=1,py=2},{py=7},{y=self.y+1}}) | ||||
|    else | ||||
|     self.orienty=1 | ||||
|     end | ||||
|   elseif kbd:btn(4) then | ||||
|    if self.rope==nil then | ||||
|    elseif self.rope==nil and kbd:btnr(4) then | ||||
|     local rx,ry,rx2,ry2=self:_rope_pos() | ||||
|     local dx,dy=12*self.orientx,12*self.orienty | ||||
|     if (dy!=0) dx=0 | ||||
| @@ -660,14 +692,11 @@ function player:update() | ||||
|      update=function() | ||||
|       return self.rope==nil or self.rope:latched() | ||||
|      end | ||||
|     },{},{}} | ||||
|    else | ||||
|     self.rope:tug() | ||||
|     self.todo={{},{},{}} | ||||
|    end | ||||
|   elseif kbd:btn(5) then | ||||
|     }} | ||||
|    elseif kbd:btnp(5) then | ||||
|     if self.rope!=nil then | ||||
|     self.rope:destroy() | ||||
|      self.rope:tug() | ||||
|     end | ||||
|    end | ||||
|   end | ||||
|  end | ||||
| @@ -686,9 +715,6 @@ function player:update() | ||||
|  | ||||
|   if self.rope:done() then | ||||
|    self.rope=nil | ||||
|    add(self.todo,{}) | ||||
|    add(self.todo,{}) | ||||
|    add(self.todo,{}) | ||||
|   end | ||||
|  end | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user