| 
1 | 1 | whale = {}  | 
2 | 2 | 
 
  | 
3 | 3 | function whale.load()  | 
4 |  | - whale.isHurt = false  | 
5 |  | - whale.hurtRemaining = 0  | 
6 |  | - whale.x = 400  | 
7 |  | - whale.y = 300  | 
8 |  | - whale.dir = 0  | 
9 |  | - whale.speed = 50  | 
10 |  | - whale.hunger = 100  | 
11 |  | - whale.health = 100  | 
12 |  | - local whale_sprite = love.graphics.newImage("assets/textures/whale.png")  | 
13 |  | - whale_sprite:setFilter("nearest", "nearest")  | 
14 |  | -whale_anim = newAnimation(whale_sprite, 32, 64, 1, 3)  | 
15 |  | - local whale_spr = love.graphics.newImage("assets/textures/whale.png")  | 
16 |  | - whale_spr:setFilter("nearest", "nearest")  | 
17 |  | -whale_anim = newAnimation(whale_spr, 32, 64, 1, 3)  | 
 | 4 | + whale.isHurt = false  | 
 | 5 | + whale.hurtRemaining = 0  | 
 | 6 | + whale.x = 400  | 
 | 7 | + whale.y = 300  | 
 | 8 | + whale.dir = 0  | 
 | 9 | + whale.speed = 50  | 
 | 10 | + whale.hunger = 100  | 
 | 11 | + whale.health = 100  | 
 | 12 | + local whale_sprite = love.graphics.newImage("assets/textures/whale.png")  | 
 | 13 | + --whale_sprite:setFilter("nearest", "nearest")  | 
 | 14 | +--whale_anim = newAnimation(whale_sprite, 32, 64, 1, 3)  | 
18 | 15 | end  | 
19 | 16 | 
 
  | 
20 | 17 | function whale.draw()  | 
21 |  | - if whale.isHurt then  | 
22 |  | - love.graphics.setColor(255, 0, 0)  | 
23 |  | - else  | 
24 |  | - love.graphics.setColor(255, 255, 255)  | 
25 |  | - end  | 
26 |  | -   | 
27 |  | -if whale.dir == "n" then  | 
28 |  | - whale_anim:draw(whale.x, whale.y, 0, 1, 1, 16, 32)  | 
29 |  | -elseif whale.dir == "s" then  | 
30 |  | - whale_anim:draw(whale.x, whale.y, 3.1415926535898, 1, 1, 16, 32)  | 
31 |  | -elseif whale.dir == "w" then  | 
32 |  | - whale_anim:draw(whale.x, whale.y, -1.5707963267949, 1, 1, 16, 32)  | 
33 |  | -elseif whale.dir == "e" then  | 
34 |  | - whale_anim:draw(whale.x, whale.y, 1.5707963267949, 1, 1, 16, 32)  | 
35 |  | -elseif whale.dir == "ne" then  | 
36 |  | - whale_anim:draw(whale.x, whale.y, 0.78539816339745, 1, 1, 16, 32)  | 
37 |  | -elseif whale.dir == "se" then  | 
38 |  | - whale_anim:draw(whale.x, whale.y, 2.3561944901923, 1, 1, 16, 32)  | 
39 |  | -elseif whale.dir == "sw" then  | 
40 |  | - whale_anim:draw(whale.x, whale.y, -2.3561944901923, 1, 1, 16, 32)  | 
41 |  | -elseif whale.dir == "nw" then  | 
42 |  | - whale_anim:draw(whale.x, whale.y, -0.78539816339745, 1, 1, 16, 32)  | 
43 |  | -else  | 
44 |  | - whale_anim:draw(whale.x, whale.y, 0, 1, 1, 16, 32)  | 
 | 18 | + if whale.isHurt then  | 
 | 19 | + love.graphics.setColor(255, 0, 0)  | 
 | 20 | + else  | 
 | 21 | + love.graphics.setColor(255, 255, 255)  | 
 | 22 | + end  | 
 | 23 | + | 
 | 24 | +local whaleImage = love.graphics.newImage("assets/textures/simple_whale.png")  | 
 | 25 | + | 
 | 26 | +if debug == true then  | 
 | 27 | +love.graphics.print("atan2: ", 10, 40)  | 
 | 28 | +love.graphics.print(angle, 100, 40)  | 
 | 29 | +love.graphics.print("MouseX: ", 10, 60)  | 
 | 30 | +love.graphics.print(mouseX, 100, 60)  | 
 | 31 | +love.graphics.print("MouseY: ", 10, 80)  | 
 | 32 | +love.graphics.print(mouseY, 100, 80)  | 
45 | 33 | end  | 
 | 34 | + | 
 | 35 | +love.graphics.draw(whaleImage, whale.x, whale.y, angle, 1, 1, 16, 32)  | 
 | 36 | + | 
46 | 37 | end  | 
47 | 38 | 
 
  | 
48 | 39 | function whale.update(dt)  | 
49 |  | - --[[ swingers.update()  | 
50 |  | - if swingers.checkGesture() then  | 
51 |  | -	gesture = swingers.getExtGesture()  | 
52 |  | - end ]]  | 
53 |  | -   | 
54 |  | - --[[ if gesture[1] ~= nil then  | 
55 |  | - whale.dir = gesture[1]  | 
56 |  | - end  | 
57 |  | -   | 
58 |  | -if whale.dir == "n" then  | 
59 |  | - whale.y = whale.y - (whale.speed*dt)  | 
60 |  | - elseif whale.dir == "s" then  | 
61 |  | - whale.y = whale.y + (whale.speed*dt)  | 
62 |  | -elseif whale.dir == "w" then  | 
63 |  | - whale.x = whale.x - (whale.speed*dt)  | 
64 |  | - elseif whale.dir == "e" then  | 
65 |  | - whale.x = whale.x + (whale.speed*dt)  | 
66 |  | - elseif whale.dir == "ne" then  | 
67 |  | - whale.y = whale.y - math.sin(whale.speed*dt)  | 
68 |  | - whale.x = whale.x + math.sin(whale.speed*dt)  | 
69 |  | - elseif whale.dir == "se" then  | 
70 |  | - whale.y = whale.y + math.sin(whale.speed*dt)  | 
71 |  | - whale.x = whale.x + math.sin(whale.speed*dt) -- THIS IS WRONG!  | 
72 |  | - elseif whale.dir == "sw" then  | 
73 |  | - whale.y = whale.y + math.sin(whale.speed*dt)  | 
74 |  | - whale.x = whale.x - math.sin(whale.speed*dt)  | 
75 |  | - elseif whale.dir == "nw" then  | 
76 |  | - whale.y = whale.y - math.sin(whale.speed*dt)  | 
77 |  | - whale.x = whale.x - math.sin(whale.speed*dt)  | 
78 |  | - end ]]  | 
79 |  | - whale_anim:update(dt)  | 
80 |  | ---swingers.checkError()  | 
 | 40 | +--whale_anim:update(dt)  | 
 | 41 | + | 
 | 42 | +mouseX = love.mouse.getX()  | 
 | 43 | +mouseY = love.mouse.getY()  | 
 | 44 | + | 
 | 45 | +angle = math.atan2(mouseY-whale.y, mouseX-whale.x)  | 
 | 46 | + | 
81 | 47 | 
 
  | 
82 | 48 | 
 
  | 
83 | 49 | if whale.x < 0 then  | 
 | 
0 commit comments