My simple game [SOLVED]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
test
Prole
Posts: 28
Joined: Sun Apr 14, 2019 2:36 pm

My simple game [SOLVED]

Post by test » Mon Apr 22, 2019 3:56 pm

I wanted to share. It works with touch. You may test it in android. The screen is weird on desktop because default window size is 800x600px on pc. If you see bad pratices in the code, tell me please.
Attachments
game.love
(16.97 KiB) Downloaded 44 times
Last edited by test on Tue May 07, 2019 7:13 pm, edited 2 times in total.

Xugro
Citizen
Posts: 61
Joined: Wed Sep 29, 2010 8:14 pm

Re: My simple game

Post by Xugro » Mon Apr 22, 2019 7:25 pm

It took me a while to figure out how the game actually works. For anyone curious: You have to click on the fire/ice symbol in your corner to "charge" up your weapon. Afterwards you can shoot a single fireball/iceball starting from your red square and flying in the direction of your touch. After each shot you have to "recharge" again. Your goal is to hit the enemy red square and not to get hit by the enemy by moving around.
test wrote:
Mon Apr 22, 2019 3:56 pm
If you see bad pratices in the code, tell me please.
A few things that I stumbled upon immediately:
  • You do not need to abbreviate variable names. Your game is takes up just a few kilobytes of space. If you write out variable names fully you wont be able to see a big difference. Just write them out fully so that they are easier to understand. As an example: I am still not sure what p1.b and p1.c do or even mean.
  • Do not use copy paste in your code. Every time you write something like player1, player2, player3, ... use an array to store all players and differentiate them on their index - e.g.: player[1], player[2], player[3], ... This way you have to write code only once for a player - e.g. player[n] where n is any number.
    This removes a lot of duplicated code. It will make changes easier (you only need to change the code in one place and not two or more) and it will help you to introduce less bugs (e.g. there is no reset2() function).

test
Prole
Posts: 28
Joined: Sun Apr 14, 2019 2:36 pm

Re: My simple game

Post by test » Mon Apr 22, 2019 7:32 pm

thank you for your time xugro. can you give an example for your second advice? I mean how to store player1 and player2 in one array. I am new at programming. By the way, p1.b and p1.c is just a mistake. I could just do my job with one variable.

Xugro
Citizen
Posts: 61
Joined: Wed Sep 29, 2010 8:14 pm

Re: My simple game

Post by Xugro » Mon Apr 22, 2019 7:53 pm

I changed your code a little bit to show you what I mean. Take a look at the attached file. Now the code for initializing a player is not duplicated any more and you only need to change it once for both players (line 39 to 56). Only the things that are different are outside the common code. You could do the same with the update and draw code.
Attachments
main.lua
Changed p1 and p2 to player-array.
(7.92 KiB) Downloaded 32 times

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 9 guests