-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
166 lines (144 loc) · 3.65 KB
/
Copy pathmain.js
File metadata and controls
166 lines (144 loc) · 3.65 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var canvas = new fabric.Canvas('myCanvas');
player_x = 10;
player_y = 10;
block_image_width = 30;
block_image_height = 30;
var player_object= "";
var block_image_object= "";
function player_update()
{
fabric.Image.fromURL("https://i.postimg.cc/zDwfFdYY/player.png", function(Img) {
player_object = Img;
player_object.scaleToWidth(150);
player_object.scaleToHeight(140);
player_object.set({
top:player_y,
left:player_x
});
canvas.add(player_object);
});
}
function new_image(get_image)
{
fabric.Image.fromURL(get_image, function(Img) {
block_image_object = Img;
block_image_object.scaleToWidth(block_image_width);
block_image_object.scaleToHeight(block_image_height);
block_image_object.set({
top:player_y,
left:player_x
});
canvas.add(block_image_object);
});
}
window.addEventListener("keydown", my_keydown);
function my_keydown(e)
{
keyPressed = e.keyCode;
console.log(keyPressed);
if(e.shiftKey == true && keyPressed == '80')
{
console.log("p and shift pressed together");
block_image_width = block_image_width + 10;
block_image_height = block_image_height + 10;
document.getElementById("current_width").innerHTML = block_image_width;
document.getElementById("current_height").innerHTML = block_image_height;
}
if(e.shiftKey && keyPressed == '77')
{
console.log("m and shift pressed together");
block_image_width = block_image_width - 10;
block_image_height = block_image_height - 10;
document.getElementById("current_width").innerHTML = block_image_width;
document.getElementById("current_height").innerHTML = block_image_height;
}
if(keyPressed == '70')
{
new_image('https://i.postimg.cc/hGnyTPLB/ironman-face.png');
console.log("f");
}
if(keyPressed == '66')
{
new_image('https://i.postimg.cc/FscwL6M0/spiderman-body.png');
console.log("b");
}
if(keyPressed == '76')
{
new_image('https://i.postimg.cc/KzF6GDqt/hulk-legs.png');
console.log("l");
}
if(keyPressed == '82')
{
new_image('https://i.postimg.cc/8s8BGtwS/thor-right-hand.png');
console.log("r");
}
if(keyPressed == '72')
{
new_image('https://i.postimg.cc/rw7ckW29/captain-america-left-hand.png');
console.log("h");
}
if(keyPressed == '38')
{
up();
console.log("up");
}
if(keyPressed == '40')
{
down();
console.log("down");
}
if(keyPressed == '37')
{
left();
console.log("left");
}
if(keyPressed == '39')
{
right();
console.log("right");
}
}
function up()
{
if(player_y >=0)
{
player_y = player_y - block_image_height;
console.log("block image height = " + block_image_height);
console.log("When Up arrow key is pressed, X = " + player_x + " , Y = "+player_y);
canvas.remove(player_object);
player_update();
}
}
function down()
{
if(player_y <=500)
{
player_y = player_y + block_image_height;
console.log("block image height = " + block_image_height);
console.log("When Down arrow key is pressed, X = " + player_x + " , Y = "+player_y);
canvas.remove(player_object);
player_update();
}
}
function left()
{
if(player_x >0)
{
player_x = player_x - block_image_width;
console.log("block image width = " + block_image_width);
console.log("When Left arrow key is pressed, X = " + player_x + " , Y = "+player_y);
canvas.remove(player_object);
player_update();
}
}
function right()
{
if(player_x <=850)
{
player_x = player_x + block_image_width;
console.log("block image width = " + block_image_width);
console.log("When Right arrow key is pressed, X = " + player_x + " , Y = "+player_y);
canvas.remove(player_object);
player_update();
}
}