Permalink
Browse files

pre-rewrite commit. I'll be moving sprite/path/state code around so t…

…hat actor drawing takes care of everything. the sprite image(s) will be transformed by it, instead.
  • Loading branch information...
1 parent 354a708 commit 680d7c81dd716feb14f2773396e6433a6fe8fa18 @Pomax committed Feb 27, 2012
Showing with 702 additions and 229 deletions.
  1. +59 −23 Actor.pde
  2. +2 −4 Boundary.pde
  3. +6 −1 Interactor.pde
  4. +1 −1 JavaScript.pde
  5. +43 −32 Level.pde
  6. +5 −4 Pickup.pde
  7. +12 −0 Player.pde
  8. +27 −12 Positionable.pde
  9. +1 −1 ShapePrimitives.pde
  10. +30 −17 Sprite.pde
  11. +0 −20 SpriteFactory.pde
  12. +2 −2 SpriteMapHandler.pde
  13. +15 −14 SpritePath.pde
  14. +1 −1 SpriteProxy.pde
  15. +12 −2 State.pde
  16. +4 −3 TilingSprite.pde
  17. +0 −1 drawbackground.pde
  18. +316 −0 level.json
  19. +31 −31 preloads.pde
  20. +135 −60 spriteengine.pde
View
@@ -10,13 +10,14 @@
* can make use of it.
*/
abstract class Actor extends Positionable {
+ boolean debug = false;
- // are we colliding with another actor?
+ // are we colliding with another actor?
boolean colliding = false;
-
+
// regular interaction with other actors
boolean interacting = true;
-
+
// should we be removed?
boolean remove = false;
@@ -25,10 +26,10 @@ abstract class Actor extends Positionable {
// all states for this actor
HashMap<String, State> states = new HashMap<String, State>();
-
+
// actor name
String name = "";
-
+
// simple constructor
Actor(String _name) { name = _name; setPosition(0,0); }
@@ -42,7 +43,7 @@ abstract class Actor extends Positionable {
/**
* Add a state to this actor's repetoire.
*/
- void addState(State state) {
+ void addState(State state) {
state.setActor(this);
states.put(state.name, state);
active = state;
@@ -51,7 +52,7 @@ abstract class Actor extends Positionable {
/**
* Get a state by name.
*/
- State getState(String name) {
+ State getState(String name) {
return states.get(name);
}
@@ -68,6 +69,34 @@ abstract class Actor extends Positionable {
}
}
+ /**
+ * get the midpoint
+ */
+ float getMidX() { return super.getMidX() - (active==null ? 0 : active.sprite.ox); }
+
+ /**
+ * get the midpoint
+ */
+ float getMidY() { return super.getMidY() - (active==null ? 0 : active.sprite.oy); }
+
+ /**
+ * check overlap between sprites,
+ * rather than between actors.
+ */
+ float[] overlap(Actor other) {
+ float[] overlap = super.overlap(other);
+ if(overlap==null || active==null || other.active==null) {
+ return overlap;
+ }
+ //
+ // TODO: add in code here that determines
+ // the intersection point for the two
+ // sprites, and checks the mask to see
+ // whether both have non-zero alph there.
+ //
+ return overlap;
+ }
+
/**
* What happens when we touch another actor?
*/
@@ -94,7 +123,7 @@ abstract class Actor extends Positionable {
void setInteracting(boolean _interacting) {
interacting = _interacting;
}
-
+
/**
* it's possible that an actor
* has to be removed from the
@@ -107,7 +136,7 @@ abstract class Actor extends Positionable {
active = null;
remove = true;
}
-
+
/**
* Draw preprocessing happens here.
*/
@@ -121,24 +150,31 @@ abstract class Actor extends Positionable {
*/
void drawObject() {
if(active!=null) {
- active.draw();
+ active.draw();
+ if(debug) {
+ fill(255,0,0);
+ ellipse(0,0,5,5);
+ noFill();
+ stroke(255,0,0);
+ rect(-width/2,-height/2,width,height);
+ }
}
else {
pushStyle();
strokeWeight(7);
stroke(200,0,100);
point(0,0); popStyle();
}
- /*
- if(active!=null && colliding) {
- pushStyle();
- noStroke();
- fill(255,0,0,150);
- rect(-width/2+active.sprite.ox,-height/2-active.sprite.oy,width,height);
- popStyle();
- }
- colliding = false;
- */
+/*
+ if(active!=null && colliding) {
+ pushStyle();
+ noStroke();
+ fill(255,0,0,150);
+ rect(-width/2+active.sprite.ox,-height/2-active.sprite.oy,width,height);
+ popStyle();
+ }
+ colliding = false;
+*/
}
// ====== KEY HANDLING ======
@@ -164,7 +200,7 @@ abstract class Actor extends Positionable {
// lock a key so that it cannot be triggered repeatedly
protected void ignore(int keyCode) {
- locked[keyCode] = true;
+ locked[keyCode] = true;
keyDown[keyCode] = false;
}
@@ -183,9 +219,9 @@ abstract class Actor extends Positionable {
// token implementation
abstract void handleInput();
- // token implementation
+ // token implementation
abstract void handleStateFinished(State which);
-
+
// token implementation
abstract void pickedUp(Pickup pickup);
}
View
@@ -110,13 +110,13 @@ class Boundary extends Positionable {
float[] blocks(float x1, float y1, float x2, float y2) {
// perform a translation-rotation about (x3,y3)
float[] tr = translateRotateXY3(x1, y1, x2, y2, x, y, xw, yh);
-
+
// Is our line segment in range? Because our
// reference line is now flat, we can simply
// check the x-coordinates.
if(tr[0] < 0 && tr[2] < 0) { return null; }
if(tr[0] > tr[6] && tr[2] > tr[6]) { return null; }
-
+
// Let's find out where these two lines meet.
float dx = tr[2] - tr[0]; // x2n - x1n;
float dy = tr[3] - tr[1]; // y2n - y1n;
@@ -186,7 +186,6 @@ class Boundary extends Positionable {
/**
* ` force along this boundary's surface
*/
- // FIXME: actually make this work
float[] redirectForce(float x, float y, float fx, float fy) {
float x1 = x, y1 = y, x2 = x+fx, y2 = y+fy;
// Will this force illegally push the actor through the boundary?
@@ -197,7 +196,6 @@ class Boundary extends Positionable {
float iy = nx2 * sina;
return new float[]{ix, iy, 1};
}
-
// No it won't, pass-through the impulse unmodified.
return new float[]{fx, fy, 0};
}
View
@@ -1,3 +1,9 @@
+/**
+ * Interactors are non-player actors
+ * that can interact with other interactors
+ * as well as player actors. However,
+ * they do not interact with pickups.
+ */
abstract class Interactor extends Actor {
// simple constructor
@@ -9,5 +15,4 @@ abstract class Interactor extends Actor {
// Interactors don't get pickups
final void pickedUp(Pickup pickup){}
-
}
View
@@ -10,7 +10,7 @@ interface JSConsole { void log(String msg); }
*/
abstract class JavaScript {
JSConsole console;
- abstract void setPaths(ArrayList<ShapePrimitive> segments);
+ abstract void setPaths(ArrayList<ShapePrimitive> segments);
}
/**
Oops, something went wrong.

0 comments on commit 680d7c8

Please sign in to comment.