Markus Ritberger

Web Developer, PHP Trainer, Android Developer

next page

Canvas Floodfill

written by: markus
April 19, 2012

In the last days i worked on my new canvas-floodfill project for html5.
It is like the paint bucket in MS paint or a bit like Magic Wand in Photoshop.
You can fill a selected field with a defined color and a limited tolerance.

the project is written in javascript, works without any extra plugins or frameworks, but sadly only in modern browsers.
The projectsite is based on modernizr, boilerplate an code igniter.

The design is based on some other modern javascript sites.

Try it out under floodfill.ritberger.at


Posted in: JavaScript

risIRCo goes online!

written by: markus
March 28, 2012

risIRCo is an IRC game based on Blobfish, i made it for one of my favourite IRC channels.

Features

  • random user placement.
  • growth based on channel activity.
  • AJAX tooltips (click on a color on the map).
  • defeated users will start on a new location.
  • incrementel map rendering with ImageMagik
  • daily map backups
  • fast sqlite backend

maybe i try to render the map live with the html5 canvas tag in the future.. maybe..


Posted in: PHP

Stopped ArtilleryWar

written by: markus
March 15, 2012

6 months have passed since the last ArtillerWar update in which I have not written a simple line of code…
To much work in my day job, a new side job , new girlfriend and a lack of motivation causes me to stop the ArtilleryWar project and focus on other projects.

Projects still in queue:

  • risIRCo – An IRC game based on Blobfish
  • Blobfish – An IRC bot on PHP-CLI
  • jQPong – A jQuery Pong port

Posted in: ArtilleryWar

PHP based non-blocking IRC-bot Template

written by: markus
November 16, 2011

In the last few months i figured out that a lot of people out there, have huge problems when it comes to code an IRC bot non-blocking.

In fact… the solution is pretty simple:

$socket = fsockopen( $server, $port);
stream_set_blocking( $socket , 0 );

php.net/manual/en/function.stream-set-blocking.php

Here is a example of a simple bot class:

IrcBotTemplate Class (948.0 B)

Without an nonblocking stream our bot would freeze as long there is no response from the server. All the timebased stuff happens in the time_things() method:

An instance of this class would look something like this:

#!/usr/bin/php -q

require_once(IrcBotTemplate.php);  
$bot = new IrcBotTemplate('www.example.com','nickname','#channel');

And the whole class for download muffles:

 
/*
 * IrcBotTemplate 
 * autor:   Markus Ritberger
 * email:   contact@ritberger.at
 * date:    16.11.2011
 * desription:
 *      IrcBotTemplate is a exampleclass of a small  
 *      non-blocking php-cli IRC-bot
 * 
 */
class IrcBotTemplate{
    private $server =       NULL;
    private $port =         NULL;
    private $nick =         NULL;
    private $user =         NULL;
    private $channel =      NULL;
    private $start =        NULL;
    private $last_action =  NULL;
    private $socket =       NULL;
    private $alive =        FALSE;
    private $line_limit =   8192;
    private $time_format =  'H:i:s';
 
    public function __construct($server,$nick,$channel,$port='6667',
       $user='username hostname servername realname') {
 
       $this->server = $server;
       $this->nick = $nick;
       $this->channel = $channel;
       $this->port = $port;
       $this->user = $user;
       $this->start = time();
       $this->last_action = $this->start; 
 
       $this->connect();
       sleep(1);
       $this->set_user($this->user);
       sleep(1);
       $this->set_nick($this->nick);
       sleep(1);
       $this->join($channel);
       $this->process();
    }
 
    private function connect(){
        $this->socket = fsockopen($this->server, $this->port);
        stream_set_blocking( $this->socket , 0 );
        $this->alive = TRUE;
    }
 
    private function set_user($userline){
        fputs($this->socket,"USER {$userline}".PHP_EOL);
    }
 
    private function set_nick($nick){
        fputs($this->socket,"NICK {$nick}".PHP_EOL);
    }
 
    private function join($channel){
        fputs($this->socket,"JOIN {$channel}".PHP_EOL);
    }
 
    private function process(){
        while($this->alive) {
            while($data = fread($this->socket,$this->line_limit)) {
                $this->response($data);
            }
            $this->time_things();
        }
    }
 
    private function response($data){
        echo $data;
        if(preg_match('~^PINGs*(.*)~', $data, $matches)){
            $this->pong($matches[1]);
        }
    }
 
    private function pong($ping){
        fputs($this->socket,"PONG {$ping}".PHP_EOL);
    }
 
    /*
     * put your time based code here. 
     * for example the current time every second
     */
    private function time_things(){
 
        if(time() > $this->last_action){
            $this->last_action = time();
                fputs($this->socket,"PRIVMSG {$this->channel} :"
                        .date($this->time_format,time()).PHP_EOL);
                echo date($this->time_format,time()).PHP_EOL;
        }
    }
}

Posted in: PHP

Artillery War Alpha v0.1.4

written by: markus
September 25, 2011

There was a funny bug this week: recursive grenade splinters.

 

Features

  • added area of effect for explosions
  • added grenade splinters + splinter sprite
  • implemented maximum number of bullets at the same time (performance)
  • removed the manual camera control
  • camera follows the level progress dynamically
  • fixed the sprite-reload bug on resume state (thx @TheMaRv for bug report)
  • fixed incorrect sprite position on pause state
  • removed modechance button.
  • slowly disappearing dead units.

Unifixed

  • totally inbalanced weapons as a result of new implemented grenade splinters
  • incorrect toucheven resolution on large screens (tablets)

ArtilleryWar (1.9 MiB)


Posted in: ArtilleryWar