Skip to content

Commit dc19f4b

Browse files
Merge pull request #46 from Stephenson-Software/rocks
Rocks
2 parents b8c338f + ac1b5e0 commit dc19f4b

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

src/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self):
1616
self.ticksPerSecond = 30
1717
self.tickSpeed = 1/self.ticksPerSecond
1818
self.limitTickSpeed = True
19-
self.gridSize = random.randrange(16, 19)
19+
self.gridSize = 16
2020
self.playerMovementEnergyCost = 0.2
2121
self.playerInteractionEnergyCost= 0.05
2222
self.worldBorder = 16

src/map.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import random
33
from apple import Apple
44
from graphik import Graphik
5+
from rock import Rock
56
from wood import Wood
67
from entity import Entity
78
from grass import Grass
@@ -41,6 +42,9 @@ def generateNewRoom(self, x, y):
4142

4243
# generate grass
4344
self.spawnGrass(newRoom)
45+
46+
# generate rocks
47+
self.spawnRocks(newRoom)
4448

4549
# generate food
4650
maxTrees = ceil(self.gridSize/2)
@@ -54,6 +58,11 @@ def spawnGrass(self, room: Room):
5458
for location in room.getGrid().getLocations():
5559
if random.randrange(1, 101) > 5: # 95% chance
5660
room.addEntityToLocation(Grass(), location)
61+
62+
def spawnRocks(self, room: Room):
63+
for location in room.getGrid().getLocations():
64+
if random.randrange(1, 101) == 1: # 1% chance
65+
room.addEntityToLocation(Rock(), location)
5766

5867
def spawnTree(self, room: Room):
5968
wood = Wood()

src/rock.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import random
2+
from entity import Entity
3+
4+
5+
# @author Daniel McCoy Stephenson
6+
# @since August 18th, 2022
7+
class Rock(Entity):
8+
def __init__(self):
9+
Entity.__init__(self, "Rock")
10+
self.color = (random.randrange(100, 110), random.randrange(100, 110), random.randrange(100, 110))
11+
12+
def getColor(self):
13+
return self.color

src/wood.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import random
12
from entity import Entity
23

34

@@ -6,7 +7,7 @@
67
class Wood(Entity):
78
def __init__(self):
89
Entity.__init__(self, "Wood")
9-
self.color = (139, 69, 19)
10+
self.color = (random.randrange(135, 145), random.randrange(65, 75), random.randrange(15, 25))
1011

1112
def getColor(self):
1213
return self.color

src/worldScreen.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from graphik import Graphik
1010
from grass import Grass
1111
from grid import Grid
12+
from rock import Rock
1213
from selectedItemPreview import SelectedItemPreview
1314
from leaves import Leaves
1415
from location import Location
@@ -136,8 +137,7 @@ def movePlayer(self, direction: int):
136137
self.changeRooms()
137138
return
138139

139-
if self.map.locationContainsEntity(newLocation, Wood):
140-
# apple trees are solid
140+
if self.locationContainsSolidEntity(newLocation):
141141
return
142142

143143
if self.player.getEnergy() < self.player.getMaxEnergy() * 0.95:
@@ -162,7 +162,7 @@ def movePlayer(self, direction: int):
162162
self.player.setTickLastMoved(self.tick)
163163

164164
def canBePickedUp(self, entity):
165-
itemTypes = [Wood, Leaves, Grass, Apple]
165+
itemTypes = [Wood, Leaves, Grass, Apple, Rock]
166166
for itemType in itemTypes:
167167
if isinstance(entity, itemType):
168168
return True
@@ -203,6 +203,9 @@ def getLocationInFrontOfPlayer(self):
203203
playerLocation = self.getLocationOfPlayer()
204204
return self.getLocationDirection(direction, self.currentRoom.grid, playerLocation)
205205

206+
def locationContainsSolidEntity(self, location):
207+
return self.map.locationContainsEntity(location, Wood) or self.map.locationContainsEntity(location, Rock)
208+
206209
def executePlaceAction(self):
207210
if len(self.player.getInventory().getContents()) == 0:
208211
self.status.set("no items", self.tick)
@@ -215,8 +218,8 @@ def executePlaceAction(self):
215218
if targetLocation == -2:
216219
self.status.set("can't place while moving", self.tick)
217220
return
218-
if self.map.locationContainsEntity(targetLocation, Wood):
219-
self.status.set("blocked by wood", self.tick)
221+
if self.locationContainsSolidEntity(targetLocation):
222+
self.status.set("location blocked", self.tick)
220223
return
221224

222225
toPlace = self.player.getInventory().getContents().pop()

0 commit comments

Comments
 (0)