-- title: miniblaster -- author: pixelbath -- desc: short description -- site: website link -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua t=0 x=96 y=24 entities={} walls={ [1]=true, [2]=true, [16]=true } config={ jump_spd=2.2, walk_spd=1.0, slide_spd=2.0, } player={ x=96, y=24, vx=0, vy=0, gx=0, gy=0, is_jmp=false, flip=0, spr=256, w_spr={257,258,256}, j_spr=259, w_spr_idx=0, w_timer=0, is_wlk=0, dir=0, -- 0=horizontal, 1=diagonal, 2=vertical slide_timer=-1, bullets={}, } debug={ pline=0, px=2, py=2, } function solid(x, y) return walls[mget((x)//8,(y)//8)] end function debug:print(msg) rect(self.px, self.py + (self.pline * 7), #msg * 4, 0, 1) print(msg, self.px, self.py + (self.pline * 7), 4, true, 1, true) self.pline = self.pline + 1 end function debug:draw() self.pline = 0 -- draw player shoot direction if false then local dx, dy = player.x+4, player.y+4 local dist = 100 if player.flip == 1 then dist = -100 end if player.dir == 0 then dx = player.x + dist elseif player.dir == 1 then dx = player.x + dist dy = player.y - 100 elseif player.dir == 2 then dy = player.y - 100 end line(player.x+4, player.y+4, dx, dy, 1) end debug:print("player: "..player.x..", "..player.y) debug:print("vy: "..tostring(player.vy)) -- controller local cont_x, cont_y = 2, 110 rect(cont_x, cont_y, 10, 5, 0) line(cont_x+1, cont_y+2, cont_x+3, cont_y+2, 8) line(cont_x+2, cont_y+1, cont_x+2, cont_y+3, 8) pix(cont_x+6, cont_y+3, 8) pix(cont_x+8, cont_y+3, 8) pix(cont_x+6, cont_y+1, 8) pix(cont_x+8, cont_y+1, 8) if btn(0) then pix(cont_x+2, cont_y+1, 10) end if btn(1) then pix(cont_x+2, cont_y+3, 10) end if btn(2) then pix(cont_x+1, cont_y+2, 10) end if btn(3) then pix(cont_x+3, cont_y+2, 10) end if btn(4) then pix(cont_x+6, cont_y+3, 10) end if btn(5) then pix(cont_x+8, cont_y+3, 10) end if btn(6) then pix(cont_x+6, cont_y+1, 10) end if btn(7) then pix(cont_x+8, cont_y+1, 10) end end function player:update() local dir_held = false local up_held = false if btn(0) then player.dir = 2 up_held = true end -- left if btn(2) then player.vx = -config.walk_spd player.flip = 1 dir_held = true if up_held then player.dir = 1 else player.dir = 0 end end -- right if btn(3) then player.vx = config.walk_spd player.flip = 0 dir_held = true if up_held then player.dir = 1 else player.dir = 0 end end -- down + jump to do a slide if btn(1) then -- slide if btnp(4) then if player.vy == 0 and player.slide_timer == -1 then player.slide_timer = 10 player.vx = config.slide_spd if player.flip == 1 then player.vx = -config.slide_spd end player.is_wlk = false end end else -- jump if btn(4) then if player.vy == 0 and not player.is_jmp then player.vy = -config.jump_spd player.is_wlk = 0 player.is_jmp = true end else if player.is_jmp and player.vy <= 0 then player.vy = 0 player.is_jmp = false end end end if btnp(5) then player:spawnBullet() end if player.slide_timer == -1 then player.vx = math.max(-1.5, math.min(1.5, player.vx)) end -- set flag if walking, clamp if not if math.abs(player.vx) < 0.01 then player.vx = 0 player.is_wlk = 0 else player.is_wlk = 1 end if solid(player.x+player.vx,player.y+player.vy) or solid(player.x+4+player.vx,player.y+player.vy) or solid(player.x+player.vx,player.y+4+player.vy) or solid(player.x+4+player.vx,player.y+4+player.vy) then player.vx = 0 end if solid(player.x,player.y+8+player.vy) or solid(player.x+7,player.y+8+player.vy) then player.vy = 0 else -- gravity, terminal velocity player.vy = math.min(6.0, player.vy + 0.12) player.spr = player.j_spr end player.x = player.x + player.vx player.y = player.y + player.vy if not dir_held and player.slide_timer == -1 then player.vx = player.vx * 0.8 end -- ground fx if player.vy == 0 then -- do slidey stuff, otherwise walk if player.slide_timer > 0 then player.slide_timer = player.slide_timer - 1 elseif player.slide_timer == 0 then player.vx = 0 player.slide_timer = -1 else if player.is_wlk == 1 then player.w_timer = player.w_timer + 1 if player.w_timer > 5 then player.w_spr_idx = (player.w_spr_idx + 1) % 3 + 1 player.spr = player.w_spr[player.w_spr_idx] player.w_timer = 0 end else player.spr = 256 end end end -- bulletsch for key, bullet in ipairs(player.bullets) do if bullet.x < -8 or bullet.x > 248 then table.remove(player.bullets, key) goto bullet_dead end if bullet.y < -8 or bullet.y > 144 then table.remove(player.bullets, key) goto bullet_dead end bullet.x = bullet.x + bullet.vx bullet.y = bullet.y + bullet.vy ::bullet_dead:: end end function player:spawnBullet() local testspd = 5 local bx, by = self.x + 4, self.y + 4 local lvx, lvy, dist = 0, 0, testspd if self.flip == 1 then dist = -testspd end if self.dir == 0 then lvx = dist elseif self.dir == 1 then lvx = dist lvy = -math.abs(dist) elseif self.dir == 2 then lvy = -math.abs(dist) end -- correct diagonal movements if lvx * lvy ~= 0 then lvx = lvx * 0.707 lvy = lvy * 0.707 end table.insert(self.bullets, { x=bx, y=by, vx=lvx, vy=lvy, }) end function player:draw() spr(player.spr, player.x, player.y, 0,1, player.flip,0,1,1) for key, bullet in ipairs(player.bullets) do circ(bullet.x, bullet.y, 1, 4) end end function TIC() cls(13) map() player:update() player:draw() debug:draw() t=t+1 end -- -- 001:ccccccccddddddddeeeeeeeeffffffff88e99e888e9889e8e988889e88888888 -- 002:dce88edcdc9e8edcdc89eedcdc889edcdc88eedcdc8e9edcdce98edcdc988edc -- 004:00000000f00f0f0f00f000ff00000000000000000000000f000000000000000f -- 005:00000000e000ddeefe0deeffff0eef0fff0eff0f0f0ef0f0fe0ef0f00e0f0f00 -- 006:00000000f0fff0fe0f000fff0000000f0000000f000000f00000000f000000f0 -- 007:00000000000ddeefe0deeff0f0eef0f0f0eff0f0f0ef0f00e0ef0f00e0f0f000 -- 008:e0000000ef000000e0f00000ff000000f0000000fff00000feff00000fefffff -- 009:000000f000000ff000000fe00000f0f0000f0f00f000f0f0000f0f00fff0ff00 -- 010:0000000008089189800000080000000880000009000809088000000800000008 -- 011:000000000000000000000000000000000000000000000088000800f000000080 -- 016:dceeeccdedeeeedced88899ced888ffded88888ded88888dfe88888efffffffe -- 020:000000000000000000000000000000f0000f000f000000f00f0fff0f00000000 -- 021:ff0ef000fe0e0f00ff0ff000f00f00000f0fff00f00feff0f000feff00000000 -- 022:0000000f0000000f0000000f00000f0f00f000f000000f0ffffff0ff00000000 -- 023:f0ef0000e0e0f000f0ff000000f00000f0fff00000feff00000fefff00000000 -- 024:000000000ddeeff0deeff00feef0f000eff0f000ef0f0000ef0f0000f0f00000 -- 025:00000000fff0fe00000fffe000000ff000000ff00000f0f000000fe00000f0e0 -- 026:0000010980000008000800080000000800000000000000080000000000000000 -- 027:f888881000000080000000000008808000000000000000800000000000000080 -- 032:2232232233333333132321211021121102102101101010100100000000000000 -- 033:2232222323233332322123121012112101010210001001001000000000000000 -- 034:0423433331121022312301112301301023102120213211003110102102220202 -- 035:3223443321221022001000111020201020102020100000002100102102220202 -- 036:3332243322121210110000002010202010101010100010000222022220012020 -- 037:3334234022011114111123030103013202131022001132121201011320202220 -- 048:01111111142244441c44cccc1322333314334444132233331211222201111111 -- 049:1111111144444444cccccccc3333333344444444333333332222222211111111 -- 050:1111111044442241cccc44c13333223144443341333322312222112111111110 -- 051:13c332211444443113c332211444443113c332211444443113c3322114444431 -- -- -- 000:008558000085580008aaa80008aaaa8008a88a8008a80a8008aa8aa808880880 -- 001:008558000085580008aaa80008aaaa8008a88a808a800a808aa80aa888800880 -- 002:0085580000855800008aa80008aaa80008a8880008a8a80008aa8a8008888800 -- 003:008558000085580008aaa80008aaaa8008a88a8008aa8aa80888088000000000 -- -- -- 005:000000200000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 006:000000200000000010101000000000001010000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 007:000000200000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 008:000000200000000000000000000000000000000000101010809020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 009:000000200000000000000000000000000010000000000000819120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 010:000000200040000000000000001010000000003040506070809020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 011:000000203141000000100000000000000000003141516171819120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 012:000000011010101010101010101010101010101010101010101001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- -- -- 000:00000000ffffffff00000000ffffffff -- 001:0123456789abcdeffedcba9876543210 -- 002:0123456789abcdef0123456789abcdef -- -- -- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000 -- -- -- 000:100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- -- -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57 --