Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post Posted: July 24th, 2017, 8:56 pm 
 

Joined: July 24th, 2017, 8:23 pm
Posts: 6
https://github.com/Aizenvolt1/Project1/ ... rstChanges

This is the first game I make and if you can help with some things I would apreciate it. I have seen the first 13 tutorials. I want some help with the firing mechanism if you see the code you will understand the problem but if you dont I will explain it anyway. You see I can't find the right way to code the firing mechanism. The way i have coded it won't help if i want the player to fire more shots. I am sure there is a better way to do it but since I am new to these things I havent figured it out yet. The game I have made is very basic the concept is similar to galaga. As i see more tutorials and learn new things i will improve my code and add new things.Also if there is a site that has images and pixels for those images and how to draw them in the code(like poo from chilis videos) I would appreciate it if you posted a link. Thanks to anyone that is kind enough to help.Press arrow keys to move SPACEBAR to fire Enter to start game and R to play again.


Last edited by Aizenvolt on August 14th, 2017, 6:18 pm, edited 1 time in total.

Top 
 Profile  
Reply with quote  
 Post Posted: July 25th, 2017, 5:13 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2844
Location: Oklahoma, United States
How many shots are you wanting at a time?

Here's an idea, make an array of Fire large enough to hold however many shots you want to allow the player to make. Right now you only have two, you could make it 20 then make it so there is a counter on how many are active. Each time the player fires, you initialize a new Fire object and increase the active counter up until the active counter is at max or max - 1 anyway.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: July 25th, 2017, 9:21 am 
 

Joined: July 24th, 2017, 8:23 pm
Posts: 6
Yeah i already do that. The problem is that when i press V to fire it fires all the ojects simultaneously. I found a way to avoid that by placing a bool inside the if statement of V and placing another if outside of the V if like this:
Code:
             if (wnd.kbd.KeyIsPressed('V') && fcount <= 2 && must == false)//Player Controls
      {
         if (fcount >= 0 && fcount < 2)
         {
            fcount1 = fcount;
            player.inhibitV = true;
            fire[fcount1].firex = player.x;
            fire[fcount1].firey = player.y;
            must = true;
         }
         if (fcount <= 1)
            fcount++;
      }

                for (int y = 0; y < 1; y++)//Second Fire enable
         {
         if (fire[y].firey < 395)
            must = false;
         }

But this doesnt help if i want to fire more than 2 shots.

Edited by Albinopapa to use the code tags.


Top 
 Profile  
Reply with quote  
 Post Posted: July 25th, 2017, 10:04 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2844
Location: Oklahoma, United States
What I do is create a firingdelay variable and a timecounter or framecounter variable, when the counter reaches the delay, allow user to fire next bullet by incrementing the activebulletcount.

pseudo code
increase framecounter
if V pressed and framecounter greater or equal to firingdelay
  • find first dead bullet in array ( either hit target or border )
  • spawn new bullet at that index
  • increase activebulletcount and
  • reset framecounter
When a collision happens,
  • kill bull
  • decrease activebulletcount

You might break things down into functions instead of having all the logic right in one function. This will help keep things in perspective.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: July 25th, 2017, 11:31 am 
 

Joined: July 24th, 2017, 8:23 pm
Posts: 6
Thx for the replay i will try that.


Top 
 Profile  
Reply with quote  
 Post Posted: July 31st, 2017, 7:36 pm 
 

Joined: July 24th, 2017, 8:23 pm
Posts: 6
I just finished tutorial 19 and as I go on I add what I learn into the code of the game.


Top 
 Profile  
Reply with quote  
 Post Posted: July 31st, 2017, 8:39 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2844
Location: Oklahoma, United States
^^
That's a good way to do it.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: August 6th, 2017, 9:17 am 
 

Joined: July 24th, 2017, 8:23 pm
Posts: 6
I am at tutorial 20 now and added more things into the game, it looks nothing like before.


Top 
 Profile  
Reply with quote  
 Post Posted: August 14th, 2017, 6:20 pm 
 

Joined: July 24th, 2017, 8:23 pm
Posts: 6
Now the game has 3 levels. I also added upgrades the grey squares increase fire number and the blue increace fire frequency.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 9 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: