Commit ef91dd39 authored by alistert's avatar alistert

Fixed text input, added animation-specific bullet starting positions for players.

parent 274ea422
...@@ -107,9 +107,10 @@ ...@@ -107,9 +107,10 @@
#define STRING_LENGTH 32 #define STRING_LENGTH 32
// Loop return type // Loop return type
#define NORMAL_LOOP 0 #define NORMAL_LOOP 0
#define KEY_LOOP 1 #define TYPING_LOOP 1
#define JOYSTICK_LOOP 2 #define SET_KEY_LOOP 2
#define SET_JOYSTICK_LOOP 3
// Return values // Return values
#define E_DATA -14 #define E_DATA -14
......
...@@ -182,12 +182,14 @@ int Controls::update (SDL_Event *event, int type) { ...@@ -182,12 +182,14 @@ int Controls::update (SDL_Event *event, int type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (type == KEY_LOOP) return event->key.keysym.sym; if (type == SET_KEY_LOOP) return event->key.keysym.sym;
for (count = 0; count < CONTROLS; count++) for (count = 0; count < CONTROLS; count++)
if (event->key.keysym.sym == keys[count].key) if (event->key.keysym.sym == keys[count].key)
keys[count].state = true; keys[count].state = true;
if (type == TYPING_LOOP) return event->key.keysym.sym;
break; break;
case SDL_KEYUP: case SDL_KEYUP:
...@@ -200,7 +202,7 @@ int Controls::update (SDL_Event *event, int type) { ...@@ -200,7 +202,7 @@ int Controls::update (SDL_Event *event, int type) {
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
if (type == JOYSTICK_LOOP) return JOYSTICKB | event->jbutton.button; if (type == SET_JOYSTICK_LOOP) return JOYSTICKB | event->jbutton.button;
for (count = 0; count < CONTROLS; count++) for (count = 0; count < CONTROLS; count++)
if (event->jbutton.button == buttons[count].button) if (event->jbutton.button == buttons[count].button)
...@@ -218,7 +220,7 @@ int Controls::update (SDL_Event *event, int type) { ...@@ -218,7 +220,7 @@ int Controls::update (SDL_Event *event, int type) {
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
if (type == JOYSTICK_LOOP) { if (type == SET_JOYSTICK_LOOP) {
if (event->jaxis.value < -16384) if (event->jaxis.value < -16384)
return JOYSTICKANEG | event->jaxis.axis; return JOYSTICKANEG | event->jaxis.axis;
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) { Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) {
Anim *anim;
// Properties based on the player // Properties based on the player
source = sourcePlayer; source = sourcePlayer;
...@@ -77,8 +79,9 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) { ...@@ -77,8 +79,9 @@ Bullet::Bullet (Player *sourcePlayer, bool lower, unsigned int ticks) {
} }
x = source->getX() + (source->getFacing()? PXO_R: PXO_L) - ITOF(sprite->getWidth() >> 1); anim = source->getAnim();
y = source->getY() - F8 - ITOF(sprite->getHeight() >> 1); x = source->getX() + anim->getShootX() + PXO_MID - F4;
y = source->getY() + anim->getShootY() - F4;
return; return;
...@@ -95,7 +98,7 @@ Bullet::Bullet (Event *sourceEvent, bool facing, unsigned int ticks) { ...@@ -95,7 +98,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]); 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();
...@@ -131,7 +134,7 @@ Bullet::Bullet (Bird *sourceBird, bool lower, unsigned int ticks) { ...@@ -131,7 +134,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]); 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;
......
...@@ -571,7 +571,7 @@ int Level::play () { ...@@ -571,7 +571,7 @@ int Level::play () {
int perfect; int perfect;
int timeBonus; int timeBonus;
int count; int count;
unsigned int width; int width;
// Arbitrary initial value // Arbitrary initial value
...@@ -744,22 +744,22 @@ int Level::play () { ...@@ -744,22 +744,22 @@ int Level::play () {
if (stats & S_PLAYERS) { if (stats & S_PLAYERS) {
width = 96; width = 39;
for (count = 0; count < nPlayers; count++) for (count = 0; count < nPlayers; count++)
if ((strlen(players[count].getName()) * 8) + 57 > width) if (panelBigFont->getStringWidth(players[count].getName()) > width)
width = (strlen(players[count].getName()) * 8) + 57; width = panelBigFont->getStringWidth(players[count].getName());
drawRect((viewW >> 1) - 32, 11, width, (nPlayers * 12) + 1, BLACK); drawRect((viewW >> 1) - 48, 11, width + 57, (nPlayers * 12) + 1, BLACK);
for (count = 0; count < nPlayers; count++) { for (count = 0; count < nPlayers; count++) {
panelBigFont->showNumber(count + 1, (viewW >> 1) - 8, panelBigFont->showNumber(count + 1,
14 + (count * 12)); (viewW >> 1) - 24, 14 + (count * 12));
panelBigFont->showString(players[count].getName(), panelBigFont->showString(players[count].getName(),
viewW >> 1, 14 + (count * 12)); (viewW >> 1) - 16, 14 + (count * 12));
panelBigFont->showNumber(players[count].teamScore, panelBigFont->showNumber(players[count].teamScore,
(viewW >> 1) + width - 40, 14 + (count * 12)); (viewW >> 1) + width + 1, 14 + (count * 12));
} }
......
...@@ -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
...@@ -127,7 +127,7 @@ int Menu::textInput (const char *request, char **text) { ...@@ -127,7 +127,7 @@ int Menu::textInput (const char *request, char **text) {
while (true) { while (true) {
character = loop(KEY_LOOP); character = loop(TYPING_LOOP);
if (character == E_QUIT) { if (character == E_QUIT) {
......
...@@ -44,7 +44,7 @@ int Menu::setupKeyboard () { ...@@ -44,7 +44,7 @@ int Menu::setupKeyboard () {
while (true) { while (true) {
character = loop(KEY_LOOP); character = loop(SET_KEY_LOOP);
if (character == E_QUIT) return E_QUIT; if (character == E_QUIT) return E_QUIT;
...@@ -123,7 +123,7 @@ int Menu::setupJoystick () { ...@@ -123,7 +123,7 @@ int Menu::setupJoystick () {
while (true) { while (true) {
control = loop(JOYSTICK_LOOP); control = loop(SET_JOYSTICK_LOOP);
if (control == E_QUIT) return E_QUIT; if (control == E_QUIT) return E_QUIT;
......
...@@ -709,6 +709,13 @@ bool Player::getFacing () { ...@@ -709,6 +709,13 @@ bool Player::getFacing () {
} }
Anim * Player::getAnim () {
return level->getAnim(anims[animType]);
}
unsigned char Player::getTeam () { unsigned char Player::getTeam () {
return team; return team;
......
...@@ -153,6 +153,7 @@ ...@@ -153,6 +153,7 @@
// Classes // Classes
class Anim;
class Bird; class Bird;
class Player : public Movable { class Player : public Movable {
...@@ -172,6 +173,7 @@ class Player : public Movable { ...@@ -172,6 +173,7 @@ class Player : public Movable {
int shield; /* 0 = none, 1 = 1 yellow, 2 = 2 yellow, 3 = 1 orange, 4 = 2 orange, 5 = 3 orange, 6 = 4 orange */ int shield; /* 0 = none, 1 = 1 yellow, 2 = 2 yellow, 3 = 1 orange, 4 = 2 orange, 5 = 3 orange, 6 = 4 orange */
bool floating; /* false = normal, true = boarding/bird/etc. */ bool floating; /* false = normal, true = boarding/bird/etc. */
bool facing; bool facing;
unsigned char animType;
unsigned char eventX; unsigned char eventX;
unsigned char eventY; /* Position of an event (spring, platform, bridge) */ unsigned char eventY; /* Position of an event (spring, platform, bridge) */
int event; /* 0 = none, 1 = spring, 2 = float up, 3 = platform, 4 = bridge */ int event; /* 0 = none, 1 = spring, 2 = float up, 3 = platform, 4 = bridge */
...@@ -221,6 +223,7 @@ class Player : public Movable { ...@@ -221,6 +223,7 @@ class Player : public Movable {
void setPosition (fixed newX, fixed newY); void setPosition (fixed newX, fixed newY);
void setSpeed (fixed newDx, fixed newDy); void setSpeed (fixed newDx, fixed newDy);
bool getFacing (); bool getFacing ();
Anim * getAnim ();
unsigned char getTeam (); unsigned char getTeam ();
void send (unsigned char *data); void send (unsigned char *data);
void receive (unsigned char *buffer); void receive (unsigned char *buffer);
......
...@@ -608,7 +608,7 @@ void Player::view (unsigned int ticks, int mspf) { ...@@ -608,7 +608,7 @@ void Player::view (unsigned int ticks, int mspf) {
void Player::draw (unsigned int ticks, int change) { void Player::draw (unsigned int ticks, int change) {
Anim *an; Anim *an;
int anim, frame; int frame;
fixed drawX, drawY; fixed drawX, drawY;
fixed xOffset, yOffset; fixed xOffset, yOffset;
...@@ -625,68 +625,63 @@ void Player::draw (unsigned int ticks, int change) { ...@@ -625,68 +625,63 @@ void Player::draw (unsigned int ticks, int change) {
// Choose player animation // Choose player animation
if (reaction == PR_KILLED) anim = anims[facing? PA_RDIE: PA_LDIE]; if (reaction == PR_KILLED) animType = facing? PA_RDIE: PA_LDIE;
else if ((reaction == PR_HURT) && else if ((reaction == PR_HURT) && (reactionTime - ticks > PRT_HURT - PRT_HURTANIM))
(reactionTime - ticks > PRT_HURT - PRT_HURTANIM)) animType = facing? PA_RHURT: PA_LHURT;
anim = anims[facing? PA_RHURT: PA_LHURT];
else if (y + PYO_MID > level->getWaterLevel()) else if (y + PYO_MID > level->getWaterLevel())
anim = anims[facing? PA_RSWIM: PA_LSWIM]; animType = facing? PA_RSWIM: PA_LSWIM;
else if (floating) anim = anims[facing? PA_RBOARD: PA_LBOARD]; else if (floating) animType = facing? PA_RBOARD: PA_LBOARD;
else if (dy >= 0) { else if (dy < 0) {
if (isOnPlatform()) { if (event == 1) animType = facing? PA_RSPRING: PA_LSPRING;
else animType = facing? PA_RJUMP: PA_LJUMP;
if (dx) { } else if (isOnPlatform()) {
if (dx <= -PXS_RUN) anim = anims[PA_LRUN]; if (dx) {
else if (dx >= PXS_RUN) anim = anims[PA_RRUN];
else if ((dx < 0) && facing) anim = anims[PA_LSTOP];
else if ((dx > 0) && !facing) anim = anims[PA_RSTOP];
else anim = anims[facing? PA_RWALK: PA_LWALK];
} else { if (dx <= -PXS_RUN) animType = PA_LRUN;
else if (dx >= PXS_RUN) animType = PA_RRUN;
else if ((dx < 0) && facing) animType = PA_LSTOP;
else if ((dx > 0) && !facing) animType = PA_RSTOP;
else animType = facing? PA_RWALK: PA_LWALK;
if (!level->checkMaskDown(x + PXO_ML, y + F12) && } else if (!level->checkMaskDown(x + PXO_ML, y + F12) &&
!level->checkMaskDown(x + PXO_L, y + F2) && !level->checkMaskDown(x + PXO_L, y + F2) &&
(event != 3) && (event != 4)) (event != 3) && (event != 4))
anim = anims[PA_LEDGE]; animType = PA_LEDGE;
else if (!level->checkMaskDown(x + PXO_MR, y + F12) && else if (!level->checkMaskDown(x + PXO_MR, y + F12) &&
!level->checkMaskDown(x + PXO_R, y + F2) && !level->checkMaskDown(x + PXO_R, y + F2) &&
(event != 3) && (event != 4)) (event != 3) && (event != 4))
anim = anims[PA_REDGE]; animType = PA_REDGE;
else if (pcontrols[C_FIRE]) else if ((lookTime < 0) && ((int)ticks > 1000 - lookTime))
anim = anims[facing? PA_RSHOOT: PA_LSHOOT]; animType = PA_LOOKUP;
else if ((lookTime < 0) && ((int)ticks > 1000 - lookTime)) else if (lookTime > 0) {
anim = anims[PA_LOOKUP];
else if (lookTime > 0) { if ((int)ticks < 1000 + lookTime) animType = facing? PA_RCROUCH: PA_LCROUCH;
else animType = PA_LOOKDOWN;
if ((int)ticks < 1000 + lookTime) }
anim = anims[facing? PA_RCROUCH: PA_LCROUCH];
else anim = anims[PA_LOOKDOWN];
} else anim = anims[facing? PA_RSTAND: PA_LSTAND];
}
} else anim = anims[facing? PA_RFALL: PA_LFALL]; else if (pcontrols[C_FIRE])
animType = facing? PA_RSHOOT: PA_LSHOOT;
} else if (event == 1) else
anim = anims[facing? PA_RSPRING: PA_LSPRING]; animType = facing? PA_RSTAND: PA_LSTAND;
else anim = anims[facing? PA_RJUMP: PA_LJUMP]; } else animType = facing? PA_RFALL: PA_LFALL;
// Choose sprite // Choose sprite
an = level->getAnim(anim); an = getAnim();
an->setFrame(frame, reaction != PR_KILLED); an->setFrame(frame, reaction != PR_KILLED);
...@@ -789,7 +784,8 @@ void Player::draw (unsigned int ticks, int change) { ...@@ -789,7 +784,8 @@ void Player::draw (unsigned int ticks, int change) {
// Show the player's name // Show the player's name
if (gameMode) if (gameMode)
panelBigFont->showString(name, FTOI(drawX - viewX), panelBigFont->showString(name,
FTOI(drawX + PXO_MID - viewX) - (panelBigFont->getStringWidth(name) >> 1),
FTOI(drawY - F32 - F16 - viewY)); FTOI(drawY - F32 - F16 - viewY));
return; return;
......
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