HTML5 Game Programming with enchant.js by Brandon McInnis Ryo Shimizu Hidekazu Furukawa Ryohei Fushimi Ryo Tanaka & Kevin Kratzer
Author:Brandon McInnis, Ryo Shimizu, Hidekazu Furukawa, Ryohei Fushimi, Ryo Tanaka & Kevin Kratzer
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
Using Collision Detection for Movement
Now the map in our game exists, but we need a way to move our character around in accordance with the data. Maps in enchant.js support a method for finding out if a specific position on the map is able to be walked on or not. This is used to determine if the character can walk on the tile or not. Do the following to implement it: 1. Under the line player.anim = [...];//Down, type in the code in Listing 4-9.
Listing 4-9.âCharacter Movement with Map Collision Detection
player.addEventListener(Event.ENTER_FRAME, function() {
//Move up
if (game.input.up) {
player.dir = DIR_UP;
player.y -= 4;
if (map.hitTest(player.x + 16, player.y + 32)) player.y += 4;
}
//Move down
else if (game.input.down) {
player.dir = DIR_DOWN;
player.y += 4;
if (map.hitTest(player.x + 16, player.y + 32)) player.y -= 4;
}
//Move left
else if (game.input.left) {
player.dir = DIR_LEFT;
player.x -= 4;
if (map.hitTest(player.x + 16, player.y + 32)) player.x += 4;
}
//Move right
else if (game.input.right) {
player.dir = DIR_RIGHT;
player.x += 4;
if (map.hitTest(player.x + 16, player.y + 32)) player.x -= 4;
}
//Frame setting
if (!game.input.up && !game.input.down &&
!game.input.left && !game.input.right) player.age = 1;//Standing Still
player.frame = player.anim[player.dir * 4 + (player.age % 4)];
});
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9926)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9802)
The Mikado Method by Ola Ellnestam Daniel Brolund(9787)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8310)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7790)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7772)
Grails in Action by Glen Smith Peter Ledbrook(7705)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7566)
Windows APT Warfare by Sheng-Hao Ma(6937)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6668)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6424)
Kotlin in Action by Dmitry Jemerov(5074)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4323)
Solidity Programming Essentials by Ritesh Modi(4055)
Functional Programming in JavaScript by Mantyla Dan(4044)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3846)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3790)
The Ultimate iOS Interview Playbook by Avi Tsadok(3768)
