1 Replies - 373 Views - Last Post: 11 April 2012 - 04:20 AM Rate Topic: -----

#1 jone kim  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 36
  • Joined: 07-January 10

make an object move out of window and again appear from another side

Posted 10 April 2012 - 08:09 PM

I am learning pygame and making snake game.
I've used polygon to make the snake.

How can I make it get out of one side and come back from another side?

I've a window size of (700,700). Suppose the snake get out from (350,0) then it should appear from (350,700) or it get out from (700,350) then it should appear from (0,350). How can I do it?

import random, pygame, sys 
from pygame.locals import *
import time

pygame.init()
windowSurface = pygame.display.set_mode((700,700),0,32)
# drawing snake
pygame.draw.polygon( windowSurface, RED, ( (210,350),(220,360),(230,350),(240,360),(250,350),(260,360),(270,350),(280,360),(290,350),(300,360),(300,355),(290,345),(280,355),(270,345),(260,355),(250,345),(240,355),(230,345),(220,355),(210,350) ))


This post has been edited by jone kim: 10 April 2012 - 08:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: make an object move out of window and again appear from another side

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 450
  • View blog
  • Posts: 795
  • Joined: 08-June 10

Re: make an object move out of window and again appear from another side

Posted 11 April 2012 - 04:20 AM

The traditional method for doing this relies on a technique called clipping. You would first clip the snake to get the first half of the polygon, then draw a second polygon on the other end of the screen. A good google for "2D clipping" should give you more than enough information on the topic, but it requires some good math.

A way to cheat at this would be to instead just draw 5 snakes, one at each: (x, y), (x + 700, y), (x - 700, y), (x, y + 700), (x, y - 700). Whenever x or y are greater than 700 or less than zero, you add or subtract 700 accordingly.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1