Skip to content

Commit

Permalink
class 1 on sonic running class
Browse files Browse the repository at this point in the history
  • Loading branch information
jackoconnordev committed Oct 15, 2023
1 parent 934dc6a commit ff5649d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion classes/sonic-speed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<h1>Press an arrow key to move Sonic</h1>
<img id="sonic-running" src="./assets/sonic-running.gif">

<script src="./script.js"></script>
<!-- <script src="./script.js"></script> -->
<script src="./script2.js"></script>
</body>

</html>

14 changes: 9 additions & 5 deletions classes/sonic-speed/script.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
// Select sonicGif in DOM so we can do things to it with javascript
const stepSize = 100;
const stepSize = 200;
const sonicGif = document.getElementById('sonic-running');

// Create functions which move Sonic around page using margins
function moveSonicDown() {
sonicGif.style.marginTop = (parseInt(window.getComputedStyle(sonicGif).marginTop) + stepSize) + 'px';
const currentMarginTop = parseInt(window.getComputedStyle(sonicGif).marginTop);
sonicGif.style.marginTop = (currentMarginTop + stepSize) + 'px';
}

function moveSonicUp() {
sonicGif.style.marginTop = (parseInt(window.getComputedStyle(sonicGif).marginTop) - stepSize) + 'px';
const currentMarginTop = parseInt(window.getComputedStyle(sonicGif).marginTop);
sonicGif.style.marginTop = (currentMarginTop - stepSize) + 'px';
}

function moveSonicRight() {
sonicGif.style.marginLeft = (parseInt(window.getComputedStyle(sonicGif).marginLeft) + stepSize) + 'px';
const currentMarginLeft = parseInt(window.getComputedStyle(sonicGif).marginLeft);
sonicGif.style.marginLeft = (currentMarginLeft + stepSize) + 'px';
}

function moveSonicLeft() {
sonicGif.style.marginLeft = (parseInt(window.getComputedStyle(sonicGif).marginLeft) - stepSize) + 'px';
const currentMarginLeft = parseInt(window.getComputedStyle(sonicGif).marginLeft);
sonicGif.style.marginLeft = (currentMarginLeft - stepSize) + 'px';
}

// Add key press event listener. Only do things for arrow keys
Expand Down
7 changes: 6 additions & 1 deletion classes/sonic-speed/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#sonic-running {
height: 100px;
height: 200px;
aspect-ratio: auto;
}

html {
/* come back to this */
background-image: url('https://stock.adobe.com/search?k=racetrack+cartoon');
}

0 comments on commit ff5649d

Please sign in to comment.