MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / GlyphCoordinate

Class GlyphCoordinate

examples/space_invaders/space_invaders.py:116–238  ·  view source on GitHub ↗

Describe a glyph rendered at a certain x, y coordinate. The GlyphCoordinate may also include optional values such as the tick at time of render, a label, and a score value.

Source from the content-addressed store, hash-verified

114
115
116class GlyphCoordinate(Base):
117 """Describe a glyph rendered at a certain x, y coordinate.
118
119 The GlyphCoordinate may also include optional values
120 such as the tick at time of render, a label, and a
121 score value.
122
123 """
124
125 __tablename__ = "glyph_coordinate"
126 id = Column(Integer, primary_key=True)
127 glyph_id = Column(Integer, ForeignKey("glyph.id"))
128 x = Column(Integer)
129 y = Column(Integer)
130 tick = Column(Integer)
131 label = Column(String)
132 score = Column(Integer)
133 glyph = relationship(Glyph, innerjoin=True)
134
135 def __init__(
136 self, session, glyph_name, x, y, tick=None, label=None, score=None
137 ):
138 self.glyph = session.query(Glyph).filter_by(name=glyph_name).one()
139 self.x = x
140 self.y = y
141 self.tick = tick
142 self.label = label
143 self.score = score
144 session.add(self)
145
146 def render(self, window, state):
147 """Render the Glyph at this position."""
148
149 col = 0
150 row = 0
151 glyph = self.glyph
152 data = glyph.glyph_for_state(self, state)
153 for color, char in [
154 (data[i], data[i + 1]) for i in range(0, len(data), 2)
155 ]:
156 x = self.x + col
157 y = self.y + row
158 if 0 <= x <= MAX_X and 0 <= y <= MAX_Y:
159 window.addstr(
160 y + VERT_PADDING,
161 x + HORIZ_PADDING,
162 char,
163 _COLOR_PAIRS[color],
164 )
165 col += 1
166 if col == glyph.width:
167 col = 0
168 row += 1
169 if self.label:
170 self._render_label(window, False)
171
172 def _render_label(self, window, blank):
173 label = self.label if not blank else " " * len(self.label)

Callers 5

init_positionsFunction · 0.85
render_messageFunction · 0.85
move_playerFunction · 0.85
move_saucerFunction · 0.85
scoreFunction · 0.85

Calls 3

ColumnClass · 0.90
ForeignKeyClass · 0.90
relationshipFunction · 0.90

Tested by

no test coverage detected