Game 2048

For my final project, I chose to make a copy of the famous game 2048. The game is relatively simple: swipe up, down, left, and right and try to combine the same numbers to eventually get to 2048. You can play the original game at http://gabrielecirulli.github.io/2048/.

The target audience is teenagers and adults who enjoy simple puzzle games.

I interviewed my mom and my brother about the real game to see what they thought about it.
My mom said it was challenging, but she's glad it's not timed so she can go her own pace. She also said it's good for a variety of ages.
My brother, who has beaten the game, says it's addicting, challenging, smooth, and easy to learn.

This is a screenshot from the real game.


Early Testing: This is a screenshot from the early tests I did to see if making 2048 was possible using App Inventor.


Alpha Version: This alpha version features images from the real game, and the tile movement works perfectly. So far, the game only goes up to the 64 tile. The tiles move with buttons, not with swipes, but I am planning to implement a swipe feature later.


Final Version: The final version features swiping to move tiles, scoring, sounds, and an info button. It functions just like the real game.




MoleMash for App Inventor 2

In the game MoleMash, a mole pops up at random positions on a playing field, and the player scores points by hitting the mole before it jumps away. This tutorial shows how to build MoleMash as an example of a simple game that uses animation.

Getting Started

Connect to the App Inventor web site and start a new project. Name it "MoleMash", and also set the screen's Title to "MoleMash". Open the Blocks Editor and connect to the phone.
Also download this picture of a mole and save it on your computer.

Introduction

You'll design the game so that the mole moves once every half-second. If it is touched, the score increases by one, and the phone vibrates. Pressing restart resets the score to zero.
This tutorial introduces:
  • image sprites
  • timers and the Clock component
  • procedures
  • picking random numbers between 0 and 1
  • text blocks
  • typeblocking

The first components

Several components should be familiar from previous tutorials:
  • Canvas named "MyCanvas". This is the area where the mole moves.
  • Label named "ScoreLabel" that shows the score, i.e., the number of times the player has hit the mole.
  • Button named "ResetButton".
Drag these components from the Palette onto the Viewer and assign their names. Put MyCanvas on top and set its dimensions to 300 pixels wide by 300 pixels high. Set the Text of ScoreLabel to "Score: ---". Set the Text of ResetButton to "Reset". Also add a Sound component and name it "Noise". You'll use Noise to make the phone vibrate when the mole is hit, similar to the way you made the kitty purr in HelloPurr.

Timers and the Clock component

You need to arrange for the mole to jump periodically, and you'll do this with the aid of a Clock component. The Clock component provides various operations dealing with time, like telling you what the date is. Here, you'll use the component as a timer that fires at regular internals. The firing interval is determined by the Clock 's TimerInterval property. Drag out a Clock component; it will go into the non-visible components area. Name it "MoleTimer". Set its TimeInterval to 500 milliseconds to make the mole move every half second. Make sure that TimerEnabled is checked.

Adding an Image Sprite

To add the moving mole we'll use a sprite.
Sprites are images that can move on the screen within a Canvas. Each sprite has a Speed and a Heading, and also an Interval that determines how often the sprite moves at its designated speed. Sprites can also detect when they are touched. In MoleMash, the mole has a speed zero, so it won't move by itself. Instead, you'll be setting the mole's position each time the timer fires. Drag an ImageSprite component onto the Viewer. You'll find this component in the Drawing and Animation category of the Palette. Place it within MyCanvas area. Set these properties for the Mole sprite:
  • Picture: Use mole.png, which you downloaded to your computer at the beginning of this tutorial.
  • Enabled: checked
  • Interval: 500 (The interval doesn't matter here, because the mole's speed is zero: it's not moving by itself.)
  • Heading: 0 The heading doesn't matter here either, because the speed is 0.
  • Speed: 0.0
  • Visible: checked
  • Width: Automatic
  • Height: Automatic
You should see the x and y properties already filled in. They were determined by where you placed the mole when you dragged it onto MyCanvas. Go ahead and drag the mole some more. You should see x and y change. You should also see the mole on your connected phone, and the mole moving around on the phone as you drag it around in the Designer. You've now specified all the components. The Designer should look like this. Notice how Mole is indented underMyCanvas in the component structure list, indicating that the sprite is a sub-component of the canvas.

Component Behavior and Event Handlers

Now you'll specify the component behavior. This introduces some new App Inventor ideas. The first is the idea of a procedure. For an overview and explanation of procedures, check out the Procedures page.
A procedure is a sequence of statements that you can refer to all at once as single command. If you have a sequence that you need to use more than once in a program, you can define that as a procedure, and then you don't have to repeat the sequence each time you use it. Procedures in App Inventor can take arguments and return values. This tutorial covers only the simplest case: procedures that take no arguments and return no values.

Define Procedures

Define two procedures:
  • MoveMole moves the Mole sprite to a new random position on the canvas.
  • UpdateScore shows the score, by changing the text of the ScoreLabel
Start with MoveMole:
  • In the Blocks Editor, under Built-In, open the Procedures drawer. Drag out a to procedure block and change the label "procedure" to "MoveMole".
    Note: There are two similar blocks: procedure then do and procedure then resu;t. Here you should use procedure then do.
    The to MoveMole block has a slot labeled "do". That's where you put the statements for the procedure. In this case there will be two statements: one to set the mole's x position and one to set its y position. In each case, you'll set the position to be a random fraction, between 0 and 1, of the difference between the size of the canvas and the size of the mole. You create that value using blocks for random fraction and multiplication and subtraction. You can find these in the Math drawer.
  • Build the MoveMole procedure. The completed definition should look like this:

    MoveMole does not take any arguments so you don't have to use the mutator function of the procedure block. Observe how the blocks connect together: the first statement uses the Mole.X set block to set mole's horizontal position. The value plugged into the block's socket is the result of multiplying:
    1. The result of the call random fraction block, which a value between 0 and 1
    2. The result of subtracting the mole's width from the canvas width
    The vertical position is handled similarly.
With MoveMole done, the next step is to define a variable called score to hold the score (number of hits) and give it initial value 0. Also define a procedureUpdateScore that shows the score in ScoreLabel. The actual contents to be shown in ScoreLabel will be the text "Score: " joined to the value of score.
  • To create the "Score: " part of the label, drag out a text block from the Text drawer. Change the block to read "Score: " rather than " ".
  • Use a join block to attach this to a block that gives the value of the score variable. You can find the join block in the Text drawer.
Here's how score and UpdateScore should look:

Add a Timer

The next step is to make the mole keep moving. Here's where you'll use MoleTimer. Clock components have an event handler called when ... Timer that triggers repeatedly at a rate determined by the TimerInterval.
Set up MoleTimer to call MoveMole each time the timer fires, by building the event handler like this:
Notice how the mole starts jumping around on the phone as soon as you define the event handler. This is an example of how things in App Inventor start happening instantaneously, as soon as you define them.

Add a Mole Touch Handler

The program should increment the score each time the mole is touched. Sprites, like canvases, respond to touch events. So create a touch event handler forMole that:
  1. Increments the score.
  2. Calls UpdateScore to show the new score.
  3. Makes the phone vibrate for 1/10 second (100 milliseconds).
  4. Calls MoveMole so that the mole moves right away, rather than waiting for the timer.
Here's what this looks like in blocks. Go ahead and assemble the when Mole.Touched blocks as shown.
Here's a tip: You can use typeblocking: typing to quickly create blocks.
  • To create a value block containing 100, just type 100 and press return.
  • To create a MoveMole block, just type MoveMole and select the block you want from the list

Reset the Score

One final detail is resetting the score. That's simply a matter of making the ResetButton change the score to 0 and calling UpdateScore.

Complete Program

Here's the complete MoleMash program:

Variations

Once you get the game working, you might want to explore some variations. For example:
  • Make the game vary the speed of the mole in response to how well the player is doing. To vary how quickly the mole moves, you'll need to change theMoleTimer's Interval property.
  • Keep track of when the player hits the mole and when the player misses the mole, and show a score with both hits and misses. To do this, you'll need do define touched handlers both for Mole, same as now, and for MyCanvas. One subtle issue, if the player touches the mole, does that also count as a touch forMyCanvas? The answer is yes. Both touch events will register.

Review

Here are some of the ideas covered in this project:
  • Sprites are touch-sensitive shapes that you can program to move around on a Canvas.
  • The Clock component can be used as a timer to make events that happen at regular intervals.
  • Procedures are defined using to blocks.
  • For each procedure you define, App Inventor automatically creates an associated call block and places it in the My Definitions drawer.
  • Making a random-fraction block produces a number between 0 and 1.
  • Text blocks specify literal text, similar to the way that number blocks specify literal numbers.
  • Typeblocking is a way to create blocks quickly, by typing a block's name.

Scan the Sample App to your Phone

Scan the following barcode onto your phone to install and run the sample app.

Download Source Code

If you'd like to work with this sample in App Inventor, download the source code to your computer, then open App Inventor, click Projects, choose Import project (.aia) from my computer..., and select the source code you just downloaded.

App Inventor 2 - How to create and store text files on your phone


This short tutorial will show you how to write text to a text file and save that file on the phone. It will also show you how to retrieve data from a text file on your phone.


How To Use App Inventor With Arduino




UPDATE: http://appinventor.mit.edu changed their whole website... So the source file that previously you could use to edit on their website, only works with AppInventor version 1.0 or also called classic that you can see here http://appinventor.mit.edu/explore/cl... Click the button: "Invent your own Apps now" . This project still works just fine with my  app and with my Arduino code. But you can only edit the source code on Appinventor classic version.

More Resources Here:
http://randomnerdtutorials.com/how-to...
This will help you understand how App Inventor works and how it can interact with your arduino via bluetooth.

You can download all my projects here:
http://randomnerdtutorials.com/download

Like my page on Facebook:
http://www.facebook.com/RandomNerdTut...
Add me on Google+:
https://plus.google.com/1042512232462...
Follow me on twitter:
https://twitter.com/RuiSantosdotme

How to make Flappy Bird with app inventor

Easy how to video of how to make Flappy bird your self for an android device with all free software. this is all done with free online software from mit app inventor.




Part1 :


Part2:


Part3 :



Part4:


Part 5:


Part 6:


Part 7:


Part 8:



Download the apk. from this link:click here

Installing and Running the Emulator in AI2

If you do not have an Android phone or tablet, you can still build apps with App Inventor. App Inventor provides an Android emulator, which works just like an Android but appears on your computer screen. So you can test your apps on an emulator and still distribute the app to others, even through the Play Store. Some schools and after-school programs develop primarily on emulators and provide a few Androids for final testing.
To use the emulator, you will first need to first install some software on your computer (this is not required for the wifi solution). Follow the instructions below for your operating system, then come back to this page to move on to starting the emulator
Important: If you are updating a previous installation of the App Inventor software, see How to update the App Inventor Software. You can check whether your computer is running the latest version of the software by visiting the page App Inventor 2 Connection Test.

Step 1. Install the App Inventor Setup Software


Step 2. Launch aiStarter (Windows & GNU/Linux only)

Using the emulator or the USB cable requires the use of a program named aiStarter. This program is the helper that permits the browser to communicate with the emulator or USB cable. The aiStarter program was installed when you installed the App Inventor Setup package. You do not need aiStarter if you are using only the wireless companion.
  • On a Mac, aiStarter will start automatically when you log in to your account and it will run invisibly in the background.
  • On Windows, there will be shortcuts to aiStarter from your Desktop, from the Start menu, from All Programs and from Startup Folder. If you want to use the emulator with App Inventor, you will need to manually launch aiStarter on your computer when you log in. You can start aiStarter this by clicking the icon on your desktop or using the entry in your start menu.

    The aiStarter Icon on Windows
    To launch aiStarter on Windows, double click on the icon (shown above). You'll know that you've successfully launched aiStarter when you see a window like the following:
  • On GNU/Linux, aiStarter will be in the folder /usr/google/appinventor/commands-for-Appinventor and you'll need to launch it manually. You can launch it from the command line with
    /usr/google/appinventor/commands-for-appinventor/aiStarter &

Step 3. Open an App Inventor project and connect it to the emulator

First, go to App Inventor and open a project (or create a new one -- use Project > Start New Project and give your project a name).
Then, from App Inventor's menu (on the App Inventor cloud-based software at ai2.appinventor.mit.edu), go to the Connect Menu and click the Emulator option.
You'll get a notice saying that the emulator is connecting. Starting the emulator can take a couple of minutes. You may see update screens like the following as the emulator starts up:

The emulator will initially appear with an empty black screen (#1). Wait until the emulator is ready, with a colored screen background (#2). Even after the background appears, you should wait until the emulated phone has finished preparing its SD card: there will be a notice at the top of the phone screen while the card is being prepared. When connected, the emulator will launch and show the app you have open in App Inventor.
If this is the first time you are using the emulator after installing the App Inventor Setup software, you will see a message asking you to update the emulator.  Follow the directions on the screen to perform the update and reconnect the emulator.   You will need to do this kind of update whenever there is a new version of the App Inventor software.
For problems with aiStarter, or if the Emulator does not connect, go to Connection Help for information about what might be wrong.

#1  #2  #3  #4 

PaintPot (Part 2) for App Inventor 2

Part 2 extends Part 1 of the tutorial to create both large and small dots, as a demonstration of how to use global variables.

Starting

Make sure you've completed the Set Up process and you have your completed project from PaintPot Part 1 loaded.
Start where you left off at the end of Part 1, with the project open in App Inventor. Use the Save As button to make a copy of PaintPot so you can work on the new version without affecting the original version. Name the copy "PaintPotV2" (with no spaces). After saving a copy, you should see PaintPotV2 in the Designer.

Creating variables

The size of the dots drawn on the canvas is determined in the when DrawingCanvas.Touched event handler where call Drawing.DrawCircle is called with r, the radius of the circle, equal to 5. To change the thickness, all we need to do is use different values for r. Use r = 2 for small dots and r = 8 for large dots.
Start by creating names for these values:
  1. Open the Blocks Editor if it isn't already open and connect the phone. Your phone should show the buttons and the canvas you built previously.
  2. In the Blocks Editor, in the Built-In column, open the Variables drawer. Drag out a initialize global name to block. Change the text that reads "name" to read "small". A yellow warning exclamation mark might appear on the block. If you mouse over this you'll see a warning message explaining that the block has an empty socket.
  3. You need to fill in the socket with a number block that specifies the value for "small" -- use 2 as the value. To create the number block, type the number 2. A menu will appear, showing you all the possible blocks that include "2" in their name. Click on the first one, which is the number 2 itself, and a number block with the value 2 should appear. Plug that in to the initialize global small to block. The yellow warning mark will disappear, because the empty socket has been filled. (The second value listed in the menu is the math block atan2 which you won't use here.)
Here are the steps in the sequence:
You've now defined a global variable named small whose value is the number 2.
Similar to small, define a global variable big, whose value is 8.
Finally, define a global variable dotsize and give it an initial value of 2.
You might wonder whether it would be better programming style to make the initial value of dotsize be the value of small rather than 2. That would be true, except for a subtle programming point: Doing that would be relying on the assumption that small will already have a value at the point in time when dotsize is assigned its value. In App Inventor, you can't make assumptions about the order in which different def blocks will be processed. In general, of course, you really would like to specify the order in which variables are assigned. You can do this by assigning all values when the application is initialized, using the Screen initialize event. The Quiz Me tutorial gives an example of initialization.

Using variables

Now go back to the touch event handler you set up in Part 1 and change the call to DrawCircle block so that it uses the value of dotsize rather than always using 5.
In the Blocks Editor, open the Variables drawer. Pull out a get block and click on the dropdown. You should see three new variables in the dropdown: small, big, and dotsize
These blocks were automatically created and put in the dropdown of get and set variable blocks, similarly to the way that x and y were created in the dropdown when you defined the when DrawingCanvas.Touched event handler in the part 1 of this tutorial. "Global" means "global variable", in contrast to the event-handler arguments, which are considered "local variables". The difference is that the argument values are accessible only within the body of the event handler, while global variables are accessible throughout the entire program.
  • Go to the when MyCanvas.Touched event handler and replace the number 5 block in call DrawCircle with the get dotsize block from the Variables drawer.

Changing the values of variables

Now set up a way to change dotsize to be small (2) or big (8). Do this with buttons.
  1. In the Designer, drag a HorizontalArrangement component into the Viewer pane below the DrawingCanvas component. Name the component "BottomButtons".
  2. Drag the existing ButtonWipe into BottomButtons.
  3. Drag two more button components from the Palette into BottomButtons, placing them next to ButtonWipe.
  4. Name the buttons "ButtonBig" and "ButtonSmall", and set their Text to read "Big dots" and "Small dots", respectively.
  5. In the Blocks Editor, create a when ... Clicked event handler for ButtonSmall that changes dotsize to be the value of small. To change dotsize use theset global dotsize to block from the MyDefinitions drawer and plug in the global small block.
  6. Make a similar event handler for ButtonBig.
The two click event handlers should look like this:
You're done! You can draw in PaintPot and use the new buttons to draw either big dots or small dots. Notice that dragging your finger still produces a thin line. That's because the changes we just made don't affect how DrawLine is called.
Here's the finished program in the Designer:
and in the Blocks Editor:
A bug for you to work on: The program you just built has a slight bug. If you start drawing before pressing any of the paint buttons, the paint color will be black; however, after you choose a color, there's no way to get back to black. Think about how you could fix that.

Review

You create global variables by using def blocks from the Variables drawer.
For each global variable you define, App Inventor automatically supplies a global block that gives the value of the variable, and a set global ... to block for changing the value of the variable. These blocks can be found in the Variables drawer.

Scan the Sample App to your Phone

Scan the following barcode onto your phone to install and run the sample app.

Download Source Code

If you'd like to work with this sample in App Inventor, download the source code to your computer, then open App Inventor, click Projects, choose Import project (.aia) from my computer..., and select the source code you just downloaded.

 
Powered by Blogger