-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDog.cpp
48 lines (38 loc) · 1.1 KB
/
Dog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Dog.h"
#include <iostream>
Dog::Dog()
{
xdir = -25;//how far it moves for each time out
ydir = 0;
image.load(":/icons/images/Dog_Left.png");//loads image from file.
rect = image.rect();
rect.setWidth(80);//sets the dimensions of the Dog
rect.setHeight(38);
}
Dog::Dog(int xSpeed)
{
xdir = xSpeed;//how far it moves for each time out
ydir = 0;
image.load(":/icons/images/Dog_Left.png");//loads image from file.
rect = image.rect();
rect.setWidth(80);//sets the dimensions of the Dog
rect.setHeight(38);
}
Dog::~Dog() {//destructor.
}
void Dog::autoMove()//moves to the left
{
if (rect.left() <= 0){
xdir = -xdir;
image.load(":/icons/images/Dog_Right.png");
//rect = image.mirrored(true,false).rect();
//rect.setWidth(40);rect.setHeight(20);
}
else if(rect.right() > 400){
xdir = -xdir;
image.load(":/icons/images/Dog_Left.png");
//rect = image.mirrored(true,false).rect();
//rect.setWidth(40);rect.setHeight(20);
}
rect.translate(xdir, ydir);
}