tag:blogger.com,1999:blog-69642664625421620022024-03-13T04:59:54.722-07:00A Computer Programming Blog<strong>Tasos Kleisas shares his programming experiences with the world</strong>Unknownnoreply@blogger.comBlogger33125tag:blogger.com,1999:blog-6964266462542162002.post-65146382444324721802018-01-18T06:40:00.001-08:002018-01-18T06:41:43.066-08:00A messenger program for the micro:bit<div dir="ltr" style="text-align: left;" trbidi="on">
Use 2 or more microbits to send messages to one another. Use A and B keys to select letters, press both A and B keys to select a letter, and select '>' character and press both A and B keys to send the message to other microbits.
<iframe allow="autoplay; encrypted-media" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/B6xTvOjSI_M?rel=0" width="560"></iframe>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-RCrQOhNySis/WmCxWnTxdnI/AAAAAAAADAM/EEk30BMb-coODuELN_tR8l-oFR1eR0B5QCLcBGAs/s1600/code.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="360" src="https://1.bp.blogspot.com/-RCrQOhNySis/WmCxWnTxdnI/AAAAAAAADAM/EEk30BMb-coODuELN_tR8l-oFR1eR0B5QCLcBGAs/s640/code.png" width="640" /></a></div>
As you can see the code is pretty simple. You can find the code in javascript in this github repository:
<a href="https://github.com/tkleisas/microbit_examples">https://github.com/tkleisas/microbit_examples</a>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-63367969031379332112017-11-29T16:39:00.002-08:002017-11-29T16:41:14.909-08:00Exploring Mandelbrot set with javascript and HTML5<div id="codebody">
<script language="javascript" type="text/javascript">
var timer;
var x0=-2.0;
var y0=-1.0;
var x1=1.0;
var y1=1.0;
var codevisible=false;
var maxiteration=256;
var canvaswidth = 0;
var canvasheight = 0;
var colors = new Array();
var cstep1 = 2 * Math.PI / 256;
var cstep2 = 2 * Math.PI / 257;
var cstep3 = 2 * Math.PI / 258;
var posX = x0 + (x1-x0) / 2.0;
var posY = y0 + (y1-y0) / 2.0;
var stepPosX = 0.0;
var stepPosY = 0.0;
var stepCount = 0;
var currStep = 0;
var zoomed = false;
var phaseR = 0;
var phaseStepR = 2*Math.PI/64;
var phaseG = 0;
var phaseStepG = 2*Math.PI/(64+16);
var phaseB = 0;
var phaseStepB = 2*Math.PI/(64+16+16);
var zoomf = 0.99;
var targetX = posX;
var targetY = posY;
animatePallete(phaseR,phaseG,phaseB);
function animatePallete(phaseR,phaseG,phaseB)
{
for (i = 0; i < 255; i++)
{
r = Math.floor((Math.sin(i * cstep1+phaseR) + 1) * 127);
g = Math.floor((Math.sin(i * cstep2+phaseG) + 1) * 127);
b = Math.floor((Math.sin(i * cstep3+phaseB) + 1) * 127);
colors[i] = rgbToHex(r, g, b);
}
}
function zoom()
{
window.clearTimeout(timer);
if (currStep >= stepCount) {
stepPosX = 0;
stepPosY = 0;
}
else
{
currStep++;
}
xposition=posX + stepPosX;
yposition=posY + stepPosY;
vwidth = (x1-x0)*zoomf;
vheight = (y1-y0)*zoomf;
stepx = vwidth / canvaswidth;
stepy = vheight / canvasheight;
x0=xposition-(canvaswidth*stepx)/2.0;
y0=yposition-(canvasheight*stepy)/2.0;
x1=xposition+(canvaswidth*stepx)/2.0;
y1=yposition+(canvasheight*stepy)/2.0;
posX = x0+(x1-x0)/2.0;
posY = y0+(y1-y0)/2.0;
drawFractal(x0,y0,x1,y1,canvaswidth,canvasheight,maxiteration,colors);
timer = setTimeout(zoom,20);
phaseR= phaseR + phaseStepR;
phaseG= phaseG + phaseStepG;
phaseB = phaseB + phaseStepB;
animatePallete(phaseR,phaseG,phaseB);
}
function clickHandler(event)
{
currStep = 0;
stepCount = 20;
x = event.offsetX;
y = event.offsetY;
stepx = (x1-x0)/canvaswidth;
stepy = (y1-y0)/canvasheight;
xNewPos = x0 + stepx*x;
yNewPos = y0 + stepy*y;
targetX = xNewPos;
targetY = yNewPos;
stepPosX = (xNewPos-posX) / stepCount;
stepPosY = (yNewPos-posY) / stepCount;
if(!zoomed)
{
zoomed = true;
zoom();
}
}
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function drawFractal(x0,y0,x1,y1,width,height,maxiteration)
{
var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
stepx = (x1-x0)/width;
stepy = (y1-y0)/height;
for(y=0;y<height;y++)
{
for(x=0;x<width;x++)
{
xpixel = x0+stepx*x;
xstart = xpixel;
ypixel = y0+stepy*y;
ystart = ypixel;
iteration = 0;
while((xpixel*xpixel + ypixel*ypixel) <= 4)
{
if(iteration >= maxiteration)
break;
xtemp = xpixel*xpixel-ypixel*ypixel+xstart;
ypixel = 2*xpixel*ypixel+ystart;
xpixel = xtemp;
iteration++;
}
if ( iteration >= maxiteration )
{
ctx.fillStyle = "#000000";
}
else
{
ctx.fillStyle = colors[iteration%256];
}
ctx.fillRect (x,y,1,1);
}
}
if(targetX>x0 && targetX<x1 && targetY>y0 && targetY<y1)
{
lx = Math.round(((targetX-x0)/(x1 - x0))*width);
ly = Math.round(((targetY-y0)/(y1 - y0))*height);
ctx.fillStyle= "#ffffff";
ctx.fillRect(0,ly,width,1);
ctx.fillRect(lx,0,1,height);
}
if(posX>x0 && posX<x1 && posY>y0 && posY<y1)
{
lx = Math.round(((posX-x0)/(x1-x0))*width);
ly = Math.round(((posY-y0)/(y1-y0))*height);
ctx.fillStyle="#ff0000";
ctx.fillRect(0,ly,width,1);
ctx.fillRect(lx,0,1,height);
}
}
function showcode()
{
if(codevisible)
{
document.getElementById("programlisting").value="";
document.getElementById("codelabel").innerHTML="Εμφάνιση Κώδικα";
document.getElementById("programlisting").style.visibility="hidden";
codevisible=false;
}
else
{
document.getElementById("programlisting").value=document.getElementById("codebody").innerHTML;
document.getElementById("codelabel").innerHTML="Απόκρυψη Κώδικα";
document.getElementById("programlisting").style.visibility="visible";
codevisible=true;
}
}
function draw()
{
canvas = document.getElementById("canvas");
canvaswidth=canvas.width;
canvasheight=canvas.height;
x0=-2.0;
y0=-1.0;
x1=1.0;
y1=1.0;
posX = x0+(x1-x0)/2.0;
posY = y0+(y1-y0)/2.0;
maxiteration=256;
drawFractal(x0,y0,x1,y1,canvaswidth,canvasheight,maxiteration,colors);
}
document.addEventListener("DOMContentLoaded", function () {
draw();
});
</script>
<canvas id="canvas" width="640" height="360" onclick="zoomf=0.99;clickHandler(event);" oncontextmenu="zoomf=1.01;clickHandler(event);return false;" ></canvas>
<br>
<button onclick="draw();">Reset</button>
<br>
<div id="programcode">
<a href="javascript:showcode();"><span id="codelabel">Show me the code:</span></a><br>
<textarea id="programlisting" cols="80" rows="40" style="visibility:hidden"></textarea>
</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-51207064878997864232015-05-04T07:39:00.002-07:002015-05-04T07:41:33.220-07:00A groovebox using Arduino uno (part 2 of N). Choosing the appropriate libraries.<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
In the last installment I introduced the Arduino uno groovebox concept. In order to be able to realize the design we need to use some libraries in order to perform the required tasks. Let me say that choosing the libraries can sometimes be an iterative process. Maybe we have to change our initial choice later. But we have to start somewhere, that is perform our first iteration. So, let's see the components we will use and the libraries we can utilize to communicate with them.<br />
1. Sound generation. This is maybe the most important component. Arduino uses a microcontroller as its processor. It is an ATMEL atmega 328p with 32Kb of flash memory, 2Kb of ram and 1Kb of EEPROM. It doesn't have a pcm codec like a PC or even raspberry pi have. So in order to produce sound we need either some additional component like an i2c dac, or we can use a PWM output and then filter it to produce a signal that can be fed to headphones, an amplifier or recording equipment. The approach I chose is to use PWM because I did not have a dac, and from the research I did, I found that PWM output does sound OK, if properly filtered. The first candidate for sound generation was Mozzi, a fantastic library with excellent documentation. You should definately check it out: <a href="http://sensorium.github.io/Mozzi/">http://sensorium.github.io/Mozzi/</a><br />
2. Library for the 128x64 OLED display: I searched for a driver/library to drive my OLED display. The display uses an SSD1306 chip. The particular display in my case was wired as SPI. You can find i2c or SPI/i2c versions in various places and with various prices. I bought 5 of those displays for under 20 euros in order to use them in various projects. The good thing about this display is that you can show a lot of information, With an 8x8 character matrix you can show 8 lines of 16 characters. That is a lot of information. The display is pretty crisp too! The only problem is that it is smallish, so if you are a bit older you may have trouble reading it. You can see details for the wiring in this Adafruit tutorial: <a href="https://learn.adafruit.com/monochrome-oled-breakouts">https://learn.adafruit.com/monochrome-oled-breakouts</a><br />
<br />
The library I initially used is this one: <a href="https://github.com/adafruit/Adafruit_SSD1306">https://github.com/adafruit/Adafruit_SSD1306</a>. This library supports both SPI and i2c and it uses the Adafruit GFX library (a separate download) for text and graphics rendering. Using the wiring documentation above and the library, I managed to connect the OLED display to arduino uno without any problems.<br />
3. Library/code for rotary encoder support. Anyone interested in reading rotary encoders with arduino should definately check out this post by Oleg Mazurov: <a href="https://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino">https://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino</a><br />
At first it was not working, but the problem was not in the code but rather on my poor soldering skills. You see I made 2 small breakout boards in order to make the encoders breadboard friendly and I created some sort circuits. When I found the problem Oleg's code worked like a charm.<br />
4. Library code for reading the buttons. No worries about this one! The support is built in arduino. Just configure the input pins with the INPUT_PULLUP parameter like this</div>
<code>
pinMode(BUTTON_1,INPUT_PULLUP);
</code><br />
<div>
<br /></div>
So in theory it seems like its all roses and we will be able to advance this in no time.<br />
<br />
Well, not so fast my friends. Why? Well these parts work OK on their own but when you try to make them work together problems <u>DO</u> occur.<br />
<br />
For example some libraries use particular pins that cannot be shared. Some others use a lot of precious ram starving the other libraries from it. So what seems a good start at first, may need some iterations before it works adequately as a system with the required functionality.<br />
So in our next blog post, we will go through some of the iterations required to make those libraries work together and even replace them with others in order to achieve the necessary interoperability and performance.<br />
<br /></div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6964266462542162002.post-85163180894023205362015-05-02T16:06:00.001-07:002015-05-04T13:14:27.558-07:00A groovebox using Arduino uno (part 1 of N)<div dir="ltr" style="text-align: left;" trbidi="on">
Hello,<br />
<br />
it's been a while since I last wrote on this blog. The previous blog entry dates back to 2009. Wow, that was six years ago... In the meantime a lot of things happened. As a citizen of a crisis plagued Greece I witness a whole nation holding its breath hoping for some kind of salvation fearing that an economic apocalypse might happen. As I find breath holding a waste of time, I started a new project that marries two of my favorite interests: Electronics and music. I am an amateur electronic musician and over the years I managed to gather a few sound producing gadgets and software. However, as every synth freak knows, I feel the urge to add new weapons to my sonic arsenal. I already have 2 Virtual Analog Synths (M-Audio Venom, Novation Mininova), and a cheap analog synth (Korg Volca keys). I recently brought back from the attic a yamaha 4 track cassette recorder and the idea of creating songs only with physical hardware, without a DAW and a computer for some reason started to resonate. What I don't have is a drum machine/groovebox hardware that could be used as the rhythm section and the backbone of the songs I write. Of course you can find a lot of grooveboxes and hardware in the market right now. But instead of buying a groovebox or a drum machine, the idea of creating my own groovebox started to grow on me for many reasons. Reason number one is to create something unique sounding with an expressive and creative workflow. As I had one or two arduino unos lying around I thought that I could base my groovebox on arduino. So I started researching and trying to shape the groovebox design in my head. I had to balance the features I wanted with the physical limitations of the parts I had in my disposal for prototyping. After quite some thought I decided on a simple design with the following specifications.<br />
1. Arduino uno based. That means that you can use a lot of existing libraries and resources and integrate rather than write code from scratch and there are a lot of documented ways to create a product out of your prototype.<br />
2. OLED LCD display. I also considered 7 segment type displays or even a color coded led scheme for visual feedback regarding the groove machine. But since I wanted to be able to edit a lot of parameters, some sort of LCD display became mandatory.<br />
3. Rotary encoders. I really like rotary encoders. I think that by using them, instead of potentiometers, is easier and really expressive.<br />
4. 4 sounds at once, in order to be able to create interesting grooves and mini songs. Also some other buttons with shift and/or mode functions.<br />
5. Low fi sound.<br />
6. Low part count and cheap to make.<br />
<br />
Little by little I started connecting the various components. Here is the prototype spaghetti of wires that I made.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-RIhYHVgl2EM/VUVVq-oy6TI/AAAAAAAACVU/luoxrWZbrm4/s1600/WP_20150502_001.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="http://3.bp.blogspot.com/-RIhYHVgl2EM/VUVVq-oy6TI/AAAAAAAACVU/luoxrWZbrm4/s400/WP_20150502_001.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
You can see six buttons. The first 4 switches act as trigger pads and the other two as shift and mode buttons. The screen used is an OLED 0.96" monochrome display that is quite small but really crisp and can be had with only 4.30 euros. The two rotary encoders and the sound output are on the upper breadboard. In the next installments of these series we will take a look on how we could decide on the sound producing library for Arduino. Until then, take care and take a look on the project code on <a href="https://github.com/tkleisas/digitalgroovebox">github</a> !</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-79478780981078225982009-11-18T10:43:00.000-08:002009-11-18T11:15:01.397-08:00Can N900 and Maemo save nokia?I absolutely love android, don't get me wrong but strong competition is a good thing. And android's only solid competition seems to be the one coming from Apple. Even though Nokia practically owns over one third of the mobile phone market, it is way behind technologically in the prestigious smartphone sector. Symbian series 60, is considered old and boooooring... Maemo is still wearing diapers (it is in my opinion, more immature than android was when it launched one year ago). So what steps can be taken by Nokia to improve the situation? Here's my short list:<br /><br />1. Abandon Symbian series 60 models in favor of Maemo.<br />2. Keep its series 40 line for dirt cheap mobile phones.<br />3. Develop a series 60 emulator that can run series 60 apps on Maemo phones.<br />4. Radically improve Maemo development tools. Let me elaborate on this. Compared to android and iPhone developer tools, Symbian series 60 tools have been really difficult to use. An entirely different sdk should be downloaded in order to support specific features found in specific models. And the SDK's were practically running only on Windows (and very specific versions of windows that is). Now, the new Maemo SDK is linux only, and it requires a lot of setup steps compared to android. So Nokia developers should make a move from windows to linux and from symbian to maemo. Whoa, that seems like a lot of work!<br />On the other hand the android SDK runs on windows, linux and MacosX, is simple to setup (at least compared to symbian and Maemo) and the emulator and the IDE are really simple to use and quite fast. In only one year android has 10,000+ apps and a lot of them are very good. Of course Nokia is starting to make some moves on the right direction. One of those moves is QT Creator, a very good cross - platform IDE, that can create QT apps that can be compiled for mobile platforms like Maemo, in good, old, speedy C++. But until Nokia bundles a simple to use QT Creator and Maemo SDK combo, I don't see developers fleeing their way.<br />However, N900, the first Maemo smartphone device, looks cool and packs a lot of power. But as we all know, the apps count, so Nokia should help developers write some cooool apps or it may be heading palm's way.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-56208628030485460232009-05-22T08:37:00.000-07:002009-05-22T11:06:37.925-07:00Robotic Space Rock 1.0.10 for android 1.5 (cupcake)Since the release of the android 1.5 SDK, I wanted to update the code of RSR to use the 1.5 SDK. It seems that as far as openGL/ES is concerned, programming is greatly simplified by the introduction of the class GLSurfaceView and the Renderer interface. It only took me a couple of hours to change the code to use the new programming interface. However I spent several days trying to find out why my application misbehaved when it was paused and then brought back to life. However I was able to track the problem down using the setDebugFlags(DEBUG_CHECK_GL_ERROR);<div>It had to do with incorrect rendering of a square (used for the moon/earth) surface. I also replaced the mediaPlayer class I was using to play back an mp3 with the JetPlayer class, which can be used to play back midi files that are a lot smaller compared to mp3's and they can use little cpu power. Now a midi file is used for playback, and the application size has reduced considerably to well under 1 Megabyte. However I did not find the time to write a proper midi song, so all you gonna hear is a repetitive ditty that is probably gonna drive you crazy...</div><div>Overall I think that the game is now a lot more responsive and fast but I only tested it on the emulator, so your feedback is welcome. Go to <a href="http://code.google.com/p/monolithandroid/downloads/list">http://code.google.com/p/monolithandroid/downloads/list</a> , download roboticspacerock1.0.10beta.apk and keep those bug reports coming...</div><div>The 1.0.9 version did not work, probably due to the <span class="Apple-style-span" style="font-family: Verdana; font-weight: bold; "><code>getHolder().setType(android.view.SurfaceHolder.</code><code>SURFACE_TYPE_GPU</code><code></code><code>);</code></span></div><div><span class="Apple-style-span" style="font-size: medium;">bug. In order for the game to work in real phones it seems that you still have to use the previous line.</span></div>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-6964266462542162002.post-17106999799783867472009-05-01T02:58:00.000-07:002009-05-01T03:15:22.227-07:00New! Improved! The 1.5 android SDK is here.The android 1.5 SDK (based on the notorious cupcake code branch) is here and it is what the first release of the SDK should have been. Support for sound recording and playback through buffer manipulation (using the AudioTrack class) is something that game developers want. And easier OpenGL programming is now easier, too. However there are still spotty places. It seems that the new SDK broke a lot of programs, especially games. And the apk size limitation of 16 MB still holds. My application RSR kinda works but when you try to exit it, it freezes. So I will have to adapt it to the new SDK release. I will rewrite the openGL parts using the new classes and see what happens. Maybe I will try to use AudioTrack class, too...Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6964266462542162002.post-57376743797825948302009-04-04T01:14:00.000-07:002009-04-04T06:10:56.922-07:00Robotic Space Rock and other games fell victims of the DMCAToday, I received a notification from google stating:<br /><br /><div>This is a notification that the application, Robotic Space Rock with package ID org.teacake.monolith.apk has been removed from Android Market due to a violation of the Developer Content Policy. Please review the Content Policies and Business and Program Policies before you create or upload additional applications. Note that repeated violations may result in a suspension of your Android Market Publisher account.<br /><br />For more information, or to contact us, please reply to this email, or visit the Android Market Help Center.<br /><br />Thanks,<br /><br />The Android Market Team<br /><br /><br />Now my application looks like this in the developer console:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_Qfga8utotf4/SdcX2xg-y7I/AAAAAAAAAO0/RJPYFJMbMso/s1600-h/DMCA.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 48px;" src="http://3.bp.blogspot.com/_Qfga8utotf4/SdcX2xg-y7I/AAAAAAAAAO0/RJPYFJMbMso/s400/DMCA.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5320747714533575602" /></a><br /><br />Additionaly they forwarded me a four page fax they received from Norris, McNaughlin &<br />Marcus P.A. who represent the Tetris Company.<br /><br />Here's the fax:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Qfga8utotf4/SdcanAjkm1I/AAAAAAAAAO8/NngjG5b_RTU/s1600-h/gview01.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 313px; height: 400px;" src="http://2.bp.blogspot.com/_Qfga8utotf4/SdcanAjkm1I/AAAAAAAAAO8/NngjG5b_RTU/s400/gview01.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5320750742227950418" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Qfga8utotf4/SdcanNwoTvI/AAAAAAAAAPE/M_Zog6THhPA/s1600-h/gview02.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 313px; height: 400px;" src="http://2.bp.blogspot.com/_Qfga8utotf4/SdcanNwoTvI/AAAAAAAAAPE/M_Zog6THhPA/s400/gview02.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5320750745772379890" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_Qfga8utotf4/SdcanoTc5rI/AAAAAAAAAPM/8I0GsknpoAo/s1600-h/gview03.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 314px; height: 400px;" src="http://4.bp.blogspot.com/_Qfga8utotf4/SdcanoTc5rI/AAAAAAAAAPM/8I0GsknpoAo/s400/gview03.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5320750752897754802" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_Qfga8utotf4/Sdcan2oE19I/AAAAAAAAAPU/Ug3e8XGEO-s/s1600-h/gview04.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 312px; height: 400px;" src="http://1.bp.blogspot.com/_Qfga8utotf4/Sdcan2oE19I/AAAAAAAAAPU/Ug3e8XGEO-s/s400/gview04.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5320750756742354898" /></a><br /><br />As you can see there are six applications listed for infringement:<br />Blocks, Cubik, Net Tetris, Netblocks, Robotics Space Rock, Tetroid<br /><br />Actually, my application is called "Robotic Space Rock", not Robotics Space Rock. However I do not use the tetris name anywhere in my application, and I do not copy or reuse tetris related art or sound. The game mechanics are also quite different. And the application is free.</div><div><br /></div><div>The question is, what should I do? I am not an american citizen nor do I live in the U.S. What's your take on this?<br /><br /></div>Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-6964266462542162002.post-82727321835142321942009-02-26T08:37:00.000-08:002009-02-26T09:22:04.091-08:00Some lessons learned from the android marketSometime in December, I released a game I wrote, Robotic Space Rock (RSR for short) in the android market. This lead to a small stream of emails from angry users, claiming that the app I published was not working. I unpublished RSR and started scratching my head and trying to figure out what went wrong. My first mistake was that I only tested RSR on the emulator, because at the time I had no access to a T-Mobile G1. As a matter of fact, I still don't because, Android Developer Phone (ADP) is not yet available in Greece where I live, and Google has not given a timeframe for the release of ADP in my region. So I searched the internet in order to find out why my users got a blank screen. A few days later, I found the problem, and corrected it. I asked for volunteers to test the corrected application before I resubmit it to the android market. Of course, my app was already buried (under 2 stars rating), so when I resubmitted, most guys were reluctant to try it out. Despite this, I continued to release updates. After a few days, I got an email from google. They asked me to rename it. Initially it was called MonolithAndroid but it seems that you are not allowed to have the term android in your application title, because it violates android market policies. So I had to rename to RSR and re-release. As days passed by, I got everything from 1 to 5 stars, and users saying that they hate or love RSR and everything in between. Some claimed that the background music slowed the game down, and others that RSR kept force closing. One of the worst things about the android market is that you cannot see the user comments of the users in the developer console, as someone would expect. This void was filled by the excellent cyrket web site by saurik. When the paid apps were introduced about a week ago, a flood of apps appeared and my app was further pushed down in the popularity rank. A few days ago, some apps with screenshots became visible through the android market website, but they were only the top rated apps. No chance for RSR appearing on the android market website, it seems...<br />So what are my conclusions for now:<br />1. Never, ever release an app, unless you thoroughly test it on a real device. If you don't get it passably right the first time, your app will be buried.<br />2. The phone memory limit is a severe limitation. My application has some original music. I wanted to add a couple of songs or more but I do not want to, because that would make it bigger and big apps, especially games are not going to stay on the phone for long. So keep your app small (under 1 MB) in order to maximize the chance of your application staying on the phone. Google should permit program installation on the SD card, increase the APK size limit and maybe increase the amount of internal storage to 1 GB or more.<br />3. Games are not that popular on the G1. It seems that geeks don't like gaming so much, or the games currently available are not so hot. So focus on applications, especially if you want to make some $$$. <br />4. Sound support for android is not good yet. If you use SoundPool, you increase the chance of your application hanging, making the user unhappy. I think that sound problems should be corrected immediately, because that affects all kinds of applications and especially games.<br />In my next blog entry I will try to compare android to iphone and symbian developer tools and market publishing. Stay tuned!Unknownnoreply@blogger.com5tag:blogger.com,1999:blog-6964266462542162002.post-31750302955840006222009-02-07T02:09:00.000-08:002009-02-07T02:15:20.109-08:00Robotic Space Rock 1.0.8 beta released!I just released Robotic Space Rock 1.0.8 beta on the android market. Here's the changelog:<br />1. Added easy mode. Now the screen spins in Normal and Expert Difficulty. The screen does not move in Easy Difficulty.<br />2. Changed texture size to 32x32 from 64x64 in order to improve performance.<br />3. Changed the way explosions are drawn.<br />4. Added a game over sound effect.<br />5. Changed the way that playfield rotation is calculated by introducing a new LinearInterpolator class.<br />As always your remarks, bug reports and suggestions are welcome!Unknownnoreply@blogger.com11tag:blogger.com,1999:blog-6964266462542162002.post-70643916491811688102009-02-05T13:31:00.000-08:002009-02-05T14:12:07.321-08:00A class for playing music and sound effects revisitedA while back, I published a class that could be used for playing music and sound effects. That class used the android.media.MediaPlayer class and was developed against a pre 1.0 android SDK version. The media player object is good for playing music, but it is not suitable for playing short sound effects. It is a heavyweight object and a bit unstable, too. But a new class called SoundPool (found in android.media package again) is available. This class is good for playing sound effects, but currently does not support .ogg or .mp3 files. Since I wanted my game to have both music and sound, I decided to design a class called SoundPoolManager which utilises both MediaPlayer and SoundPool objects. SoundPool objects are used to play sound effects and MediaPlayer objects are used to play back looping music.<div>SoundPoolManager creates a new thread and uses a LinkedList to queue sound events. So when you want to play a sound, you create a SoundPoolEvent and push it to the sound event queue. The SoundPoolManager thread picks up the queued events and plays them back for you. Time to show you some code:</div><div><br /></div><div> </div><br />This is the Sound interface used to abstract soundplaying functions.<br /><code><br />package org.teacake.monolith.apk;<br />public interface Sound {<br /> <br /> public void addSound(int resid, boolean isLooping);<br /> public void startSound();<br /> public void stopSound();<br /> public void stopSound(int resid);<br /> public void playSound(int resid);<br /> public void startMusic(int resid);<br /> public void stopMusic(int resid);<br /> public void pauseMusic(int resid);<br /> public void resumeMusic(int resid);<br />}<br /></code><br /><br />And now for the main dish, SoundPoolManager class<br /><code><br />package org.teacake.monolith.apk;<br />import android.media.SoundPool;<br />import android.util.Log;<br />class SoundPoolEvent<br />{<br /> public SoundPoolEvent(int eventType,int eventSound)<br /> {<br /> this.eventType = eventType;<br /> this.eventSound = eventSound;<br /> }<br /> public int eventType;<br /> public int eventSound;<br /> <br /> public static final int SOUND_PLAY=0;<br /> public static final int SOUND_STOP=1;<br /> public static final int SOUND_MUSIC_PLAY=2;<br /> public static final int SOUND_MUSIC_PAUSE=3;<br /> public static final int SOUND_MUSIC_STOP=4;<br /> public static final int SOUND_MUSIC_RESUME=5;<br />}<br />class SoundStatus<br />{<br /> public SoundStatus()<br /> {<br /> <br /> }<br /> public static final int STATUS_LOOPING_NOT_STARTED=0;<br /> public static final int STATUS_LOOPING_PAUSED=1;<br /> public static final int STATUS_LOOPING_PLAYING=2;<br /> <br /> <br />}<br />public class SoundPoolManager extends Thread implements Sound<br />{<br /> SoundPoolManager(android.content.Context context)<br /> {<br /> this.context = context;<br /> soundEvents = new java.util.LinkedList<SoundPoolEvent>();<br /> sounds = new java.util.HashMap<Integer, Boolean>();<br /> handles = new java.util.HashMap<Integer, Integer>();<br /> mediaPlayers = new java.util.HashMap<Integer, android.media.MediaPlayer>();<br /> isRunning = false;<br /> <br /> }<br /> public void addSound(int resid, boolean isLooping)<br /> {<br /> <br /> sounds.put(resid, new Boolean(isLooping));<br /> if(isLooping)<br /> {<br /> try<br /> {<br /> android.media.MediaPlayer mp = android.media.MediaPlayer.create(context, resid);<br /> mp.setLooping(true);<br /> mp.seekTo(0);<br /> //mp.prepare();<br /> mediaPlayers.put(resid, mp);<br /> <br /> <br /> //mp.seekTo(0);<br /> //mp.setAudioStreamType(android.media.AudioManager.STREAM_MUSIC);<br /> }<br /> catch(Exception e)<br /> {<br /> Log.d("ERROR",e.getMessage());<br /> }<br /> <br /><br /> <br /> }<br /> }<br /> <br /> public void run()<br /> {<br /> android.media.MediaPlayer mp = null;<br /> while(isRunning)<br /> {<br /> try<br /> {<br /> while(soundEvents.size()>0)<br /> {<br /> SoundPoolEvent event = soundEvents.remove();<br /> if(event!=null)<br /> {<br /> switch(event.eventType)<br /> {<br /> case SoundPoolEvent.SOUND_PLAY:<br /> android.media.AudioManager mgr = (android.media.AudioManager) context.getSystemService(android.content.Context.AUDIO_SERVICE); <br /> int streamVolume = mgr.getStreamVolume(android.media.AudioManager.STREAM_MUSIC); <br /> soundPool.play(handles.get( event.eventSound).intValue(), streamVolume, streamVolume, 1, 0, 1.0f);<br /><br /> break;<br /> case SoundPoolEvent.SOUND_STOP:<br /><br /> break;<br /> case SoundPoolEvent.SOUND_MUSIC_PLAY:<br /> currentPlayer = event.eventSound;<br /> if(sounds.get(currentPlayer)!=null)<br /> {<br /> mp = mediaPlayers.get(currentPlayer);<br /> <br /> if(!mp.isPlaying())<br /> {<br /> mp.seekTo(0);<br /> mp.start();<br /> }<br /> }<br /> <br /> break;<br /> case SoundPoolEvent.SOUND_MUSIC_STOP:<br /> currentPlayer = event.eventSound;<br /> mp = mediaPlayers.get(currentPlayer);<br /> mp.pause(); <br /> break;<br /> case SoundPoolEvent.SOUND_MUSIC_PAUSE:<br /> currentPlayer = event.eventSound;<br /> mp = mediaPlayers.get(currentPlayer);<br /> mp.pause(); <br /> break;<br /> case SoundPoolEvent.SOUND_MUSIC_RESUME:<br /> currentPlayer = event.eventSound;<br /> mp = mediaPlayers.get(currentPlayer);<br /> mp.start();<br /> break;<br /> <br /> }<br /><br /> }<br /> }<br /> }<br /> catch(Exception e)<br /> {<br /> //Log.d("Error",e.getMessage());<br /> }<br /><br /> try<br /> {<br /> this.wait(100);<br /> //java.lang.Thread.currentThread().sleep(100);<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> } <br /> }<br /> }<br /><br /><br /> public void startSound()<br /> {<br /> this.soundPool = new android.media.SoundPool(this.sounds.size(),android.media.AudioManager.STREAM_MUSIC,100);<br /> java.util.Iterator <Integer> iterator = sounds.keySet().iterator();<br /> <br /> while(iterator.hasNext())<br /> {<br /> int soundid = iterator.next().intValue();<br /> int soundhandle = this.soundPool.load(this.context, soundid, 1);<br /> handles.put(new Integer(soundid), new Integer(soundhandle));<br /> }<br /> <br /> isRunning=true;<br /> this.start();<br /> }<br /> public void stopSound()<br /> {<br /> java.util.Iterator <Integer> iterator = sounds.keySet().iterator();<br /> <br /> while(iterator.hasNext())<br /> {<br /> <br /> int soundid = iterator.next().intValue();<br /> if(this.sounds.get(soundid).booleanValue())<br /> {<br /> android.media.MediaPlayer mp = mediaPlayers.get(soundid);<br /> mp.stop();<br /> mp.release();<br /> mp=null;<br /> }<br /> else<br /> {<br /> this.soundPool.pause( this.handles.get(soundid).intValue());<br /> this.soundPool.stop(this.handles.get(soundid).intValue());<br /> <br /> }<br /> <br /> <br /> } <br /> <br /> isRunning=false;<br /> this.soundPool.release();<br /> }<br /><br /> public int currentPlayer;<br /> private boolean isRunning;<br /> private java.util.HashMap<Integer, Boolean> sounds;<br /> private java.util.HashMap<Integer, Integer> handles;<br /> private android.content.Context context;<br /> private java.util.LinkedList<SoundPoolEvent > soundEvents;<br /> private java.util.HashMap<Integer, android.media.MediaPlayer> mediaPlayers;<br /> public void stopSound(int resid)<br /> {<br /> if(soundEvents!=null)<br /> {<br /> try<br /> {<br /> soundEvents.add(new SoundPoolEvent(SoundPoolEvent.SOUND_STOP,resid));<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> } <br /> }<br /> public void playSound(int resid)<br /> {<br /> if(soundEvents!=null)<br /> {<br /> try<br /> {<br /> soundEvents.add(new SoundPoolEvent(SoundPoolEvent.SOUND_PLAY,resid));<br /> this.notify();<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> }<br /> }<br /> public void startMusic(int resid)<br /> {<br /> if(soundEvents!=null)<br /> {<br /> try<br /> {<br /> soundEvents.add(new SoundPoolEvent(SoundPoolEvent.SOUND_MUSIC_PLAY,resid));<br /> this.notify();<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> } <br /> }<br /> public void stopMusic(int resid)<br /> {<br /> if(soundEvents!=null)<br /> {<br /> try<br /> {<br /> soundEvents.add(new SoundPoolEvent(SoundPoolEvent.SOUND_MUSIC_STOP,resid));<br /> this.notify();<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> } <br /> }<br /> public void pauseMusic(int resid)<br /> {<br /> if(soundEvents!=null)<br /> {<br /> try<br /> {<br /> soundEvents.add(new SoundPoolEvent(SoundPoolEvent.SOUND_MUSIC_PAUSE,resid));<br /> this.notify();<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> } <br /> }<br /> public void resumeMusic(int resid)<br /> {<br /> if(soundEvents!=null)<br /> {<br /> try<br /> {<br /> soundEvents.add(new SoundPoolEvent(SoundPoolEvent.SOUND_MUSIC_RESUME,resid));<br /> this.notify();<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> } <br /> }<br /> SoundPool soundPool;<br /> <br /> <br />}<br /><br /></code><br />How do you use it?<br />First create an instance of the class.<br />Then add the resources to the SoundPoolManager (Sounds and music tracks)<br />Then start the SoundManager thread.<br />Then use the playSound() method to play a sound effect or playMusic() to play a song.<br /><code><br />SoundPoolManager m = new SoundPoolManager(context);<br />m.addSound(R.raw.bang, false);<br />m.addSound(R.raw.mysong,true);<br />m.startSound();<br />m.playSound(R.raw.bang);<br />m.playMusic(R.raw.mysong);<br /></code><br />If you want to pause the music use the pause call.<br /><br />Use the stopSound() method to stop the sound thread.<br />The code is crude and the method names are not quite appropriate but it is published under the assumption that you may find it useful. You can take a look at the Robotic Space Rock code found at <a href="http://code.google.com/p/monolithandroid">http://code.google.com/p/monolithandroid</a> for actual examples.Unknownnoreply@blogger.com10tag:blogger.com,1999:blog-6964266462542162002.post-10119035210766481872009-01-28T23:16:00.001-08:002009-01-28T23:26:42.819-08:00MonolithAndroid renamed to Robotic Space RockToday, I received an email from google asking me to rename the game I published for free in the android market. The game is called MonolithAndroid. Was called, actually, because from now on, it shall be called Robotic Space Rock! Yes, they informed me that I cannot use the word android, becase users may think that it is officialy endorsed from google, so I decided to drop the MonolithAndroid name alltogether and use the new improved and b-moviey name Robotic Space Rock.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-69748144076810058612009-01-22T03:17:00.000-08:002009-01-22T04:02:38.381-08:00How to display a license agreement on your android application.It is usually good practice to present the user with a license agreement the first time it uses an app. You can show the user a preferably short text with the license agreement. A license agreement gives you some legal protection if your application causes a problem to someone. You can use a checkbox to indicate that the user accepted the license agreement and proceed to the application.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Qfga8utotf4/SXhYJljREEI/AAAAAAAAAN0/RAVhvgy1Gw0/s1600-h/eula.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 267px; height: 400px;" src="http://2.bp.blogspot.com/_Qfga8utotf4/SXhYJljREEI/AAAAAAAAAN0/RAVhvgy1Gw0/s400/eula.png" alt="" id="BLOGGER_PHOTO_ID_5294078283696115778" border="0" /></a><br />We can use the shared preference mechanism to check if the user has agreed to the license agreement during the activity. If the user has previously agreed to the license then we proceed as normal. Otherwise, we show him the EULA. If the user checks the "I accept the license agreement" checkbox and presses OK, then we write to the preferences that the user accepted the license. If the user presses Cancel, we exit the app. You can see this in the following code excerpt<br /><code><br />private android.widget.CheckBox checkboxAcceptLicense;<br />private android.widget.Button buttonOK;<br />private android.widget.Button buttonCancel;<br />private android.widget.TextView textviewLicense;<br />public SharedPreferences.Editor prefsEditor;<br />public SharedPreferences prefs;<br />public android.view.View licenseView;<br />private boolean soundInitialized;<br />/** Called when the activity is first created. */<br />@Override<br />public void onCreate(Bundle icicle) {<br />super.onCreate(icicle);<br />soundInitialized = false;<br />prefs = this.getPreferences(android.content.Context.MODE_PRIVATE);<br />prefsEditor = prefs.edit();<br />if(!prefs.getBoolean("LicenseAccepted", false))<br />{<br /><br />//this.licenseView = this.findViewById(R.layout.licenseagreement);<br />this.licenseView = View.inflate(this, R.layout.licenseagreement, null);<br />this.setContentView(licenseView);<br />this.checkboxAcceptLicense = (android.widget.CheckBox)this.findViewById(R.id.checkLicenseAgreement);<br />this.textviewLicense = (android.widget.TextView)this.findViewById(R.id.textviewLicenseAgreement);<br />this.buttonOK= (android.widget.Button)this.findViewById(R.id.buttonOK);<br />this.buttonCancel = (android.widget.Button)this.findViewById(R.id.buttonCancel);<br />this.buttonCancel.setOnClickListener(<br /> new View.OnClickListener()<br /> {<br /> public void onClick(View view)<br /> {<br /> exitNotAcceptedApplication();<br /> }<br /> }<br /> );<br />this.buttonOK.setOnClickListener(<br />new View.OnClickListener()<br />{<br />public void onClick(View view)<br />{<br /> if(checkboxAcceptLicense.isChecked())<br /> {<br /> prefsEditor.putBoolean("LicenseAccepted", true);<br /> prefsEditor.commit();<br /> licenseView.setVisibility(View.INVISIBLE);<br /><br /> initActivity();<br /> }<br /><br />}<br />}<br />);<br />}<br />else<br />{<br />initActivity();<br />}<br /><br /><br /><br />}<br /></code><br />the initActivity() method contains the actual code that you would normally execute on the onCreate() method of your Activity. The layout file for the license agreement is the following (licenseagreement.xml):<br /> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><span style="color: rgb(63, 127, 127);">xml</span> <span style="color: rgb(127, 0, 127);">version</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"1.0"</i></span> <span style="color: rgb(127, 0, 127);">encoding</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"utf-8"</i></span><span style="color: rgb(0, 128, 128);">?></span></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><</span><span style="color: rgb(63, 127, 127);">LinearLayout</span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:id</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"@+id/widget24"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_width</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"fill_parent"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_height</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"fill_parent"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:background</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"#ffffffff"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:padding</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"0px"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">xmlns:android</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"http://schemas.android.com/apk/res/android"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:orientation</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"vertical"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="color: rgb(0, 128, 128);"><span style="font-family:Monospace;"><span style="font-size:85%;">></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><br /></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><</span><span style="color: rgb(63, 127, 127);">TextView</span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:id</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"@+id/textviewLicenseAgreement"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_width</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"wrap_content"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_height</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"wrap_content"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:padding</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"0px"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:text</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"Monolith Android Licence Agreement. This software package is provided to you, the end user, by the sofware package creator, Tasos Kleisas, as is. The software package is provided free of charge by the developer. However, the means of delivering the software to your device, (mobile phone, computer or other) may induce a service fee. The developer cannot be held responsible for any damage or loss that you may suffer by the use or installation of this application package to your device. Use at your own risk. The code, sound effects, and music are copyrighted by Tasos Kleisas (C) 2007-2009."</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textSize</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"14sp"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textColor</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"#000000"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:typeface</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"normal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textStyle</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"normal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_weight</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"0"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_gravity</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"left"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="color: rgb(0, 128, 128);"><span style="font-family:Monospace;"><span style="font-size:85%;">></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><!--</span--><span style="color: rgb(63, 127, 127);">TextView</span><span style="color: rgb(0, 128, 128);">></span></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><br /></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><</span><span style="color: rgb(63, 127, 127);">CheckBox</span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:id</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"@+id/checkLicenseAgreement"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_width</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"fill_parent"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_height</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"wrap_content"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><br /></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:text</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"I accept the license agreement"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textColor</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"#000000"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textSize</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"12sp"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:typeface</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"normal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textStyle</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"normal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:checked</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"false"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><br /></p> <p style="margin-bottom: 0in;" align="left"><br /></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:orientation</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"horizontal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="color: rgb(0, 128, 128);"><span style="font-family:Monospace;"><span style="font-size:85%;">></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><!--</span--><span style="color: rgb(63, 127, 127);">CheckBox</span><span style="color: rgb(0, 128, 128);">></span></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><</span><span style="color: rgb(63, 127, 127);">TableRow</span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:id</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"@+id/widget32"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_width</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"fill_parent"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><br /></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_height</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"wrap_content"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:orientation</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"horizontal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="color: rgb(0, 128, 128);"><span style="font-family:Monospace;"><span style="font-size:85%;">></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><</span><span style="color: rgb(63, 127, 127);">Button</span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:id</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"@+id/buttonOK"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_width</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"wrap_content"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_height</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"wrap_content"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:padding</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"10px"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:text</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"OK"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textSize</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"14sp"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:typeface</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"normal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textStyle</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"normal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_weight</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"0"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_gravity</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"left"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="color: rgb(0, 128, 128);"><span style="font-family:Monospace;"><span style="font-size:85%;">></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><!--</span--><span style="color: rgb(63, 127, 127);">Button</span><span style="color: rgb(0, 128, 128);">></span></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><</span><span style="color: rgb(63, 127, 127);">Button</span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:id</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"@+id/buttonCancel"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_width</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"wrap_content"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_height</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"wrap_content"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:padding</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"10px"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:text</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"Cancel"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textSize</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"14sp"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:typeface</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"normal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:textStyle</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"normal"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_weight</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"0"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(127, 0, 127);">android:layout_gravity</span><span style="color: rgb(26, 26, 26);">=</span><span style="color: rgb(42, 0, 255);"><i>"left"</i></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="color: rgb(0, 128, 128);"><span style="font-family:Monospace;"><span style="font-size:85%;">></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><br /></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><!--</span--><span style="color: rgb(63, 127, 127);">Button</span><span style="color: rgb(0, 128, 128);">></span></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><!--</span--><span style="color: rgb(63, 127, 127);">TableRow</span><span style="color: rgb(0, 128, 128);">></span></span></span></span></p> <p style="margin-bottom: 0in;" align="left"><span style="font-family:Monospace;"><span style="font-size:85%;"><span style="color: rgb(0, 128, 128);"><!--</span--><span style="color: rgb(63, 127, 127);">LinearLayout</span><span style="color: rgb(0, 128, 128);">></span></span></span></span></p> <p style="margin-bottom: 0in;">Unfortunately, as you can see the server messed up the xml layout a bit. But you can find the full code at <a href="http://code.google.com/p/monolithandroid/source/browse/">http://code.google.com/p/monolithandroid/source/browse/</a><br /></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-88401799285471615792009-01-22T03:01:00.000-08:002009-01-26T00:52:03.096-08:00Android 3D graphics and SurfaceViewIf you want to use OpenGL/ES, you have to use a SurfaceView class. The problem is that there are various parameters for the SurfaceView class. This, for example may work fine in the emulator:<br /><code><br />getHolder().setType(android.view.SurfaceHolder.SURFACE_TYPE_NORMAL);<br /></code><br />on a real device, however, you may get a blank screen, or very slow redraws, so you should use this:<br /><code><br />getHolder().setType(android.view.SurfaceHolder.</code><code>SURFACE_TYPE_GPU</code><code>);<br /></code><br />or even this:<br /><code><br />getHolder().setType(android.view.SurfaceHolder.</code><code></code><code>SURFACE_TYPE_HARDWARE</code><code></code><code>);<br /></code><br />So i came up with this solution for the SurfaceView initialization:<br /><code><br />public GameSurfaceView(Context context,GameOverlay overlay,Sound soundManager)<br />{<br />super(context);<br />this.soundManager = soundManager;<br />this.context = context;<br />this.overlay = overlay;<br />this.viewType = GLThread.VIEW_INTRO;<br />this.gameType = Game.GAME_MONOLITH;<br />getHolder().addCallback(this);<br />try<br />{<br /> getHolder().setType(android.view.SurfaceHolder.</code><code>SURFACE_TYPE_GPU</code><code></code><code>);<br />}<br />catch(Exception e)<br />{<br /> try<br /> {<br /> getHolder().setType(android.view.SurfaceHolder.</code><code>SURFACE_TYPE_HARDWARE</code><code>);<br /> }<br /> catch(Exception e2)<br /> {<br /> try<br /> {<br /> getHolder().setType(android.view.SurfaceHolder.SURFACE_TYPE_NORMAL);<br /> }<br /> catch(Exception e3)<br /> {<br /> }<br /> }<br />}<br />}<br /></code><br />So in the code above, we first try to get a hardware accelerated surface (fastest), if that fails a gpu memory surface(still fast) and if that fails a normal software surface.Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6964266462542162002.post-63432833334502124202009-01-20T08:46:00.000-08:002009-01-20T09:43:09.063-08:00MonolithAndroid 1.0.4 beta is outIt' s been almost two weeks since I released an updated version of MonolithAndroid. But now version 1.0.4 beta is out! I've corrected a few bugs and added some features but there are still some critters in there. So to sum up, here's a small changelog.<br /><br />1. Switched from using media player for sound effects and music to a hybrid SoundPool / MediaPlayer implementation. Now the sounds are played using SoundPool and the music is played with MediaPlayer. Of course some problems remain. The most important problem is that the music cannot reliably be stopped.<br />2. Added a highscore table. Now you can find out who is the best player. The highscore table persists, so if you restart the game, your highscore is still there.<br />3. Added an options menu. Now you can select the type of game you want to play, the level and the difficulty. Two types of game are provided: Classic, which resembles a well known 6 letter game, and Monolith. Monolith introduces special white blocks. If you complete a line with a white block in it, the game grid evolves according to Conway's game of life. The difficulty setting enables you to choose between two settings. Normal is your meat and potatoes game. You can drag the touch screen to rotate the playfield. That may be useful practice for the expert difficulty mode. In Expert, the playfield rotates in various axes (depending on the level you currently play) so if you suffer from motion sickness do not play this mode! Ahhh, you have been warned! The level (1-10) determines the speed of the falling blocks as well as the rotation of the screen in expert mode. In the options screen you can enable/disable the music (not currently working) and the sound effects of the game. When you are happy with the game options go to OK, press right and then choose Play to start your game.<br />4. Changed the music format from mp3 to ogg because it reportedly causes less crashes on the MediaPlayer.<br />5. The program now exits if you press the back or the home button.<br /><br />A bit of a warning... I do not currently own an android hardware device, because they are not available yet in Greece where I live. So if you happen to install the game on a real device I would like to hear your comments and bug reports. You can download a signed apk from <a href="http://code.google.com/p/monolithandroid/downloads/list">http://code.google.com/p/monolithandroid/downloads/list</a>. Choose the monolithandroid 1.0.4 beta apk. You can post your comments here, or you can use the issue tracker found on <a href="http://code.google.com/p/monolithandroid/issues/list">http://code.google.com/p/monolithandroid/issues/list</a><br />Here's a grainy video made from the emulator. You can almost hear me talking in the background...<br /><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/neJOwlsmKmU&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/neJOwlsmKmU&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6964266462542162002.post-36936439816784564582009-01-07T06:03:00.000-08:002009-01-07T06:09:06.962-08:00Monolithandroid 1.0.3 beta releaseThe release frenzy continues with the release of monolithandroid 1.0.3 beta apk. This release corrects the texture loading problem of the previous 1.0.2 beta release. The problem manifested itself as holes in the textures used. Instead of using custom loading code, we use a function from the GLUtils class. So try it out!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-28864335649933824402009-01-06T23:15:00.000-08:002009-01-07T02:15:07.848-08:00monolithandroid 1.0.2 beta version update<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_Qfga8utotf4/SWR_t0cbhCI/AAAAAAAAAM0/YmoXKjUSds8/s1600-h/device.png"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 267px; height: 400px;" src="http://1.bp.blogspot.com/_Qfga8utotf4/SWR_t0cbhCI/AAAAAAAAAM0/YmoXKjUSds8/s400/device.png" alt="" id="BLOGGER_PHOTO_ID_5288492287588533282" border="0" /></a><br />A new apk is up for grabs. I am referring to the monolithandroid 1.0.2 beta which can be found at <a href="http://code.google.com/p/monolithandroid/downloads/list">http://code.google.com/p/monolithandroid/downloads/list</a> The new apk uses the <br />setType(SurfaceHolder.SURFACE_TYPE_GPU) parameter during the initialization of the display surface. Maybe the omission of this parameters caused the black screens on the G1 devices in the previous releases. However this change has caused the textures to appear incorrectly in the emulator.Note the picture on the left. The texture is full of black holes. I do not know if this occurs in an actual hardware device however... Can a guy with a real phone try it out and tell us the result?Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-35302932402423744632008-12-30T12:28:00.000-08:002008-12-30T12:45:24.435-08:00Another monolithandroid beta is outI just released another monolithandroid beta (monolithandroid1.0.1beta.apk). It seems that most of the previous beta 1.0.0 problems were related to 3 things.<br />First, the prepareAsync call used in media player to play sounds caused problems. Now synchronous playback is used.<br />Second, The textures that I was using were pretty big. Now the texture sizes (used for the moon and earth) are reduced below 64x64 pixels. Third, I had a starfield class that drew 3d points in order to give the player the illusion of space travel. The problem was I was trying to draw 10000 points which is way too much. Now only 100 points are drawn. So go to <a href="http://code.google.com/p/monolithandroid">http://code.google.com/p/monolithandroid</a> and grab the latest apk. Give it a try on your android phone and you may even have some fun. I hope that the music won't drive you crazy! Post your comments here or use the Issue tracker found on <a href="http://code.google.com/p/monolithandroid">http://code.google.com/p/monolithandroid</a><br />Oh, and don't forget to say what device you used for your tests!<br />I would like to take the opportunity to wish you a happy new year.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-11576338865494814462008-12-23T02:44:00.000-08:002008-12-23T03:02:23.085-08:00MonolithAndroid needs you!That is, I need beta testers to try the game out on a real hardware device like the T-Mobile G1. Yesterday, I published MonolithAndroid version 1.0.0 on the android market. Because I live in Greece, I cannot get hold of an actual G1 Phone, so I only tested my application on the emulator. And it seems that testing on the emulator is not enough. Hours after monolithandroid was published on android market, I got a couple of emails saying that the program presented them with a black screen and they only heard some music but they saw no graphics. So I unpublished the application. And here's where I need your help.<br />I would like you to download the installation package from http://code.google.com/p/monolithandroid and try it out on your TMobile G1. And here's what I would like to know:<br /><br />1. Does the application start?<br />2. Do you hear music?<br />3. Can you see the letters MonolithAndroid going on and off?<br />4. You only see a black screen?<br />5. If the game seems to run, does it run smoothly, or it feels sluggish?Unknownnoreply@blogger.com5tag:blogger.com,1999:blog-6964266462542162002.post-15204723986551958572008-09-23T07:17:00.000-07:002008-09-23T08:01:03.921-07:00Some thoughts on google android as a gaming platformWith the launch of the first android device (T-Mobile G1) just around the corner, I would like to share with you a few thoughts regarding the viability of the android platform for gaming purposes.<br />Android has rich multimedia and graphics api's:<br />1.Support for openGL/ES and 2D drawing.<br />2.Media api's.<br />3.Support for sensors (GPS and accelerometer).<br />4.Networking.<br />5.Optional touch interface.<br /><br />So in theory, it should be ideal for gaming, right?<br /><br />Well yes, but there are some caveats:<br />1. Not all devices will support touch interfaces and sensors.<br />2. Not all devices will have the same screen size.<br />3. For gaming, some sort of joystick or D-PAD device is essential. A D-PAD was standard in the various emulator images, since the first SDK, but the first device (The T-Mobile G1) comes without a D-PAD! Instead, we get a tiny trackball, not the best IO device for gaming!<br />So the problem is that as it seems, we will have a lot of different devices, with different configurations. Some will have touch interfaces, some will not, some will have a D-PAD, some will have trackballs, some will have acceleration sensors and so on. So, a game developer that develops for android will have the same kind of problems that a PC game programmer has. Different screen sizes and IO devices and so on... That increases the amount of time and resources a developer has to use in order to make his game playable on most phones. The same problems that drive a lot of PC game developers to game consoles.<br /><br />So how can this be remedied? Well I guess that one possible solution is the introduction of a limited set of device profiles. Something like basic, gaming and advanced profiles, that will provide the developer with the same set of IO features. <br />Otherwise, I see a lot of developers fleeing to the apple iPhone, with it's game console simplicity, rather than the android's PC like capabilities.<br /><br />I'd love to see your opinion on those thoughts, so shoot!Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6964266462542162002.post-41714950359335646552008-08-26T13:54:00.000-07:002008-08-26T14:06:12.272-07:00Yet another SDK updateI just returned from my summer holidays and found a brand new android SDK (0.9beta) available for download. I downloaded it, and found that it introduces a lot of changes. Packages were renamed and openGL/ES programming has changed quite a lot. Even menus are now different. So a lot of work is required to update monolithandroid in order to make it work with this SDK. Maybe I will be able to pump out a new, compatible version till the end of the week. Since this SDK is a 0.9 beta version, not a lot of things will change in the final 1.0 release and that means that the next releases will require a lot less work. And since the first android devices are scheduled for release in Q4, maybe we will be able to get our hands on a device just in time for Christmas. Now I must leave you and return to my project. I have a lot of work to do and correct some nasty bugs. Stay tuned!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-12374001927801619562008-08-04T04:39:00.000-07:002008-08-04T04:54:31.730-07:00Summer <> developmentSummer (especially in Greece) is really counterproductive. While the android engineers are working hard to put the finishing touches on our beloved operating system, I am going to the beach every day, drinking beer and coffee, and enjoying the summer vacations. No time for android programming. Tomorrow, my girlfriend and I are going to Crete for a twenty day vacation. We are going to visit our friends in Chania, and go to the archeological sites of Knossos and Faistos. We will end up camping in Gaidouronisi and relax next to the sea. When we return I hope that a new android SDK will be available for download and that one or more devices will be scheduled for release before the end of the year. Next summer I hope that I will be travelling with my android phone.<br />For those who are lucky enough to be on vacation, enjoy the sea and the sun. For those of you who are still working, take care guys, and don't burnout. Take a break, too.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6964266462542162002.post-72124570024244976672008-05-27T14:34:00.000-07:002008-05-27T14:36:40.452-07:00Video for monolithandroid 1.0.3c alphaI decided to put together a video to show graphics, gameplay and music for my game, monolithandroid. Comments are welcome!<br /><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/aYeol_2j9YY&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/aYeol_2j9YY&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6964266462542162002.post-81091762633818417732008-05-24T06:24:00.000-07:002008-05-24T07:05:43.448-07:00Working with textures in android's OpenGL/ES.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_Qfga8utotf4/SDgYVmMyo2I/AAAAAAAAAIU/yPaGyeHy71A/s1600-h/monolithandroid_textures.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_Qfga8utotf4/SDgYVmMyo2I/AAAAAAAAAIU/yPaGyeHy71A/s400/monolithandroid_textures.jpg" alt="" id="BLOGGER_PHOTO_ID_5203936128737125218" border="0" /></a>
<br />As you may recall, I use textures to draw the moon backdrop for my android application, monolithandroid. Originally, I only used one texture and I used some code from Ed Burnette's forthcoming book "Hello, Android". However, I decided to add more textures in order to improve the game's graphics. So I created a class named GLTextures, that can be used to make working with multiple textures easier.
<br />Here's the code:
<br /><code>
<br />package org.teacake.monolith.apk;
<br />import javax.microedition.khronos.opengles.*;
<br />
<br />import android.content.Context;
<br />import android.graphics.Bitmap;
<br />import android.graphics.BitmapFactory;
<br />import java.lang.Integer;
<br />import java.nio.ByteBuffer;
<br />import java.nio.ByteOrder;
<br />import java.nio.IntBuffer;
<br />public class GLTextures {
<br /> public GLTextures(GL10 gl,Context context)
<br /> {
<br /> this.gl = gl;
<br /> this.context = context;
<br /> this.textureMap = new java.util.HashMap<Integer, Integer> ();
<br /> }
<br />
<br /> public void loadTextures()
<br /> {
<br /> int[] tmp_tex = new int[textureFiles.length];
<br /> gl.glGenTextures(textureFiles.length, tmp_tex, 0);
<br /> textures = tmp_tex;
<br /> for(int i=0;i<textureFiles.length;i++)
<br /> {
<br /> Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), textureFiles[i]);
<br /> ByteBuffer bb = extract(bmp);
<br /> // Get a new texture name
<br /> // Load it up
<br /> this.textureMap.put(new Integer(textureFiles[i]),new Integer(i));
<br /> int tex = tmp_tex[i];
<br /> int width = bmp.getWidth();
<br /> int height = bmp.getHeight();
<br /> gl.glBindTexture(GL10.GL_TEXTURE_2D, tex);
<br /> gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA,width, height, 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
<br /> gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
<br /> gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
<br />
<br /> }
<br /> }
<br /> public void setTexture(int id)
<br /> {
<br /> try
<br /> {
<br /> int textureid = this.textureMap.get(new Integer(id)).intValue();
<br /> gl.glBindTexture(GL10.GL_TEXTURE_2D, this.textures[textureid]);
<br />
<br /> }
<br /> catch(Exception e)
<br /> {
<br /> return;
<br /> }
<br /> }
<br /> private static ByteBuffer extract(Bitmap bmp)
<br /> {
<br /> ByteBuffer bb = ByteBuffer.allocateDirect(bmp.height() * bmp.width() * 4);
<br /> bb.order(ByteOrder.BIG_ENDIAN);
<br /> IntBuffer ib = bb.asIntBuffer();
<br /> // Convert ARGB -> RGBA
<br /> for (int y = bmp.height() - 1; y > -1; y--)
<br /> {
<br />
<br /> for (int x = 0; x < bmp.width(); x++)
<br /> {
<br /> int pix = bmp.getPixel(x, bmp.getHeight() - y - 1);
<br /> int alpha = ((pix >> 24) & 0xFF);
<br /> int red = ((pix >> 16) & 0xFF);
<br /> int green = ((pix >> 8) & 0xFF);
<br /> int blue = ((pix) & 0xFF);
<br />
<br /> // Make up alpha for interesting effect
<br />
<br /> //ib.put(red << 24 | green << 16 | blue << 8 | ((red + blue + green) / 3));
<br /> ib.put(red << 24 | green << 16 | blue << 8 | alpha);
<br /> }
<br /> }
<br /> bb.position(0);
<br /> return bb;
<br /> }
<br />
<br />
<br />
<br /> public void add(int resource)
<br /> {
<br /> if(textureFiles==null)
<br /> {
<br /> textureFiles = new int[1];
<br /> textureFiles[0]=resource;
<br /> }
<br /> else
<br /> {
<br /> int[] newarray = new int[textureFiles.length+1];
<br /> for(int i=0;i<textureFiles.length;i++)
<br /> {
<br /> newarray[i]=textureFiles[i];
<br /> }
<br /> newarray[textureFiles.length]=resource;
<br /> textureFiles = newarray;
<br /> }
<br /> }
<br /> private java.util.HashMap <Integer, Integer> textureMap;
<br /> private int[] textureFiles;
<br /> private GL10 gl;
<br /> private Context context;
<br /> private int[] textures;
<br />}
<br /></code>
<br />
<br />So, what can you use this code for?
<br />This code enables you to load resources as textures.
<br />At first you create a GLTextures object like this:
<br /><code>
<br /> GLTextures textures = new GLTextures(gl, context);
<br /></code>
<br />Then you add the resource images you want to use as textures:
<br /><code>
<br /> this.textures.add(R.drawable.moon);
<br /> this.textures.add(R.drawable.earth);
<br /></code>
<br />And then you loadup the textures:
<br /><code>
<br /> textures.loadTextures();
<br /></code>
<br />When you want to use the texture in your OpenGL code, you can use:
<br /><code>
<br /> textures.setTexture(R.drawable.moon);
<br /> .
<br /> .
<br /> //OpenGL drawing code
<br /> .
<br /> .
<br /></code>
<br />Actually the setTexture() method calls glBindTexture() which sets the current texture to the correct one.
<br />Of course, you have to enable textures in your OpenGL code in order to do that! If you want more details and examples study the classes GLThread, Square and GLTextures found at <a href="http://code.google.com/p/monolithandroid">http://code.google.com/p/monolithandroid</a>
<br />As you may find, loading pictures and converting them to textures can take a lot of time, so one improvement that you can make is to create a caching scheme. You can, for example, store the textures in a file, after converting them from a picture for the first time, so the next time the application is run, it will load the textures without having to do a conversion. Happy hacking!Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-6964266462542162002.post-21344185361972213172008-05-18T10:38:00.000-07:002008-05-18T11:20:10.984-07:00A simple class for playing music and sound effects for androidI think that android has a few problems in the area of sound/music playback. After much digging, the only way that I have found to play back music and sound effects is android.media.MediaPlayer. I wanted to add music and sound effects to my game monolithandroid. So I came up with the following class, aptly named SoundSystem. This class uses a separate thread for playback, because we don't want our sound to slowdown our game rendering.<br /><br /><code><br />package org.teacake.monolith;<br />import android.media.MediaPlayer;<br />import android.os.Handler;<br />import android.os.Message;<br />import android.os.SystemClock;<br />public class SoundSystem extends Thread<br />{<br /> public SoundSystem(android.content.Context context)<br /> {<br /> action = SOUND_DO_NOTHING;<br /> lastEventTime= SystemClock.uptimeMillis();<br /> this.context = context;<br /> try<br /> {<br /> musicPlayer = android.media.MediaPlayer.create(context, R.raw.intro);<br /> soundPlayerRotateBlock = android.media.MediaPlayer.create(context, R.raw.rotate);<br /> soundPlayerExplosion = android.media.MediaPlayer.create(context, R.raw.explosion2);<br /> soundPlayerPlaceBlock = android.media.MediaPlayer.create(context, R.raw.place);<br /> musicPlayer.prepare();<br /> musicPlayer.setLooping(1);<br /> musicPlayer.seekTo(0);<br /> soundPlayerRotateBlock.prepare();<br /> soundPlayerRotateBlock.seekTo(0);<br /> soundPlayerExplosion.prepare();<br /> soundPlayerExplosion.seekTo(0);<br /> }<br /> catch(Exception e)<br /> {<br /> }<br /> }<br /> private void startMusic()<br /> {<br /> if(musicPlayer==null)<br /> {<br /> return;<br /> }<br /> try<br /> {<br /> if(musicPlayer.isPlaying())<br /> {<br /> return;<br /> }<br /> else<br /> {<br /> musicPlayer.start();<br /> }<br /> }<br /> catch(Exception e)<br /> {<br /> } <br /> }<br /> private void stopMusic()<br /> {<br /> if(musicPlayer==null)<br /> {<br /> return;<br /> }<br /> try<br /> {<br /> musicPlayer.stop();<br /> }<br /> catch(Exception e)<br /> {<br /> }<br /> }<br /> private void playRotateBlock()<br /> {<br /> int duration=0;<br /> int currentPosition=0;<br /> if(soundPlayerRotateBlock==null)<br /> {<br /> return;<br /> }<br /> try<br /> {<br /> duration=soundPlayerRotateBlock.getDuration();<br /> currentPosition=soundPlayerRotateBlock.getCurrentPosition();<br /> //if(currentPosition==duration-1)<br /> {<br /> soundPlayerRotateBlock.seekTo(0);<br /> soundPlayerRotateBlock.start();<br /> }<br /> }<br /> catch(Exception e)<br /> {<br /> }<br /> }<br /> private void playExplosion()<br /> {<br /> int duration=0;<br /> int currentPosition=0;<br /> if(soundPlayerExplosion==null)<br /> {<br /> return;<br /> }<br /> try<br /> {<br /> duration=soundPlayerExplosion.getDuration();<br /> currentPosition=soundPlayerExplosion.getCurrentPosition();<br /> //if(currentPosition==duration-1)<br /> {<br /> soundPlayerExplosion.seekTo(0);<br /> soundPlayerExplosion.start();<br /> }<br /> }<br /> catch(Exception e)<br /> {<br /> }<br /> }<br /> private void playPlaceBlock()<br /> {<br /> int duration=0;<br /> int currentPosition=0;<br /> if(soundPlayerPlaceBlock==null)<br /> {<br /> return;<br /> }<br /> try<br /> {<br /> duration=soundPlayerPlaceBlock.getDuration();<br /> currentPosition=soundPlayerPlaceBlock.getCurrentPosition();<br /> //if(currentPosition==duration-1)<br /> {<br /> soundPlayerPlaceBlock.seekTo(0);<br /> soundPlayerPlaceBlock.start();<br /> }<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> }<br /> @Override<br /> public void run()<br /> {<br /> while(!done)<br /> {<br /> switch(action)<br /> {<br /> case SOUND_START_MUSIC:<br /> startMusic();<br /> break;<br /> case SOUND_STOP_MUSIC:<br /> stopMusic();<br /> break;<br /> case SOUND_PLAY_ROTATE_BLOCK:<br /> playRotateBlock();<br /> break;<br /> case SOUND_PLAY_EXPLOSION:<br /> playExplosion();<br /> break;<br /> case SOUND_PLAY_PLACE_BLOCK:<br /> playPlaceBlock(); <br /> break;<br /> }<br /> action=SOUND_DO_NOTHING;<br /> try<br /> {<br /> java.lang.Thread.currentThread().sleep(100);<br /> }<br /> catch(Exception e)<br /> {<br /> }<br /> }<br /> }<br /> public boolean done;<br /> public final Handler messageHandler = new Handler() {<br /> @Override<br /> public void handleMessage(Message msg)<br /> {<br /> try<br /> {<br /> action=msg.what;<br /> }<br /> catch(Exception e)<br /> {<br /> }<br /> }<br /> };<br /> private android.content.Context context;<br /> public long lastEventTime;<br /> public int action;<br /> public static final int SOUND_DO_NOTHING=-1;<br /> public static final int SOUND_START_MUSIC=0;<br /> public static final int SOUND_STOP_MUSIC=1;<br /> public static final int SOUND_PLAY_ROTATE_BLOCK=2;<br /> public static final int SOUND_PLAY_EXPLOSION=3;<br /> public static final int SOUND_PLAY_PLACE_BLOCK=4;<br /> private android.media.MediaPlayer musicPlayer;<br /> private android.media.MediaPlayer soundPlayerRotateBlock;<br /> private android.media.MediaPlayer soundPlayerExplosion;<br /> private android.media.MediaPlayer soundPlayerPlaceBlock;<br />}<br /><br /></code><br />As you can see the run() method calls the appropriate method for playing each sound, depending on the message received. How do we send a message to the thread? By using the following code:<br /><br /><code><br /> android.os.Message message = android.os.Message.obtain(soundSystem.messageHandler, SoundSystem.SOUND_START_MUSIC);<br /> message.sendToTarget();<br /></code><br /><br />Notice that we use a MediaPlayer object for each sound. I don't know how heavyweight the MediaPlayer object is, and if it is suitable for use for playing 10's or even 100's of sounds. So that could be a problem if you use a lot of sounds for your game. Also, we use synchronous playback, and that could be a problem, too, if our sounds are long. But since it is only version 1.0, it will be improvedUnknownnoreply@blogger.com0