1 /*
2 Copyright (C) 2009-2021 Parallel Realities
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19
20 #include "../headers.h"
21
22 #include "../audio/audio.h"
23 #include "../entity.h"
24 #include "../graphics/animation.h"
25 #include "../item/item.h"
26 #include "../item/key_items.h"
27 #include "../system/error.h"
28 #include "../system/properties.h"
29
30 extern Entity *self, player;
31 extern Game game;
32
33 static void dropChickenFeed(int);
34
addChickenFeedBag(int x,int y,char * name)35 Entity *addChickenFeedBag(int x, int y, char *name)
36 {
37 Entity *e = getFreeEntity();
38
39 if (e == NULL)
40 {
41 showErrorAndExit("No free slots to add a Chicken Feed Bag");
42 }
43
44 loadProperties(name, e);
45
46 e->x = x;
47 e->y = y;
48
49 e->dirY = ITEM_JUMP_HEIGHT;
50
51 e->type = KEY_ITEM;
52
53 e->face = LEFT;
54
55 e->action = &doNothing;
56 e->touch = &keyItemTouch;
57 e->activate = &dropChickenFeed;
58 e->die = &keyItemRespawn;
59
60 e->draw = &drawLoopingAnimationToMap;
61
62 setEntityAnimation(e, "STAND");
63
64 return e;
65 }
66
dropChickenFeed(int val)67 static void dropChickenFeed(int val)
68 {
69 Entity *e;
70
71 if (self->thinkTime <= 0 && game.status == IN_GAME && player.element != WATER)
72 {
73 e = addTemporaryItem("item/chicken_feed", player.x + (player.face == RIGHT ? player.w : 0), player.y + player.h / 2, player.face, player.face == LEFT ? -5 : 5, ITEM_JUMP_HEIGHT);
74
75 e->touch = &entityTouch;
76
77 playSoundToMap("sound/common/throw", EDGAR_CHANNEL, player.x, player.y, 0);
78
79 self->thinkTime = self->maxThinkTime;
80 }
81 }
82