Rodrixar

Monday, October 11

Java Applet Tutorial

How to create a Java Online Game

Overview


In this simple introductory Java Applet tutorial, we’ll build a straightforward Super Mario Brother online. We’ll actually just animate Luigi running around the screen and responding to user input. The controls will be very basic: move Luigi using the left and right arrow keys (← to move him to the left, and → to move him to the right), and change the speed at which he moves by pressing the up and down keys. The controls are shown on the screen and are indicated by the "thread break" marker.

For a quick demo of the final product, checkout the box below:



Also, be sure to grab some sprite images for your game:

Super Luigi Brother Online Frame 0,1Super Luigi Brother Online Frame 0,2Super Luigi Brother Online Frame 0,3Super Luigi Brother Online Frame 0,4Super Luigi Brother Online
Super Luigi Brother Online Frame 1,0Super Luigi Brother Online Frame 1,1Super Luigi Brother Online Frame 1,2Super Luigi Brother Online Frame 1,3Super Luigi Brother Online Frame 1,4


The Set Up: Intro to Java Applets

Probably the first thing you’ll notice about Java Applets is the fact that they don’t have a main() method like all other Java programs do. Instead, Java Applets will have an init() method, which must be a public, void returning method (similar to the standard main).
Also, Java applets are meant to be viewed through a browser, so be sure to create an HTML file to run your app in. I will show you how to do that when we get to that point.
Finally, I will show you the libraries we’ll be working with, and therefore will need to import.

The Java.Applet Library

In order to create our demo applet, go ahead and import the following libraries to your Luigi.java file. This will be the file we’ll build for this tutorial.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;


Those libraries take care of making our applet, loading files from a web server, and listening and responding to user input events.

Sprite Animation in Java

In order to simplify this tutorial, and yet make this code somewhat more portable and expandable, let’s create a class that will handle the individual sprite animations that we’ll use. Actually, let’s create a class to represent Luigi, who will be our hero in this case. This class will basically have the following member variables:

private int x; // Luigi’s on screen x-coordinate
private int y; // Luigi’s on screen y-coordinate
private int dtX; // The delta-x; the amount of units to move Luigi horizontally each time he moves
private int pos; // To keep track of when Luigi moves outside the screen
private String name; // Represents the name of our character
private boolean K_RIGHT; // Is the user pressing the right key
private boolean K_LEFT; // Is the user pressing the left key
Image[] src; // An array to keep all the sprite images used in the game


That’s pretty simple stuff. We can initialize those variables right on our constructor. I’ve found it helpful to offer at least a couple of choices to the programmer using your code, so in this tutorial, we’ll create two constructors for this Sprite class: one with parameters to initialize a Sprite object (a character for your game), and one that takes no parameters. This second constructor will actually just call the first-mentioned constructor with some default values. This way we have two methods doing the same thing, but not duplicating hardly any code at all. So here are the constructors:

public Sprite(String pName, int pX, int pY)
{
name = pName;
x = pX;
y = pY;
dtX = 10;
pos = 0;
src = new Image[8];
K_RIGHT = false;
K_LEFT = false;
}

public Sprite()
{
this("Tupac", 10, 10); // The name and starting position of our default character
}


And in order to keep this class simple, yet functional, let’s add a few methods:

public int x() // returns the x position of your character
public int y() // returns the y position of your character
public void walk(String dir) // moves your character horizontally
public void stand(String dir) // changes the character’s sprite image if he’s not moving
public int pos() // returns the x position of the character
public boolean K_LEFT() // tell us if the user is pressing the right key
public boolean K_RIGHT() // tell us if the user is pressing the right key
public void setKey(String dir, boolean state) // respond to the user pressing the right or left key


You will notice that our Sprite class could have used less methods, had only the member states been more accessible. It is good practice, however, to restrict member states as much as reasonably possible, and create good ol’ getters and setters. Yes, the Java likes programmers that use a getter and setter whenever possible.

Sprite Class Code

Most methods should be pretty self-explanatory and easy to follow… For the most part we just check for the current state of our character, increment his x-position by a uniform amount (determined by delta-X), and make sure he is never displayed outside the screen boundaries.

class Sprite
{
private int x;
private int y;
private int dtX;
private int pos;
private String name;
private boolean K_RIGHT;
private boolean K_LEFT;
Image[] src;

public Sprite(String pName, int pX, int pY)
{
name = pName;
x = pX;
y = pY;
dtX = 10;
pos = 0;
src = new Image[8];
K_RIGHT = false;
K_LEFT = false;
}

public Sprite()
{
this("Tupac", 10, 10);
}

public int x()
{
return x;
}

public int y()
{
return y;
}

public void walk(String dir)
{
if (dir == "left")
{
x -= dtX;
if (pos < pos =" 5;"> 7)
pos = 5;

if (x < -50) x = 450; } else if (dir == "right") { x += dtX; if (pos > 3)
pos = 1;
if (pos <> 3)
pos = 1;

if (x > 450)
x = -50;
}
}

public void stand(String dir)
{
if (dir == "left")
{
pos = 4;
}
else if (dir == "right")
{
pos = 0;
}
}

public int pos()
{
return pos;
}

public boolean K_LEFT()
{
return K_LEFT;
}

public boolean K_RIGHT()
{
return K_RIGHT;
}

public void setKey(String dir, boolean state)
{
if (dir == "right")
K_RIGHT = state;
if (dir == "left")
K_LEFT = state;
}
}



Java Applet’s Main()
As mentioned earlier, the method main() is not used in applets like in regular java apps. Here we use the method init(). In our case, we’ll be extending the class Applet (all applets will), and we’ll implement the following classes and interfaces: ActionListener (for general event listening), KeyListener (for specific keyboard events), and Runnable (to create threads!).
Once inside your main game class, just do what you would in any other class, but keep in mind that the program will enter in through init(). In this tutorial, we’ll create the following state variables:

final static int WIDTH = 500; // the width of our screen area
final static int HEIGHT = 200; // the height of our screen area
private int FPS; // not really the framerate, just a way to keep the animation constant
private String TSE; // phrase to display if we get an Interrupted Exception while trying to put our animation thread to sleep for FPS milliseconds
Thread runner; // where we’ll keep Luigi
Image image; // this is how we’ll add a double buffer to our app
Graphics graphics; // this is also part of the double buffer method we’re using.
Sprite hero; // the manifestation of our Sprite class


As far as the methods we’ll use to control our awesome Super Mario Brother Online game, featuring Luigi, we’ll keep it simple. Most methods are defined because we’re implementing interfaces that require us to define them, even if we make them blank. This is a key feature of the Java Language. Be sure to understand Java’s polymorphism, inheritance, interfaces, and abstract classes if this confuses you. In case you don’t know what any of that means, it might sound like a lot of new stuff to learn, but really, it’s just one single concept, which is not really very complicated to understand. But it is very fundamental that you at least have a general idea about those topics if you want to become a decent Java Game Programmer…

public void paint(final Graphics g)
public void actionPerformed(ActionEvent e)
public void keyTyped(KeyEvent key) {}
public void keyReleased(KeyEvent key) {
public void keyPressed(KeyEvent key)
public void start()
public void stop()
public void run()
public void update(Graphics g)


The main meat of the code takes place inside the run method of our runner thread. You can think of this as the Luigi thread. Basically, we check for the current state of the app. If the user is pressing a key, for example, that will be a different state than the app would be in if no keys were being pressed at the time the thread performs this checks. The thread basically checks for those states constantly… If the right or left key is in fact being pressed, he call Luigi’s move method and moving to the right or left based on the app state. We then tell the app to refresh the screen images, and we tell the thread (just Luigi’s thread) to sleep() for a brief amount of time. If we don’t do this crucial step, the thread will run as fast as it can. This would mean the thread would run faster/slower depending on the computer running the app. Adding the call to sleep() makes our app constant across different computers.

In case you don’t know much about threads, what happens is that our app will do various things in different threads, but all at the same time. It would be weird to check first if there are keys being pressed, then if so, tell Luigi to move, then redraw his image on the screen, then make sure he’s not outside the screen, etc… through threads we can check on a key being pressed on the keyboard, while at the same time we can be redrawing the screen, and at the same time we can be performing a calculating to see where Luigi is positioned.

public class Luigi extends Applet implements ActionListener, KeyListener, Runnable
{
/**
*
*/
private static final long serialVersionUID = 1L;

final static int WIDTH = 500;
final static int HEIGHT = 200;
private int FPS;
private String TSE;
Thread runner;
Image image;
Graphics graphics;
Sprite hero;

public void init()
{
image = createImage(WIDTH, HEIGHT);
graphics = image.getGraphics();
FPS = 100;

resize(WIDTH, HEIGHT);
hero = new Sprite("Luigi", 20, 50);

addKeyListener(this);

setLayout(new FlowLayout());
setBackground(Color.white);

/***
* Here we’re loading the images from a sub-directory called "luigi_img" where the images are stored. Since we’re using the java.net library, we can actually load the images straight from a web server (like "http://www.rodrigo-silveira.com/dharma/cs246/img/luigi.png").
*
***/
hero.src[0] = getImage(getDocumentBase(), "luigi_img/luigi,0r.gif");
hero.src[1] = getImage(getDocumentBase(), "luigi_img/luigi,1r.gif");
hero.src[3] = getImage(getDocumentBase(), "luigi_img/luigi,2r.gif");
hero.src[2] = getImage(getDocumentBase(), "luigi_img/luigi,3r.gif");
hero.src[4] = getImage(getDocumentBase(), "luigi_img/luigi,0l.gif");
hero.src[5] = getImage(getDocumentBase(), "luigi_img/luigi,1l.gif");
hero.src[7] = getImage(getDocumentBase(), "luigi_img/luigi,2l.gif");
hero.src[6] = getImage(getDocumentBase(), "luigi_img/luigi,3l.gif");
}

public void paint(final Graphics g)
{
update(g);
}

public void actionPerformed(ActionEvent e)
{
repaint();
}

public void keyTyped(KeyEvent key) {}
public void keyReleased(KeyEvent key) {
if (key.getKeyCode() == KeyEvent.VK_RIGHT)
{
hero.setKey("right", false);
hero.stand("right");
}
else if (key.getKeyCode() == KeyEvent.VK_LEFT)
{
hero.setKey("left", false);
hero.stand("left");
}

else if (key.getKeyCode() == KeyEvent.VK_UP)
{
FPS++;
}
else if (key.getKeyCode() == KeyEvent.VK_DOWN)
{
FPS--;
}
}

public void keyPressed(KeyEvent key)
{
if (key.getKeyCode() == KeyEvent.VK_RIGHT)
{
hero.setKey("left", false);
hero.setKey("right", true);
}
else if (key.getKeyCode() == KeyEvent.VK_LEFT)
{
hero.setKey("right", false);
hero.setKey("left", true);
}
repaint();
}

public void start()
{
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}

public void stop(){}

public void run()
{
while (runner != null)
{
repaint();

try
{
Thread.sleep(FPS);
if (hero.K_LEFT())
{
hero.walk("left");
}
else if (hero.K_RIGHT())
{
hero.walk("right");
}
}
catch(InterruptedException e)
{
TSE = "Exception caught while trying to put thread to sleep...";
}
}
}

public void update(Graphics g)
{
g.drawImage(image, 0, 0, this);
g.drawImage(hero.src[hero.pos()],hero.x(),hero.y(),this);

g.setColor(Color.red);
g.drawString("Luigi (" + hero.x() + ", " + hero.y() + ")", 10, 10);
g.setColor(Color.black);
g.drawString("Thread break = " + FPS, 10, 25);

// Display errors
if (TSE != null)
g.drawString("Thread Sleep Error: " + TSE, 10, 40);
}
}

Conclusion

While this Java Applet tutorial was almost overly simplistic, the concepts we covered are pretty important. In case you don’t quite understand the way threads work, or how we can implement interfaces in Java, this would be a recommended subject to learn next. If you did follow the code without much confusion, then the challenge would be for you to try to improve on it. You will notice that by pressing the up/down arrow keys you can dynamically change the value of FPS, which will tell the thread to do what it does more times per second. Right now the FPS speed controls both the animation speed (how fast we change the image frames), and how fast Luigi moves. Can you think of a better way to do this? What if we want to move Luigi faster, but keep the animation as smooth? Try implementing different things, but be sure to check back soon for my follow up tutorial, where we’ll be adding more physics to Luigi. We’ll make him slide (like if he is running on ice), and jump. We’ll also add some background imagery to make the level prettier to look at.

Monday, August 30

JS Prototype Tutorial

5 Ways to Speed up Javascript



One big problem the entire internet suffered from when Macromedia Flash became popular, was that people were overusing this new exciting technology, and the overall performance of their site was far too poor. Sadly, we are starting to see a similar pattern as Javascript libraries like Prototype, JQuery, MooTools, Scriptaculous, etc. Sites are looking great, but the effects, though relatively light-weight, are getting cluttered, which slow down the page load, and the results are at times counter-productive.

In this JS tutorial, we’ll talk about a needed subject, which will benefit both the site owner and users. This subject is Javascript Speed up techniques.

1. External File Cache


The first thing I have seen many programmers take for granted is the browser’s ability to cache code for them. Caching code has many benefits that some people don’t realize. For one thing, if you store your Javascript on your user’s machine, you don’t have to download it every time the user requests it. If the user doesn’t have to download something, the page load will be faster – obvious. The down side of this could be the fact that if you change the code too often, then the Javascript your user has cached will be different. This is especially bad if the cached js has bugs in it, and the new code you deploy is a patch to it.

Overall, caching your Javascript is a best-practice to be observed. The way you cache your scripts is to store it in an external file and link it in to your main HTML file by using the following syntax:

<script type="text/javascript" src="file-name.js"></script>


Make sure you place this line of code inside the head of your HTML document. If this code is not placed within your <head> and </head> tags, the document will not validate with the W3C. This takes us to the next tip to help you speed up your javascript.

2. Code Placement


Some people have suggested that a good way to speed up your code is to place it at the end of your HTML document. This makes some sense, and can be confusing since Google specifically instructs webmasters to place the Google Analytics code just before the closing </body> tag. The reasoning behind adding Javascript to the end of your file is that everything else (images, CSS, text, etc.) can load first, so while the js script is loading, the user can still see everything else on the page (the main reason they visit your site for). However, placing the code at the end of your file won’t allow you to cache the file.

The solution is to add the code to the <head> portion of your file through an external file. If the script loading interrupts the rest of the page load, you may need to change your design structure. Abstracting your code into classes and functions will keep the code from loading unless you tell it to. Any code that you do need loaded automatically can be called on your document’s onload event. This way the code will be loaded only after the rest of the file is loaded, and it will still be cached. In libraries like Prototype or JQuery, you can use the document.ready() function.

3. Reduce HTTP Requests


A simple analysis of a regular page load reveals that most of the loading time of a web page is spent sending and receiving HTTP requests to and from the server. The immediate solution to this, simply enough, is to reduce the number of requests you make to your server. One way to do this with your Javascript is to include all of your js code on a single file (so only one HTTP request is necessary to load it), then cache the file so it doesn’t need to be downloaded again. In CSS, as a side note, a common technique is called Image Spriting, where all of the images referenced in your CSS are combined into one single, larger image file, so only one HTTP request is necessary to pull all those images from the server.

4. Inline your functions


A tedious, yet masterful habit to pick up is to have two versions of your scripts. One version is well commented, well designed and coded, and carefully structured, while the other version – the version you deploy, is highly optimized. This will be covered more in-depth in the next section, but in short, a main way to speed up your js is to avoid the overhead involved in calling functions. The easiest way to accomplish this is to inline each and every function call in your code. Javascript doesn’t have an “inline” function definition like C++, so the way you do this is to physically paste the entire function every time it is called. This will greatly speed up your code execution.

5. Compress your Code


Finally, after you optimize your code and inline your functions, the final thing to do to get the most out of your script, is to compress your code. Some people prefer to obfuscate their code to discourage people to straight copy their own code. Google offers a great tool known as the
Closure Compiler, which compiles your Javascript code into very compact, optimized code. This extra step definitely takes extra work, but is an absolute must have for anyone wanting to speed up their javascript libraries.



Saturday, August 21

Home is Where Your Destiny is

The sun still laid low behind the rising mountains. The thin, cold rain bathed his car as he sat in silence driving southward. The flat road vanished to a far away point straight in front of him, leveled with his eyes. In his mind's eye the memories were vivid and fresh, and the time that had passed since he'd last been home seemed to be less than it really had. After his many travels, the traveler was anxious to be back, and curious to see his dear family again. The stores he'd heard over the years told him of little change, and the traveler wondered what he'd find. Through the many layers of uncertainty, insecurity, and the fear of disappointing his family, deep inside, the traveler was glad to be coming home.

As he entered the small town of Kibou, Tabi, as he was known as a child, noticed how much things had remain the same. There were new additions to the town, of course, such as the two-story Walmart that could be seen from the distance, a new IMax theater was built to entertain the mind, high buildings sophisticated the market place, an international airport facilitated transportation, and the few middle schools, high schools, and the community college had been rebuilt in order to accomodate the eager seekers of knowledge. As Tabi looked around him, it was clear that Kibou had merely kept up with times.

The street where his parents lived had seen busy days before. Weekend gatherings were common place back in the day. Today was no exception. Pound after pound of fresh-cut meat was leveled against the grill, the children ran around the Haytae backyard, the women sat around wearing their sun dress talking about the latest topics that went around town, while the men spoke of recent sporting outcomes, business events, and other such subjects.

Tuesday, April 13

How to JavaScript: Prototype Slideshow Tutorial

Javascript Slideshow: A Web 2.0 Tutorial (a prototype tutorial)




Here's a quick Prototype tutorial for those looking for a simple javascript slideshow. This is not intended to be a JQuery discussion or tutorial, but a quick prototype tutorial. The desired result is an efficient, useful javascript slideshow coded in prototype js.

Before we get started, be sure to download the external Prototype files. In this amazing web 2.0 tutorial we'll use the effects.js and prototype.js files. In addition to this prototype tutorial, visit the official site of Prototype or learn more about Javascript .

Demo

For a quick demo on what the final product of this prototype tutorial is to look like, please refer to the header of this very blog (Rodrixar). Image changes after 3.5 seconds.

1. The goal

Our goal in this prototype tutorial is to come up with a javascript slideshow. The way it will work is that you'll have one image displaying, then after a predetermined amount of time (4 seconds in my example) the image will fade out and a different image will be showing behind it, and after another 4 seconds that image will fade out and a new one will display behind it. Then when the last image fades out, the first image will display.

The code design will be as follows:

  • An array will hold the filename for each image to be displayed
  • There will be 2 image elements on screen at all times, both stacked atop each other
  • A timer will call our main function every 4 seconds
  • This function perform the following tasks:
    1. Fade the top image so the image behind it will display
    2. After the fading effect is done, the front image will be the same as the back image (his step will be invisible to the human eye)
    3. Then the back image will be assigned a different value (it will display the next image in the array)
    4. Lastly, we'll check if we've hit the end of the array. If so have, we'll be sure the back image displays the first image of the array so the loop continues forever and ever (or until the person viewing your slideshow clicks away from your page)
  • The function will set the timer to come back in another 4 seconds

2. The setup

First thing we'll do is set up the HTML file. Though this is a prototype tutorial and a web 2.0 tutorial, I'll assume you could use the extra explanation. So open up your favorite text editor and be sure to have the following lines of code:


<html>
<head>

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="effects.js"></script>

<script type="text/javascript">

</script>

<style type="text/css">
#iSlideShell { width: 250px; height: 250px; position: relative; }
#iSlideShell img { position: absolute; }
</style>

</head>

<body>

<div id="iSlideShell">
<img id="iSlideBack" src="img1.jpg"/>
<img id="iSlideFront" src="img1.jpg"/>
</div>

</body>
</html>

This is our basic HTML setup. Be sure the external javascript files are referenced right (that the link points to the right directory where you have the files saved). Also, be sure the the images in the <img> tags point to first 2 images you'd like displayed. Note that the top image (the one that will show first) is the one in the second <img> tag (since they're stacked through the css position absolute command). Make sure also that the <div> has the same height and width as the images in your slideshow. If the images you use aren't the same dimension we'll need to make a few slight adjustments to the <div> but this won't be covered in this prototype tutorial.

Now we'll set up the images we'll be using in our slideshow.

3. The Javascript

Inside the Javascript tags in the HTML code we'll set up the following variables:

var i = 0;
var iSlides = new Array("img1", "img2", "img3", "img4", "img5");

These will be our variables. The i will keep track of where we are as we loop through the array (iSlides), which is a list of all the images we want to display. Note that you don't include the file extension in the array, but only the filename. For this javascript tutorial you will need to use images of the same file type.


Next we'll add our function, which I'll call iAnimate. I'm not sure why I have the tendency of adding the letter "i" to the front of my variables and function. Maybe it's because iLike it :)

function r$(id) { return document.getElementById(id); }

function iAnimate()
{

r$('iSlideFront').show();
r$('iSlideBack').show();
r$('iSlideFront').fade();
r$("iSlideFront").src = r$("iSlideBack").src;

i == (iSlides.length - 1) ? i = 0 : i++;
r$("iSlideBack").src = "img/" + iSlides[i] + ".jpg";

setTimeout('iAnimate()', 4000);
}

window.onload = iAnimate;

The function "r$" may look like Prototype and/or JQuery, but all it is is a shortcut function I created so I don't have to type "document.getElementById()" over and over...

The first thing the function does is be sure both images are showing. In Prototype (and in JQuery), when you "hide" or "fade" (or "fadeOut") and element, that elements changes opacity gradually and finally has its css attribute "display" set to "none". By calling the show() function, we make sure the display for both images is set to "block". Once that's done, we fade the front image.

Then we make sure the front image is the same as the back image. This may seem pointless the very first time the function is called, since no visible change takes place, but once the first image fades, this is important.

The next step is to find out what the next image is in the array, and assign that to the back image. The conditional statements ? : checks if the variable i is equal to the total amount of images in the array minus 1. The reason it's (length - 1) is because the first image in the array is represented by iSlides[0] (zero is the first element in an array in Javascript). If this statement returns true, that means we've displayed the last image in the array, so now we must display the first one. That's when the assignment i = 0 gets called. If the statement returns false, we increment i by 1.

The back image (iSlideBackthen gets assigned the next image of the array, and the timer is set to explode in 4000 milliseconds, or 4 whole seconds. Once those 4 seconds are counted by the computer's clock, iAnimate() is called again, and the fun starts all over!

4. Conclusion

This is all there is to it. My goal was to make this as simple as possible, but making this javascript slideshow more robust shouldn't be too difficult with some basic understanding of javascript, prototype, html, or css.

One of the main benefits the code provided in this javascript slideshow (other than, but because of its simplicity) is the fact that the only images loaded are the ones currently displayed. Most prototype tutorials and JQuery tutorials I've seen load all images as the page loads (longer loading times), then they do what they must. In this javascript slideshow, if the user leaves the page after only 3 images have loaded, that's all the loading the code will do. This will save you resources and loading time.

Any questions, feel free to post in this prototype tutorial.

5. The Code

Here's the complete code for those of you reading my prototype tutorial that are mindful of the mileage on your mouse and your daily keystroke allowance:

<html>
<head>

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="effects.js"></script>

<script type="text/javascript">
var i = 0;
var iSlides = new Array("img1", "img2", "img3", "img4", "img5");

function r$(id) { return document.getElementById(id); }

function iAnimate()
{
r$('iSlideFront').show();
r$('iSlideBack').show();
r$('iSlideFront').fade();
r$("iSlideFront").src = r$("iSlideBack").src;

i == (iSlides.length - 1) ? i = 0 : i++;
r$("iSlideBack").src = "img/" + iSlides[i] + ".jpg";

setTimeout('iAnimate()', 4000);
}

window.onload = iAnimate;
</script>

<style type="text/css">
#iSlideShell { width: 250px; height: 250px; position: relative; }
#iSlideShell img { position: absolute; }
</style>

</head>

<body>

<div id="iSlideShell">
<img id="iSlideBack" src="img1.jpg"/>
<img id="iSlideFront" src="img1.jpg"/>
</div>

</body>
</html>

Prototype Tutorial

Friday, April 9

Chinese Proverbs & Chinese Sayings

Chinese Proverbs



A lot of people have been asking me why I haven't posted ancient Chinese proverbs lately, especailly after posting about the journey of a thousand miles . So here are some of my favorite Chinese proverbs.

A bird does not sing because it has an answer; but because it has a song


My thoughts on it can be answered with the not-so-popular,

Not everything that's doable is worth doing; but whatever is done must be done well


Actually, I made up this and other nice proverbs from other Chinese proverbs. Nevertheless, let us not forget that,

He who cannot but does is better than he who can but won't


At the beginning of a new phase in my life, I take comfort in knowing that,

A journey of a thousand miles must begin with a single step


It was pointed out last week that because a journey of a thousand miles does begin with the first step, we must watch our step! Remember also that

When ten hours is given you to cut down a tree, spend the first eight sharpening your ax.


Again, not from real Chinese Proverbs, but a good thought nontheless. On a more realistic note, since this collection of Chinese Proverbs is so popular, let me post a few legit Chinese Proverbs:
  • When you drink the water, remember the spring

  • Keep your broken arm inside your sleeve

  • He who strikes the first blow admits he's lost the argument

  • Do not remove a fly from your friend's forehead with a hatchet

  • If you don't want anyone to know, don't do it

  • An ant may well destroy a whole dam

  • Don't use a cannon to kill a mosquito

  • Dismantle the bridge shortly after crossing it

  • Dream different dreams while on the same bed

  • Do not employ handsome servants

  • Crows everywhere are equally black

  • To believe in one's dreams is to spend all of one's life asleep

  • He who treads softly goes far



The journey is the reward


In sharing Chinese Proverbs I like the philosophy they help us keep in perspective. A wise student of Chinese proverbs ponders them but remembers them. Here are a few that I've heard around the office this week:
  • Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime

  • A wise man makes his own decisions, an ignorant man follows the public opinion

  • Learning is a treasure that will follow its owner everywhere

  • A hundred men may make an encampment, but it takes a woman to make a home

  • A truly great man never puts away the simplicity of a child

  • One step at a time is good walking

  • To be uncertain is to be uncomfortable, but to be certain is to be ridiculous

  • Have a mouth as sharp as a dagger but a heart as soft as tofu

  • Once on a tiger's back, it is hard to alight

  • Shed no tears until seeing the coffin

  • Waiting for a rabbit to hit upon a tree and be killed in order to catch it

  • Only when all contribute their firewood can they build up a strong fire

Chinese Pagoda

Sunday, February 21

Motivation at Work | Staying Motivated about your Job | Motivate yourself today!

Secret of Success:

Motivation at Work


by Rodrigo Silveira

This 3 part series will cover ways to find motivation at work. As I notice my own co-workers get more frustrated each day in the office, I can’t help but notice the one key factor they all share: staying motivated at work.

By definition, the word motivation refers to a state of being, an act or a process. So staying motivated is something that requires work and conscious attention. Much like working to maintain a healthy body, there are things you must understand and do to motivate yourself and sustain the attitude. Below are three tips that to staying motivated at work.

Motivation at Work | Tip# 1

Be passionate about your job

This is one of the great secrets of success and finding motivation at work. A common answer that millionaires give as to the key reason to their success is that they make a profession out of their passion. When you are in love with your job it’s much easier to find motivation to work and stay motivated.

Motivation at Work | Tip# 2

Set goals to improve your performance

Visualize yourself a year from now. What is different about your job? Are you still doing the same thing, the same way? What if you could be earning twice as much as you do today? If you set a goal to achieve something in your career, then find ways to accomplish that, how can you lose your motivation as your work every day?

Motivation at Work | Tip# 3

Take some time off

When you’re at work be sure to work. When you go play be sure to play. But never work while you play, and under no circumstances play at work. However, one of the fastest ways to motivation at work is to take the time to get away from work. When you do, leave your work in the office. Take your mind completely out of your career and enjoy some quality time with your loved ones doing things together that makes you happy. Then when you get back to the office focus on your important tasks and be your best motivator. Diversifying your activities will keep you motivated and looking forward to your next break with your family.

Rodrigo Silveira




Motivation at Work


Motivation at work: The key to faster, more frequent promotions is motivation at work. Don't wait until a co-worker motivates you, be proactive in motivating yourself at work.


Sunday, February 14

Motivational Stories | A Heart of Peace

Heart of PeaceA Heart of Peace
by Rodrigo Silveira



Today's Motivational Short Story by Rodrigo Silveira is a true story I heard from a good friend of mine. The person that shared this experience with me is a very successful business man from Utah. The subject of this motivational story is his partner, whose name is Alvin Sorano from El Salvador.

Back in the 60s, somewhere in El Salvador, Alvin's father (whose name I do not know, but will refer to from this point on as Richard) was a body guard to the President of El Salvador. One day, however, Mr. Sorano father was involved in some sort of accident and broke his back. Due to the circumstance, the President decided to release Richard of his duties. Sadly, the President also decided that Richard knew too much information. For this reason he demanded that Richard be killed.

As the President's servants made their way to Alvin's home in order to get rid of his father, Richard was tipped off about the situation. He then put Alvin (who was 10 years old at the time) and his little sister (age 11) atop a horse and told them to hide at a certain place and return in two weeks, by which time a plan would be put in place to move the two of them to the United States. Shortly thereafter Richard was captured and shot nine times before he was left for dead.

Miraculously, someone found Richard's body and rushed him to the nearest hospital as he struggled for his live. As the President received news that Richard was still breathing, he sent out his servants to the hospital and ordered them to stay there until Richard was dead. Not long afterwards the line went flat, and Richard departed this world.

Two weeks later, Alvin and his sister returned home, and as arranged, were moved to the States. Their mother had been moved earlier, and soon the three of them were together in Southern California. Alvin and his family was also joined by two of his older brothers.

At the age of 16, on a nice spring day, Alvin decided for the first time to skip class and come home in the middle of the day. As he sat on his living room at 12:00 p.m. that day, a couple of Christian missionaries knocked on his door wanting to share the Good Word with Alvin. He asked that the missionaries come back that evening, so Alvin, his mother, and the rest of the family could hear the message. The missionaries came back as agreed, and soon after Alvin and his mother were converted to this new religion. Alvin says joining this new faith was the day his live turned around for the better.

Seven months after his baptism, as Alvin was now 17 years old, his two older brothers came to him with automatic guns and a message for him. They said that the man living just a few blocks up the street was the man that had coldly murdered their father all those years ago, and they should now to take his life in revenge. A good detail to be added to the plot at this point is that when Alvin was just a little kid and Richard was still working for the government, for whatever reason, Richard gathered the family together one evening and made the announcement that all major decisions were to go through Alvin. His word would be the final saying on any specific matter. So this was the reason the two older brothers came to 17 year old Alvin before shooting the man who'd taken their father about a decade before.

Alvin told his brothers to stay put. He walked to the man's house on his own, no guns in hand. The door received three brief knocks. The man answered and was greeted by Alvin. They shook hands. Alvin introduced himself and let the man know he was the son of the Richard Sorano, the former bodyguard to the President, whom he had killed. Alvin then said the following words:

I forgive you. My family and I hold no bad feelings towards you. I forgive you.

He then turned around and left the house.

Walking up to his brothers (who were 21 and 25 years of age) and say:

It's over. We kill him and this will go on from generation to generation. The hatred must stop here. We must break the cycle.

The brothers were obedient to Alvin's instructions.

Several years went by and one day Alvin discovered a surprising truth. The man whom he had forgiven, the man who had murdered his father, he was also a government agent back in the 1960s. When the President had ordered him to kill Richard, this man actually refused to do so. He told the President he was no murderer and that he could not do this. The President then firmly told this gentleman that if he would not kill Richard, then he would have him killed for not following his orders. Not only that, the President told this man that he would also kill the man's wife, all his sons, all his daughters, and then all his relatives. What a situation! What would you do?

The man, in an attempt to save his family, went through and shot Richard as commanded by the evil President. Since that day, he exiled himself to the United States, living in hell for the thing he had done. His live had been so miserable ever since. Then one day he was visited at home by non other than the teenage son of the very person he'd murdered. This was the day Alvin told him he was forgiven. WOW! How do you think Alvin's words made this man feel?

Alvin had a heart of peace.


Rodrigo Silveira


Motivational Short Stories by Rodrigo Silveira is dedicated to motivate, inspire, educate, uplift, and convince people that self-motivation, self-development, and inspiration through stories is the key to success. The motivational short stories found here are written by Rodrigo Silveira unless otherwise indicated. Rodrigo Silveira has been inspiring and motivating people through story telling since 2007. Follow Rodrigo Silveira on Twitter and receive motivational short stories updates on your phone.


Thursday, February 11

Inspiring Stories | The Toughest Step to Take is the Last Step to be Taken

Motivational Short Stories by Rodrigo Silveira

Inspiring Stories

I really like the above video. From the title of it you might think it's a "funny" video. It isn't. Well, maybe it is, what can I say. The point is that there is a priceless lesson to learn from this gentleman's distraction. Today's Motivational Short Stories by Rodrigo Silveira we'll talk about ways to start and finish strong. I believe of all things in life, this is one of the great secrets of success.

It's not over until it's over

Sometimes we get to a point where we think we're doing pretty good. This sometimes happens at work, at play, at life, at school, or at whatever else matters. This is a good thing. A lot of times we can see great results, too, which only inspires us to stay motivated and do even more of what we're currently doing. The danger lies when we stop seeing people following after us. When we get to the point where we think we're doing so good that nobody can stop us. Then we stop working as hard, we no longer pay attention to the important details that brought us to that point. This is the beginning of our painful downfall.

When we get to the last stretch of anything worthwhile, the arduous work that took us to that point usually leaves us tired, gasping for air, and looking for the next resting area. When running the race of life and your legs are about to give out, your lungs are in the verge of implosion, and you can hardly think straight, why not keep going for just a little longer? Once the finish line has been crossed and your triumph secured, what else should matter?

Focus on what's most important

A great soccer player of the past, who happens to be a great source of inspiration to me, once said that, "you don't have to always be important, only when it's necessary." Not everything we do is important. Different things have different levels of importance. The goal of a champion is to discern what is important and what is not, and what is a greater priority over what needs to be done at the moment. The trick is to take a step back and see the few things that, if done well, would really make a significant difference. Some people call this the 80/20 rule. There are basic things we do that only make up some 20% of the overall process, but those tasks that amount to 20% of the work done contribute to 80% of the results.

Usually the first 5%, the 15% in the middle, and the last 5% of an operation make up the key areas of importance. If you focus on getting started well, then staying motivated and keeping the energy levels high, then giving it your all on the last 5% of a task, that usually makes a very profound difference.

Start with the end in mind

A famous motivational speaker once asked the question: When should you start building a house? His answer: As soon as it's finished. This is wise counsel. I know people that give up half way through something, while others call it quits before they even get started. There are always reasons, of course - the negative relatives, the up-hill journey that seems too challenging, the obstacles are too much to handle, etc. You've all seen that before.

If you are able to paint a colorful picture of your desired goal, then you have a decent foundation to get started, and a source of inspiration to remind you of what is important to you.

In summary, as you start your next project or as you continue an existing one, remember to:

  • Start with the end in mind
  • Focus on what's most important - and don't get distracted by things not important
  • It's not over until it's over - even when the odds are against you



Rodrigo Silveira

Motivation Short Stories by Rodrigo Silveira: Who is Rodrigo Silveira?

Rodrigo Silveira started Motivational Short Stories in 2007. His short stories are told with the purpose of providing inspiration, motivation, and uplifting those who can affored to get inspired and motivated. Rodrigo started out on his own, and through the help of some key people, Rodrigo has been able to acheive great success. He now dedicates his time sharing his motivation through short motivational stories so others may find success in their lives as Rodrigo has been successful in his.

Monday, February 8

Short Motivational Stories by Rodrigo Silveira : Now on Twitter

Follow Rodrigo Silveira on TwitterTwitter
Here's a true Motivational Short Story for all of you living both in the 21st century and on a budget. I realize that a lot of people are now carrying very nice phones these days, but there are a lot of people confused about who's map is better - Verizon or AT&T. A lot of us don't know what our phone can do, what it should do, and how much we're being charged for holding the phone to our ear a few times a day. With that, I thought it would be nice to offer you fine people a free service that is indeed useful.

Behold, Twitter! Most of you have probably heard of it, but I'm not sure that a lot of us care about it that much. Twitter is the 12th most visited site in the internet today. The main thing about it is that people can post whatever they wish as long as their post has no more than 140 characters. While a lot of people constantly say what they do ("just got done brushing my teeth", "ordering a double quarter pounder at 12th south state street with my friends", etc), and others spam the service with pointless advertising ("visit the best site in the web: www.(...).com"), Twitter can be used for good. It actually can be a great resource for anyone looking for a handy short motivational story. Here's why and how:

1) You can access Twitter from your phone - not having to have a $30+/month for mobile internet service. You can access people's Tweets through your regular unlimited text messaging service.

2) You can post your own Tweets right from your phone.

The text messaging commands for Twitter are as follows (remember, these commands are especially designed for Tweets from Motivational Short Stories by Rodrigo Silveira):

(These commands are entered as the content of your text messages, sent to the phone number 40404)

ON motivationstory - This command turns on notifications from the user MotivationStory (Rodrigo Silveira).

FOLLOW motivationstory - This command registers you as a follower of Rodrigo Silveira.

GET motivationstory - Get the latest update from Rodrigo Silveira

@motivationstory + message - This sends a message to Rodrigo Silveira and saves it in his replies tab. Remember, the message must be less than 140 characters in length.

Motivational Short Stories by Rodrigo Silveira - on your phone, anywhere, any time

Now you can register an account with Twitter and receive our updates daily, straight on your phone. Get daily tips for success, short motivation stories, inspiration quotes, motivational short stories, and much more.

Tuesday, February 2

Motivation Stories | Daily Inspirational quotes

Inspiring Stories

Stories to inspire, motivate, and uplift

by Rodrigo Silveira


Today was a good day to start the week. I'm excited for this week because of what happened today. If you could use some motivation, here's a good motivational short story told by Rodrigo Silveira...

Motivational Short Story - Pain Helps to Heal

My good co-worker left the office last Thursday with a big smiling silly. He was going to spend that night by himself playing video games, then the next morning he'd be flying down to San Diego where he was to be married a few hours later. Today I sent him a text message to see how he was doing. He replied positively.

To contrast, I have another good friend that I met through work who is in a similar situation. He, as recently as when the sun last rose, is engaged to a girl he's known for some time, but not quite 300 days, I don't think. I'm not sure what the deal is in that relationship, but they seem to always be walking on thin, slippery ground. Plus the ground they walk on looks cracked and built on a layer of sand or something.

If there's a lesson I can draw from the experience of my second friend, here's the message I'd deliver for this week's motivational short stories:

Allow yourself to cry

Before letting all emotions drive you toward the dark, dangerous road of a terrible decision, I would recommend you to take a step back, find a comfortable place and allow yourself to cry. Let all those emotions out. Forget about the chaos around you, and just let it all out. Be loud if you must. Then lay your wet head down and close your eyes. Let the darkness of the night calmly surround you as you embrace the sorrows of the soul.

Awake and Arise

Next thing you do is get up the next day and bring yourself together. Whether you're the man or the woman, you must be strong. You must be your strongest support system. Nobody should motivate you more than yourself. This is the key to the happy ending of your story. Forget the waters below, and focus on building a bridge on which to cross the raging waters. Now that you're more calm and rested, focus on that day's worries. Take some time to think clearly and decide what you need to do. Seriously and thoroughly analyze the situation, and weight the proposition. It's best rip the bandaid all at once, if that's the conclusion of your studies of your wound. Be strong, be motivated to stay strong, and keep your head up.

Write your Lessons Down

Now the only two things you will have left are a stronger character, and a lesson to guide you through until next time. The best thing to do is keep this lesson (the abstract concept) alive. Some people find that expressing the lesson through creativity helps them understand it further, express it more clearly, and remember it in the future. This is how a lot of the inspiring music, moving poetry, memorable movies, and the greatest motivational short stories are generated.

Remember, birds do sing after the storm. A broken heart will heal, but a reckless decision to stay in a bad situation will kill. Sometimes it doesn't rain on a lot of people, but the sun does shine on us all. Every problem usually has a pretty simple solution, but sometimes we lack the brains to find it, and the back to go through with it.

Ask not for less problems, but ask for more wisdom. Don't wish it were easier, wish you were better.

Rodrigo Silveira

For more Motivational Short Stories, Inspiring Stories, motivational quotes, motivational lines, or my favorite motivational short story, check back often. You can read more motivational short stories on my blog. Check out our archived Motivational Short Stories section. Thanks, Rodrigo Silveira!


Saturday, January 30

Rodrigo Silveira: The Official Blog

It's late. I'm sure I'll be reading this in a few weeks and I'll wonder if I should continue to bring work home and program until 3 in the morning. Maybe playing old NES games in my Wii, playing GTA3, watching 24, or just plain going to bed with my dear wife whenever she got tired and clocked out for the day would have been more productive.

Lately I've been thinking up of some really clever stuff... A lot of it has to do with turning clever programming into profitable endeavors, but a lot of it also has to do with improving existing projects and making things more efficient. One goal that I've had, though this specific goal's priority level, in my mind, was a low 2 or 3... This goal, as challenged by a fellow business partner, is to rank an uncontested number 1 in Google, Bing, and Yahoo! for my own name. Turns out that your mother wasn't all that creative when she chose your very unique name. If you do a Google Search for your own name, chances are there already are a few people with the same name. Yes, there are other Rodrigo Silveiras out there. I call them "the others." So my goal is to SEO a few pages here and there and outrank the others. I'm the only Rodrigo Silveira that can be on the web!

Anyhow, as I was working for the last few hours listening to some random music I had saved on an old CD I had burned when I was in High School, this song started playing that made my mind wander... I managed to complete the site I was working on then, but I replayed the song a few times. My mind is still wandering... Here's the song for those of you wondering what it was:


Usually I don't listen to this type of music, but as I hinted earlier, it's really late and I've been programming most of today. I think I've programmed close to 450 hours so far this year (last 30 days). That's actually something like 62% of the month (720 hours) spent programming.

Anyhow, so this song has always made me think of one of my best friends growing up. Usually there were different feelings that this song made me feel... But for some reason today it was different. I miss my friend. As a matter of fact, I miss all my friends from that period of my life. This friend that I always think about when I listen to this song..., he was the smart one in our group. He was probably the most talented of us all. He was good at everything. He always supported me in the things I attempted, and he'd take the time to teach me how to be better. During the first two years that I had moved to a different country, we managed to keep in touch somewhat. I wrote him a few times, but it wasn't until the 10th or 15th month that he responded to my first letter. Then one day there was a second letter from him. He seemed happy. He mentioned how his father, a man whom I had never met (as his parents were divorced since before we met) was about to be a father for the third time. His sister was doing good too, he mentioned, and he concluded saying that he missed me and wished me good luck. Less than two weeks later a different friend of mine emailed me saying this good friend of mine, the one that had written me the letters, had been murdered.

The story is still somewhat of a mystery to me as nobody has given me a lot of details and I haven't had the contacts to ask for any. But from what I've been told, he had been using some hardcore drugs pretty heavily. One day, as he went about to handle a situation with some people at around 2 or 3 in the morning, a car that had been parked (probably waiting for him) drove by and ran him over and drove away. Some lady that was near by saw him and called the ambulance, but the cocaine overdose kicked in, he started to seizure, and from there not even the medics were able to keep him with us. At his funeral all our friends signed a big flag of his favorite soccer team and laid it on top of his coffin, which they carried to his graveside while chanting this soccer team's main song. Apparently this was a sock to a lot more people than just me, as I wasn't the only know aware of his pain.

That is how loneliness can kill a man. At first nobody can really tell how much a man hurts. Each man's face expresses it differently. Each man's eyes see it differently, but when wet, they all feel the same. I think this is what makes the mystery and journey of life so special. Being able to remember something that is good, that once was real, and that now only exists internally. Being able to nourish and cultivate a reality that no longer matters, gaining strength from something as irrelevant and useless to our future as something that we will never be able to touch again, this, I believe, is the root of a good life.

Life is a great school. And I believe any great lesson is worth writing down. This is the purpose of my blog. And I think just as the universe would be a terrible waste of space if we were the only ones using it, so would these life's little lessons be if nobody knew about them. I know our lives can all be summarized in the same sentence, but as I take the time to relearn from mine as I write it down, why not do my best to expose my stories to as many people as will take the time to read them?! Thank you, SEO for making this possible...

Thank you for reading, and keep your head up. Because it doesn't matter where the sun goes during the night because when the morning comes, so does the sun. Life experiences are something worth treasuring.

Monday, January 18

Funny Mike Tyson Interview

Interviewing Tyson Post Match




Showtime interviewer Jim Gray tried to interview the heavy weight champion of the world, but it was hard for him to get 3 coherent words out of Mike Tyson's mouth. The fighter kept saying that Allah is blessing the people and all praise is due to him... But Tyson would also say that he wanted to kill Lenox Lewis and his children... No wonder people think Mike Tyson is an animal - a "brutal, vicious, and ruthless" animal.

Check out my YouTube channel for more Funny Videos.

Thanks!