fixed black market generator: if "generate lake" flag is also set, black market will...
[k8vacspelynky.git] / mapent / MapCharacter.vc
blob417f452a14daf9f1b88eb1bb6c2dac5e949b69f9
1 /**********************************************************************************
2  * Copyright (c) 2008, 2009 Derek Yu and Mossmouth, LLC
3  * Copyright (c) 2010, Moloch
4  * Copyright (c) 2018, Ketmar Dark
5  *
6  * This file is part of Spelunky.
7  *
8  * You can redistribute and/or modify Spelunky, including its source code, under
9  * the terms of the Spelunky User License.
10  *
11  * Spelunky is distributed in the hope that it will be entertaining and useful,
12  * but WITHOUT WARRANTY.  Please see the Spelunky User License for more details.
13  *
14  * The Spelunky User License should be available in "Game Information", which
15  * can be found in the Resource Explorer, or as an external file called COPYING.
16  * If not, please obtain a new copy of Spelunky from <http://spelunkyworld.com/>
17  *
18  **********************************************************************************/
19 // ////////////////////////////////////////////////////////////////////////// //
20 // dunno, she is an item in the original code
21 class ObjCharacter : MapEnemy;
23 int holdXOfs, holdYOfs;
26 // turn them around if they are looking at a wall
27 final void initFixDirection () {
28        if (level.isSolidAtPoint(ix-4, iy+8)) dir = Dir.Right;
29   else if (level.isSolidAtPoint(ix+16+4, iy+8)) dir = Dir.Left;
33 // MapEnemy handler is ok
34 // override void onStunnedHitEnemy (MapEnemy enemy)
36 // MapEnemy handler is ok
37 //override bool onExplosionTouch (MapObject xplo)
40 // return `false` to do standard weapon processing
41 override bool onTouchedByPlayerWeapon (PlayerPawn plr, PlayerWeapon wpn) {
42   if (heldBy) return false;
43   wpn.hitEnemy = true;
44   hp -= 1;
45   spillBlood(); //k8: was iy-8, why?
46   return true;
50 override bool onTouchedByPlayer (PlayerPawn plr) {
51   return false;
55 override void onBulletHit (ObjBullet bullet) {
56   if (heldBy) heldBy.holdItem = none;
57   countsAsKill = true;
58   hp -= bullet.damage;
59   spillBlood();
60   yVel = -6;
61   xVel = bullet.xVel*0.3;
65 override void fixHoldCoords () {
66   if (heldBy) {
67     xVel = 0;
68     yVel = 0;
69     xAcc = 0;
70     yAcc = 0;
71     int dx = (heldBy.dir == Dir.Left ? -4 : 4);
72     int dy = (heldBy.status == DUCKING && fabs(heldBy.xVel) < 2 ? 4 : 0);
73     dx += holdXOfs;
74     dy += holdYOfs;
75     setXY(heldBy.fltx+dx, heldBy.flty+dy);
76     prevFltX = heldBy.prevFltX+dx;
77     prevFltY = heldBy.prevFltY+dy;
78     updateGrid();
79     if (spriteRName) dir = heldBy.dir;
80   }
84 // virtual
85 // return `true` if item hits the character
86 // this is called after item's event
87 override bool onHitByItem (MapItem proj) {
88   return false;
92 // return `true` if this entity can be sacrificed
93 override bool canBeSacrificed (MapTile altar) {
94   return !bloodless;
98 override bool onSacrificed (MapTile altar) {
99   level.performSacrifice(self, altar);
100   return true;
104 override void thinkFrame () {
105   // remove corpse
106   if (status == DEAD && removeCorpse) {
107     if (deathTimer > 0) {
108       deathTimer -= 1;
109     } else {
110       spillBlood();
111       instanceRemove();
112     }
113   }
117 defaultproperties {
118   objName = 'BaseCharacter';
120   //setCollisionBounds(-4, -4, 4, 8);
121   imageSpeed = 0.5;
122   //trigger = true;
123   //startled = false;
124   swimming = false;
125   heavy = true;
126   bloodLeft = 4;
127   dead = false;
128   status = IDLE;
129   dir = Dir.Left;
130   bounced = false;
131   burning = false;
132   removeCorpse = false; // only applies to enemies that have corpses (Caveman, Yeti, etc.)
133   deathTimer = 200; // how many steps after death until corpse is removed
134   canPickUp = true;
135   canBeHitByBullet = true;
136   canBeNudged = false;
137   canBeStunned = true;
139   activeWhenHeld = true; // for animation
140   spectralWhenHeld = false;