In [1]:
%matplotlib inline
from __init__ import *
from default_layout import layout

import numpy as np
import matplotlib
from matplotlib import pyplot as plt
plt.style.use('ggplot')

In [2]:
block = CollidableAABB(np.array([0.5, 0.5, 0]), np.array([0.5, 0.5]))
mario = CollidableRigid(np.array([0, 0.7, 0]), np.array([0.5, 0.3]))
mario.prev_state = np.array([[-1, 0, 0], [1, 0, 0], [0, 0, 0]])
mario.displacement_difference()


Out[2]:
array([ 1.        , -0.29980469,  0.        ])

In [3]:
block.collide(mario)


Out[3]:
{'hit': {'delta': array([ 0.5       , -0.14990234]),
  'normal': array([-1.,  0.], dtype=float16),
  'position': array([-0.02106112,  0.76394478]),
  'time': 0.5},
 'position': array([-0.501     ,  0.85039746]),
 'time': 0.499}

In [4]:
block = CollidableAABB(np.array([0, -0.5, 0]), np.array([0.5, 0.5]))
mario = CollidableRigid(np.array([0, 0.3, 0]), np.array([0.5, 0.3]))
block.collide(mario)


Out[4]:
{'hit': None,
 'position': array([ 0.        ,  0.30004883], dtype=float16),
 'time': 1}

In [5]:
block = CollidableAABB(np.array([0, -0.5, 0]), np.array([0.5, 0.5]))
mario = CollidableRigid(np.array([0, 0.3, 0]), np.array([0.5, 0.3]))
mario.prev_state[:, 0] = [-1, 0.3, 0]
print block.collide(mario)
print mario.prev_state
print mario.state


{'position': array([ 0.        ,  0.30004883], dtype=float16), 'hit': None, 'time': 1}
[[-1.          0.          0.        ]
 [ 0.30004883  0.          0.        ]
 [ 0.          0.          0.        ]]
[[ 0.          0.          0.        ]
 [ 0.30004883  0.          0.        ]
 [ 0.          0.          0.        ]]

In [6]:
layout[3:8, 3:8]


Out[6]:
array([[1, 0, 0, 0, 0],
       [1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [1, 1, 1, 0, 0]])

In [7]:
sim = MarioSimulation(layout, {"init_pos": (5.7, 3.2, 0), "dtype": "float16"})
sim.mario.state[0:2, 1] = [0.4, 0.6]

In [8]:
pos, collision = sim.run(None, None, None)
print pos
print collision


- next unchecked state:
[[ 6.09765625  0.39990234  0.        ]
 [ 3.79882812  0.60009766  0.        ]
 [ 0.          0.          0.        ]]
- collision status:
((5, 2), {'position': array([ 5.69921875,  3.19921875], dtype=float16), 'hit': {'position': array([ 5.9765625,  4.03125  ], dtype=float16), 'delta': array([ 0.,  0.], dtype=float16), 'normal': array([-1.,  0.], dtype=float16), 'time': 0}, 'time': 0})
(5, 2)
{'position': array([ 5.69921875,  3.19921875], dtype=float16), 'hit': {'position': array([ 5.9765625,  4.03125  ], dtype=float16), 'delta': array([ 0.,  0.], dtype=float16), 'normal': array([-1.,  0.], dtype=float16), 'time': 0}, 'time': 0}

In [9]:
sim.mario.state[0:2, 0] -= collision["hit"]["delta"]
print sim.mario.state


[[ 6.09765625 -0.39990234  0.        ]
 [ 3.79882812  0.60009766  0.        ]
 [ 0.          0.          0.        ]]

In [10]:
hit_edge_reaction(collision)


Out[10]:
<function momentum_handler.hit_sides>

In [11]:
sim.mario.radius


Out[11]:
array([ 0.5,  1. ])

In [16]:
sim = MarioSimulation(layout, {"init_pos": (4, 5.7, 0), "dtype": "float16"})
sim.mario.state[0:2, 1] = [0, -0.4]

In [17]:
pos, collision = sim.run(None, None, None)
print pos
print collision


- next unchecked state:
[[ 4.          0.          0.        ]
 [ 5.30078125 -0.39990234  0.        ]
 [ 0.          0.          0.        ]]
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-17-dca55c9565ac> in <module>()
----> 1 pos, collision = sim.run(None, None, None)
      2 print pos
      3 print collision

/Users/Lithium/Dropbox/Courses/UCI/junior/CS 175/Project/master-repo/malrio/src/SuperMarioBros/simulation.py in run(self, input, observer, action, printable)
    103             self.mario.reaction(hit_edge_reaction(closest_collision[1]))
    104 
--> 105         return closest_collision
    106 """
    107         if printable: print '- next state with oldspeed:\n', self.mario.state

UnboundLocalError: local variable 'closest_collision' referenced before assignment

In [ ]: