Guest User

Monster Sad! Source

a guest
Aug 24th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.31 KB | None | 0 0
  1. --monster sad for ludum dare 33
  2. --by logan buchanan
  3. --username:ninebears
  4.  
  5. up = true
  6. down = true
  7. left = true
  8. right = true
  9.  
  10.  
  11. max_life = 100
  12.  
  13.  
  14. --0 = start
  15. --1 = game
  16. --2 = life loss
  17. --3 = happy loss
  18. --4 = victory
  19. state = 0
  20.  
  21. --happiness value of objects
  22. house_worth = 5
  23. fence_worth = 1
  24. plant_worth = 2
  25. tree_worth = 2
  26. statue_worth= 20
  27.  
  28. timer = 0
  29.  
  30.  
  31. function make_object(x, y)
  32.  
  33. local o = {}
  34. o.x = x
  35. o.y = y
  36. o.dx = 0
  37. o.dy = 0
  38. o.w = 8
  39. o.h = 8
  40. o.sprite = 0
  41. o.type = null
  42. o.cleared = false
  43.  
  44. return o
  45.  
  46. end
  47.  
  48.  
  49. function make_player(x, y)
  50.  
  51. local pl = make_object(x, y)
  52.  
  53. pl.life = 100
  54. pl.happy = 50
  55. pl.sprite = 0
  56. pl.type = 2
  57. pl.dx = 1.5
  58. pl.dy = 1.5
  59.  
  60. return pl
  61.  
  62. end
  63.  
  64. function make_enemy(x, y, type)
  65.  
  66. local en = make_object(x, y)
  67.  
  68. en.type = type
  69. --peasant
  70. if(type == 0) then
  71. en.sprite = 64
  72. end
  73. --knight
  74. if(type == 1) then
  75. en.sprite = 80
  76. end
  77.  
  78. return en
  79.  
  80. end
  81.  
  82. function make_king(x, y, type)
  83.  
  84. local k = make_enemy(x, y, type)
  85.  
  86. k.sprite = 67
  87.  
  88. add(enemies,k)
  89.  
  90. end
  91.  
  92. function make_blood(x, y, type)
  93.  
  94. local bl = make_object(x, y)
  95. bl.type = type
  96. bl.maxframes = 6
  97.  
  98. if(bl.type == 0) then
  99. bl.init = 96
  100. bl.frame =96
  101. end
  102. if(bl.type == 1) then
  103. bl.init = 112
  104. bl.frame =112
  105. end
  106.  
  107. return bl
  108.  
  109. end
  110.  
  111. function draw_blood(bl)
  112.  
  113. if(timer%3 == 0) bl.frame +=1
  114. if(bl.frame>=bl.init+bl.maxframes) then
  115. del(blood, bl)
  116. end
  117. spr(bl.frame, bl.x, bl.y, 1,1)
  118.  
  119. end
  120.  
  121. function draw_player(pl)
  122.  
  123. if(timer%10 == 0) pl.sprite += 1
  124.  
  125. if(pl.sprite>= 2) pl.sprite = 0
  126.  
  127. spr(pl.sprite, pl.x-pl.w/2, pl.y-pl.h/2, 1,1)
  128.  
  129. end
  130.  
  131. function draw_enemy(en)
  132.  
  133. if(en.sprite == 67) then
  134. spr(en.sprite, en.x-en.w/2, en.y-en.h/2,1,1)
  135. return
  136. end
  137.  
  138. if(en.type == 0)then
  139. if(timer%5 == 0) en.sprite +=1
  140. if(en.sprite>66) en.sprite =64
  141. end
  142. if(en.type == 1)then
  143. if(timer%5 == 0) en.sprite +=1
  144. if(en.sprite>82) en.sprite =80
  145. end
  146.  
  147. spr(en.sprite, en.x-en.w/2, en.y-en.h/2,1,1)
  148.  
  149. end
  150.  
  151. function move_enemy(en)
  152.  
  153. if(en.type == 0)then
  154. player_pos = make_object(player.x, player.y)
  155. en_pos = make_object(en.x, en.y)
  156.  
  157. sub_vec(player_pos,en_pos)
  158. normalize(player_pos)
  159. mult_vec(player_pos, 0.4)
  160. nullify_en_movement_peasant(en,player_pos)
  161. sub_vec(en, player_pos)
  162. end
  163. if(en.type == 1) then
  164.  
  165. player_pos = make_object(player.x, player.y)
  166. en_pos = make_object(en.x, en.y)
  167.  
  168. sub_vec(player_pos,en_pos)
  169. normalize(player_pos)
  170. nullify_en_movement_knight(en,player_pos)
  171. add_vec(en, player_pos)
  172.  
  173. end
  174.  
  175. end
  176.  
  177. function move_player(pl)
  178.  
  179. if left then
  180. pl.x += -pl.dx
  181. end
  182. if right then
  183. pl.x += pl.dx
  184. end
  185. if up then
  186. pl.y += -pl.dy
  187. end
  188. if down then
  189. pl.y += pl.dy
  190. end
  191.  
  192. end
  193.  
  194. function spawn_enemy(x, y, type)
  195.  
  196. en = make_enemy(x, y, type)
  197.  
  198. add(enemies, en)
  199.  
  200. end
  201.  
  202. function fill_room()
  203.  
  204. local x = curr_room.x
  205. local y = curr_room.y
  206.  
  207. local xpos = x*128
  208. local ypos = y*128
  209.  
  210. --all enemy spawns
  211. --don't judge me i didn't
  212. --have time to make a
  213. --better solution
  214.  
  215. --top left corner
  216. if(x==0 and y==0)then
  217. spawn_enemy(xpos+50, ypos+50,0)
  218. end
  219. --statue room
  220. if(x==1 and y==0)then
  221.  
  222. spawn_enemy(xpos+32, ypos+64,1)
  223. spawn_enemy(xpos+64, ypos+64,1)
  224. spawn_enemy(xpos+64, ypos+32,1)
  225. spawn_enemy(xpos+64, ypos+96,1)
  226. end
  227. --castle entrance
  228. if(x==2 and y==0)then
  229. spawn_enemy(xpos+64, ypos+32,1)
  230. spawn_enemy(xpos+32, ypos+64,1)
  231. spawn_enemy(xpos+96, ypos+64,1)
  232.  
  233. end
  234. --kings hall
  235. if(x==3 and y==0)then
  236. spawn_enemy(xpos+25, ypos+40,1)
  237.  
  238. spawn_enemy(xpos+25, ypos+88,1)
  239. make_king(xpos+96,ypos+64,0)
  240. end
  241. --top right
  242. if(x==4 and y==0)then
  243.  
  244. spawn_enemy(xpos+86, ypos+40,0)
  245. end
  246. --left beside village
  247. if(x==0 and y==1)then
  248. spawn_enemy(xpos+45, ypos+52,0)
  249.  
  250. end
  251. --left village (tree grove)
  252. if(x==1 and y==1)then
  253.  
  254. spawn_enemy(xpos+40, ypos+40,0)
  255. spawn_enemy(xpos+40, ypos+85,0)
  256. spawn_enemy(xpos+55, ypos+100,0)
  257. spawn_enemy(xpos+100, ypos+30,0)
  258. spawn_enemy(xpos+90, ypos+110,0)
  259.  
  260. end
  261. --central village
  262. if(x==2 and y==1)then
  263. spawn_enemy(xpos+64, ypos+64,0)
  264. spawn_enemy(xpos+20, ypos+50,0)
  265. spawn_enemy(xpos+100, ypos+50,0)
  266. spawn_enemy(xpos+30, ypos+90,0)
  267. spawn_enemy(xpos+65, ypos+90,0)
  268.  
  269. end
  270. --right village
  271. if(x==3 and y==1)then
  272.  
  273. spawn_enemy(xpos+45, ypos+45,0)
  274. spawn_enemy(xpos+90, ypos+45,0)
  275. spawn_enemy(xpos+64, ypos+96,0)
  276. end
  277. --solo house right village
  278. if(x==4 and y==1)then
  279.  
  280. spawn_enemy(xpos+30, ypos+35,0)
  281. end
  282. --bottom left village
  283. if(x==0 and y==2)then
  284.  
  285. end
  286. --tree house grove
  287. if(x==1 and y==2)then
  288. spawn_enemy(xpos+64, ypos+50,0)
  289.  
  290. end
  291. --village entrance
  292. if (x == 2 and y == 2)then
  293. spawn_enemy(xpos+45,ypos+50, 1)
  294. spawn_enemy(xpos+75, ypos+50,1)
  295. end
  296. --farms outside village
  297. if(x==3 and y==2)then
  298. spawn_enemy(xpos+45, ypos+60,0)
  299. spawn_enemy(xpos+85, ypos+60,0)
  300.  
  301. end
  302. --bottom right village
  303. if(x==4 and y==2)then
  304.  
  305. end
  306.  
  307.  
  308. end
  309.  
  310. function check_move_inputs()
  311.  
  312. if btn(0,0) then
  313. left = true else left = false
  314. end
  315. if btn(1,0) then
  316. right = true else right = false
  317. end
  318. if btn(2,0) then
  319. up = true else up = false
  320. end
  321. if btn(3,0) then
  322. down = true else down = false
  323. end
  324.  
  325. end
  326.  
  327. function check_solids_player(pl,layer)
  328.  
  329. --checks left
  330. if(fget(mget(flr((pl.x/8 - ((pl.w/2)+1)/8)), flr(pl.y/8)), layer)) then
  331. if(layer == 0 and pl.type == 2)left = false
  332. if(layer == 0 and pl.type == 0 or pl.type == 1) return 0
  333. if(layer == 1) then
  334.  
  335. spr_num = mget(flr((pl.x/8 - ((pl.w/2)+1)/8)), flr(pl.y/8))
  336.  
  337. set_sprite(pl, 0, spr_num)
  338. sfx(0)
  339. end
  340. end
  341. --checks right
  342. if(fget(mget(flr((pl.x/8 + ((pl.w/2))/8)), flr(pl.y/8)), layer)) then
  343. if(layer == 0 and pl.type == 2)right = false
  344. if(layer == 0 and pl.type == 0 or pl.type == 1) return 1
  345. if(layer == 1) then
  346.  
  347. spr_num = mget(flr((pl.x/8 + ((pl.w/2))/8)), flr(pl.y/8))
  348.  
  349. set_sprite(pl, 1, spr_num)
  350. sfx(0)
  351. end
  352. end
  353. --checks up
  354. if(fget(mget(flr(pl.x/8), flr((pl.y/8 - ((pl.h/2)+1)/8))), layer)) then
  355.  
  356. if(layer == 0 and pl.type == 2)up = false
  357. if(layer == 0 and pl.type == 0 or pl.type == 1) return 2
  358. if(layer == 1)then
  359.  
  360. spr_num = mget(flr(pl.x/8), flr((pl.y/8 - ((pl.h/2)+1)/8)))
  361.  
  362. set_sprite(pl, 2, spr_num)
  363. sfx(0)
  364. end
  365. end
  366. --checks down
  367. if(fget(mget(flr(pl.x/8), flr((pl.y/8 + ((pl.h/2))/8))), layer)) then
  368. if(layer == 0 and pl.type == 2)down = false
  369. if(layer == 0 and pl.type == 0 or pl.type == 1) return 3
  370. if(layer == 1) then
  371. --here you can change the sprite on the map
  372. --live trees to dead trees!!
  373. --buildings o destroyed buildings!
  374. spr_num = mget(flr(pl.x/8), flr((pl.y/8 + ((pl.h/2))/8)))
  375.  
  376. set_sprite(pl, 3, spr_num)
  377. sfx(0)
  378. end
  379. end
  380.  
  381. end
  382.  
  383. function set_sprite_down(pl, n)
  384. mset(flr(pl.x/8), flr((pl.y/8 + ((pl.h/2))/8)), n)
  385. end
  386.  
  387. function set_sprite_up(pl, n)
  388. mset(flr(pl.x/8), flr((pl.y/8 - ((pl.h/2)+1)/8)), n)
  389. end
  390.  
  391. function set_sprite_right(pl, n)
  392. mset(flr((pl.x/8 + ((pl.w/2))/8)), flr(pl.y/8), n)
  393. end
  394.  
  395. function set_sprite_left(pl, n)
  396. mset(flr((pl.x/8 - ((pl.w/2)+1)/8)), flr(pl.y/8), n)
  397. end
  398.  
  399. function set_sprite(pl, dir, n)
  400. --left
  401. if(dir == 0) then
  402. --tree top
  403. if(spr_num == 23) then
  404. set_sprite_left(pl, 24)
  405. player.happy += tree_worth
  406.  
  407. end
  408.  
  409. --tree bottom
  410. if(spr_num == 39) then
  411. set_sprite_left(pl, 40)
  412. player.happy += tree_worth
  413. end
  414. --houses
  415. if(spr_num >=70 and spr_num<=72)then
  416. set_sprite_left(pl,spr_num+3)
  417. player.happy += house_worth
  418. end
  419. --houses
  420. if(spr_num >=86 and spr_num<=88)then
  421. set_sprite_left(pl,spr_num+3)
  422. player.happy += house_worth
  423. end
  424. --fence
  425. if(spr_num == 36) set_sprite_left(pl,37) player.happy += fence_worth
  426. --statue
  427. if(spr_num ==25) set_sprite_left(pl,26) player.happy += statue_worth
  428. --garden
  429. if(spr_num ==53) set_sprite_left(pl,54) player.happy += plant_worth
  430. end
  431. --right
  432. if(dir == 1) then
  433. --tree top
  434. if(spr_num == 23) then
  435. set_sprite_right(pl, 24)
  436. player.happy += tree_worth
  437. end
  438.  
  439. --tree bottom
  440. if(spr_num == 39) then
  441. set_sprite_right(pl, 40)
  442. player.happy += tree_worth
  443. end
  444.  
  445. if(spr_num >=70 and spr_num<=72)then
  446. set_sprite_right(pl,spr_num+3)
  447. player.happy += house_worth
  448. end
  449. if(spr_num >=86 and spr_num<=88)then
  450. set_sprite_right(pl,spr_num+3)
  451. player.happy += house_worth
  452. end
  453. if(spr_num == 36) set_sprite_right(pl,37) player.happy += fence_worth
  454. --statue
  455. if(spr_num ==25) set_sprite_right(pl,26) player.happy += statue_worth
  456. --garden
  457. if(spr_num ==53) set_sprite_right(pl,54) player.happy += plant_worth
  458. end
  459. --up
  460. if(dir == 2) then
  461. --tree top
  462. if(spr_num == 23) then
  463. set_sprite_up(pl, 24)
  464. player.happy += tree_worth
  465. end
  466.  
  467. --tree bottom
  468. if(spr_num == 39) then
  469. set_sprite_up(pl, 40)
  470. player.happy += tree_worth
  471. end
  472.  
  473. if(spr_num >=70 and spr_num<=72)then
  474. set_sprite_up(pl,spr_num+3)
  475. player.happy += house_worth
  476. end
  477. if(spr_num >=86 and spr_num<=88)then
  478. set_sprite_up(pl,spr_num+3)
  479. player.happy += house_worth
  480. end
  481. if(spr_num == 36) set_sprite_up(pl,37) player.happy += fence_worth
  482. --statue
  483. if(spr_num ==25) set_sprite_up(pl,26) player.happy += statue_worth
  484. --garden
  485. if(spr_num ==53) set_sprite_up(pl,54) player.happy += plant_worth
  486. end
  487. --down
  488. if(dir == 3) then
  489. --tree top
  490. if(n == 23) then
  491. set_sprite_down(pl, 24)
  492. player.happy += tree_worth
  493. end
  494.  
  495. --tree bottom
  496. if(n == 39) then
  497. set_sprite_down(pl, 40)
  498. player.happy += tree_worth
  499. end
  500.  
  501. if(spr_num >=70 and spr_num<=72)then
  502. set_sprite_down(pl,spr_num+3)
  503. player.happy += house_worth
  504. end
  505. if(spr_num >=86 and spr_num<=88)then
  506. set_sprite_down(pl,spr_num+3)
  507. player.happy += house_worth
  508. end
  509. if(spr_num == 36) set_sprite_down(pl,37) player.happy += fence_worth
  510. --statue
  511. if(spr_num ==25) set_sprite_down(pl,26) player.happy += statue_worth
  512. --garden
  513. if(spr_num ==53) set_sprite_down(pl,54) player.happy += plant_worth
  514. end
  515.  
  516. end
  517.  
  518. function check_room()
  519.  
  520. curr_room.x = flr(player.x/128)
  521. curr_room.y = flr(player.y/128)
  522.  
  523.  
  524. end
  525.  
  526. function box_collide(rect1, rect2)
  527.  
  528. if (rect1.x < rect2.x + rect2.w and
  529. rect1.x + rect1.w > rect2.x and
  530. rect1.y < rect2.y + rect2.h and
  531. rect1.h + rect1.y > rect2.y) then
  532.  
  533. return true
  534.  
  535. end
  536.  
  537. return false
  538. end
  539.  
  540. function collisions()
  541.  
  542. for en in all(enemies) do
  543.  
  544. if(box_collide(player, en)) then
  545.  
  546. if(en.type == 0) then
  547. player.happy += 5
  548. sfx(2)
  549. end
  550. if(en.type == 1) then
  551. player.happy += 1
  552. player.life -= 20
  553. sfx(3)
  554. end
  555.  
  556. if(en.sprite ==67)then
  557. --victory
  558. sfx()
  559. state = 4
  560. end
  561.  
  562. local bl = make_blood(en.x-en.w/2, en.y-en.h/2, en.type)
  563. add(blood, bl)
  564. del(enemies, en)
  565. end
  566.  
  567. end
  568.  
  569. end
  570.  
  571. function store_rooms()
  572.  
  573. for x=0,4 do
  574. for y=0,3 do
  575.  
  576. local room = make_object(x, y)
  577. add(rooms,room)
  578.  
  579. end
  580. end
  581.  
  582. end
  583.  
  584. function clear_room()
  585.  
  586. for rm in all(rooms) do
  587.  
  588. if(rm.x == curr_room.x and rm.y == curr_room.y) then
  589.  
  590. if(count(enemies)<=0)then
  591.  
  592. rm.cleared = true
  593.  
  594. end
  595.  
  596. end
  597.  
  598. end
  599.  
  600. end
  601.  
  602. --checks if room is cleared
  603. function room_cleared()
  604.  
  605. for rm in all(rooms) do
  606.  
  607. if(curr_room.x==rm.x and curr_room.y==rm.y)then
  608. if(rm.cleared) return true
  609. end
  610.  
  611. end
  612. return false
  613. end
  614.  
  615. function draw_hud()
  616.  
  617. rectfill(curr_room.x*128+10, curr_room.y*128+110, curr_room.x*128+10+(player.life/3), curr_room.y*128+113,8)
  618. rectfill(curr_room.x*128+10, curr_room.y*128+115, curr_room.x*128+10+(player.happy/3), curr_room.y*128+118,10)
  619. --print("hp",curr_room.x*128+10, curr_room.y*128+110, 0)
  620. end
  621.  
  622. function update_player_values(pl)
  623.  
  624. if(curr_room.x == 2 and curr_room.y == 3) then
  625. pl.happy -= 0.2
  626. else
  627. pl.happy -= 0.1
  628. end
  629.  
  630. if(mget(flr(pl.x/8), flr(pl.y/8)) ==2) then
  631. if(pl.life < max_life)pl.life += 0.5
  632. end
  633.  
  634. end
  635.  
  636. function check_loss(pl)
  637.  
  638. if(pl.life <=0)then
  639. --lose
  640. sfx(7)
  641. state = 2
  642. end
  643. if(pl.happy <= 0) then
  644. --lose
  645. sfx(7)
  646. state = 3
  647. end
  648.  
  649. end
  650.  
  651. function check_z_press()
  652.  
  653. if(btn(4,0)) then
  654. sfx(1)
  655. if(state == 0) state = 1
  656.  
  657. end
  658.  
  659. if(btn(5, 0)) then
  660.  
  661. if(state == 2 or state == 3 or state == 4) then
  662.  
  663. _init()
  664.  
  665. end
  666.  
  667. end
  668. end
  669.  
  670. function _init()
  671.  
  672. state = 0
  673. timer = 0
  674.  
  675. enemies = {}
  676. blood = {}
  677. rooms = {}
  678. prev_room = make_object(0, 0)
  679. curr_room = make_object(2, 3)
  680. store_rooms()
  681. player = make_player(curr_room.x*128+64,curr_room.y*128+64)
  682. check_room()
  683. end
  684.  
  685.  
  686. function _update()
  687.  
  688. if(state != 1) check_z_press()
  689.  
  690. if(state == 1)then
  691. check_room()
  692.  
  693. --check to see if rooms have changed
  694. if(curr_room.x != prev_room.x or curr_room.y != prev_room.y) then
  695.  
  696. for en in all(enemies) do
  697. del(enemies, en)
  698. end
  699.  
  700. if(not room_cleared())then
  701. fill_room()
  702. end
  703.  
  704.  
  705.  
  706. end
  707.  
  708. clear_room()
  709. check_move_inputs()
  710. check_solids_player(player, 0)
  711. check_solids_player(player, 1)
  712. move_player(player)
  713. update_player_values(player)
  714. collisions()
  715.  
  716. check_loss(player)
  717. prev_room = make_object(curr_room.x, curr_room.y)
  718.  
  719. timer += 1
  720.  
  721. end
  722. end
  723.  
  724.  
  725. function _draw()
  726.  
  727. if(state==0) draw_start()
  728.  
  729. if(state==1)then
  730. cls()
  731.  
  732. camera((curr_room.x*128), curr_room.y*128)
  733. map(0, 0, 0, 0, 256, 256)
  734.  
  735. foreach(enemies, draw_enemy)
  736. foreach(enemies, move_enemy)
  737. foreach(blood, draw_blood)
  738. draw_player(player)
  739.  
  740. draw_hud()
  741.  
  742.  
  743. end
  744.  
  745. if(state == 2) draw_loss_life()
  746.  
  747. if(state == 3) draw_loss_happy()
  748.  
  749. if(state == 4) draw_victory()
  750.  
  751. end
  752.  
  753.  
  754. function draw_start()
  755.  
  756. cls()
  757. camera(0, 0)
  758. spr(102, 40, 10, 6, 2)
  759.  
  760. print("troll is sad!", 40, 40, 7)
  761. print("his cave make him even sadder!",2, 50, 7)
  762. print("destruction make troll happy!", 4, 60, 7)
  763. print("human king make troll angry!", 6, 70, 7)
  764. print("yellow", 0, 80, 10)
  765. print("bar is troll happiness", 30, 80, 7)
  766. print("red", 0, 90, 8)
  767. print("bar is troll health",15, 90, 7)
  768. print("cave bed heals, but hurts happy", 0, 100, 7)
  769. print("kill the human king!",25, 110, 7)
  770. print("press z to start", 30, 120, 7)
  771.  
  772. end
  773.  
  774. function draw_victory()
  775.  
  776. cls()
  777. camera(0, 0)
  778. spr(102, 40, 10, 6, 2)
  779.  
  780. print("you killed the human king!", 10, 40, 7)
  781. print("no more stinky cave for troll!", 0, 50, 7)
  782. print("troll is happy once more!",12, 60, 7)
  783. print("press x to restart", 30, 80, 7)
  784.  
  785. end
  786.  
  787. function draw_loss_life()
  788.  
  789. cls()
  790. camera(0, 0)
  791. spr(102, 40, 10, 6, 2)
  792.  
  793. print("troll was killed!",30, 40, 7)
  794. print("looks like his search for", 10, 50, 7)
  795. print("happiness ended poorly", 15, 60, 7)
  796. print("the human village is safe", 10, 70, 7)
  797. print("but at what cost?",30, 80, 7)
  798. print("press x to restart", 30, 100, 7)
  799.  
  800. end
  801.  
  802. function draw_loss_happy()
  803.  
  804. cls()
  805. camera(0, 0)
  806. spr(102, 40, 10, 6, 2)
  807.  
  808. print("troll became too sad!", 20, 40, 7)
  809. print("troll just didn't see the point", 0, 50, 7)
  810. print("troll is going to live in cave", 2, 60, 7)
  811. print("for rest of sad life.", 20, 70, 7)
  812. print("press x to restart", 30, 90, 7)
  813.  
  814. end
  815.  
  816. function sub_vec(vec1, vec2)
  817.  
  818. vec1.x -= vec2.x
  819. vec1.y -= vec2.y
  820.  
  821. end
  822.  
  823. function add_vec(vec1, vec2)
  824.  
  825. vec1.x += vec2.x
  826. vec1.y += vec2.y
  827.  
  828. end
  829.  
  830. function mult_vec(vec,sca)
  831.  
  832. vec.x = vec.x*sca
  833. vec.y = vec.y*sca
  834.  
  835. end
  836.  
  837. function normalize(vec)
  838.  
  839. length = sqrt((vec.x*vec.x) + (vec.y*vec.y))
  840.  
  841. vec.x = (vec.x) / length
  842. vec.y = (vec.y) / length
  843.  
  844. end
  845.  
  846. function nullify_en_movement_knight(en, vec)
  847.  
  848. if(check_solids_player(en, 0) == 0) then
  849.  
  850. if(vec.x < 0) null_x(vec)
  851.  
  852. end
  853.  
  854. if(check_solids_player(en, 0) == 1) then
  855.  
  856. if(vec.x > 0) null_x(vec)
  857.  
  858. end
  859.  
  860. if(check_solids_player(en, 0) == 2) then
  861.  
  862. if(vec.y < 0) null_y(vec)
  863.  
  864. end
  865.  
  866. if(check_solids_player(en, 0) == 3) then
  867.  
  868. if(vec.y > 0) null_y(vec)
  869.  
  870. end
  871.  
  872. end
  873.  
  874. function nullify_en_movement_peasant(en, vec)
  875.  
  876. if(check_solids_player(en, 0) == 0) then
  877.  
  878. if(vec.x > 0) null_x(vec)
  879.  
  880. end
  881.  
  882. if(check_solids_player(en, 0) == 1) then
  883.  
  884. if(vec.x < 0) null_x(vec)
  885.  
  886. end
  887.  
  888. if(check_solids_player(en, 0) == 2) then
  889.  
  890. if(vec.y > 0) null_y(vec)
  891.  
  892. end
  893.  
  894. if(check_solids_player(en, 0) == 3) then
  895.  
  896. if(vec.y < 0) null_y(vec)
  897.  
  898. end
  899.  
  900. end
  901.  
  902. function null_x(vec)
  903. vec.x = 0
  904. end
  905.  
  906. function null_y(vec)
  907. vec.y = 0
  908. end
Advertisement
Add Comment
Please, Sign In to add comment