Commit 4a9aa467 authored by alistert's avatar alistert

Improved bullets and launching platforms.

parent 2a31393c
...@@ -52,14 +52,14 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) { ...@@ -52,14 +52,14 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) {
direction = source->getFacing()? 1: 0; direction = source->getFacing()? 1: 0;
direction |= lower? 2: 0; direction |= lower? 2: 0;
x = source->getX() + (source->getFacing()? PXO_R: PXO_L);
y = source->getY() - F8;
dx = level->getBullet(type)[B_XSPEED + direction] * 500 * F1;
if (type == 4) { if (type == 4) {
// TNT // TNT
type = -1; type = -1;
sprite = level->getSprite(130);
dx = 0;
dy = 0; dy = 0;
time = ticks + T_TNT; time = ticks + T_TNT;
...@@ -68,6 +68,8 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) { ...@@ -68,6 +68,8 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) {
} else { } else {
sprite = level->getSprite(((unsigned char *)level->getBullet(type)) [B_SPRITE + direction]);
dx = level->getBullet(type)[B_XSPEED + direction] * 500 * F1;
dy = level->getBullet(type)[B_YSPEED + direction] * 250 * F1; dy = level->getBullet(type)[B_YSPEED + direction] * 250 * F1;
time = ticks + T_BULLET; time = ticks + T_BULLET;
...@@ -75,6 +77,9 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) { ...@@ -75,6 +77,9 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) {
} }
x = source->getX() + (source->getFacing()? PXO_R: PXO_L) - ITOF(sprite->getWidth() >> 1);
y = source->getY() - F8 - ITOF(sprite->getHeight() >> 1);
return; return;
} }
...@@ -90,6 +95,7 @@ Bullet::Bullet (Event *sourceEvent, bool facing, unsigned int ticks) { ...@@ -90,6 +95,7 @@ Bullet::Bullet (Event *sourceEvent, bool facing, unsigned int ticks) {
source = NULL; source = NULL;
type = sourceEvent->getProperty(E_BULLET); type = sourceEvent->getProperty(E_BULLET);
direction = facing? 1: 0; direction = facing? 1: 0;
sprite = level->getSprite(((unsigned char *)level->getBullet(type)) [B_SPRITE + direction]);
anim = level->getAnim(sourceEvent->getProperty(facing? E_LSHOOTANIM: E_RSHOOTANIM)); anim = level->getAnim(sourceEvent->getProperty(facing? E_LSHOOTANIM: E_RSHOOTANIM));
x = sourceEvent->getX() + anim->getShootX(); x = sourceEvent->getX() + anim->getShootX();
...@@ -125,6 +131,7 @@ Bullet::Bullet (Bird *sourceBird, bool lower, unsigned int ticks) { ...@@ -125,6 +131,7 @@ Bullet::Bullet (Bird *sourceBird, bool lower, unsigned int ticks) {
type = 30; type = 30;
direction = source->getFacing()? 1: 0; direction = source->getFacing()? 1: 0;
direction |= lower? 2: 0; direction |= lower? 2: 0;
sprite = level->getSprite(((unsigned char *)level->getBullet(type)) [B_SPRITE + direction]);
x = sourceBird->getX() + (source->getFacing()? PXO_R: PXO_L); x = sourceBird->getX() + (source->getFacing()? PXO_R: PXO_L);
y = sourceBird->getY(); y = sourceBird->getY();
dx = level->getBullet(type)[B_XSPEED + direction] * 500 * F1; dx = level->getBullet(type)[B_XSPEED + direction] * 500 * F1;
...@@ -230,7 +237,8 @@ bool Bullet::step (unsigned int ticks, int msps) { ...@@ -230,7 +237,8 @@ bool Bullet::step (unsigned int ticks, int msps) {
// Check if a player has been hit // Check if a player has been hit
for (count = 0; count < nPlayers; count++) { for (count = 0; count < nPlayers; count++) {
if (players[count].overlap(x, y, F1, F1)) { if (players[count].overlap(x, y,
ITOF(sprite->getWidth()), ITOF(sprite->getHeight()))) {
// If the hit was successful, destroy the bullet // If the hit was successful, destroy the bullet
if (players[count].hit(source, ticks)) return true; if (players[count].hit(source, ticks)) return true;
...@@ -249,7 +257,8 @@ bool Bullet::step (unsigned int ticks, int msps) { ...@@ -249,7 +257,8 @@ bool Bullet::step (unsigned int ticks, int msps) {
while (event) { while (event) {
// Check if the event has been hit // Check if the event has been hit
if (event->overlap(x, y, 0, 0)) { if (event->overlap(x, y,
ITOF(sprite->getWidth()), ITOF(sprite->getHeight()))) {
// If the event is hittable, hit it and destroy the bullet // If the event is hittable, hit it and destroy the bullet
if (event->hit(source, ticks)) return true; if (event->hit(source, ticks)) return true;
...@@ -304,19 +313,12 @@ bool Bullet::step (unsigned int ticks, int msps) { ...@@ -304,19 +313,12 @@ bool Bullet::step (unsigned int ticks, int msps) {
void Bullet::draw (int change) { void Bullet::draw (int change) {
Sprite *sprite;
if (next) next->draw(change); if (next) next->draw(change);
if (type == -1) sprite = level->getSprite(130);
else sprite =
level->getSprite(((unsigned char *)level->getBullet(type))
[B_SPRITE + direction]);
// Show the bullet // Show the bullet
sprite->draw( sprite->draw(
FTOI(getDrawX(change)) - (sprite->getWidth() >> 1) - FTOI(viewX), FTOI(getDrawX(change)) - FTOI(viewX),
FTOI(getDrawY(change)) - (sprite->getHeight() >> 1) - FTOI(viewY)); FTOI(getDrawY(change)) - FTOI(viewY));
return; return;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Part of the OpenJazz project * Part of the OpenJazz project
* *
* *
* Copyright (c) 2005-2009 Alister Thomson * Copyright (c) 2005-2010 Alister Thomson
* *
* OpenJazz is distributed under the terms of * OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0 * the GNU General Public License, version 2.0
...@@ -51,21 +51,21 @@ ...@@ -51,21 +51,21 @@
class Bird; class Bird;
class Event; class Event;
class Player; class Player;
class Sprite;
class Bullet : public Movable { class Bullet : public Movable {
private: private:
Bullet *next; Bullet *next;
Player *source; // If NULL, was fired by an event Player *source; // If NULL, was fired by an event
Sprite *sprite;
int type; // -1 is TNT, otherwise indexes the bullet set int type; // -1 is TNT, otherwise indexes the bullet set
int direction; // 0: Left, 1: Right, 2: L (lower), 3: R (lower) int direction; // 0: Left, 1: Right, 2: L (lower), 3: R (lower)
unsigned int time; // Time at which the bullet will self-destruct unsigned int time; // Time at which the bullet will self-destruct
public: public:
Bullet (Player *sourcePlayer, bool lower, Bullet (Player *sourcePlayer, bool lower, unsigned int ticks);
unsigned int ticks); Bullet (Event *sourceEvent, bool facing, unsigned int ticks);
Bullet (Event *sourceEvent, bool facing,
unsigned int ticks);
Bullet (Bird *sourceBird, bool lower, unsigned int ticks); Bullet (Bird *sourceBird, bool lower, unsigned int ticks);
~Bullet (); ~Bullet ();
......
...@@ -362,8 +362,7 @@ bool Event::step (unsigned int ticks, int msps) { ...@@ -362,8 +362,7 @@ bool Event::step (unsigned int ticks, int msps) {
else if (y > localPlayer->getY()) dy = -ES_SLOW; else if (y > localPlayer->getY()) dy = -ES_SLOW;
else dy = 0; else dy = 0;
} else if (!localPlayer->getFacing() && } else if (!localPlayer->getFacing() && (x > localPlayer->getX() + F32)) {
(x > localPlayer->getX() + F32)) {
dx = -ES_FAST; dx = -ES_FAST;
...@@ -382,26 +381,19 @@ bool Event::step (unsigned int ticks, int msps) { ...@@ -382,26 +381,19 @@ bool Event::step (unsigned int ticks, int msps) {
case 34: case 34:
// Launching platform // Launching event
if (ticks > level->getEventTime(gridX, gridY)) { if (ticks > level->getEventTime(gridX, gridY)) {
if (y <= TTOF(gridY) + F16 - (set[E_YAXIS] * F2)) { if (animType == E_LEFTANIM)
dy = -(F16 + y - (TTOF(gridY) - (set[E_MULTIPURPOSE] * F12))) * 10;
level->setEventTime(gridX, gridY, ticks + (set[E_MOVEMENTSP] * 1000)); else
dy = 0; dy = (F16 + y - (TTOF(gridY) - (set[E_MULTIPURPOSE] * F12))) * 10;
} else dy = -(y + (set[E_YAXIS] * F2) - TTOF(gridY)) / 100;
} else { } else {
if (y < TTOF(gridY) + F16) dy = (y + (set[E_YAXIS] * F2) - TTOF(gridY)) / 100; dy = TTOF(gridY) + F16 - y;
else { dy = ((dy << 10) / msps) * set[E_MOVEMENTSP];
y = TTOF(gridY) + F16;
dy = 0;
}
} }
...@@ -734,6 +726,25 @@ bool Event::step (unsigned int ticks, int msps) { ...@@ -734,6 +726,25 @@ bool Event::step (unsigned int ticks, int msps) {
break; break;
case 34:
// Launching event
if (ticks > level->getEventTime(gridX, gridY)) {
if (y <= F16 + TTOF(gridY) - (set[E_MULTIPURPOSE] * F12))
animType = E_RIGHTANIM;
else if (y >= F16 + TTOF(gridY)) {
animType = E_LEFTANIM;
level->setEventTime(gridX, gridY, ticks + (set[E_YAXIS] * 50));
}
} else animType = E_LEFTANIM;
break;
case 36: case 36:
// Walk from side to side and down hills, staying on-screen // Walk from side to side and down hills, staying on-screen
...@@ -872,8 +883,8 @@ bool Event::step (unsigned int ticks, int msps) { ...@@ -872,8 +883,8 @@ bool Event::step (unsigned int ticks, int msps) {
if (set[E_MODIFIER] == 6) { if (set[E_MODIFIER] == 6) {
if (width && height && if (width && height &&
players[count].overlap(x, y - height, width - F8, height) && players[count].overlap(x, y - height, width - F8, F8) &&
(players[count].getY() <= y + (PYS_FALL / msps) - height) && (players[count].getY() <= F8 + ((PYS_FALL * msps) >> 10) + y - height) &&
!level->checkMaskDown(players[count].getX() + PXO_MID, PYO_TOP + y - height)) { !level->checkMaskDown(players[count].getX() + PXO_MID, PYO_TOP + y - height)) {
// Player is on a platform // Player is on a platform
...@@ -881,7 +892,7 @@ bool Event::step (unsigned int ticks, int msps) { ...@@ -881,7 +892,7 @@ bool Event::step (unsigned int ticks, int msps) {
players[count].setEvent(gridX, gridY); players[count].setEvent(gridX, gridY);
players[count].setPosition( players[count].setPosition(
players[count].getX() + ((dx * msps) >> 10), players[count].getX() + ((dx * msps) >> 10),
players[count].getY() + ((dy * msps) >> 10)); F4 + y - height);
} else players[count].clearEvent(gridX, gridY); } else players[count].clearEvent(gridX, gridY);
......
...@@ -306,9 +306,9 @@ void Player::control (unsigned int ticks, int msps) { ...@@ -306,9 +306,9 @@ void Player::control (unsigned int ticks, int msps) {
// Remove the bullet from the arsenal // Remove the bullet from the arsenal
if (ammoType != -1) ammo[ammoType]--; if (ammoType != -1) ammo[ammoType]--;
/* If the current ammo type has been exhausted, use the previous /* If the current ammo type has been exhausted or TNT has been used,
non-exhausted ammo type */ use the previous non-exhausted ammo type */
while ((ammoType > -1) && !ammo[ammoType]) ammoType--; while (((ammoType > -1) && !ammo[ammoType]) || (ammoType == 3)) ammoType--;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment