6 changed files with 117 additions and 2 deletions
@ -0,0 +1,58 @@ |
|||||
|
@keyframes cactusMov { |
||||
|
0%{ |
||||
|
left: 580px; |
||||
|
} |
||||
|
|
||||
|
100%{ |
||||
|
left: -20px; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@keyframes jump { |
||||
|
0%{ |
||||
|
top: 150px; |
||||
|
} |
||||
|
30%{ |
||||
|
top: 130px; |
||||
|
} |
||||
|
50%{ |
||||
|
top: 80px; |
||||
|
} |
||||
|
80%{ |
||||
|
top: 130px; |
||||
|
} |
||||
|
100%{ |
||||
|
top: 150px; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.game { |
||||
|
width: 600px; |
||||
|
height: 200px; |
||||
|
border-bottom: 1px solid #000; |
||||
|
margin: auto; |
||||
|
} |
||||
|
|
||||
|
#putis { |
||||
|
width: 50px; |
||||
|
height: 50px; |
||||
|
background-image: url(../../../assets/images/downGame/dino.png); |
||||
|
background-size: 50px 50px; |
||||
|
position: relative; |
||||
|
top: 150px; |
||||
|
} |
||||
|
|
||||
|
#cactus { |
||||
|
width: 20px; |
||||
|
height: 40px; |
||||
|
background-image: url(../../../assets/images/downGame/cactus.png); |
||||
|
background-size: 20px 40px; |
||||
|
position: relative; |
||||
|
top: 110px; |
||||
|
left: 580px; |
||||
|
animation: cactusMov 1s infinite linear; |
||||
|
} |
||||
|
|
||||
|
.jump { |
||||
|
animation: jump 0.3s linear; |
||||
|
} |
@ -0,0 +1,53 @@ |
|||||
|
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; |
||||
|
import {ActionService} from "../../services/action.service"; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'app-downgame-page', |
||||
|
styleUrls: ['./downgame-page.component.scss'], |
||||
|
template: ` |
||||
|
<div class="game" (click)="jump()"> |
||||
|
<div id="putis" #putis [ngClass]="{'jump':isJump}"></div> |
||||
|
<div id="cactus" #cactus></div> |
||||
|
</div> |
||||
|
` |
||||
|
}) |
||||
|
export class DowngamePageComponent implements OnInit { |
||||
|
|
||||
|
constructor(private actionService: ActionService) { } |
||||
|
|
||||
|
@ViewChild('putis', {static: false}) |
||||
|
putis!: ElementRef; |
||||
|
|
||||
|
@ViewChild('cactus', {static: false}) |
||||
|
cactus!: ElementRef; |
||||
|
|
||||
|
isAlive!: NodeJS.Timeout; |
||||
|
|
||||
|
isJump: boolean = false; |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.createGame(); |
||||
|
} |
||||
|
|
||||
|
createGame() { |
||||
|
this.isAlive = setInterval (() => { |
||||
|
//console.log(this.putis, window.getComputedStyle(this.putis.nativeElement).top)
|
||||
|
|
||||
|
let putisTop = this.putis ? parseInt(window.getComputedStyle(this.putis.nativeElement).top) : 0; |
||||
|
let cactusLeft = this.cactus ? parseInt(window.getComputedStyle(this.cactus.nativeElement).left) : 0; |
||||
|
|
||||
|
if (cactusLeft < 50 && cactusLeft > 0 && putisTop >= 140) { |
||||
|
alert("GAME OVER!") |
||||
|
} |
||||
|
}, 10) |
||||
|
} |
||||
|
|
||||
|
jump() { |
||||
|
if (!this.isJump) { |
||||
|
this.isJump = true; |
||||
|
setTimeout(() => { |
||||
|
this.isJump = false; |
||||
|
}, 300); |
||||
|
} |
||||
|
} |
||||
|
} |
After Width: | Height: | Size: 7.7 KiB |
After Width: | Height: | Size: 15 KiB |
Loading…
Reference in new issue