Well I can basically show what I’ve done:
/**
* @author Daniel
*/
var upkey = false;
var rightkey = false;
var downkey = false;
var leftkey = false;
var leftMouse = false;
var rightMouse = false;
var bullet: Bullet[];
var gamelogics = Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame {
time: 1ms
action: function() {
if((robot.translateY + robot.height) < 450){
robot.translateY+=.4;
}
if(upkey){
robot.translateY-=.5;
}
else if(downkey){
robot.translateY-=.4;
}
if(rightkey){
robot.translateX += .2;
}
else if(leftkey){
robot.translateX -= .2;
}
for(b in bullet){
if(b.translateX > 5000){
delete b from bullet;
}
else
b.translateX+= 1;
}
}
}
}
def robot = new Robot;
public class RenderWindow extends Scene{
init{
this.content = [
Group{
onKeyPressed: function(e:KeyEvent){
if (e.code == KeyCode.VK_DOWN) {
downkey = true;
} else if (e.code == KeyCode.VK_UP) {
upkey = true;
}else if (e.code == KeyCode.VK_LEFT) {
leftkey = true;
}else if (e.code == KeyCode.VK_RIGHT) {
rightkey = true;
}
} // onKeyPressed
onKeyReleased: function(e: KeyEvent){
if (e.code == KeyCode.VK_DOWN) {
downkey = false;
} else if (e.code == KeyCode.VK_UP) {
upkey = false;
}else if (e.code == KeyCode.VK_LEFT) {
leftkey = false;
}else if (e.code == KeyCode.VK_RIGHT) {
rightkey = false;
}
} // onKeyReleased
onMousePressed: function(e:MouseEvent){
if(e.button == MouseButton.PRIMARY){
leftMouse = true;
}
if(e.button == MouseButton.SECONDARY){
rightMouse = true;
}
};
onMouseReleased: function(e:MouseEvent){
if(e.button == MouseButton.PRIMARY){
leftMouse = false;
var b = Bullet{
translateY : robot.translateY;
translateX : robot.translateX;
};
insert b into bullet;
}
if(e.button == MouseButton.SECONDARY){
rightMouse = false;
}
};
content: bind[
Rectangle {
x: 0,
y: 0,
width: 500,
height: 500,
fill: Color.LIGHTGRAY
},
robot
bullet
]
}
];
gamelogics.play();
}
}
public class Robot extends CustomNode{
public-read var width = 30;
public-read var height = 30;
override function create():Node{
Rectangle {
x: 0,
y: 0,
width: 30,
height: 30,
fill: Color.STEELBLUE
cache: true
};
};
}
public class Bullet extends CustomNode{
var r = Random{};
override function create():Node{
Group{
content: [
Line {
var temp = r.nextInt(10);
startX: r.nextInt(10)
startY: temp
endX: r.nextInt(100)
endY: temp
strokeWidth: 1
stroke: Color.SLATEGRAY
}
]
effect: MotionBlur {
angle: 10
radius: 20
}
cache: true
}
}
}
Stage {
title: "Robot Game"
width: 500
height: 500
scene: RenderWindow{}
}
Just working around with the basics first. If you have any tips to improve this or point out what I’ve done wrong, that would be great. Seems to lag a little when I fire a lot of bullets, and its not the motion blur that’s causing it.