-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
145 lines (106 loc) · 3.59 KB
/
main.lua
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
--[[
require 'World'
require 'Player'
require 'Player_draw'
require 'Coin'
require 'Animation'
require 'BoundingBox'
require 'Sprite'
require 'Goblin'
require 'Projectile_Sword'
require 'Weapon'
require 'Weapon_Sword'
require 'Weapon_Empty'
]]
require 'require'
require.tree('GameFiles')
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
IMG_TILE_WIDTH = 32
IMG_TILE_HEIGHT = 32
GLOBAL_COUNTER = 0
Levels = {}
for i = 1, 2, 1 do
Levels[i] = require ('Levels/' .. i)
end
DEBUG = false
function love.keypressed(key, scancode, isrepeat)
local mx, my = camera:getMousePosition()
if key == "g" and not isrepeat then
--local goblin = Goblin(mx, my)
--world:addSprite(goblin)
end
end
function love.load()
love.graphics.setDefaultFilter( "nearest", "nearest")
TILEMAP = love.graphics.newImage("gfx/Tilemap.png")
PLAYER_IDLE = love.graphics.newImage("gfx/metroidvania/herochar_sprites(new)/herochar_idle_anim_strip_4.png")
PLAYER_RUN = love.graphics.newImage("gfx/metroidvania/herochar_sprites(new)/herochar_run_anim_strip_6.png")
PLAYER_JUMP_UP = love.graphics.newImage("gfx/metroidvania/herochar_sprites(new)/herochar_jump_up_anim_strip_3.png")
PLAYER_JUMP_DOWN = love.graphics.newImage("gfx/metroidvania/herochar_sprites(new)/herochar_jump_down_anim_strip_3.png")
PLAYER_ATTACK = love.graphics.newImage("gfx/metroidvania/herochar_sprites(new)/herochar_attack_anim_strip_4(new).png")
PLAYER_DAMAGE = love.graphics.newImage("gfx/metroidvania/herochar_sprites(new)/herochar_hit_anim_strip_3.png")
ITEM_ICONSET = love.graphics.newImage("gfx/Ocean's Nostalgia - Icons Pack 1/MV/Color/Iconset.png")
QUADS = {}
local QUADSIZE = 32
for x = 0, 255*2*2, 1 do
QUADS[x] = love.graphics.newQuad((x % QUADSIZE) *QUADSIZE, math.floor(x/QUADSIZE) *QUADSIZE, QUADSIZE, QUADSIZE, 1024, 1024)
end
world = World()
player = Player(world, 100, 100)
camera = Camera(world, player)
print(player.x, camera.x)
tilePicker = TilePicker(world, camera)
file = love.filesystem.newFile("level.lua")
end
function bool2String(bool)
if bool then
return "true"
else
return "false"
end
end
function love.update(dt)
GLOBAL_COUNTER = GLOBAL_COUNTER + dt
if dt <= 0.1 then
camera:update(dt)
end
--print(currentSelection)
if love.keyboard.isDown("f2") then
local data = "local function Level() \nlocal self = {}\n"
local tile, chunk
chunk = world:getChunk(player.x, player.y)
print(player.x, player.y)
for x = 0, TILES_PER_CHUNK_WIDTH -1, 1 do
data = data .. "self[" .. x .. "] = {}\n"
for y = 0, TILES_PER_CHUNK_HEIGHT -1, 1 do
tile = chunk:getTile(x * TILE_WIDTH, y * TILE_HEIGHT)
if x == 0 and y == 0 then
print((tile.solid), bool2String(tile.solid))
end
data = data .. "self[" .. x .. "]" .. "[" .. y .. "] = {solid = " .. bool2String(tile.solid) .. ", gfx_id = " .. tile.gfx_id .. "} \n"
end
end
data = data .. "return self\n"
data = data .. "end\nreturn Level"
love.filesystem.write( "level.lua", data)
end
if love.keyboard.isDown("f5") then
DEBUG = not DEBUG
end
tilePicker:update(dt)
end
function love.wheelmoved(x, y)
if y > 0 then--up
tilePicker.currentSelection = (tilePicker.currentSelection - 1) % 1020
elseif y < 0 then--down
tilePicker.currentSelection = (tilePicker.currentSelection + 1) % 1020
end
end
function love.draw()
love.graphics.setDefaultFilter( "nearest" )
camera:draw()
--love.graphics.draw(TILEMAP, QUADS[0], 100, 010)
tilePicker:draw()
--love.graphics.setBackgroundColor(135/255, 206/255, 235/255)
end