Changeset 1211


Ignore:
Timestamp:
Apr 10, 2012, 3:15:37 AM (8 years ago)
Author:
sam
Message:

mrpigeon: split enemy into red and blue enemies.

Location:
trunk/mrpigeon
Files:
3 added
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/mrpigeon/Makefile.am

    r1205 r1211  
    55    mrpigeon.cpp mrpigeon.h \
    66    player.cpp player.h \
    7     enemy.cpp enemy.h
     7    enemy.cpp enemy.h \
     8    blueenemy.cpp blueenemy.h \
     9    redenemy.cpp redenemy.h
    810mrpigeon_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
    911mrpigeon_LDADD =
  • trunk/mrpigeon/blueenemy.cpp

    r1207 r1211  
    2020
    2121#include "mrpigeon.h"
    22 #include "enemy.h"
     22#include "blueenemy.h"
    2323
    24 Enemy::Enemy(MrPigeon *in_game) :
    25     game(in_game),
     24BlueEnemy::BlueEnemy(MrPigeon *in_game) :
     25    Enemy(in_game),
    2626    enemytime(0.0f)
    2727{
    2828    enemy_casualblue = Tiler::Register("mrpigeon/gfx/enemy_CasualBLUE_walk.png", ivec2(16,24), ivec2(0)); /* 6 frames */
    2929    enemy_casualblueattack = Tiler::Register("mrpigeon/gfx/enemy_CasualBLUE_walkAttack.png", ivec2(16,24), ivec2(0)); /* 6 frames */
     30
     31    position = vec3(512, 81, 0);
     32    velocity = vec3(-0.15f, 0, 0);
    3033}
    3134
    32 void Enemy::TickGame(float deltams)
     35void BlueEnemy::TickGame(float deltams)
    3336{
    34     WorldEntity::TickGame(deltams);
     37    Enemy::TickGame(deltams);
    3538
    3639    deltams *= game->GetSpeed();
    3740
    3841    enemytime = fmod(deltams + enemytime, 700.0f);;
     42
     43    position += velocity * deltams;
    3944}
    4045
    41 void Enemy::TickDraw(float deltams)
     46void BlueEnemy::TickDraw(float deltams)
    4247{
    4348    WorldEntity::TickDraw(deltams);
    4449
    45     Scene::GetDefault()->AddTile(enemy_casualblue, (int)(enemytime * 6 / 700.0f), ivec3(420, 81, 0), 0, vec2(-3.0f, 3.0f));
    46     Scene::GetDefault()->AddTile(enemy_casualblueattack, (int)(enemytime * 6 / 700.0f), ivec3(320, 81, 0), 0, vec2(-3.0f, 3.0f));
     50    /* + 48 because of vertical flip */
     51    Scene::GetDefault()->AddTile(position.x > 255 ? enemy_casualblue : enemy_casualblueattack, (int)(enemytime * 6 / 700.0f), position + vec3(48.0f, 0, 0), 0, vec2(-3.0f, 3.0f));
    4752}
    4853
    49 Enemy::~Enemy()
     54BlueEnemy::~BlueEnemy()
    5055{
    5156    Tiler::Deregister(enemy_casualblue);
  • trunk/mrpigeon/enemy.cpp

    r1205 r1211  
    2323
    2424Enemy::Enemy(MrPigeon *in_game) :
    25     game(in_game),
    26     enemytime(0.0f)
     25    game(in_game)
    2726{
    28     enemy_casualblue = Tiler::Register("mrpigeon/gfx/enemy_CasualBLUE_walk.png", ivec2(16,24), ivec2(0)); /* 6 frames */
    29     enemy_casualblueattack = Tiler::Register("mrpigeon/gfx/enemy_CasualBLUE_walkAttack.png", ivec2(16,24), ivec2(0)); /* 6 frames */
    3027}
    3128
     
    3532
    3633    deltams *= game->GetSpeed();
    37 
    38     enemytime = fmod(deltams + enemytime, 700.0f);;
    3934}
    4035
     
    4237{
    4338    WorldEntity::TickDraw(deltams);
    44 
    45     Scene::GetDefault()->AddTile(enemy_casualblue, (int)(enemytime * 6 / 700.0f), ivec3(420, 81, 0), 0, vec2(-3.0f, 3.0f));
    46     Scene::GetDefault()->AddTile(enemy_casualblueattack, (int)(enemytime * 6 / 700.0f), ivec3(320, 81, 0), 0, vec2(-3.0f, 3.0f));
    4739}
    4840
    4941Enemy::~Enemy()
    5042{
    51     Tiler::Deregister(enemy_casualblue);
    52     Tiler::Deregister(enemy_casualblueattack);
    5343}
    5444
  • trunk/mrpigeon/enemy.h

    r1205 r1211  
    77{
    88public:
     9    char const *GetName() { return "<enemy>"; }
     10
     11protected:
    912    Enemy(MrPigeon *game);
    1013    virtual ~Enemy();
    1114
    12     char const *GetName() { return "<enemy>"; }
    13 
    14     MrPigeon *game;
    15 
    16 protected:
    1715    virtual void TickGame(float deltams);
    1816    virtual void TickDraw(float deltams);
     
    2119            *enemy_casualblueattack;
    2220
    23     float enemytime;
     21    MrPigeon *game;
    2422};
    2523
  • trunk/mrpigeon/mrpigeon.cpp

    r1207 r1211  
    2626#include "player.h"
    2727#include "enemy.h"
     28#include "blueenemy.h"
     29#include "redenemy.h"
    2830
    2931MrPigeon::MrPigeon() :
     
    3537    player = new Player(this);
    3638    Ticker::Ref(player);
    37     enemy = new Enemy(this);
    38     Ticker::Ref(enemy);
     39
     40    for (int i = 0; i < 10; i++)
     41        enemies[i] = NULL;
    3942
    4043    hud_progress = Tiler::Register("mrpigeon/gfx/HUD_timeline.png", ivec2(160,16), ivec2(0));
     
    8689    deltams *= GetSpeed();
    8790
    88     railtime = fmod(deltams + railtime, 1000.0f);;
    89     backtime = fmod(deltams + backtime, 10000.0f / 288 * active_deco_width);;
     91    /* Delete enemies that went past us */
     92    for (int i = 0; i < 10; i++)
     93    {
     94        if (enemies[i] && enemies[i]->position.x < -100.0f)
     95        {
     96            Ticker::Unref(enemies[i]);
     97            enemies[i] = NULL;
     98        }
     99    }
     100
     101    /* Spawn enemies if necessary */
     102    spawntime += deltams;
     103    if (spawntime > 600.0f)
     104    {
     105        if (RandF(1.0f) < 0.2f)
     106            spawntime -= 300.0f;
     107        spawntime -= 600.0f;
     108        for (int i = 0; i < 10; i++)
     109        {
     110            if (enemies[i] == NULL)
     111            {
     112                if (RandF(1.0f) < 0.4f)
     113                    enemies[i] = new BlueEnemy(this);
     114                else if (totaltime > 9000.0f && RandF(1.0f) < 0.3f)
     115                    enemies[i] = new RedEnemy(this);
     116
     117                if (enemies[i])
     118                    Ticker::Ref(enemies[i]);
     119                break;
     120            }
     121        }
     122    }
     123
     124    /* Scroll background etc. */
     125    railtime = fmod(railtime + deltams, 1000.0f);;
     126    backtime = fmod(backtime + deltams, 10000.0f / 288 * active_deco_width);;
    90127
    91128    ivec3 buttons = Input::GetMouseButtons();
     
    135172
    136173    Ticker::Unref(player);
    137     Ticker::Unref(enemy);
     174    for (int i = 0; i < 10; i++)
     175        if (enemies[i])
     176            Ticker::Unref(enemies[i]);
    138177
    139178    Input::UntrackMouse(this);
  • trunk/mrpigeon/mrpigeon.h

    r1205 r1211  
    1111
    1212    float GetSpeed() { return speed; }
     13    class Enemy *const *GetEnemies() { return enemies; }
    1314
    1415protected:
     
    1718
    1819    class Player *player;
    19     class Enemy *enemy;
     20    class Enemy *enemies[10];
    2021
    2122    TileSet *hud_progress,
     
    3334
    3435    double totaltime;
    35     float railtime, backtime;
     36    float railtime, backtime, spawntime;
    3637    float speed;
    3738};
  • trunk/mrpigeon/player.cpp

    r1205 r1211  
    2121#include "mrpigeon.h"
    2222#include "player.h"
     23#include "enemy.h"
    2324
    2425#define GRAVITY 0.0007f
     
    2627
    2728#define LEN_KICKAIR 500.0f
     29#define LEN_KICKFLOOR 300.0f
    2830
    2931Player::Player(MrPigeon *in_game) :
     
    5759    case WALKING:
    5860    case FUNKING:
    59         velocity.y = JUMPVEL;
    60         state = JUMPING;
     61        {
     62            Enemy *const *enemies = game->GetEnemies();
     63            bool must_kick = false;
     64            for (int i = 0; i < 10; i++)
     65                if (enemies[i]
     66                     && enemies[i]->position.x > position.x + 60.0f - 30.0f
     67                     && enemies[i]->position.x < position.x + 60.0f + 30.0f)
     68                {
     69                    must_kick = true;
     70                    break;
     71                }
     72            if (must_kick)
     73            {
     74                walktime = 0.0f;
     75                state = KICKFLOOR;
     76            }
     77            else
     78            {
     79                velocity.y = JUMPVEL;
     80                state = JUMPING;
     81            }
     82        }
    6183        break;
    6284    case JUMPING:
     
    88110        walktime = fmod(deltams + walktime, 700.0f);;
    89111        break;
     112    case KICKFLOOR:
     113        walktime += deltams;
     114        if (walktime > LEN_KICKFLOOR)
     115            state = WALKING;
     116        break;
    90117    case FALLING:
    91118        velocity.y -= deltams * GRAVITY;
     
    131158        active_set = player_walkraisefist;
    132159        active_frame = (int)(walktime * 8 / 700.0f);
     160        break;
     161    case KICKFLOOR:
     162        active_set = player_kickfloor;
     163        active_frame = (int)(walktime * 3 / LEN_KICKFLOOR);
    133164        break;
    134165    case FALLING:
  • trunk/mrpigeon/player.h

    r1205 r1211  
    3737       WALKING,
    3838       FUNKING,
     39       KICKFLOOR,
    3940       FALLING,
    4041       JUMPING,
Note: See TracChangeset for help on using the changeset viewer.