{"id":88,"date":"2026-04-17T13:48:12","date_gmt":"2026-04-17T13:48:12","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/r_najim\/?p=88"},"modified":"2026-04-17T13:48:12","modified_gmt":"2026-04-17T13:48:12","slug":"friday-april-17-2026","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/r_najim\/2026\/04\/17\/friday-april-17-2026\/","title":{"rendered":"Friday April 17, 2026"},"content":{"rendered":"\n<p class=\"has-text-align-left\">              <strong>This Free Friday I am working on a project on YouTube a Snake Game part 2.<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=QFvqStqPCRU\">https:\/\/www.youtube.com\/watch?v=QFvqStqPCRU<\/a><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code> class MAIN:\n    def __init__(self):\n        self.snake = SNAKE()\n        self.fruit = FRUIT()\n\n    def update(self):\n        self.snake.move_snake()\n\n    def draw_elements(self):\n            self.fruit.draw_fruit()\n            self.snake.draw_fruit()\n\n    def check_collisiion(self):\n        if self.fruit.pos == self.snake.body&#91;0]:\n            self.fruit.randomize()\n            self.snake.add_block()<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>This is a third class called main it will contain the entire game logic and the snake and fruit object<\/strong>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class FRUIT:\n  def __init__(self):\n        self.randomize()\n\n  def draw_fruit(self):\n      fruit_rect = pygame.Rect(int(self.pos.x * cell_size),int(self.pos.y * cell_size),cell_size,cell_size)\n      pygame.draw.rect(screen,(126,166,114),fruit_rect)\n\n  def randomize(self):\n      self.x = random.randint(0,cell_number - 1)\n      self.y = random.randint(10,cell_number - 1)\n      self.pos = Vector2(self.x,self.y)\n      <\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>This is a more updated code of the class fruit.<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class SNAKE:\n    def __init__(self):\n        self.body = &#91;Vector2(5,10), Vector2(6,10), Vector2(7,10)]\n        self.direction = Vector2(1,0)\n        self.new_block = False\n\n    def draw_snake(self):\n        for block in self.body:\n            x_pos -=int(block.x * cell_size)\n            y_pos -= int(block.y * cell_size)\n            block_rect = pygame.rect(x_pos,y_pos,cell_size,cell_size)\n            pygame.draw.rect(screen,(183,191,122),block_rect)\n\n    def move_snake(self):\n        if self.new_block == True:\n            body_copy = self.body&#91;:]\n            body_copy.insert(0,body_copy&#91;0] + self.direction)\n            self.body = body_copy&#91;:]\n            self.new_block = False\n        else:\n            body_copy = self.body&#91;:-1]\n            body_copy.insert(0,body_copy&#91;0] + self.direction)\n            self.body = body_copy&#91;:]\n\n    def add_block(self):\n        self.new_block = True<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>This is a more updated code of the class snake.<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            pygame.quit()\n            sys.exit()\n            if event.type == SCREEN_UPDATE:\n                main_game.update()\n            if event.type == pygame.KEYDOWN:\n                if event.key == pygame.K_UP:\n                    main_game.snake.direction = Vector2(0,-1)\n                if event.key == pygame.K_RIGHT:\n                    main_game.snake.direction = Vector2(1,0)\n                if event.key == pygame.K_DOWN:\n                    main_game.snake.direction = Vector2(0,1)\n                if event.key == pygame.K_LEFT:\n                    main_game.snake.direction = Vector2(-1,0)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>This part of the code is for the snake to move up, down and  right, to left.<\/strong><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This Free Friday I am working on a project on YouTube a Snake Game part 2.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/comments?post=88"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":89,"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/posts\/88\/revisions\/89"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/r_najim\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}