source: abuse/trunk/src/morpher.cpp @ 682

Last change on this file since 682 was 682, checked in by Sam Hocevar, 8 years ago

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

File size: 2.4 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "common.h"
16
17#include "morpher.h"
18#include "game.h"
19#include "objects.h"
20#include "view.h"
21
22void morph_char::draw(game_object *who, view *v)
23{
24    if (fleft)
25    {
26        ivec2 pos = the_game->GameToMouse(ivec2(who->x - (cx >> 16),
27                                                who->y - (cy >> 16)), v);
28        mor->show(main_screen, pos.x, pos.x, color_table, pal, 1000);
29        cx += dcx;
30        cy += dcy;
31        fleft--;
32    }
33}
34
35
36
37morph_char::morph_char(game_object *who, int to_type, void (*stat_fun)(int), int anneal, int frames)
38{
39  mor=NULL;
40  CharacterType *t1=figures[who->otype],*t2=figures[to_type];
41  if (!t1->has_sequence(morph_pose) || t1->morph_mask<0 ||
42      !t2->has_sequence(morph_pose) || t2->morph_mask<0)
43    fleft=0;
44  else
45  {
46    if (anneal==-1)
47    {
48      switch (morph_detail)
49      {
50    case HIGH_DETAIL :
51    { anneal=30; } break;
52    case MEDIUM_DETAIL :
53    { anneal=15; } break;
54    case LOW_DETAIL :
55    { anneal=8; } break;
56    case POOR_DETAIL :
57    { anneal=3; } break;
58      }
59    }
60
61    fleft=frames;
62    TransImage *h1=new TransImage(cache.img(t1->morph_mask),"morph tmp"),
63                *h2=new TransImage(cache.img(t2->morph_mask),"morph tmp");
64    super_morph *sm=new super_morph(h1,h2,anneal,stat_fun);
65    if (sm->t)
66    {
67      delete h1;
68      delete h2;
69      figure *f1=t1->get_sequence(morph_pose)->get_figure(0),
70      *f2=t2->get_sequence(morph_pose)->get_figure(0);
71      image *i1=f1->forward->ToImage(),
72      *i2=f2->forward->ToImage();
73
74      mor=new smorph_player(sm,pal,i1,i2,fleft,who->direction);
75      delete i2;
76      delete i1;
77      delete sm;
78
79      if (who->direction>0)
80      {
81    cx=((int)f1->xcfg)<<16;
82    dcx=(((int)f2->xcfg-(int)f1->xcfg)<<16)/(fleft-1);
83      } else
84      {
85    cx=(mor->w-((int)f1->xcfg))<<16;
86    dcx=((((int)f1->xcfg-(int)f2->xcfg))<<16)/(fleft-1);
87      }
88      cy=((int)f1->height()-1)<<16;
89      dcy=((f2->height()-f1->height())<<16)/(fleft-1);
90    } else
91    {
92      delete sm;
93      fleft=0;
94    }
95  }
96}
97
98
99
100
101
102
103
104
105
106
107
Note: See TracBrowser for help on using the repository browser.