@@ -3,15 +3,56 @@ function intit() {
3
3
pen = canvas . getContext ( '2d' )
4
4
W = canvas . width = 1000
5
5
H = canvas . height = 500
6
+ cw = 70
7
+ //fighter
8
+ fighter = new Image ( )
9
+ fighter . src = "./assets/superhero.png"
10
+
11
+ //virus image
12
+ virus_img = new Image ( )
13
+ virus_img . src = "./assets/v1.png"
14
+
15
+ //virus class
16
+ class virusclass {
17
+ constructor ( x , y , direction , speed ) {
18
+ this . x = x
19
+ this . y = y
20
+ this . direction = direction
21
+ this . speed = speed
22
+ this . update_virus = function ( ) {
23
+ if ( this . y > H - cw ) {
24
+ this . direction = "up"
25
+ this . speed *= - 1
26
+ } else if ( this . y < 0 ) {
27
+ this . direction = "down"
28
+ this . speed *= - 1
29
+ }
30
+ this . y += this . speed
31
+ }
32
+
33
+ }
34
+ }
35
+ virus1 = new virusclass ( W / 3 - 100 , 0 , "down" , 30 )
36
+ virus2 = new virusclass ( W / 2 , H - cw , "up" , 30 )
37
+ virus3 = new virusclass ( W - 200 , 0 , "down" , 30 )
6
38
}
7
39
8
40
9
41
function draw ( ) {
10
-
42
+ // console.log("in draw")
43
+ // console.log(virus.y)
44
+ pen . clearRect ( 0 , 0 , W , H )
45
+ pen . drawImage ( fighter , 20 , 200 , cw , cw )
46
+ pen . drawImage ( virus_img , virus1 . x , virus1 . y , cw , cw )
47
+ pen . drawImage ( virus_img , virus2 . x , virus2 . y , cw , cw )
48
+ pen . drawImage ( virus_img , virus3 . x , virus3 . y , cw , cw )
11
49
}
12
50
13
51
function update ( ) {
14
-
52
+ // console.log("in update")
53
+ virus1 . update_virus ( )
54
+ virus2 . update_virus ( )
55
+ virus3 . update_virus ( )
15
56
}
16
57
17
58
function gameloop ( ) {
0 commit comments