Chrome Dinosaur Game With CloudX

Introduction: Chrome Dinosaur Game With CloudX

About: Am an Embedded Systems Engineer, an Inventor, Tech Instructor and Educationist, Father of Opensource Technology in Africa, Co-Founder ByteHub Embedded

The popular T-Rex Dinosaur Chrome offline game must have been developed to help you have your fun while waiting for your browser connection online to be re-established. Definitely, it is meant to take that unnecessary boredom away while on the wait.

A school of thought reasons that the small arms in the dinosaur icon depict that Chrome −like that dinosaur, is having trouble reaching the Internet. While it is also said that T-Rex momentarily reminds us that without the Internet Connectivity −that has brought a whole lot of evolution to us, we would still be trapped in the Dinosaur Age of Primitivity. Wow, how funny is that! Quite on point!

Therefore, we bring from our stables a Chrome Dinosaur Game Experience using the CloudX −as part of our DIY (Do It Yourself), to you all. In this project, we will be working with a joystick control as a major module of interest that will be interfacing with our CloudX MCU (microcontroller) board.

Step 1: Hardware Requirement

Step 2: CloudX Microcontroller Module

CloudX module is an electronics design hardware tool that allows you a much convenient and easy way of interfacing with the physical world via a simple microcontroller board. The whole platform is based on an open-source physical computing. Its simplicity of an IDE (Integrated Development Environment) really makes it a perfect fit for beginners, yet retaining an enough functionality to allow the advanced end-users navigate their way through. In a nut-shell, CloudX provides for a much simplified process of handling the microcontroller −by abstracting away the normal complex details associated with it; while at the same time offering a very rich user-experience platform. It finds wide applications cutting across board:

schools, as a great Educational tool;

industrial and commercial products;

and as a great utility tool in the hands of a hobbyist.

Step 3: Joystick Module

Certainly, you must have come across a typical joystick before −in one way or the other, especially if you are a game lover. It is usually used to control motion both in video games and general robotics. Also, a variant of it is adopted as an input device for a smaller electronic equipment like a mobile phone.

In games, it provides for a much realistic two-dimensional control where we may want to control the back and forth motion as well as left/right turns. And here in this project, we are making use of the type known as an Analog Joystick.

It is, in its commonest sense, a mere combination of two potentiometers (variable resistors) for X and Y planes respectively; with the joystick shaft serving as the pointer of a potentiometer.
So, as we navigate through via the stick (shaft), it simply reads the voltages that obtain at the potentiometers and furnishes CloudX MCU with their equivalent analog values; and by so doing, gives us both the magnitude and the direction of the motion in question.

Joystick module 5-pins’ description :
GND – negative terminal (-ve) of the power supply to be connected here

+5V – +5V, positive terminal (+ve) of the power supply to be connected here

VRx – X-axis analog ouput voltage Pin

The equivalent analog voltage of motion made in the x-axis direction is obtained here for the MCU use.This feeds into the analog MCU (microcontroller) pin of interest.

VRy – Y-axis analog output voltage Pin

The equivalent analog voltage of motion made in the x-axis direction is obtained for your MCU use.

This feeds into the analog MCU pin of interest.

SW − the pin connects to an in-built push-button switch

It is a digital pin.

It connects to ground whenever the joystick is pressed down; and literally floats, by default, when otherwise. Hence, it is advised that the pin is pulled up to Vcc via a resistor, so that any sensible reading could be made out of it by the MCU.

It can be used for various purposes; or can just be left idle when no use is actually intended for it.

Step 4: The Hardware Connections With CloudX Microcontroller

Step 5: ​The Circuit Diagram

The microcontroller module, being at the center of operation here, can be powered on:

· either via the Vin and the Gnd points (ie. connecting them up to your external power-supply-unit’s +ve and –ve terminals respectively) on the board;

· or through your CloudX USB softcard module.

More also, as can be clearly seen from the circuit diagram above, the sensor is interfaced with the MCU (microcontroller) module such that the -pin (middle pin) is connected to A0 of the MCU pin.

As it regards the LCD module, it is basically being used in the 4-bit communication mode:

the RS pin gets connected to the CloudX-MCU’s pin1,

whereas the En pin, D4 pin, D5 pin, D6 pin and D7 pin are connected to the MCU’s pin2, pin3, pin4, pin5 and pin6 respectively. 1kΩ resistor is connected to the LCD Vo pin through to ground to set the display contrast. (However, one is at liberty to experiment with say a 10kΩ variable resistor to adjust the contrast to a one’s more desired point).

Step 6: The Software Program

#include <CloudX\CloudX.h>

#include<CloudX\stdlib.h>

#include<CloudX\InternalMemory.h>

#include<CloudX\Adc.h>

#include<CloudX\Lcd.h>

#include<CloudX\JOYSTICK.h>

#define TONE_PIN 7

void do_delay(int ms_delay, int num_ms, int us_delay, int num_us)

{

int i;

for(i=0;i

delayms(250);

delayms(10);

for(i=0;i

delayus(250);

delayus(100);

// delayus(us_delay);

}

void generate_tone(long frequency, long duration)

{

long total_delay_time; // in microseconds

long total_ms_delay_time, total_us_delay_time;

int num_us_delays, num_ms_delays, ms_delay_time, us_delay_time;

long num_periods;

total_delay_time = (1000000/frequency)/2-10; // calculate total delay time (10 for error)

total_ms_delay_time = total_delay_time/1000; // total delay time of ms

num_ms_delays = total_ms_delay_time/250; // number of 250ms delays needed

ms_delay_time = total_ms_delay_time%250; // left over ms delay time needed

total_us_delay_time = total_delay_time%1000; // total delay time of us (ms already acounted for)

num_us_delays = total_us_delay_time/250; // number of 250us delays needed

us_delay_time = total_us_delay_time%250; // left over us delay time needed

num_periods = ((long)duration*1000)/(1000000/frequency);

while((num_periods--) != 0)

{

do_delay(ms_delay_time, num_ms_delays, us_delay_time, num_us_delays);

digitalWrite(TONE_PIN , HIGH);

do_delay(ms_delay_time, num_ms_delays, us_delay_time, num_us_delays);

digitalWrite(TONE_PIN , LOW);

}

return;

}

const char game[] = {14,11,15,4,23,30,12,10};

const char character[] = {20,20,21,29,7,4,4,0};

void CustomChar2(char pos_row, char pos_char) {

char i;

lcdCmd(80);

for (i = 0; i<=7; i++) lcdWriteCP(character[i]);

lcdCmd(return_home);

lcdWrite(pos_row, pos_char, 2);

}

void CustomChar(char pos_row, char pos_char) {

char i;

lcdCmd(64);

for (i = 0; i<=7; i++) lcdWriteCP(game[i]);

lcdCmd(return_home);

lcdWrite(pos_row, pos_char, 0);

}

const char Car[] = {0,0,0,14,14,31,31,10};

void CustomChar3(char pos_row, char pos_char) {

char i;

lcdWrite(72);

for (i = 0; i<=7; i++) lcdWriteCP(character[i]);

lcdCmd(return_home);

lcdWrite(pos_row, pos_char, 1);

}

char speed = 0,xx,yy,boy_row=0,boy_col=0,score[4],check=0,checkscore=0; int HighScore=0;

setup(){

//setup here

analogSetting();

lcdSetting(1,2,3,4,5,6);

lcdCmd(lcd_clear);

pin7Mode = OUTPUT;

pin7 = LOW;

lcdWriteText(1,3,"Dino - Jump") ;

lcdWriteText(2,3,"Car - Race") ;

if(readMemory(0)==0xff) writeMemory(0,0);

boy_row = 2;

boy_col = 1;

check = 0;

loop(){

//Program here

lcdCmd(lcd_clear);

checkscore++;

for (speed =17; speed!=0; speed--){

if(JOYSTICK_Y(A1) == JOYSTICK_UP) {

check++;

if(boy_row != 1) lcdWrite(boy_row,boy_col , ' ');

boy_row = 1;

}

else {

lcdWrite(1,boy_col , ' ');

boy_row = 2;

check = 0;

}

if(JOYSTICK_Y(A1) == JOYSTICK_DOWN) {

if(boy_row != 2) lcdWrite(boy_row,boy_col , ' ');

boy_row = 2;

}

if(JOYSTICK_X(A0) == JOYSTICK_LEFT) {

if(boy_col == 1) boy_col=1;

else { lcdWrite(boy_row,boy_col , ' ');

boy_col--;

}

}

if(JOYSTICK_X(A0) == JOYSTICK_RIGHT) {

if(boy_col == 16) boy_col=16;

else { lcdWrite(boy_row,boy_col , ' ');

if((boy_row == 2) && (boy_col==speed));

else boy_col++;

}

}

if(JOYSTICK_CENTRE(8) == LOW) {

lcdCmd(lcd_clear);

intTostr(score,readMemory(0), DEC);

lcdWriteText(1,1,"Highscore: ");

lcdWriteTextCP(score);

delayMs(1000);

lcdCmd(lcd_clear);

}

if((boy_row == 1) && (boy_col==speed)) HighScore++; //increment scores

if(((boy_row == 2) && (boy_col==speed)) || (check >5)){ //Check gameOver

lcdCmd(lcd_clear);

lcdWriteText(1,1,"GAME OVER") ;

lcdWriteText(2,1,"Score: ") ;

intTostr(score,HighScore, DEC);

lcdWriteTextCP(score);

generate_tone(1900,30);

delayms(2000);

lcdCmd(lcd_clear);

boy_row = 2;

check = 0;

boy_col = 1;

speed = 16;

if(HighScore > readMemory(0)){

writeMemory(0,HighScore);

}

HighScore = 0;

checkscore = 0;

}

else

{

CustomChar(boy_row,boy_col);

CustomChar2(2,speed);

lcdWrite(2, speed+1, ' ');

delay_ms(40);

// delay_ms();

}

}

}

}

Step 7:

Share

    Recommendations

    • Water Contest

      Water Contest
    • Fix It! Contest

      Fix It! Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    Discussions