1

I'm trying to make a boat that moves on a curved line but I only managed to get it to move from one point to another (Straight Line). I want to make it move in a curve like when a boat moves around a country, because it can not go over land.

class virus(object):
    moveRight = [image.load("res/virusMove/right1.png"),
                 image.load("res/virusMove/right2.png"),
                 image.load("res/virusMove/right3.png"),
                 image.load("res/virusMove/right4.png"),
                 image.load("res/virusMove/right5.png"),
                 image.load("res/virusMove/right6.png"),
                 image.load("res/virusMove/right7.png"),
                 image.load("res/virusMove/right8.png"),
                 image.load("res/virusMove/right5.png"),]
    moveLeft = [image.load("res/virusMove/left1.png"),
                image.load("res/virusMove/left2.png"),
                image.load("res/virusMove/left3.png"),
                image.load("res/virusMove/left4.png"),
                image.load("res/virusMove/left5.png"),
                image.load("res/virusMove/left6.png"),
                image.load("res/virusMove/left7.png"),
                image.load("res/virusMove/left8.png"),
                image.load("res/virusMove/left5.png")]

    def __init__(self, x, y, width, height, end):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.path = [x, end]
        self.moveUnits = 0
        self.vel = 5

    def draw(self, screen):
        self.move()
        if self.moveUnits +1 >= 24:
            self.moveUnits = 0
        if self.vel > 0:
            screen.blit (self.moveRight[self.moveUnits//3], (self.x, self.y))
            self.moveUnits += 1
        else:
            screen.blit (self.moveLeft[self.moveUnits//3], (self.x, self.y))
                self.moveUnits += 1
    def move(self):
        if self.vel > 0:
            if self.x < self.vel + self.path[1]:
                self.x += self.vel
            else:
                self.vel = self.vel * -1
                self.x += self.vel
                self.moveUnits = 0
        else:
            if self.x > self.path[0] - self.vel:
                self.x += self.vel
            else:
                self.vel = self.vel * -1
                self.x += self.vel
                self.moveUnits = 0               

and then I did something like

def drawScreen():
    virus.draw(screen)
virus = virus(100, 640, 64, 64, 750) 

and then i put the drawScreen in my running loop

Lucas Scott
  • 455
  • 3
  • 10
ChewyCarrot
  • 222
  • 2
  • 12
  • Whats wrong with what you currently have, and what is the changed desired outcome? – code11 May 24 '18 at 13:00
  • right now, i can get it from point a to point b, which is just a straight line, I would like to be able to move it along a curved path. – ChewyCarrot May 24 '18 at 20:24
  • You could try using quadratics to calculate position movement. Just cut it off when you reach your point. – Mercury Platinum May 24 '18 at 21:43
  • how would I do so? My main objective is that the object is a boat, and I dont want it to travel over land(my map), so the lines can be "boxy" and not completely curved. – ChewyCarrot May 25 '18 at 01:15
  • 1
    You don't really need just moving in a curve then, what you need is a path finding algorithm and that can be anywhere from very simple to very complicated. Have a google search for the pac-man path finding algorithm for example. – ChatterOne May 25 '18 at 07:21

0 Answers0