Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Commit

Permalink
Fixed errors + no game screen
Browse files Browse the repository at this point in the history
  • Loading branch information
videah committed Oct 13, 2015
1 parent 69e5ee7 commit 4b78921
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 16 deletions.
Binary file added game/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/bubble.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/inspector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 143 additions & 3 deletions game/main.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,151 @@
-- LövePotion example/no game screen

-- love.load() is called once when a LövePotion game is ran.
function love.load()

math.randomseed(os.time()) -- Seeds the random number generator with the time (Actually makes it random)

-- Sets the current screen for draw calls to draw to.
-- Lasts until it is called again.
love.graphics.setScreen('top')

logo = {} -- Creates a table to hold variables for the logo (x, y, image etc.)
potionText = {} -- Creates a table to hold variables for the text

bubbles = {} -- Creates a table to hold all the bubbles

font = love.graphics.newFont() -- Creates a new font, when no arguments are given it uses the default font

-- Loads images from filepaths
logo.image = love.graphics.newImage('potionlogo.png')
background = love.graphics.newImage('bg.png')

inspector = love.graphics.newImage('inspector.png')
message = love.graphics.newImage('nogame.png')
messagebg = love.graphics.newImage('bubble.png')


-- Sets the logo position to the center of the screen, using love.graphics.getWidth()/getHeight()
-- and Image:getWidth()/getHeight()
logo.x = (love.graphics.getWidth() / 2) - (logo.image:getWidth() / 2)
logo.y = (love.graphics.getHeight() / 2) - (logo.image:getHeight() / 2)

-- Sets the texts position, by setting variables in the potionText table
potionText.x = 50
potionText.y = 75

-- Sets the background color to a nice blue
love.graphics.setBackgroundColor(88, 186, 255)

end

-- love.draw() is called every frame. Any and all draw code goes here. (images, shapes, text etc.)
function love.draw()

love.graphics.print("Replace me in game/main.lua.", 0, 0)
-- Start drawing to the top screen
love.graphics.setScreen('top')

-- Reset the current draw color to white
love.graphics.setColor(255, 255, 255)

-- Draw the background image
love.graphics.draw(background, 0, 0)

-- Cycle through all the bubbles in the bubble list, and draw them on their current screen
for i, bubble in ipairs(bubbles) do
love.graphics.setScreen(bubble.state)
love.graphics.rectangle('fill', bubble.x, bubble.y, bubble.size, bubble.size)
end

love.graphics.setScreen('top') -- Reset the screen to top after drawing bubbles on bottom.

-- Draws the framerate
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle('fill', 10, 15, font:getWidth('FPS: ' .. love.timer.getFPS()) + 10, font:getHeight() + 3)
love.graphics.setColor(35, 31, 32)
love.graphics.setFont(font)
love.graphics.print('FPS: ' .. love.timer.getFPS(), 15, 15)

love.graphics.setColor(255, 255, 255)

-- Draw LövePotion logo
love.graphics.rectangle('fill', logo.x - 3, logo.y - 3, 128 + 6, 128 + 6)
love.graphics.draw(logo.image, logo.x, logo.y)

-- Start drawing to the bottom screen
love.graphics.setScreen('bottom')

-- Draw the baby inspector with the no-game text
love.graphics.draw(inspector, 0, 20)
love.graphics.draw(messagebg, 160, 0)
love.graphics.draw(message, 185, 10)

end

function love.keypressed(key, isrepeat)
-- love.update(dt) is called every frame, and is used for game logic.
-- The dt argument is delta-time, the average time between frames.
-- Use this to make your game framerate independent.
function love.update(dt)

-- Makes the LövePotion logo bounce up and down
logo.y = 50 + math.cos(love.timer.getTime() * 2) * 16


-- Randomly spawn bubbles at the bottom of the bottom screen
if math.random(1, 7) == 1 then

local newBubble = {x = 0, y = 0, speed = 0, size = 0, state = 'bottom'}

newBubble.speed = math.random(50, 125)
newBubble.size = math.random(10, 50)
newBubble.x = math.random(-400, 400)
newBubble.y = love.graphics.getHeight() + newBubble.size

table.insert(bubbles, newBubble)

end

-- Cycle through the bubble list, and update their position.
-- If the bubble reaches the top of the bottom screen, change to the top screen.
-- If the bubble reaches the top of the top screen, remove the bubble.
for i, bubble in ipairs(bubbles) do

bubble.y = bubble.y - bubble.speed * dt

if bubble.state == 'top' then

if bubble.y < -bubble.size then
table.remove(bubbles, i)
end

end

if bubble.state == 'bottom' then
if bubble.y < -bubble.size then
bubble.x = bubble.x + 40
bubble.y = love.graphics.getHeight() + bubble.size
bubble.state = 'top'
end
end

if bubble.x < -50 or bubble.x > 350 then
table.remove(bubbles, i)
end

end

end


-- love.keypressed is called when any button is pressed.
-- The argument key is the key that was pressed.
-- Not all input code goes here, if you want to check if a button is down then
-- use love.update(dt) along with love.keyboard.isDown().
function love.keypressed(key)

if key == "start" then love.event.quit() end
-- If the start button is pressed, we return to the Homebrew Launcher
if key == 'start' then
love.event.quit()
end

end
Binary file added game/nogame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/potionlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main() {

luaL_dostring(L, "_defaultFont_ = love.graphics.newFont(); love.graphics.setFont(_defaultFont_)");

luaL_dostring(L, "print(''); print('\x1b[1;36mLovePotion 1.0.5 BETA\x1b[0m (LOVE for 3DS)'); print('')"); // Ew.
luaL_dostring(L, "print(''); print('\x1b[1;36mLovePotion 1.0.6 BETA\x1b[0m (LOVE for 3DS)'); print('')"); // Ew.

luaL_dostring(L, "package.path = 'game/?.lua;game/?/init.lua'"); // Set default requiring path.
luaL_dostring(L, "package.cpath = 'game/?.lua;game/?/init.lua'");
Expand Down
21 changes: 11 additions & 10 deletions source/objects/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,20 @@

const char *imageInit(love_image *self, const char *filename) {

if (!fileExists(filename)) return "Could not open image. Does not exist.";
int type = getType(filename);

const char *ext = fileExtension(filename);

if (strncmp(ext, "png", 3) == 0) {
if (type == 0) { // PNG

self->texture = sfil_load_PNG_file(filename, SF2D_PLACE_RAM);

} else if (strncmp(ext, "bmp", 3) == 0) {
} else if (type == 1) { // JPG

self->texture = sfil_load_BMP_file(filename, SF2D_PLACE_RAM);
self->texture = sfil_load_JPEG_file(filename, SF2D_PLACE_RAM);

} else if (strncmp(ext, "jpeg", 4) == 0 || strncmp(ext, "jpg", 3) == 0) {
} else if (type == 2) { // BMP

self->texture = sfil_load_JPEG_file(filename, SF2D_PLACE_RAM);
self->texture = sfil_load_BMP_file(filename, SF2D_PLACE_RAM);

} else {
return "Unknown image type.";
}

return NULL;
Expand All @@ -57,6 +53,11 @@ int imageNew(lua_State *L) { // love.graphics.newImage()
char final[strlen(rootDir) + strlen(filename) + 2];
combine(final, rootDir, filename);

if (!fileExists(final)) luaError(L, "Could not open image. Does not exist.");

int type = getType(final);
if (type == 4) luaError(L, "Unknown image type.");

love_image *self = luaobj_newudata(L, sizeof(*self));
luaobj_setclass(L, CLASS_TYPE, CLASS_NAME);

Expand Down
19 changes: 17 additions & 2 deletions source/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ int fileExists (char *filename){
}

void luaError(lua_State *L, char *message) {
lua_pushstring(L, message);
lua_error(L);
luaL_error(L, message);
}

const char *fileExtension(const char *filename) {
Expand All @@ -74,4 +73,20 @@ char* concat(char *s1, char *s2) {
strcat(result, s2);

return result;
}

int getType(const char *name) {

const char *ext = fileExtension(name);

if (strncmp(ext, "png", 3) == 0) {
return 0;
} else if (strncmp(ext, "jpeg", 4) == 0 || strncmp(ext, "jpg", 3) == 0) {
return 1;
} else if (strncmp(ext, "bmp", 3) == 0) {
return 2;
} else {
return 4;
}

}

0 comments on commit 4b78921

Please sign in to comment.