Browse files

Plant now works correctly. Jeremy fixed the fireball and shell so now…

… they kill and act normally.
  • Loading branch information...
1 parent f2a51f7 commit e7bb5f6f9130ad75a29b4c10e38f57c9cfc0a256 @adaughe2 adaughe2 committed Apr 27, 2011
Showing with 92 additions and 73 deletions.
  1. +89 −34 Movable.cpp
  2. +2 −0 Movable.h
  3. +0 −36 Plant.cpp
  4. +1 −3 Plant.h
View
123 Movable.cpp
@@ -12,6 +12,7 @@
#include "Movable.h"
#include "Level.h"
+#include <iostream>
//---------------------------------------------------------
@@ -34,12 +35,13 @@ bool Movable::canMove()
Drawable *dLeft = this->checkLeft();
Drawable *dBottom = this->checkBottom();
Drawable *dTop = this->checkTop();
+ count_ = 720;
bool keepGoing = true;
- if (this->objectType() == MARIOFIREBALL)
+ if (this->objectType() == MARIOFIREBALL && dRight != NULL && dLeft != NULL && dTop != NULL && dBottom != NULL)
{
- /*
+
bool killed = false;
if (this->getXVelocity() < 0)
{
@@ -87,7 +89,7 @@ bool Movable::canMove()
{
Level::sharedLevel()->removeDrawable(this);
}
- */
+
}
else
{
@@ -99,7 +101,7 @@ bool Movable::canMove()
keepGoing = false;
}
// check if goomba, mushroom, shell, can fall off edge
- else
+ else if (this->objectType() != MARIOFIREBALL)
{
this->setYVelocity(-2.0);
}
@@ -135,9 +137,9 @@ bool Movable::canMove()
}
}
}
- if (this->objectType() == SHELL)
+ if (this->objectType() == SHELL && dRight != NULL && dLeft != NULL && dTop != NULL && dBottom != NULL)
{
- /*
+
if (dRight->objectType() == GOOMBA || dRight->objectType() == TURTLE || dRight->objectType() == PLANT)
{
Level::sharedLevel()->removeDrawable(dRight);
@@ -152,7 +154,7 @@ bool Movable::canMove()
{
Level::sharedLevel()->removeDrawable(dBottom);
}
- */
+
}
return keepGoing;
@@ -163,43 +165,96 @@ bool Movable::canMove()
void Movable::updateScene()
{
- double currentXVelocity, currentYVelocity;
- double updatedLeft, updatedRight, updatedTop, updatedBottom;
-
- // get velocities
- currentXVelocity = this->getXVelocity();
- currentYVelocity = this->getYVelocity();
-
- // update position to check next move
- updatedLeft = this->left() + currentXVelocity;
- this->setLeft(updatedLeft);
- updatedRight = this->right() + currentXVelocity;
- this->setRight(updatedRight);
- updatedTop = this->top() + currentYVelocity;
- this->setTop(updatedTop);
- updatedBottom = this->bottom() + currentYVelocity;
- this->setBottom(updatedBottom);
+ if (this->objectType() == PLANT)
+ {
+ // uses the private variable count_ to time the movement of the piranha plant
+ // if the count is between 120 and 91 the plant should move upward
+ if (count_ >= 690 && count_ <= 720)
+ {
+ this->setYVelocity(-0.5);
+ }
+ // if the count is between 90 and 61 the plant should stay stationary on top of the block
+ else if (count_ >=360 && count_ <= 689)
+ {
+ this->setYVelocity(0.0);
+ }
+ // if the count is between 60 and 31 the plant should be moving back down
+ else if (count_ >= 330 && count_ <= 359)
+ {
+ this->setYVelocity(0.5);
+ }
+ // if the count is between 30 and 0 the plant should be stationary and hiding
+ else if (count_ >= 0 && count_ <= 329)
+ {
+ this->setYVelocity(0.0);
+
+ // when the count reaches 0 it will reset back to 0
+ if (count_ == 0)
+ {
+ count_ = 720;
+ }
+
+ }
+ double currentXVelocity, currentYVelocity;
+ double updatedLeft, updatedRight, updatedTop, updatedBottom;
+
+ // get velocities
+ currentXVelocity = this->getXVelocity();
+ currentYVelocity = this->getYVelocity();
- // if canMove is false, can't move that direction, reverse x direction
- // if canMove is true, movement can stay
- if (!canMove()) {
- // undo potential move
- updatedLeft = this->left() - currentXVelocity;
+ // update position to check next move
+ updatedLeft = this->left() + currentXVelocity;
this->setLeft(updatedLeft);
- updatedRight = this->right() - currentXVelocity;
+ updatedRight = this->right() + currentXVelocity;
this->setRight(updatedRight);
- updatedTop = this->top() - currentYVelocity;
+ updatedTop = this->top() + currentYVelocity;
this->setTop(updatedTop);
- updatedBottom = this->bottom() - currentYVelocity;
+ updatedBottom = this->bottom() + currentYVelocity;
this->setBottom(updatedBottom);
+ count_--;
+
+ }
+
+ else
+ {
+ double currentXVelocity, currentYVelocity;
+ double updatedLeft, updatedRight, updatedTop, updatedBottom;
+
+ // get velocities
+ currentXVelocity = this->getXVelocity();
+ currentYVelocity = this->getYVelocity();
- // reverse x
- currentXVelocity = (-1) * currentXVelocity;
- this->setXVelocity(currentXVelocity);
+ // update position to check next move
updatedLeft = this->left() + currentXVelocity;
this->setLeft(updatedLeft);
updatedRight = this->right() + currentXVelocity;
this->setRight(updatedRight);
+ updatedTop = this->top() + currentYVelocity;
+ this->setTop(updatedTop);
+ updatedBottom = this->bottom() + currentYVelocity;
+ this->setBottom(updatedBottom);
+
+ // if canMove is false, can't move that direction, reverse x direction
+ // if canMove is true, movement can stay
+ if (!canMove()) {
+ // undo potential move
+ updatedLeft = this->left() - currentXVelocity;
+ this->setLeft(updatedLeft);
+ updatedRight = this->right() - currentXVelocity;
+ this->setRight(updatedRight);
+ updatedTop = this->top() - currentYVelocity;
+ this->setTop(updatedTop);
+ updatedBottom = this->bottom() - currentYVelocity;
+ this->setBottom(updatedBottom);
+
+ // reverse x
+ currentXVelocity = (-1) * currentXVelocity;
+ this->setXVelocity(currentXVelocity);
+ updatedLeft = this->left() + currentXVelocity;
+ this->setLeft(updatedLeft);
+ updatedRight = this->right() + currentXVelocity;
+ this->setRight(updatedRight);
+ }
}
}
View
2 Movable.h
@@ -42,6 +42,8 @@ class Movable: public AllMovable {
// there are no methods to reverse velocity; this change can be handled directly by changing
// instance variables.
void updateScene();
+
+ int count_;
};
//---------------------------------------------------------
View
36 Plant.cpp
@@ -25,7 +25,6 @@ Plant::Plant()
setPoints(0);
setXVelocity(0.0);
setYVelocity(1.0);
- count_ = 120;
sprite();
}
@@ -75,41 +74,6 @@ void Plant::shootFireball()
}
-//---------------------------------------------------------
-
-void Plant::updateScene()
-{
- // uses the private variable count_ to time the movement of the piranha plant
- // if the count is between 120 and 91 the plant should move upward
- if (count_ >= 91 && count_ <= 120)
- {
- this->setYVelocity(1.0);
- }
- // if the count is between 90 and 61 the plant should stay stationary on top of the block
- else if (count_ >= 61 && count_ <= 90)
- {
- this->setYVelocity(0.0);
- }
- // if the count is between 60 and 31 the plant should be moving back down
- else if (count_ >= 31 && count_ <= 60)
- {
- this->setYVelocity(-1.0);
- }
- // if the count is between 30 and 0 the plant should be stationary and hiding
- else if (count_ >= 0 && count_ <= 30)
- {
- this->setYVelocity(0.0);
-
- // when the count reaches 0 it will reset back to 0
- if (count_ == 0)
- {
- count_ = 120;
- }
-
- }
- count_--;
-
-}
//---------------------------------------------------------
View
4 Plant.h
@@ -21,7 +21,7 @@
class Plant: public Movable {
private:
GLuint texture_[2];
- int texturePos, count_;
+ int texturePos;
void sprite();
public:
// openGL draw method
@@ -38,8 +38,6 @@ class Plant: public Movable {
int objectType() { return PLANT; }
// method to shoot fireball from plant
void shootFireball();
- // tracks the movement of the plant since the plant will always move
- void updateScene();
};

0 comments on commit e7bb5f6

Please sign in to comment.