indexing description: "[ An EM_GOOF_OBJECT that is under the laws of physics. Therefor the EM_GOOF_FORCE are applicable when it is added to EM_GOOF_PHYSICS. ]" date: "$Date$" revision: "$Revision$" class EM_GOOF_PHYSICABLE inherit EM_GOOF_ACCELERABLE redefine process, make end EM_GOOF_DESTRUCTABLE undefine process, make end EM_GOOF_COLLIDABLE undefine process, draw, make redefine collide end create make feature -- Initialization make(img: EM_BITMAP x: DOUBLE y: DOUBLE phs: EM_GOOF_PHYSICS) is -- Make physicable do Precursor{EM_GOOF_ACCELERABLE}(img,x,y,phs) Precursor{EM_GOOF_DESTRUCTABLE}(img,x,y,phs) create force.make(0,0) mass := 1 make_rect(x,y,img.width,img.height,0) end feature {EM_GOOF_OBJECT, EM_GOOF_PHYSICS, EM_GOOF_FORCE} -- Properties force: EM_VECTOR_2D -- Force applied to the physicable feature -- Properties mass: DOUBLE -- How much mass? set_mass(a_mass: DOUBLE) is -- Set mass require mass_not_zero: a_mass > a_mass.zero do mass := a_mass ensure mass_set: mass = a_mass end friction: DOUBLE -- How much friction does apply? (speed limitation) set_friction(a_friction: DOUBLE) is -- Set friction do friction := a_friction ensure friction_set: friction = a_friction end feature {EM_GOOF_OBJECT, EM_GOOF_PHYSICS} -- Processing process(time_length: DOUBLE) is -- Process this object local addup: EM_VECTOR_2D do if movement.length > movement.length.zero then addup := movement.twin addup.stretch(-friction,-friction) force := force + addup end force := force / mass acceleration.add(force) force := force.zero Precursor{EM_GOOF_ACCELERABLE}(time_length) update_position(position) end feature -- Handler collide(a_collision: EM_COLLISION [EM_COLLIDABLE]) is -- It collides local other: EM_COLLIDABLE this: EM_COLLIDABLE do if a_collision.collidables.first = collidable then this := a_collision.collidables.first other := a_collision.collidables.second else this := a_collision.collidables.second other := a_collision.collidables.first end movement := movement.reflection(a_collision.collision_direction.to_vector) acceleration := acceleration.reflection(a_collision.collision_direction.to_vector) position := last_position.twin this.reset_center(position.twin) end end