A54Studio-Android Randomness

Code or Bust The <B><font CLASS="bigtitle">COOLEST</font></B> Games Ever Made

Populate an array at runtime

July 15, 2012

 This populates an array from previous Preferences at runtime.  Only call this once.  It will save them under yourNameVar1,yourNameVar2, etc.  I used a boolean, but you could use anything.  You can also save them individually to save processor time, but this will write them all at once if needed.
 
 
public void achievements(){
achieve=new Boolean[80];
SharedPreferences settings = getSharedPreferences(yourVar, 0);
for (int i = 0; i < 79; i++) {
achieve[i] = settings.getBoolean("yourVarName"+i, false);
}
}
 
 public void achievementswrite(){
     SharedPreferences settings = getSharedPreferences(yourVar, 0);
SharedPreferences.Editor editor = settings.edit();
for (int i = 0; i < 79; i++) {
editor.putBoolean("yourVarName"+i, achieve[i]);
   editor.commit();
   
}

Tags: android, array, java, populate array, reading, save persistent state, shared preferences, writing


Posted at: 07:27 AM | 0 Comments | Add Comment | Permalink

Draw text with line breaks on canvas!

June 23, 2012

 
 Here is a nice way to draw on a canvas text WITH linebreaks automatic!!
My Levels.actualLevel refers to which level the game is on and it will iterate through the 3 objectives. 
 
 
 CharSequence complete[] ={"whatever you want it to be.","whatever"}
 TextPaint objectives=new TextPaint();
 
 
 
private void missionObjectives(Canvas canvas) {
int obCheck=(Levels.actualLevel-1)*3;
for (int i = 0; i < 3; i++) {
StaticLayout mTextLayout = new StaticLayout(complete[obCheck+i],objectives, canvas.getWidth(), Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
canvas.save();
canvas.translate(5,(45+(i*15)));
mTextLayout.draw(canvas);
canvas.restore();
}
}

Posted at: 07:10 AM | 2 Comments | Add Comment | Permalink

Grid style dynamic menu in surface view

June 9, 2012

I was expirimenting with making buttons in a style similar to Angry Birds and others.  Here is what I came up with, it can be modified a million ways and uses rect collision for the touch event.

fivebywidth is the screen width/5 

 

public void missionGrid(Canvas canvas) {

//////////level counter will add the numbers to the grid starting at one 

int levelcounter=0;

int achieveCount=0;

int setup=heightbreakdown*15;

///////////// /////////This sets the touch event as the e1 rect

if(BumperJumper.toucher2==true){ EnemyCars.e1.set(BumperJumper.X,BumperJumper.Y, BumperJumper.X+1,BumperJumper.Y+1);

    }

for (int j = 0; j < 5; j++) { 

for (int i = 0; i < 5; i++) { levelcounter++;

   

        rect = new Rect(fivebywidth*i,fivebywidth*j+setup,fivebywidth*(i+1),fivebywidth*(j+1)+setup);

        

         

          

        p.setMaskFilter(new BlurMaskFilter(10, Blur.INNER));

 //////////////The next line calls the method that checks for collision between our button(rect) and our touch event and calls the correct level.  Also if touched shows touch on the button to whatever color you set, else untouched shows another color you set.

          if(BumperJumper.toucher2==true&&CollisionButton(rect,EnemyCars.e1)){Levels.actualLevel=(byte) levelcounter;

         p.setShader(new LinearGradient(0,fivebywidth*j+setup,0,fivebywidth*(j+1)+setup, Color.rgb(0,0,128),Color.rgb(0, 0, 0), Shader.TileMode.MIRROR));}

         ...

[More]

Tags: android, android coding, android java, android sample code, android surface view, angry bird style menu, code or bust, java, menu sample


Posted at: 07:00 AM | 0 Comments | Add Comment | Permalink

Basic high score method for android

May 26, 2012

Here is a simple top 5 highscore method to read and save.  Score is the variable you bring in when you call it.  It then loads the array, sorts, and saves.  
 
 
public void high(){
 // Restore preference
SharedPreferences settings = getSharedPreferences(SPY_JUMP, 0);
for (int i = 0; i < 5; i++) {
highscorelist[i] = settings.getInt(hscount[i], 50);
}

if (score>=highscorelist[0]){highscorelist[4]=highscorelist[3];
    highscorelist[3]=highscorelist[2];
    highscorelist[2]=highscorelist[1];
    highscorelist[1]=highscorelist[0];
    highscorelist[0]=score;
}
else{
if (score>=highscorelist[1]){highscorelist[4]=highscorelist[3];
    highscorelist[3]=highscorelist[2];
    highscorelist[2]=highscorelist[1];
    highscorelist[1]=score;
}
else{
     if (score>=highscorelist[2]){highscorelist[4]=highscorelist[3];
         highscorelist[3]=highscorelist[2];
         highscorelist[2]=score;
 
         }else{
               if (score>=highscorelist[3]){highscorelist[4]=highscorelist[3];
               highscorelist[3]=score;
 
              }else{
                if (score>=highscorelist[4]){highscorelist[4]=score;
 
}}}}}
 
SharedPreferences.Editor editor = settings.edit();
for (int i = 0; i < 5; i++) {
editor.putInt(hscount[i], highscorelist[i]);
   editor.commit();
    }
}

Tags: android, high scores, java, programming, saving, saving high scores, saving high scores in android


Posted at: 06:11 AM | 0 Comments | Add Comment | Permalink

Do away with collision double checking on android!

May 21, 2012

chart

 While working on a game, I realized I have been double checking for collisions against each other for some.  This way is hashed out where they won't double check.

int c=0;


for (int i = 0; i < enumbers; i++) {
for (int e = c; e < enumbers; e++) {blah,blah,c++;}}


Posted at: 09:44 PM | 0 Comments | Add Comment | Permalink

Final combo checking and such

April 18, 2012

  Got it working pretty sweet.  When a hit occurs I implement this.
 
                            BumperJumper.comboCycle++;  /////combo
                            BumperJumper.comboCount=1;   /////counting 
 
 Then this checks the combo, resets the counter, but not the cycle unless it has timed out.  This way a combo can be linked if within 40 cycles.  Even made it snazzy by making the text grow as the timer fades.  Simple touch.
 
 
    switch(comboCycle){
case 1:combo[0]++;break;
case 2:combo[1]++;break;
case 3:combo[2]++;break;
case 4:combo[3]++;break;
case 5:combo[4] ++;break;
}
if(comboCount!=0&&comboCycle>1){
if(comboCount<40){
comboCount++;
   paint.setTextSize(widthx/20+comboCount);
   paint.setColor(Color.GREEN);
   canvas.drawText(""+comboCycle+"x combo",(widthx/2),80,paint);
}
else{comboCount=0;comboCycle=0;}
}

Tags: android, code, easter eggs, eclipse, games, java, sample, sdk, variables


Posted at: 01:48 PM | 1 Comment | Add Comment | Permalink

Games and endless easter eggs

April 15, 2012

  I often enjoyed playing games that had tons of easter eggs in them, but never really thought about how much work goes into them until I started coding.  In the soon to be beta game I am working on, I wanted to include some good easter eggs, but how.  I wanted some double and triple combos to add up, so I add variables in a single loop instance.  In order to work properly, I have to add another variable that tracks every time that variable equals a set amount.  For instance.

   byte combo=0;

   byte comboCount[]={0,0,0,0,0};/////0=single,1=double,2=triple.etc.

 Now we are talking.  Set the loop rolling and every time a combo happens, it will log it at the end and reset it.

 at the end of the loop I put 

  switch(combo){

     case 1:comboCount[0]++;break;

     case 2:comboCount[1]++;break;

     case 3:comboCount[2]++;break;

     case 4:comboCount[3]++;break;

     case 5:comboCount[4]++; break;

   }

   combo=0; 

 

Pretty simple, but they can get pretty complex depending on what you are tracking. 

Tags: android, code, easter eggs, eclipse, games, java, sample, sdk, variables


Posted at: 10:19 PM | 0 Comments | Add Comment | Permalink

Brief introduction.

March 22, 2012

I started last year when I got reeled in by App Inventor.  I spent months learning the ropes and getting the hang of how it worked only to find out the games I was intending to make would make it crash due to their size.....SO, I put on my big boy pants and downloaded Eclipse and the android SDK.  Having originally put a less than adequate game on the market that I stripped down to make work in AI, I started learning.  I now have a HUGE new respect for the most simple games if they are executed well.  I've been working hard trying to polish my code and user interfaces.  I am going to start posting some code for anyone who may need it because I have learned so much from others doing it also.  

Tags: a54 studio, a54studio, android, android sdk, eclipse, games, java, programming, sdk


Posted at: 10:57 PM | Permalink

Posts by Date

Recent Posts

Archives