{"id":519,"date":"2019-11-30T11:31:48","date_gmt":"2019-11-30T11:31:48","guid":{"rendered":"https:\/\/www.danielparente.net\/en\/2019\/11\/30\/code-a-frogger-style-road-crossing-game-wireframe-27\/"},"modified":"2019-11-30T11:31:48","modified_gmt":"2019-11-30T11:31:48","slug":"code-a-frogger-style-road-crossing-game-wireframe-27","status":"publish","type":"post","link":"https:\/\/www.danielparente.net\/en\/2019\/11\/30\/code-a-frogger-style-road-crossing-game-wireframe-27\/","title":{"rendered":"Code a Frogger-style road-crossing game | Wireframe #27"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div>\n<p><em>Guide a frog across busy roads and rivers. <strong>Mark Vanstone<\/strong> shows you how to code a simple remake of Konami\u2019s arcade game, Frogger.<\/em><\/p>\n<div id=\"attachment_54653\" style=\"width: 910px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-54653 size-full\" src=\"https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/frogger-screenshot.png\" alt=\"\" width=\"900\" height=\"1028\" srcset=\"https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/frogger-screenshot.png 900w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/frogger-screenshot-219x250.png 219w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/frogger-screenshot-768x877.png 768w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/frogger-screenshot-500x571.png 500w\" sizes=\"(max-width: 900px) 100vw, 900px\"\/><\/p>\n<p class=\"wp-caption-text\">Konami\u2019s original Frogger: so iconic, it even featured in a 1998 episode of Seinfeld.<\/p>\n<\/div>\n<h2>Frogger<\/h2>\n<p>Why did the frog cross the road? Because Frogger would be a pretty boring game if it didn\u2019t. Released in 1981 by Konami, the game appeared in assorted bars, sports halls, and arcades across the world, and became an instant hit. The concept was simple: players used the joystick to move a succession of frogs from the bottom of the screen to the top, avoiding a variety of hazards \u2013 cars, lorries, and later, the occasional crocodile. Each frog had to be safely manoeuvred to one of five alcoves within a time limit, while extra points were awarded for eating flies along the way.<\/p>\n<p>Before Frogger, Konami mainly focused on churning out clones of other hit arcade games like Space Invaders and Breakout; Frogger was one of its earliest original ideas, and the simplicity of its concept saw it ported to just about every home system available at the time. (Ironically, Konami\u2019s game would fall victim to repeated cloning by other developers.) Decades later, developers still take inspiration from it; Hipster Whale\u2019s Crossy Road turned Frogger into an endless running game; earlier this year, Konami returned to the creative well with Frogger in Toy Town, released on Apple Arcade.<\/p>\n<h2>Code your own Konami Frogger<\/h2>\n<p>We can recreate much of Frogger\u2019s gameplay in just a few lines of Pygame Zero code. The key elements are the frog\u2019s movement, which use the arrow keys, vehicles that move across the screen, and floating objects \u2013 logs and turtles \u2013 moving in opposite directions. Our background graphic will provide the road, river, and grass for our frog to move over. The frog\u2019s movement will be triggered from an <code>on_key_down()<\/code> function, and as the frog moves, we switch to a second frame with legs outstretched, reverting back to a sitting position after a short delay. We can use the inbuilt Actor properties to change the image and set the angle of rotation.<\/p>\n<div id=\"attachment_54656\" style=\"width: 827px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-54656\" src=\"https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/Screen1.png\" alt=\"\" width=\"817\" height=\"638\" srcset=\"https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/Screen1.png 817w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/Screen1-300x234.png 300w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/Screen1-768x600.png 768w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/Screen1-500x390.png 500w\" sizes=\"(max-width: 817px) 100vw, 817px\"\/><\/p>\n<p class=\"wp-caption-text\">In our Frogger homage, we move the frog with the arrow keys to avoid the traffic, and jump onto the floating logs and turtles.<\/p>\n<\/div>\n<p>For all the other moving elements, we can also use Pygame Zero Actors; we just need to make an array for our cars with different graphics for the various rows, and an array for our floating objects in the same way.<br \/>In our <code>update()<\/code> function, we need to move each Actor according to which row it\u2019s in, and when an Actor disappears off the screen, set the x coordinate so that it reappears on the opposite side.<\/p>\n<p>Handling the logic of the frog moving across the road is quite easy; we just check for collision with each of the cars, and if the frog hits a car, then we have a squashed frog. The river crossing is a little more complicated. Each time the frog moves on the river, we need to make sure that it\u2019s on a floating Actor. We therefore check to make sure that the frog is in collision with one of the floating elements, otherwise it\u2019s game over.<\/p>\n<p>There are lots of other elements you could add to the example shown here: the original arcade game provided several frogs to guide to their alcoves on the other side of the river, while crocodiles also popped up from time to time to add a bit more danger. Pygame Zero has all the tools you need to make a fully functional version of Konami\u2019s hit.<\/p>\n<div id=\"attachment_54655\" style=\"width: 2076px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-54655 size-full\" src=\"https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/wf27-code.jpg\" alt=\"\" width=\"2066\" height=\"1541\" srcset=\"https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/wf27-code.jpg 2066w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/wf27-code-300x225.jpg 300w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/wf27-code-768x573.jpg 768w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/wf27-code-500x373.jpg 500w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/wf27-code-1448x1080.jpg 1448w\" sizes=\"(max-width: 2066px) 100vw, 2066px\"\/><\/p>\n<p class=\"wp-caption-text\">Here\u2019s Mark\u2019s code, which gets a Frogger homage running in Python. To get it working on your system, you\u2019ll first need to <a href=\"http:\/\/wfmag.cc\/pgzero\" target=\"_blank\" rel=\"noopener\">install Pygame Zero<\/a>. And to <a href=\"http:\/\/wfmag.cc\/wfmag27\" target=\"_blank\" rel=\"noopener\">download the full code, go here.<\/a><\/p>\n<\/div>\n<h2>Get your copy of Wireframe issue 27<\/h2>\n<p>You can read more features like this one in <a href=\"http:\/\/wfmag.cc\/issues\" target=\"_blank\" rel=\"noopener\">Wireframe issue 27<\/a>, available now at Tesco, WHSmith, all good independent UK newsagents, and the Raspberry Pi Store, Cambridge.<\/p>\n<p>Or you can buy Wireframe directly from Raspberry Pi Press \u2014 delivery is available worldwide. And if you\u2019d like a handy digital version of the magazine, you can also <a href=\"https:\/\/wireframe.raspberrypi.org\/issues\/25\" target=\"_blank\" rel=\"noopener\">download issue 27 for free<\/a> in PDF format.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-54660\" src=\"https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/01_WF27-FLAT.png\" alt=\"\" width=\"744\" height=\"978\" srcset=\"https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/01_WF27-FLAT.png 744w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/01_WF27-FLAT-190x250.png 190w, https:\/\/www.raspberrypi.org\/app\/uploads\/2019\/11\/01_WF27-FLAT-500x657.png 500w\" sizes=\"(max-width: 744px) 100vw, 744px\"\/><\/p>\n<p>Make sure to follow Wireframe on\u00a0<a href=\"http:\/\/twitter.com\/wireframemag\" target=\"_blank\" rel=\"noopener\">Twitter<\/a>\u00a0and\u00a0<a href=\"http:\/\/www.facebook.com\/wireframemag\" target=\"_blank\" rel=\"noopener\">Facebook<\/a>\u00a0for updates and exclusive offers and giveaways. Subscribe on the <a href=\"http:\/\/wfmag.cc\/subscribe\" target=\"_blank\" rel=\"noopener\">Wireframe website<\/a> to save up to 49% compared to newsstand pricing!<\/p>\n<\/div>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><br \/>\n<br \/>[ad_2]<br \/>\n<br \/><a href=\"https:\/\/www.raspberrypi.org\/blog\/code-a-frogger-style-road-crossing-game-wireframe-27\/\" target=\"_blank\" rel=\"noopener\">Source link <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Guide a frog across busy roads and rivers. Mark Vanstone shows you how to code a simple remake of Konami\u2019s arcade game, Frogger. Konami\u2019s original Frogger: so iconic, it even featured in a 1998 episode of Seinfeld. Frogger Why did the frog cross the road? Because Frogger would be a pretty boring game if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":520,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-519","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"blocksy_meta":[],"jetpack_featured_media_url":"https:\/\/e928cfdc7rs.exactdn.com\/info\/uploads\/sites\/3\/2019\/11\/Code-a-Frogger-style-road-crossing-game-Wireframe-27.png?strip=all","jetpack_shortlink":"https:\/\/wp.me\/p2TFCd-8n","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/posts\/519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/comments?post=519"}],"version-history":[{"count":0,"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/posts\/519\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/media\/520"}],"wp:attachment":[{"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/media?parent=519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/categories?post=519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.danielparente.net\/en\/wp-json\/wp\/v2\/tags?post=519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}