aboutsummaryrefslogtreecommitdiffstats
path: root/src/objecttypes.js
blob: e9f69f0537f19e9d46f11c3986c2bce87e0f6ca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// bg
function Background(x_offset) {
	GameObject.call(this, "bg");
	this.x_offset = x_offset;
	this.initPosition();

	this.x_speed = 10
	this.objectType = "background";
}

Background.prototype = Object.create(GameObject.prototype);
Background.prototype.constructor = Background;

Background.prototype.update = function() {
	this.sprite.position.x -= this.x_speed

	if (this.sprite.position.x < -Settings.STAGE_WIDTH) {
		this.sprite.position.x = Settings.STAGE_WIDTH - this.x_speed;
	}
}

Background.prototype.initPosition = function() {
	this.sprite.position.x = this.x_offset;
	this.sprite.position.y = 0;
	this.sprite.anchor.x = 0;
	this.sprite.anchor.y = 0;
}

var bg1 = new Background(0);
var bg2 = new Background(Settings.STAGE_WIDTH);

// logo
var logo1 = new GameObject("logo1");
logo1.update = function() {
	this.sprite.rotation = 0.1 * Math.sin(0.001 * Date.now());
}

logo1.initPosition = function() {
	logo1.sprite.position.y = Settings.STAGE_WIDTH * 0.2
}
logo1.initPosition();

// press space to play text
var logo2 = new GameObject("logo2");
logo2.initPosition = function() {
	this.sprite.position.y = Settings.STAGE_HEIGHT * 0.6;
}
logo2.initPosition();

// background box for score display at gameover
var scoreBg = new PIXI.Graphics();
scoreBg.beginFill(0xAAAAAA, 1.0);
scoreBg.visible = false;

// score display
var scoreText = new PIXI.Text("W", { font: '35px Arial', fill: 'white', align: 'left' });
scoreText.visible = false;
scoreText.update = function() {
	this.text = "Tomia vältelty " + player.score + " tuntia";
}

scoreText.moveToCorner = function() {
	this.position.x = Settings.STAGE_WIDTH * 0.5;
	this.position.y = Settings.STAGE_HEIGHT * 0.05;
}

scoreText.moveToCenter = function() {
	this.position.x = Settings.STAGE_WIDTH * 0.5 - this.width / 2;
	this.position.y = Settings.STAGE_HEIGHT * 0.5 - this.height / 2;
}
scoreText.moveToCorner();

// gameover screen title text
var gameOverText = new PIXI.Text("Onneksi olkoon!", { font: '35px Arial', fill: 'black', align: 'center' });
gameOverText.visible = false;
gameOverText.position.x = Settings.STAGE_WIDTH * 0.5 - gameOverText.width / 2;;
gameOverText.position.y = Settings.STAGE_HEIGHT * 0.4 - gameOverText.height / 2;;

// move the gameover bg box now that we now the width of the text
var yDiff = scoreText.position.y - gameOverText.position.y + gameOverText.height;
scoreBg.drawRect(Settings.STAGE_WIDTH * 0.2, gameOverText.position.y - 10, Settings.STAGE_WIDTH * 0.6, -yDiff);

// integral sign
function Integral(y) {
	GameObject.call(this, "int");

	this.initPosition()
	this.sprite.position.y = y;

	this.speed = -10;
	this.objectType = "integral";

}

Integral.prototype = Object.create(GameObject.prototype);
Integral.prototype.constructor = Integral;

Integral.prototype.initPosition = function() {
	this.sprite.position.x = Settings.STAGE_WIDTH + this.sprite.width;
	this.sprite.position.y = Settings.STAGE_HEIGHT + this.sprite.height;
	this.sprite.anchor.x = 0;
	this.sprite.anchor.y = 0.5;
}

Integral.prototype.update = function() {
	this.sprite.position.x += this.speed;
}