Modified the EspeakParadise testing game a bit -- experimenting with dinamicly adding...
[alterverse.git] / src / org / alterverse / world / MovableObject.java
blobe6f92a75bd3ff1e58a954445a1c48c1c0d7dd795
1 /***************************************************************************
2 * Copyright (C) 2010 by the Alterverse team *
3 * email: rynkruger@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write see: *
17 * <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
20 package org.alterverse.world;
22 import org.alterverse.shapes.*;
24 public class MovableObject extends GameObject {
25 double oldX;
26 double oldY;
27 double oldZ;
28 public MovableObject(double x, double y, double z, Shape shape) {
29 super(x,y,z,shape);
30 oldX=0;
31 oldY=0;
32 oldZ=0;
35 public void onBump(GameObject other) {
36 if (other.isSolid() && this.isSolid()) {
37 double dx=oldX-x;
38 double dy =oldY-y;
39 double dz=oldZ-z;
40 if (dx==0&&dy==0&&dz==0)
41 return;
42 while (this.isTouching(other)) {
43 setPosition(getX()+dx,getY()+dy,getZ()+dz);
44 // System.out.printf("%f,%f,%f delta %f,%f,%f\n",x,y,z,dx,dy,dz);
47 setX(getX()*2-other.getX());
48 setY(getY()*2-other.getY());
49 // setZ(getZ()*2-other.getZ());
54 public void setPosition(double x,double y,double z) {
55 oldX=this.x;
56 oldY=this.y;
57 oldZ=this.z;
58 super.setPosition(x,y,z);