{"id":168,"date":"2026-05-08T15:11:59","date_gmt":"2026-05-08T15:11:59","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/d_harkless\/?p=168"},"modified":"2026-05-08T15:11:59","modified_gmt":"2026-05-08T15:11:59","slug":"free-friday-5-8-26","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/d_harkless\/2026\/05\/08\/free-friday-5-8-26\/","title":{"rendered":"Free Friday 5-8-26"},"content":{"rendered":"\n<p>Today in class, I continued my space war game. I added a enemy, game border, and collisions.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"955\" height=\"803\" src=\"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-content\/uploads\/2026\/05\/image-1.png\" alt=\"\" class=\"wp-image-169\" style=\"aspect-ratio:1.1893015950268788;width:661px;height:auto\" srcset=\"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-content\/uploads\/2026\/05\/image-1.png 955w, https:\/\/theroyalscode.com\/students\/d_harkless\/wp-content\/uploads\/2026\/05\/image-1-300x252.png 300w, https:\/\/theroyalscode.com\/students\/d_harkless\/wp-content\/uploads\/2026\/05\/image-1-768x646.png 768w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><\/figure>\n\n\n\n<p>This is the code for the enemy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Enemy(Sprite):\n    def __init__(self, spriteshape, color, startx, starty):\n        Sprite.__init__(self, spriteshape, color, startx, starty)\n        self.speed = 6 \n        self.setheading(random.randint(0,360))       \n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>enemy = Enemy(\"circle\", \"red\", -100, 0) \n<\/code><\/pre>\n\n\n\n<p>This is the code that keeps track of things that are important in the game and the game border.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Game():\n    def __init__(self):\n        self.level = 1\n        self.score = 0\n        self.state = \"playing\"\n        self.pen = turtle.Turtle()\n        self.lives = 3 \n\n    def draw_border(self):\n        #Draw border\n        self.pen.speed(0)\n        self.pen.color(\"white\")\n        self.pen.pensize(3)\n        self.pen.penup()\n        self.pen.goto(-300, 300)\n        self.pen.pendown()\n        for side in range(4):\n            self.pen.fd(600)\n            self.pen.rt(90)\n        self.pen.penup()\n        self.pen.ht()\n<\/code><\/pre>\n\n\n\n<p>This is the code that keeps the enemy and player from going off screen<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if self.xcor() > 290:\n            self.setx(290)\n            self.rt(60)\n\n        if self.xcor() &lt;-290:\n            self.setx(-290)\n            self.rt(60)\n\n        if self.ycor() > 290:\n            self.sety(290)\n            self.rt(60)\n\n        if self.ycor() &lt;-290:\n            self.sety(-290)\n            self.rt(60)<\/code><\/pre>\n\n\n\n<p>This is the code for collisions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> def is_collision(self, other): \n        if (self.xcor() >= (other.xcor() - 20)) and \\\n        (self.xcor() &lt;= (other.xcor() + 20)) and \\\n        (self.xcor() >= (other.xcor() - 20)) and \\\n        (self.xcor() &lt;= (other.xcor() + 20)): \n            return True\n        else:\n            return False    <\/code><\/pre>\n\n\n\n<p>This is the code that checks for collisions<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if player.is_collision(enemy):\n        x = random.randint(-250, 250)\n        y = random.randint(-250, 250)\n        enemy.goto(x, y)\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today in class, I continued my space war game. I added a enemy, game border, and collisions. This is the code for the enemy This is the code that keeps track of things that are important in the game and the game border. This is the code that keeps the enemy and player from going [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-168","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/posts\/168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/comments?post=168"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/posts\/168\/revisions"}],"predecessor-version":[{"id":170,"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/posts\/168\/revisions\/170"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/media?parent=168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/categories?post=168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/d_harkless\/wp-json\/wp\/v2\/tags?post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}