Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
lib/Donkey/Donkey.cpp@12:50a7abf21f18, 2019-05-08 (annotated)
- Committer:
 - Kern_EL17KJTF
 - Date:
 - Wed May 08 01:28:25 2019 +0000
 - Revision:
 - 12:50a7abf21f18
 - Parent:
 - 11:b288d01533cc
 - Child:
 - 15:9e8d1b6fe81e
 
Game basics fully working
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Kern_EL17KJTF | 10:28575a6eaa13 | 1 | /* | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 2 | ELEC2645 Project | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 3 | Donkey.cpp | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 4 | Class file for Donkey Kong in Donkey Kong game. | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 5 | */ | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 6 | #include "Donkey.h" | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 7 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 8 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 9 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 10 | Donkey::Donkey() | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 11 | { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 12 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 13 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 14 | Donkey::~Donkey() | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 15 | { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 16 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 17 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 18 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 19 | int donkeykong_x = 0; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 20 | int donkeykong_y = 32; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 21 | int donkey_kong_speed = 10; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 22 | int donkey_direction; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 23 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 24 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 25 | void Donkey::donkeykong_movement(Gamepad &pad, N5110 &lcd) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 26 | int game_dk_walking_right_1[16][16] = { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 27 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 28 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 29 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 30 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 31 | {1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 32 | {1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 33 | {1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 34 | {1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 35 | {1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 36 | {1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 37 | {1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 38 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 39 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 40 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 41 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 42 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 43 | }; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 44 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 45 | int game_dk_walking_left_1[16][16] = { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 46 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 47 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 48 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 49 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 50 | {1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 51 | {1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 52 | {1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 53 | {1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 54 | {1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 55 | {1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 56 | {1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 57 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 58 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 59 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 60 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 61 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 62 | }; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 63 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 64 | int game_dk_stationary[16][16] = { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 65 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 66 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 67 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 68 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 69 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 70 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 71 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 72 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 73 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 74 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 75 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 76 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 77 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 78 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 79 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 80 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,}, | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 81 | }; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 82 | donkey_direction = pad.get_direction(); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 83 | if (donkey_direction == NE || donkey_direction == E || donkey_direction == SE) { | 
| Kern_EL17KJTF | 12:50a7abf21f18 | 84 | donkeykong_x = donkeykong_x + 3; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 85 | lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_walking_right_1); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 86 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 87 | else if (donkey_direction == NW || donkey_direction == W || donkey_direction == SW) { | 
| Kern_EL17KJTF | 12:50a7abf21f18 | 88 | donkeykong_x = donkeykong_x - 3; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 89 | lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_walking_left_1); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 90 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 91 | else { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 92 | lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_stationary); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 93 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 94 | lcd.refresh(); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 95 | if (donkeykong_x > 68) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 96 | donkeykong_x = 68; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 97 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 98 | if (donkeykong_x < 0) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 99 | donkeykong_x = 0; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 100 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 101 | } | 
| Kern_EL17KJTF | 11:b288d01533cc | 102 |