Skip to content

Commit

Permalink
Add logic or & and operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Secret-chest committed Dec 30, 2022
1 parent 81203c0 commit d885d80
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions block.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def evaluateBlockValue(self, eventContainer=eventContainer.EventContainer):
except ZeroDivisionError:
raise ZeroDivisionError(_("zero-division-error"))
return self.value

elif self.opcode == "operator_random": # pick random from () to ()
decimals1 = len(str(math.modf(float(self.getInputValue("from"))))) - 2
decimals2 = len(str(math.modf(float(self.getInputValue("to"))))) - 2
Expand All @@ -71,6 +72,7 @@ def evaluateBlockValue(self, eventContainer=eventContainer.EventContainer):
decimals = decimals2
self.value = random.randint(int(self.getInputValue("from")) * 10 ** decimals, int(self.getInputValue("to")) * 10 ** decimals) / 10 ** decimals
return self.value

elif self.opcode == "operator_equals": # () = ()
self.value = self.getInputValue("operand1") == self.getInputValue("operand2")
return self.value
Expand All @@ -80,12 +82,14 @@ def evaluateBlockValue(self, eventContainer=eventContainer.EventContainer):
elif self.opcode == "operator_gt": # () > ()
self.value = self.getInputValue("operand1") > self.getInputValue("operand2")
return self.value

elif self.opcode == "motion_xposition": # x position
self.value = self.target.x
return self.value
elif self.opcode == "motion_xposition": # y position
self.value = self.target.y
return self.value

elif self.opcode == "sensing_mousex": # mouse x
newX, newY = pygame.mouse.get_pos()
newX = newX - config.screenWidth // 2
Expand All @@ -96,14 +100,22 @@ def evaluateBlockValue(self, eventContainer=eventContainer.EventContainer):
newY = newY - config.screenWidth // 2
self.value = newY
return self.value

elif self.opcode == "sensing_keypressed": # key pressed?
self.value = KEY_MAPPING[self.getMenuValue("key_option")] in eventContainer.keys
return self.value
elif self.opcode == "sensing_mousedown": # mouse down?
self.value = pygame.mouse.get_pressed()[0]
return self.value

elif self.opcode == "operator_not": # not <>
self.value = not self.target.blocks[self.getBlockInputValue("operand")].evaluateBlockValue(eventContainer)
return self.value
elif self.opcode == "sensing_mousedown": # mouse down?
self.value = pygame.mouse.get_pressed()[0]
elif self.opcode == "operator_and": # <> and <>
self.value = self.target.blocks[self.getBlockInputValue("operand1")].evaluateBlockValue(eventContainer) and self.target.blocks[self.getBlockInputValue("operand2")].evaluateBlockValue(eventContainer)
return self.value
elif self.opcode == "operator_or": # <> or <>
self.value = self.target.blocks[self.getBlockInputValue("operand1")].evaluateBlockValue(eventContainer) or self.target.blocks[self.getBlockInputValue("operand2")].evaluateBlockValue(eventContainer)
return self.value

# Returns block input value
Expand Down

0 comments on commit d885d80

Please sign in to comment.