Skip to content

Commit 93f7e64

Browse files
committed
Implemented AppleSapling
1 parent 48689ad commit 93f7e64

22 files changed

Lines changed: 2613 additions & 21 deletions

.kiro/specs/apple-sapling-drop/design.md

Lines changed: 692 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Requirements Document
2+
3+
## Introduction
4+
5+
This feature implements a dual-item drop system for AppleTree destruction. When an AppleTree is destroyed, it will drop two distinct items (Apple and AppleSapling) at the tree's position, positioned a few pixels apart. This extends the existing single-item drop pattern to support multiple item drops from a single tree, following the same pattern used by BambooTree (BambooStack + BambooSapling) and SmallTree (TreeSapling + WoodStack).
6+
7+
## Glossary
8+
9+
- **Game System**: The Woodlanders game application that manages game state, rendering, and player interactions
10+
- **AppleTree**: A tree entity in the game world that can be attacked and destroyed by players, rendered at 128x128 pixels
11+
- **Apple**: An item entity representing an apple fruit, extracted from the sprite sheet at coordinates (0, 128) with 64x64 dimensions
12+
- **AppleSapling**: An item entity representing a young apple tree sapling, extracted from the sprite sheet at coordinates (192, 254) with 64x64 dimensions
13+
- **Item Drop**: The process of spawning item entities at a tree's position when the tree is destroyed
14+
- **Render Size**: The visual dimensions at which an item is displayed on screen (32x32 pixels for both items)
15+
- **Sprite Sheet**: The texture atlas file (assets.png) containing all game sprites
16+
- **Player Class**: The class responsible for handling player actions including tree attacks in single-player mode
17+
- **MyGdxGame Class**: The main game class responsible for rendering items and managing game state
18+
- **Multiplayer Mode**: Game mode where tree destruction is handled by the server
19+
- **Single-Player Mode**: Game mode where tree destruction is handled locally by the Player class
20+
- **ItemType Enum**: Network enumeration defining item types for multiplayer synchronization
21+
- **PlayerState**: Network class representing a player's state including position, health, and inventory counts for multiplayer synchronization
22+
- **Inventory System**: The player inventory system that stores collected items and persists them in save files
23+
24+
## Requirements
25+
26+
### Requirement 1
27+
28+
**User Story:** As a player, I want AppleTree to drop two items when destroyed, so that I can collect both Apple and AppleSapling resources
29+
30+
#### Acceptance Criteria
31+
32+
1. WHEN an AppleTree health reaches zero, THE Game System SHALL spawn one Apple item at the tree's base position
33+
2. WHEN an AppleTree health reaches zero, THE Game System SHALL spawn one AppleSapling item at the tree's base position offset by 8 pixels horizontally from the Apple
34+
3. WHERE the game is in single-player mode, THE Player Class SHALL create both item instances and add them to the game's item collections when an AppleTree is destroyed
35+
4. WHERE the game is in multiplayer mode, THE Game System SHALL handle apple item spawning through the server's item spawn messaging system
36+
5. WHEN apple items are spawned, THE Game System SHALL use unique identifiers for each item based on the tree's position key with suffixes "-apple" and "-applesapling"
37+
38+
### Requirement 2
39+
40+
**User Story:** As a player, I want apple items to be visually distinct and properly sized, so that I can easily identify and collect them
41+
42+
#### Acceptance Criteria
43+
44+
1. THE MyGdxGame Class SHALL render Apple items at 32x32 pixels on screen
45+
2. THE MyGdxGame Class SHALL render AppleSapling items at 32x32 pixels on screen
46+
3. THE Apple Class SHALL extract its texture from sprite sheet coordinates (0, 128) with source dimensions 64x64
47+
4. THE AppleSapling Class SHALL extract its texture from sprite sheet coordinates (192, 254) with source dimensions 64x64
48+
5. THE MyGdxGame Class SHALL maintain separate collections for Apple and AppleSapling items to enable independent rendering and collision detection
49+
50+
### Requirement 3
51+
52+
**User Story:** As a player, I want to be able to pick up apple items by walking over them, so that I can collect the resources
53+
54+
#### Acceptance Criteria
55+
56+
1. WHEN the player's collision box overlaps with an Apple item, THE Player Class SHALL remove the Apple from the game world
57+
2. WHEN the player's collision box overlaps with an AppleSapling item, THE Player Class SHALL remove the AppleSapling from the game world
58+
3. THE Player Class SHALL check for apple item pickups during each update cycle using the same collision detection pattern as other items
59+
4. WHEN an apple item is picked up in multiplayer mode, THE Game System SHALL send an item pickup message to the server
60+
5. THE Player Class SHALL dispose of apple item textures when items are picked up to prevent memory leaks
61+
6. THE Player Class SHALL use a 32-pixel pickup range from the player's center to the item's center
62+
63+
### Requirement 4
64+
65+
**User Story:** As a player, I want AppleSapling items to be added to my inventory when picked up, so that I can use them for planting later
66+
67+
#### Acceptance Criteria
68+
69+
1. WHEN an AppleSapling item is picked up, THE Inventory System SHALL add one AppleSapling to the player's inventory
70+
2. THE Inventory System SHALL support the AppleSapling item type in the ItemType enumeration
71+
3. THE Inventory System SHALL display the AppleSapling count in the inventory UI
72+
4. THE Inventory System SHALL allow the player to select AppleSapling from the inventory for planting
73+
5. WHEN the player saves the game, THE World Save System SHALL persist the AppleSapling inventory count
74+
6. WHEN the player loads a saved game, THE World Save System SHALL restore the AppleSapling inventory count
75+
76+
### Requirement 5
77+
78+
**User Story:** As a multiplayer client, I want AppleSapling items to synchronize correctly across all players, so that everyone sees the same game state
79+
80+
#### Acceptance Criteria
81+
82+
1. THE ItemType Network Enum SHALL include an APPLE_SAPLING entry for network synchronization
83+
2. WHEN an AppleSapling is spawned in multiplayer mode, THE Game Server SHALL broadcast an ItemSpawnMessage with type APPLE_SAPLING
84+
3. WHEN an AppleSapling is picked up in multiplayer mode, THE Game Server SHALL broadcast an ItemPickupMessage for the AppleSapling
85+
4. WHEN a client receives an AppleSapling spawn message, THE Game Client SHALL create an AppleSapling instance at the specified position
86+
5. WHEN a client receives an AppleSapling pickup message, THE Game Client SHALL remove the AppleSapling from the local collection
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Implementation Plan
2+
3+
- [x] 1. Add AppleSapling collection to MyGdxGame
4+
- Add `Map<String, AppleSapling> appleSaplings` field declaration with other item collections
5+
- Initialize `appleSaplings = new HashMap<>()` in create() method
6+
- Wire appleSaplings collection to player with `player.setAppleSaplings(appleSaplings)` in create()
7+
- _Requirements: 2.5_
8+
9+
- [x] 2. Implement AppleSapling rendering in MyGdxGame
10+
- Create `drawAppleSaplings()` method with viewport culling logic
11+
- Render AppleSapling items at 32x32 pixels using batch.draw()
12+
- Call `drawAppleSaplings()` in render() method after `drawApples()`
13+
- _Requirements: 2.2_
14+
15+
- [x] 3. Add AppleSapling support to Player class
16+
- Add AppleSapling import statement at top of Player.java
17+
- Add `Map<String, AppleSapling> appleSaplings` field declaration
18+
- Implement `setAppleSaplings()` setter method
19+
- _Requirements: 1.3_
20+
21+
- [x] 4. Implement dual-item drop logic for AppleTree destruction
22+
- Modify the AppleTree destruction block in Player's attack handling (around line 932)
23+
- Keep existing Apple spawn at tree's base position with key `targetKey`
24+
- Add AppleSapling spawn at position offset by 8 pixels horizontally using key `targetKey + "-applesapling"`
25+
- Add AppleSapling to appleSaplings collection
26+
- Add console logging for AppleSapling drop
27+
- _Requirements: 1.1, 1.2, 1.5_
28+
29+
- [x] 5. Implement AppleSapling pickup detection and handling
30+
- Create `checkAppleSaplingPickups()` method in Player class that iterates appleSaplings and checks collision
31+
- Create `pickupAppleSapling()` method that handles single-player pickup (dispose, remove, add to inventory) and multiplayer pickup (send message)
32+
- Add call to `checkAppleSaplingPickups()` in Player's `update()` method after `checkApplePickups()`
33+
- _Requirements: 3.2, 3.3, 3.4, 3.5, 4.1_
34+
35+
- [x] 6. Add APPLE_SAPLING to inventory ItemType enum
36+
- Open src/main/java/wagemaker/uk/inventory/ItemType.java
37+
- Add APPLE_SAPLING entry after APPLE with parameters (false, 0, false)
38+
- _Requirements: 4.2_
39+
40+
- [x] 7. Add APPLE_SAPLING to network ItemType enum
41+
- Open src/main/java/wagemaker/uk/network/ItemType.java
42+
- Add APPLE_SAPLING entry after APPLE
43+
- _Requirements: 5.1_
44+
45+
- [x] 8. Add AppleSapling inventory support to Inventory class
46+
- Open src/main/java/wagemaker/uk/inventory/Inventory.java
47+
- Add `appleSaplingCount` field
48+
- Implement getAppleSaplingCount(), setAppleSaplingCount(), addAppleSapling(), and removeAppleSapling() methods
49+
- _Requirements: 4.1_
50+
51+
- [x] 9. Update InventoryManager for AppleSapling
52+
- Open src/main/java/wagemaker/uk/inventory/InventoryManager.java
53+
- Add APPLE_SAPLING case to addItemToInventory() method
54+
- Update syncFromServer() method signature to include appleSaplingCount parameter
55+
- Add appleSaplingCount sync logic in syncFromServer()
56+
- Update getSelectedItemType() to return APPLE_SAPLING for slot 8
57+
- Update checkAndAutoDeselect() to check appleSaplingCount for slot 8
58+
- _Requirements: 4.1, 5.2, 5.3_
59+
60+
- [x] 10. Update InventorySyncMessage for AppleSapling
61+
- Open src/main/java/wagemaker/uk/network/InventorySyncMessage.java
62+
- Add appleSaplingCount field to message
63+
- Update constructor and getters
64+
- _Requirements: 5.2_
65+
66+
- [x] 11. Update InventoryUpdateMessage for AppleSapling
67+
- Open src/main/java/wagemaker/uk/network/InventoryUpdateMessage.java
68+
- Add appleSaplingCount field to message
69+
- Update constructor and getters
70+
- _Requirements: 5.2_
71+
72+
- [x] 11.5. Update PlayerState for AppleSapling
73+
- Open src/main/java/wagemaker/uk/network/PlayerState.java
74+
- Add `appleSaplingCount` field to player state
75+
- Implement getAppleSaplingCount() and setAppleSaplingCount() methods
76+
- Update ClientConnection to use appleSaplingCount in InventoryUpdateMessage and InventorySyncMessage constructors
77+
- Update GameMessageHandler to pass appleSaplingCount to syncFromServer() method
78+
- _Requirements: 5.2, 5.3_
79+
80+
- [x] 12. Update multiplayer item spawn handling for AppleSapling
81+
- Locate server-side tree destruction handler
82+
- Add AppleTree destruction case with dual-item spawn logic
83+
- Broadcast ItemSpawnMessage for Apple with type APPLE
84+
- Broadcast ItemSpawnMessage for AppleSapling with type APPLE_SAPLING
85+
- Locate client-side ItemSpawnMessage handler
86+
- Add APPLE_SAPLING case to create AppleSapling instances from spawn messages
87+
- Add AppleSapling to appleSaplings collection
88+
- _Requirements: 5.2, 5.4_
89+
90+
- [x] 13. Update multiplayer item pickup handling for AppleSapling
91+
- Locate server-side ItemPickupMessage handler
92+
- Verify it handles APPLE_SAPLING pickup messages generically
93+
- Locate client-side pickup message handler
94+
- Add APPLE_SAPLING case to remove AppleSapling from collection and add to inventory
95+
- Verify inventory synchronization for APPLE_SAPLING items
96+
- _Requirements: 5.3, 5.5, 4.1_
97+
98+
- [x] 14. Update world save/load support for AppleSapling inventory
99+
- Open src/main/java/wagemaker/uk/world/WorldSaveData.java
100+
- Add appleSaplingCount field to save data
101+
- Update save logic to include appleSaplingCount
102+
- Update load logic to restore appleSaplingCount
103+
- _Requirements: 4.5, 4.6_
104+
105+
- [x] 15. Update InventoryRenderer for AppleSapling display
106+
- Open src/main/java/wagemaker/uk/ui/InventoryRenderer.java
107+
- Add AppleSapling rendering at slot 8
108+
- Extract AppleSapling texture from sprite sheet at (192, 254)
109+
- Display appleSaplingCount next to AppleSapling icon
110+
- _Requirements: 4.3_
111+
112+
- [x] 16. Test single-player dual-drop functionality
113+
- Start single-player game
114+
- Attack and destroy AppleTree
115+
- Verify both Apple and AppleSapling spawn 8 pixels apart
116+
- Verify items render at 32x32 pixels
117+
- Verify console logs show correct drop positions
118+
- Walk over Apple and verify pickup
119+
- Walk over AppleSapling and verify pickup + inventory increase
120+
- Check inventory UI shows AppleSapling count
121+
- Save game and verify AppleSapling count persists
122+
- Load game and verify AppleSapling count restored
123+
- _Requirements: 1.1, 1.2, 2.1, 2.2, 3.1, 3.2, 4.1, 4.3, 4.5, 4.6_
124+
125+
- [x] 17. Test multiplayer dual-drop synchronization
126+
- Start server and connect 2+ clients
127+
- Client attacks AppleTree until destroyed
128+
- Verify both items spawn on all clients
129+
- Verify items render correctly on all clients
130+
- Verify items are positioned correctly on all clients
131+
- Client picks up Apple
132+
- Verify removal on all clients
133+
- Client picks up AppleSapling
134+
- Verify removal on all clients
135+
- Verify inventory synchronization across clients
136+
- Test with multiple players attacking different AppleTrees simultaneously
137+
- _Requirements: 1.4, 5.2, 5.3, 5.4, 5.5_

0 commit comments

Comments
 (0)