mirror of
https://github.com/DragonRidersUnite/book
synced 2024-11-17 07:48:43 +01:00
feat: additional illustrations
This commit is contained in:
parent
453d3137d0
commit
6f0fe0dcae
4 changed files with 2 additions and 6 deletions
|
@ -139,8 +139,6 @@ Whoa! We just refactored that code. It's easier to change (ETC) now, which is a
|
|||
|
||||
You can move your dragon completely off the screen, lost in the great unknown! This isn't ideal. Let's make it so our little buddy can't leave the bounds of the screen.
|
||||
|
||||
[TODO: drawing about boundaries]
|
||||
|
||||
``` ruby
|
||||
{{#include code/chapter_02/app/main.rb}}
|
||||
```
|
||||
|
|
|
@ -87,8 +87,6 @@ There's a lot of important concepts in those three newly added lines of code. In
|
|||
|
||||
Looping through an array of data in each `#tick` and then doing _something_ is the stuff games are made of! Here are some ways this can be applied in all sorts of games: enemy behavior, checking for collision, animating. As our game (and any game you make) gets more complex, looping through collections of data becomes more and more common.
|
||||
|
||||
[TODO: illustration of game loop and then a little loop inside where we loop through collections]
|
||||
|
||||
## Switching to Hashes
|
||||
|
||||
So far throughout the book we've been using arrays to represent the entities in our game, whether it be the player's dragon sprite or our fireball text that gets displayed. Remember `[args.state.player_x, args.state.player_y, 'fireball']`? Arrays are wonderful and important, but they aren't so great for representing structured data because it's difficult to remember what each piece of data in the array's positions represents. Remembering that `fireball[2]` is the text value and not the y value is tricky. Luckily, DragonRuby has a more verbose and clear data structure we can use for managing our data. It's called a hash! Much like arrays, hashes are extremely useful.
|
||||
|
|
|
@ -58,9 +58,9 @@ The fireballs our dragon spits just fly behind our targets and off the screen in
|
|||
|
||||
Collision detection is when one object overlaps with another object in our game. Because we're manufacturing the space the game exists in, there's no physics like we have in real life. We need to simulate that by checking to see if two objects are attempting to exist in the same point and react accordingly.
|
||||
|
||||
Our fireball sprite is a 32x32 square, so we want to check in every single game loop whether or not the points of the fireball's square overlapping with any of the points of the targets. If they are overlapping, then we do that _something_.
|
||||
Our fireball sprite is a 32x32 square, so we want to check in every single game loop whether or not the points of the fireball's square overlapping with any of the points of the target sprites. If they are overlapping, then we do that _something_.
|
||||
|
||||
TODO: graphic of overlapping rects/squares explained
|
||||
![diagram showing two rectangles overlapping and not overlapping](./img/c04-rect-overlap.png)
|
||||
|
||||
We could employ trigonometry to determine if a given point in one shape overlaps with another, but DragonRuby gives us a helpful method to handle this for us: `args.geometry.intersect_rect? rect_1, rect_2`
|
||||
|
||||
|
|
BIN
src/img/c04-rect-overlap.png
Normal file
BIN
src/img/c04-rect-overlap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
Loading…
Reference in a new issue