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