package com.kenny.mvc
{
import flash.events.Event;
import flash.utils.Dictionary;
/**
* ...
* @author Hai
*/
public final class Controller
{
private var _handlers:Object;
private var _state:State;
private var _subscribers:Dictionary;
public function Controller()
{
_handlers = new Object();
_state = new State(_notify);
_subscribers = new Dictionary();
}
public function registerHandler($eventType:String, $handler:Function)
{
_handlers[$eventType] = $handler;
}
public function handleEvent($event:Event): Boolean
{
if (_handlers.hasOwnProperty($event.type)) return _handlers[$event.type].call(null, $event, _state);
else return false;
}
public function subscribe($propertyNames:Array, $callback:Function)
{
var subscriber:Object = {
callback: $callback,
args: $propertyNames
}
for each (var name:String in $propertyNames) {
if (_subscribers[name]) _subscribers[name].push(subscriber);
else _subscribers[name] = [subscriber];
}
_notifySubscriber(subscriber);
}
private function _notify($name:*)
{
if (_subscribers[$name]) for each (var subscriber:Object in _subscribers[$name]) _notifySubscriber(subscriber);
}
private function _notifySubscriber($subscriber:Object)
{
$subscriber.callback.apply(null, $subscriber.args.map(_getValue));
}
private function _getValue($name:*, ...rest): *
{
return _state[$name];
}
}
}
import flash.utils.Dictionary;
import flash.utils.flash_proxy;
import flash.utils.Proxy;
dynamic class State extends Proxy
{
private var _data:Dictionary;
private var _notify:Function;
public function State($notify:Function)
{
_data = new Dictionary();
_notify = $notify;
}
override flash_proxy function setProperty($name:*, $value:*): void
{
if (_data[$name] !== $value) {
_data[$name] = $value;
_notify($name);
}
}
override flash_proxy function getProperty($name:*): *
{
return _data[$name];
}
}
Inventions?
Monday, December 19, 2011
The Best MVC Framework Ever
Wednesday, November 16, 2011
Tuesday, January 22, 2008
Pull-up Sun Shade
Automobile interiors often suffer intense heat when parked in the mid-day sun. Sun Shades protect the interior by blocking sun light entering through the windshield. Similarly side window shades blocks a portion of sun light from entering through side and back window. Side and back windows can also be tinted to provide some protection.Currently all sunshades are in the form of removable foldable aluminum foil sheets or nylon meshes. This invention is a type of sunshade that is integrated with the automobile in the form of a pull-up sheet made of any of the above protective material, to be installed right behind the windshield. THe sheet has to be pulled up by a person from the dashboard and hooked to the rearview mirror. The sheet may not be pulled up when the car is turned on.
Wednesday, December 26, 2007
Aimbot for ZWok
An Aimbot for ZWok can be implemented as a Win32 application that captures keyboard and mouse events using system hooks, and use a set of keyboard mnemonics for calibration as well as aiming.
Assumption:
We make the simplifying assumption that, in ZWok, gravity is constant in all levels and that there is no wind or drag. The motion of the projectile is given by the following equations:
x = x0 + v0t cos(theta)
y = y0 + v0t sin(theta) + .5 g t^2
where (x0, y0) is the initial position, v0 the initial velocity (magnitude only), theta the angle of discharge, and g the gravitational acceleration. Solving the first equation for v0t and substituting into the second, we get equation [1]:
y = y0 + (x-x0) tan(theta) + .5 (g/v0^2) (x-x0)^2 / cos(theta)^2
Calibration:
Calibration is the process of determining the value of g from an actual projectile. To do that, in ZWok, we shoot a random projectile and capture:
1. The starting point (x0, y0)
2. The aim vector (v0, theta)
3. A random point on the curve (x1, y1)
Substituting the values into the equation [1] and solving for g, we get:
g = (v0^2) * {[2 cos(theta)^2 (y1-y0) / (x1-x0)^2] - [sin(2theta) / (x1-x0)]}
Application
Now that we have g, we can substitute it back into equation [1], which now can be used to trace the path of a projectile from any starting point and initial velocity.
Our Aimbot can implement a simple interface with one key combination (for example, CTRL-SHIFT-X) for marking position on the screen. The first key press will mark the starting position, the second time marks the target. After that the Aimbot begins tracking the mouse position and computes in real-time the aim vector, using equation [1] to determine how close the projectile comes to hitting the target and display the deviation numerically or using a graphical fill bar. Advanced bots can even plot out the path on the screen.
Note that ZWok targets can move. Aimbot is useful only if you know the target won't move next turn, or if you know where it is moving to. It is possible to specify another point that the projectile has to pass through, and provide an additional deviation meter for aiming.
Assumption:
We make the simplifying assumption that, in ZWok, gravity is constant in all levels and that there is no wind or drag. The motion of the projectile is given by the following equations:
x = x0 + v0t cos(theta)
y = y0 + v0t sin(theta) + .5 g t^2
where (x0, y0) is the initial position, v0 the initial velocity (magnitude only), theta the angle of discharge, and g the gravitational acceleration. Solving the first equation for v0t and substituting into the second, we get equation [1]:
y = y0 + (x-x0) tan(theta) + .5 (g/v0^2) (x-x0)^2 / cos(theta)^2
Calibration:
Calibration is the process of determining the value of g from an actual projectile. To do that, in ZWok, we shoot a random projectile and capture:
1. The starting point (x0, y0)
2. The aim vector (v0, theta)
3. A random point on the curve (x1, y1)
Substituting the values into the equation [1] and solving for g, we get:
g = (v0^2) * {[2 cos(theta)^2 (y1-y0) / (x1-x0)^2] - [sin(2theta) / (x1-x0)]}
Application
Now that we have g, we can substitute it back into equation [1], which now can be used to trace the path of a projectile from any starting point and initial velocity.
Our Aimbot can implement a simple interface with one key combination (for example, CTRL-SHIFT-X) for marking position on the screen. The first key press will mark the starting position, the second time marks the target. After that the Aimbot begins tracking the mouse position and computes in real-time the aim vector, using equation [1] to determine how close the projectile comes to hitting the target and display the deviation numerically or using a graphical fill bar. Advanced bots can even plot out the path on the screen.
Note that ZWok targets can move. Aimbot is useful only if you know the target won't move next turn, or if you know where it is moving to. It is possible to specify another point that the projectile has to pass through, and provide an additional deviation meter for aiming.
Subscribe to:
Posts (Atom)
