package org.drools.games.invaders4;

import org.drools.games.KeyPressed
import org.drools.games.Run
import org.drools.games.invaders.Ship
import org.drools.games.GameUI
import org.drools.games.invaders.InvadersConfiguration

global GameUI ui
global InvadersConfiguration conf


import javax.imageio.ImageIO
import java.awt.Color;
import java.awt.Graphics

dialect "mvel"

rule DrawShip agenda-group "Draw" when
  s : Ship()
      Run()
then
   g = ui.getGraphics();
   g.setColor( Color.BLACK ); // background
   g.fillRect( s.x - s.dx - s.dy, s.y, conf.shipWidth, conf.shipHeight ); // restore the previous blackground
   g.drawImage( ImageIO.read( GameUI.class.getResource( "invaders/ship.gif" ) ), s.x, s.y, s.width, s.height, ui.getCanvas() );
end