The Dodge Game

1,793 views
Skip to first unread message

Scott Ferguson

unread,
Nov 5, 2015, 10:23:55 PM11/5/15
to app-inventor-de...@googlegroups.com
Changes log: 2015/11/07 - adjusted ball speed and scoreboard for emulator; added reset option to reset best score and level

YouTube video walkthrough: https://youtu.be/6p3l4AQMl3s

This project is also available in the App Inventor Gallery.

This is a simple game of dodgeball.
Your player is a blue ball which must be dragged to a blue square on the opposite side of the Canvas while avoiding red bouncing balls.
Based on 'The Dodge Game' (http://www.juegos.com/juego/dodge-game)
There are 25 levels.
A ball is added at each level.
10 points are earned for each level completed.
Once at level 25, no new balls are added but you can work to improve your best score.
Best Score and Level saved between sessions.




Here is the YouTube video transcript:


Hello App Inventors


This is a walkthrough of the Dodge Game - a game of dogeball


It is set to run in Landscape orientation so I will rotate the emulator using Ctrl+F11


The object of the game is to drag the blue circle player to the blue square goal without touching any of the red dodge balls.


I have played the game before so I am going to reset the scores and level then play a couple of levels.


(reset, play)


Let's look at the components used in this app in the Designer:


(switch to designer)


The screen is set to landscape orientation with responsive sizing.


A Game canvas is set to 100% in width and height


Your player is a round Ball sprite and the goal is a square blue imagesprite.


25 red Ball sprites for dodgeballs.


The game begins with one dodgeball and the number of balls increases for each level up to 25.


Level 25 is the last lavel and can be played many times to improve your Best Score.


You can reset the level back to 1 and Best Score to 0 at the startup screen as you have seen.


Two Notifiers are used - one for the Welcome dialog and one for replaying a failed level.


Sound effects for level up, best score and failed level are included.


A ConfirmationDelay Clock Timer is used to display a confirmation message when the user taps the Reset button.


Let's switch to the Blocks editor:


Many of my projects will contain a procedure block named READ_ME or About which contains the documentation for the project in a comment bubble.



Iniitializing the game and prompting the user:


The Screen1.Initialize event block is the first event block executed when the app loads. (point to it)


The global variables are also initialized at this time. (circle them)


The global DodgeBalls list contains components for the 25 ball sprites. (expand and collapse)


The Goal Imagesprite's Width and Height are set to a percentage of the GameCanvas Width and Height.


This insures that the relative size of the Goal will be the same for different devices screen sizes.


You.Radius is likewise sized to a percent of the GameCanvas.Width.


GameCanvas.FontSize is set to a percentage of the GameCanvas.Height and it's PaintColor value set to green for the scoreboard text.


The global Best and Level variables are set by the values saved in the TinyDB SavedGameState database, if any.


Then the DisplayWelcomeHelp dialog is executed which tells how to play or reset the game.


If Play is tapped, then the scoreboard is displayed, the Round Player and Goal sprites are positioned and the dodge balls are set free to start the level.


If reset is tapped, the Best Score and Level values are reset, a confirmation message is displayed and the Confirmation.Timer is started.


After a three second delay, the Welcome dialog is redisplayed for the user to start the game when ready.

===


Playing a level:


Once the Play button is tapped, the scoreboard is displayed.


Since it draws text on the canvas, the canvas must be cleared each time the scoreboard is updated.

The GameCanvas.DrawText block is used to display the Level, Score and Best Score centered on the top of the screen.

---

StageHeroAndGoal creates a list of corner coordinates for the player and goal sprites to be positioned at the start of the level. The Goal's position is picked at random first, that location is removed from the list then the player location is picked.

Both sprites are placed at their start positions.

---

DisperseDodgeBalls enables the number of balls for the level and sends them out from the center of the game canvas -- each in a random direction.

The Goal and You sprites are enabled last to prevent triggering the You.CollidedWith event block.

---

The global Dragging and Goal variables are used to keep track of the game state.

Dragging is true when the player sprite is enabled and free to be dragged, 

Goal is true when the Player reaches the goal.

DodgeBallsRadiusPercent is used to set the size of the dodgeballs.

====


The when You.CollidedWith event block is triggered when the You sprite touches either the goal sprite or one of the dodgeball sprites.


In either case, the You, Goal and all dodgeball sprites are disabled and hidden.


If the Goal was touched, then the Goal variable is set to true and 10 points are added to Score.


If the current level is less than the number of dodgeballs, then the level is increased by 1.


If the new score is greater than the Best Score then replace best score with the new score.

Save the level and best score in the TinyDB database.

Play the level up sound effect.

If the score was not greater than the best score, play the score sound effect.


Display the score board, reset the You and Goal sprites and set the dodgeballs free for the next level.


If a dodgeball was touched, then play the failed sound effect and display a levels help menu.


The user can choose to try the level again or quit the game.


If they choose to replay, the scoreboard is displayed, the You and Goal sprites are set and the dodgeballs released.


If they choose to quit then the app is closed.

---

While the dodgeballs are in play, they will bounce off a GameCanvas edge.


The when You.Dragged event block is used to drag the You sprite to avoid the dodgeballs. 


And that covers all of the blocks for this project and app.


Happy Inventing!

===


---

sf




DodgeGame.aia
Reply all
Reply to author
Forward
0 new messages