Skip to content

Instantly share code, notes, and snippets.

@alexlau811
Created April 21, 2015 18:54
Show Gist options
  • Save alexlau811/6e12d9e8270404114226 to your computer and use it in GitHub Desktop.
Save alexlau811/6e12d9e8270404114226 to your computer and use it in GitHub Desktop.
Code Avengers Sample Code
// Help message
new Game.Text('Warrior! Grab all', 50, 0);
new Game.Text('Hong Kong 1 Dollar to save the world!!', 50, 25);
// Setup player & guns
function createPlayer1() {
var player = new Game.Player(0, 0, '/image/game/player1.png');
player.onKilled = createPlayer1;
var gun = new Game.Gun();
gun.setPositions([new Point(5, -25), new Point(25, 15), new Point(-5, 25), new Point(-20, 15)]);
player.gun = gun;
}
function createPlayer2() {
var player = new Game.Player(350, 550, '/image/game/player2.png', 'w', 'a', 's', 'd');
player.onKilled = createPlayer2;
var gun = new Game.Gun();
gun.setPositions([new Point(5, -25), new Point(25, 15), new Point(-5, 25), new Point(-20, 15)]);
player.gun = gun;
player.fireKey ='e'; // little hack to enable player 2 gun
}
createPlayer1();
createPlayer2();
// Background
new Game.BackgroundImage('/image/game/tile/1.png')
// Some constants
var OFFSET_X = 100;
var OFFSET_Y = 200;
var SIZE = 50;
// Setup rock
new Game.Obstacle(OFFSET_X + SIZE * -2, OFFSET_Y + SIZE * -1)
new Game.Obstacle(OFFSET_X + SIZE * -1, OFFSET_Y + SIZE * -1)
new Game.Obstacle(OFFSET_X + SIZE * 1, OFFSET_Y + SIZE * -1)
new Game.Obstacle(OFFSET_X + SIZE * 2, OFFSET_Y + SIZE * -1)
new Game.Obstacle(OFFSET_X + SIZE * 3, OFFSET_Y + SIZE * -1)
new Game.Obstacle(OFFSET_X + SIZE * 4, OFFSET_Y + SIZE * -1)
new Game.Obstacle(OFFSET_X + SIZE * 5, OFFSET_Y + SIZE * -1)
new Game.Obstacle(OFFSET_X + SIZE * 6, OFFSET_Y + SIZE * -1)
new Game.Obstacle(OFFSET_X + SIZE * -2, OFFSET_Y + SIZE * 5)
new Game.Obstacle(OFFSET_X + SIZE * -1, OFFSET_Y + SIZE * 5)
new Game.Obstacle(OFFSET_X + SIZE * 0, OFFSET_Y + SIZE * 5)
new Game.Obstacle(OFFSET_X + SIZE * 1, OFFSET_Y + SIZE * 5)
new Game.Obstacle(OFFSET_X + SIZE * 2, OFFSET_Y + SIZE * 5)
new Game.Obstacle(OFFSET_X + SIZE * 3, OFFSET_Y + SIZE * 5)
new Game.Obstacle(OFFSET_X + SIZE * 5, OFFSET_Y + SIZE * 5)
new Game.Obstacle(OFFSET_X + SIZE * 6, OFFSET_Y + SIZE * 5)
// Setup coins image
Game.GoodItem.source = 'http://wisardcoin.altervista.org/_Asia/_Coin_HongKong/Large/HongKong_1d_2_o.gif';
// Game.BadItem.source = 'http://wisardcoin.altervista.org/_Asia/_Coin_HongKong/Large/HongKong_50c_2_o.gif'; // hard
Game.BadItem.source = 'http://wisardcoin.altervista.org/_Asia/_Coin_HongKong/Large/HongKong_20c_2_o.gif';
// Setup coins
var i;
for (i = 0; i < 5 * 5; i++) {
var bad = Game.random(0, 1);
if (bad < 0.5) {
new Game.GoodItem(OFFSET_X + Math.floor(i / 5) * SIZE, OFFSET_Y + (i % 5) * SIZE)
} else {
new Game.BadItem(OFFSET_X + Math.floor(i / 5) * SIZE, OFFSET_Y + (i % 5) * SIZE)
}
}
new Game.Scoreboard()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment