summaryrefslogtreecommitdiffhomepage
path: root/samples/05_mouse
diff options
context:
space:
mode:
author_Tradam <[email protected]>2021-12-16 19:22:26 -0500
committerGitHub <[email protected]>2021-12-16 19:22:26 -0500
commit5954b9beb4d4a3b4f248d72d1851195f030558a8 (patch)
treefecd8aa840a25afdb502915b0fdb4d03b7ed339a /samples/05_mouse
parent2f845281f133849256b57bb08fd3e9ae57600784 (diff)
parenteaa29e72939f5edf61735ccbb73c36ee89369f65 (diff)
downloaddragonruby-game-toolkit-contrib-master.tar.gz
dragonruby-game-toolkit-contrib-master.zip
Merge branch 'DragonRuby:master' into masterHEADmaster
Diffstat (limited to 'samples/05_mouse')
-rw-r--r--samples/05_mouse/01_mouse_click/app/main.rb18
-rw-r--r--samples/05_mouse/02_mouse_move/app/main.rb4
-rw-r--r--samples/05_mouse/03_mouse_move_paint_app/app/main.rb1
-rw-r--r--samples/05_mouse/04_coordinate_systems/app/main.rb4
4 files changed, 24 insertions, 3 deletions
diff --git a/samples/05_mouse/01_mouse_click/app/main.rb b/samples/05_mouse/01_mouse_click/app/main.rb
index c1a6e29..e37a753 100644
--- a/samples/05_mouse/01_mouse_click/app/main.rb
+++ b/samples/05_mouse/01_mouse_click/app/main.rb
@@ -33,9 +33,11 @@
- args.outputs.borders: An array. The values generate a border.
The parameters are [X, Y, WIDTH, HEIGHT, RED, GREEN, BLUE]
+ For more information about borders, go to mygame/documentation/03-solids-and-borders.md.
- args.outputs.labels: An array. The values generate a label.
The parameters are [X, Y, TEXT, SIZE, ALIGNMENT, RED, GREEN, BLUE, ALPHA, FONT STYLE]
+ For more information about labels, go to mygame/documentation/02-labels.
=end
@@ -47,12 +49,23 @@ class TicTacToe
# Starts the game with player x's turn and creates an array (to_a) for space combinations.
# Calls methods necessary for the game to run properly.
def tick
- state.current_turn ||= :x
- state.space_combinations = [-1, 0, 1].product([-1, 0, 1]).to_a
+ init_new_game
render_board
input_board
end
+ def init_new_game
+ state.current_turn ||= :x
+ state.space_combinations ||= [-1, 0, 1].product([-1, 0, 1]).to_a
+
+ state.spaces ||= {}
+
+ state.space_combinations.each do |x, y|
+ state.spaces[x] ||= {}
+ state.spaces[x][y] ||= state.new_entity(:space)
+ end
+ end
+
# Uses borders to create grid squares for the game's board. Also outputs the game pieces using labels.
def render_board
square_size = 80
@@ -128,6 +141,7 @@ class TicTacToe
def input_restart_game
return unless state.game_over
gtk.reset
+ init_new_game
end
# Checks if x or o won the game.
diff --git a/samples/05_mouse/02_mouse_move/app/main.rb b/samples/05_mouse/02_mouse_move/app/main.rb
index b015277..d9387dc 100644
--- a/samples/05_mouse/02_mouse_move/app/main.rb
+++ b/samples/05_mouse/02_mouse_move/app/main.rb
@@ -14,9 +14,11 @@
- args.inputs.keyboard.key_down.KEY: Determines if a key is being held or pressed.
Stores the frame the "down" event occurred.
+ For more information about the keyboard, go to mygame/documentation/06-keyboard.md.
- args.outputs.sprites: An array. The values generate a sprite.
The parameters are [X, Y, WIDTH, HEIGHT, PATH, ANGLE, ALPHA, RED, GREEN, BLUE]
+ For more information about sprites, go to mygame/documentation/05-sprites.md.
- args.state.new_entity: Used when we want to create a new object, like a sprite or button.
When we want to create a new object, we can declare it as a new entity and then define
@@ -194,7 +196,7 @@ class ProtectThePuppiesFromTheZombies
def calc_kill_zombie
# Find all zombies that intersect with the player. They are considered killed.
- killed_this_frame = state.zombies.find_all { |z| z.sprite.intersect_rect? state.player_sprite }
+ killed_this_frame = state.zombies.find_all { |z| z.sprite && (z.sprite.intersect_rect? state.player_sprite) }
state.zombies = state.zombies - killed_this_frame # remove newly killed zombies from zombies collection
state.killed_zombies += killed_this_frame # add newly killed zombies to killed zombies
diff --git a/samples/05_mouse/03_mouse_move_paint_app/app/main.rb b/samples/05_mouse/03_mouse_move_paint_app/app/main.rb
index b177fd6..9303949 100644
--- a/samples/05_mouse/03_mouse_move_paint_app/app/main.rb
+++ b/samples/05_mouse/03_mouse_move_paint_app/app/main.rb
@@ -34,6 +34,7 @@
- args.outputs.labels: An array. The values in the array generate a label.
The parameters are [X, Y, TEXT, SIZE, ALIGN, RED, GREEN, BLUE, ALPHA, FONT STYLE]
+ For more information about labels, go to mygame/documentation/02-labels.md.
- ARRAY#inside_rect?: Returns true or false depending on if the point is inside the rect.
diff --git a/samples/05_mouse/04_coordinate_systems/app/main.rb b/samples/05_mouse/04_coordinate_systems/app/main.rb
index 8e5578f..fcfa090 100644
--- a/samples/05_mouse/04_coordinate_systems/app/main.rb
+++ b/samples/05_mouse/04_coordinate_systems/app/main.rb
@@ -5,6 +5,7 @@
- args.inputs.mouse.click.position: Coordinates of the mouse's position on the screen.
Unlike args.inputs.mouse.click.point, the mouse does not need to be pressed down for
position to know the mouse's coordinates.
+ For more information about the mouse, go to mygame/documentation/07-mouse.md.
Reminders:
@@ -20,12 +21,15 @@
- args.outputs.labels: An array that generates a label.
The parameters are [X, Y, TEXT, SIZE, ALIGN, RED, GREEN, BLUE, ALPHA, FONT STYLE]
+ For more information about labels, go to mygame/documentation/02-labels.md.
- args.outputs.solids: An array that generates a solid.
The parameters are [X, Y, WIDTH, HEIGHT, RED, GREEN, BLUE, ALPHA]
+ For more information about solids, go to mygame/documentation/03-solids-and-borders.md.
- args.outputs.lines: An array that generates a line.
The parameters are [X, Y, X2, Y2, RED, GREEN, BLUE, ALPHA]
+ For more information about lines, go to mygame/documentation/04-lines.md.
=end