Go to page Previous  1 ... 35, 36, 37, 38, 39, 40, 41  Next  [ 816 posts ]  Reply to topicPost new topic 
Coding Help, Questions and Issues relating to coding
Author Message
 [zz]
 Post subject: Re: Coding Help
PostPosted: Thu Mar 24, 2016 3:59 am 
User avatar
I, Papyrus, am awesome!
Member
[*]
[*]
[*]
Oh my god, I didn't even knew yprevious is a valid variable! :huh: o_O
That was actually exactly what I had in mind, but didn't knew how to save the previous y position. Now that I know that yprevious is valid, I can finally do my original idea, and it really worked, so thank you very much (now waits for a response at VG-Resource).

_________________
My games:
Spoiler:

What I also support:
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [at]
 Post subject: Re: Coding Help
PostPosted: Thu Mar 24, 2016 4:33 am 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
Even if yprevious wasn't a built-in variable, you could still make it yourself by just setting the value at a time it becomes outdated in the next frame.
For instance:

//All movement-related code here
yprevious = y;
y += yspeed;

As you could see, yprevious will always be outdated by the time all the movement is calculated, because it's set just before the actual y-value is changed.

I know you don't need it now, but I'm just saying. After all, you probably won't have as many built-in variables that are easy to replicate by the user in other game engines if you ever switch.

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
 [fi]
 Post subject: Re: Coding Help
PostPosted: Sat Mar 26, 2016 11:40 am 
User avatar
:3c
Member
[*]
[*]
[*]
[*]
[*]

I'm having problems with saving the screen on a surface in GMS. I'm not sure what I'm doing wrong.

objPause create event:
Code:
paused = false;

surf = surface_create(view_wview,view_hview);


Step event:
Code:
if keyboard_check_pressed(vk_escape)
{
    if paused = false
    {
        //background
        surface_set_target(surf);
        bg = background_create_from_surface(bg,view_xview[0],view_yview[0],view_wview[0],view_hview[0],1,0);
        surface_reset_target();
       
        instance_deactivate_all(true);
        paused = true;
    }
    else
    {
        instance_activate_all();
        paused = false;
        background_delete(bg);
    }
}


and the draw event:
Code:
if paused
{
    draw_background(bg,view_xview,view_yview);
    draw_text(view_xview+10,view_yview+10,"PAUSE");
}


I might be doing something out of order. I don't know, I'm not that good with surfaces.

_________________
YouTube | Steam | Twitter

My signature is very empty now that I've removed the advertising. :(
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Thu Mar 31, 2016 5:27 pm 
User avatar
Lucario and/or Braixen = best avatar
Member
[*]
[*]
[*]
[*]
[*]

Edit: NVM fixed it lol. I was drawing the surface too small and at the wrong coordinates :v

Spoiler:

_________________
Games I've made:

Spoiler:

Fangame(s) I support:
Spoiler:


You can find me on:
Image Image Image Image Image


These are my Smashers of choice:
Image
 
Top
Offline 
 
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Fri Apr 01, 2016 3:35 am 
User avatar
C# Programmer
Member
[*]
[*]
[*]
[*]
@Catonator I think you have to have the surface set/resets in the draw event, not the step event.

_________________
MFGG TKO (scrapped) - Animations
Image
"It feels that time is better spent on original creations" - Konjak
Focus on the performance, the idea, not the technical bits or details - Milt Kahl
 
Top
Offline 
 
 
 [fi]
 Post subject: Re: Coding Help
PostPosted: Fri Apr 01, 2016 6:33 am 
User avatar
:3c
Member
[*]
[*]
[*]
[*]
[*]

It doesn't work even then. The sprite is created and surface is working, is just isn't drawn. Replacing my own surface with application_surface works properly, but the screen is super zoomed in for some reason.

_________________
YouTube | Steam | Twitter

My signature is very empty now that I've removed the advertising. :(
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Fri Apr 08, 2016 7:32 pm 
User avatar
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Hm, first of all, I think the surface should be created in the Step event (which, it should be created before the surface sets target) rather than the Create event. Then, when the game is unpaused, you should add this line somewhere in the bracket that contains the unpausing code in the Step event:

Code:
surface_free ( surf );


Finally, I think you should add the following line somewhere inside the bracket in the Draw event:

Code:
draw_surface ( surf, 0, 0 );

_________________
Image
 
Top
Offline 
 User page at mfgg.net
 
 [gb]
 Post subject: Re: Coding Help
PostPosted: Fri Apr 08, 2016 9:01 pm 
User avatar
Member
How could I make a line of objects following each other, so each object follows the one in front of it? Like the eggs in Yoshi's Island?

_________________
Image
 
Top
Offline 
 
 
 [tr]
 Post subject: Re: Coding Help
PostPosted: Sat Apr 09, 2016 7:30 am 
User avatar
Thanks DonnieTheGuy!
Administrator
[A]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
Jeorge535 wrote:
How could I make a line of objects following each other, so each object follows the one in front of it? Like the eggs in Yoshi's Island?

I think Friendly Dictator (or someone else) has a tutorial of this on the main site.
EDIT: http://www.mfgg.net/index.php?act=resdb ... 4&id=30094

_________________
Image
 
Top
Offline 
 
 
 [gb]
 Post subject: Re: Coding Help
PostPosted: Sat Apr 09, 2016 6:41 pm 
User avatar
Member
Mors wrote:
Jeorge535 wrote:
How could I make a line of objects following each other, so each object follows the one in front of it? Like the eggs in Yoshi's Island?

I think Friendly Dictator (or someone else) has a tutorial of this on the main site.
EDIT: http://www.mfgg.net/index.php?act=resdb ... 4&id=30094

I saw this tutorial, expect the 'objects' in this tutorial are not actually objects in Game Maker, but sprites which are drawn in the draw event of the 'leader' object. In my game, I've got an object called obj_egg_following for the followers How can I set it so each instance of obj_egg_following follows the one in front of it, then the first one follows Yoshi? Sorry I'm basically asking the same question again, I should've been more specific.

_________________
Image
 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Sat Apr 09, 2016 8:56 pm 
User avatar
Member
[*]
Jeorge535 wrote:
How could I make a line of objects following each other, so each object follows the one in front of it? Like the eggs in Yoshi's Island?

I don't know how it would be implemented in GML (I've only used Python and C++), but here's some pseudocode of how I would do it:
Code:
When loading level:
   Create a bunch of egg objects at coordinates x,y.
   Create a list of coordinates called coordinate_list.
   Add the coordinates of the first egg to every index in coordinate_list.

While level is running:
   Update the position of the first egg.
   Shift all of the values in coordinate_list right once. The first index is now empty.
   Add the coordinates of the first egg to coordinate_list[0].
   Update the coordinates of the 2nd egg to be, for example, coordinate_list[16].
   Update the coordinates of the 3rd egg to be, for example, coordinate_list[32].
   Repeat for all eggs in a for loop.

Basically, every time you update the position of your 1st egg you move the 2nd egg to where the first one was 16 updates ago. If you repeat this for all of your eggs, they will line up and follow the path the first egg took. You only do the movement calculations for the first egg and the rest follow its trail. If the 1st egg is moving towards Yoshi's position, the rest follow and eventually converge on him like in Yoshi's Island. If you used coordinate_list[8] and coordinate_list[16] to control the trailing eggs, for example, they would follow each other a lot more closely.

_________________
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Sun Apr 17, 2016 5:28 pm 
User avatar
Member
[*]
Jeorge535, I got your PM asking for more clarification. I'll go ahead and leave my answer here so that other people can benefit from it. Nobody likes searching for an answer online and having it disappear into privacy. :laugh:

Code:
Does GML have some kind of array? When I mentioned coordinate_list, I was talking about making a data structure that looks like this:

[(0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]

So let me walk you through this more visually. When Yoshi enters the map, you spawn a bunch of eggs at a coordinate like (3, 2), yes? The first step is to fill your entire array with those values:

[(3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2)]

Yoshi then moves, and the first egg object moves towards him. Let's say it moves to (4, 2). So first you shift all of the values in coordinate_list right one index...

[(0, 0), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2)]

And then you add the new coordinates to index 0.

[(4, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2)]

The 1st egg moves to index 0, the 2nd egg moves to index 3, the 3rd egg moves to index 6, etc. At this point, the 1st egg has moved and the rest are still at (3,2). Now, we keep moving the first egg and updating the list like so...

Egg 1                    Egg 2                   Egg 3
[(4, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2)]
[(6, 3), (4, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2)]
[(7, 4), (6, 3), (4, 2), (3, 2), (3, 2), (3, 2), (3, 2), (3, 2)]
[(8, 5), (7, 4), (6, 3), (4, 2), (3, 2), (3, 2), (3, 2), (3, 2)]

Notice how now, the coordinates (4,2) are at index 3 aka coordinate_list[3]. Egg 2 will move to (4,2), which is where Egg 1 was three frames ago. And once Egg 1 updates its position 3 more times, Egg 3 will move to (4,2). The result is that you do movement calculations for Egg 1 while Egg 2 and Egg 3 follow the same path a few frames later. Keep in mind, this is just an example. The list doesn't have to be 8 indexes long and you don't need to use index 3 and index 6 for your eggs. If you use much larger values like a 64-long list with indexes 8 and 16, the eggs will space out more and look better.

_________________
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Sat Jul 16, 2016 10:33 pm 
User avatar
AKA the Greenish Hero
Member
[*]
How do I make an object constantly move itself directly between two other objects? For example, how do I make Obj_C stay between Obj_A and Obj_B at all times regardless of how A and B moves around?

_________________
Want to try an original game?
viewtopic.php?f=8&t=13625

Click it and you'll live forever!
 
Top
Offline 
 
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Sat Jul 16, 2016 11:01 pm 
User avatar
もう帰らない
Member
[*]
[*]
[*]
[*]
With a simple mathematical formula that goes something like this:

Code:
c.x = min(a.x, b.x) + abs(a.x - b.x) / 2
c.y = min(a.y, b.y) + abs(a.y - b.y) / 2

_________________
https://onpon4.github.io
 
Top
Offline 
 
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Wed Jul 20, 2016 1:55 am 
User avatar
Member
[*]
Hey, guys! I've been learning C++ for the past few months and I have question. Instead of my current project, I've decided to practice with something simpler like a Mario game. So, what is the approach most programmers take when implementing interactive tiles? Question Mark blocks you can hit, springs you can jump on, spikes that damage you, etc. I have 2 ideas of how I could implement those.

Solution 1: Tiles are integers.
I have a Level object filled with a grid of integers representing each tile. Whenever Mario collides with a tile, I go through an enormous switch statement checking the integer. If it's 0, he collides. If 1, he takes damage. If 2, he hit a brick block. Etc etc etc. Obviously, this has the drawback of requiring another switch case every time I add a new type of tile.

Solution 2: Tiles are inherited objects.
I have a Level object filled with a grid of Tile objects. All Tile objects have an activate() function. Each type of tile (i.e. Ladder, Brick, Spike) inherits from the Tile object and has its own virtual activate() function. Whenever Mario hits a tile, it calls that tile's activate() and it responds accordingly. This method seems better than the switch statement, but requires a new inherited class for each tile added.

Alternatively, there could be a ton of approaches I don't know about. I don't know how the actual Mario games implement tile interactions, for instance.

_________________
 
Top
Offline 
 User page at mfgg.net
 
 [us]
 Post subject: Re: Coding Help
PostPosted: Sat Jul 30, 2016 2:55 pm 
User avatar
C# Programmer
Member
[*]
[*]
[*]
[*]
I prefer a more entity component based system where batches of input data are transformed into output data. Entities are the result of related data affecting eachother. For your case:

1)Update and store all tile collision data
2)Categorize data by output (applies damage, shows items, causes upward velocity(springs), etc)
3a)Foreach damage tile, apply damage to victims (player, enemies, etc)
3b)Foreach item tile, show an item (Mystery blocks)
3c)Foreach velocity change tile, apply it (springs)

Note that you don't necessarily need a player object to apply damage or velocity to. For damage, you just need the health. For velocity, you just need the physics object. By only using the necessary data, you avoid unnecessary coupling and the systems become more flexible. For example, you could create lava using the above by tagging the tile data as damaging and changing velocity (Mario jumping up due to lava damage), speed boost pads instead of just jump spring, and note blocks too.

_________________
MFGG TKO (scrapped) - Animations
Image
"It feels that time is better spent on original creations" - Konjak
Focus on the performance, the idea, not the technical bits or details - Milt Kahl
 
Top
Offline 
 
 
 [aq]
 Post subject: Re: Coding Help
PostPosted: Sat Jul 30, 2016 3:23 pm 
User avatar
Obey.
Member
[*]
[*]
Hey, guys! I've been learning C++ for the past few months and I have question. Instead of my current project, I've decided to practice with something simpler like a Mario game. So, what is the approach most programmers take when implementing interactive tiles? Question Mark blocks you can hit, springs you can jump on, spikes that damage you, etc. I have 2 ideas of how I could implement those.

Solution 1: Tiles are integers.
I have a Level object filled with a grid of integers representing each tile. Whenever Mario collides with a tile, I go through an enormous switch statement checking the integer. If it's 0, he collides. If 1, he takes damage. If 2, he hit a brick block. Etc etc etc. Obviously, this has the drawback of requiring another switch case every time I add a new type of tile.

Solution 2: Tiles are inherited objects.
I have a Level object filled with a grid of Tile objects. All Tile objects have an activate() function. Each type of tile (i.e. Ladder, Brick, Spike) inherits from the Tile object and has its own virtual activate() function. Whenever Mario hits a tile, it calls that tile's activate() and it responds accordingly. This method seems better than the switch statement, but requires a new inherited class for each tile added.

Alternatively, there could be a ton of approaches I don't know about. I don't know how the actual Mario games implement tile interactions, for instance.


Keep the tiles in a contigous array (like the former solution). Minecraft used to hold tile-maps in an array of 2-byte elements. The first byte is the tile ID, and the lower half of the second byte is the tile state (specific data based on tile ID). The drawback with this approach is that some tiles only need one tile state. Minecraft now holds tile-maps in an array of 2-byte elements, where each tile state has a unique tile ID. This is better since it allows some tiles to have more states than other tiles, which leaves more room for more tile IDs.

For entity-tile interaction, order of updates matter (ex. see the above post).

_________________
I am your supreme leader
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Wed Aug 10, 2016 3:03 pm 
User avatar
Member
[*]
Funny you guys would mention that. I've actually learned rather recently about data-driven Entity Component systems. It's a really hard concept for me to wrap my head around but it's supposedly cache-friendly and easily expandable. I'll be giving it a shot and reporting back if I have any issues.

DarkBlueYoshi, that's pretty interesting. I always figured Minecraft used such a lightweight system since it has to handle so many loaded blocks.

_________________
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Coding Help
PostPosted: Thu Aug 18, 2016 3:30 pm 
User avatar
Member
i was hoping if anyone could give me some help at game-coding? never tried, so don't know any game coding language. kinda half decent at html but that's about it

_________________
i did a YOUTUBE

https://www.youtube.com/channel/UCWhEB2 ... EAVCeLF-vg
 
Top
Offline 
 
 
 [at]
 Post subject: Re: Coding Help
PostPosted: Thu Aug 18, 2016 3:43 pm 
Cliax Codec X Splatoon
Member
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]
[*]

[*]
[*]
ollydgaming wrote:
i was hoping if anyone could give me some help at game-coding? never tried, so don't know any game coding language. kinda half decent at html but that's about it
Well, I recommend you either start with GameMaker: Studio or Unity. They both have large userbases, lots of tutorials, and are among the easiest to get into for beginners. Here's some pros and cons so you can decide which one fits your needs better:

GameMaker: Studio
Pros
  • Easy game creation for 2D games
  • Custom coding language GML which takes aspects from object-oriented programming languages and makes it more accessible for beginners
  • Very fast prototyping
Cons
  • Very limited to no 3D functionality
  • Inefficient and slow
  • Can teach bad coding habits
  • Buggy IDE

Unity
Pros
  • Uses C# and JavaScript which are also used professionally
  • Very stable, userfriendly and flexible IDE
  • More convenient to do complex tasks in (networking, shaders, ...)
  • Perfect for 3D
Cons
  • Somewhat inconvenient to use for 2D
  • While free, the pro version can only be obtained via a subscription (afaik)

I will refrain from saying which one I prefer (though people who know me know what it is anyway). Just trying to give a brief overview on these two game engines, as they're likely the ones of the most interest to you.

_________________
Image

Cliax Codec is a combination of top-down and third-person shooter. The gameplay will blend platforming, puzzle and shmup elements together to create a unique gameplay experience. You will take control of four playable characters which rise against a team that seemingly wants to take over the world - but are their motives really that cliché, or are there deeper motives behind their actions?

Currently designing Chapter 1-6, 5%

GOTM titles
Spoiler:
Fan Art
Spoiler:
 
Top
Offline 
 User page at mfgg.net
 
« Previous topic | Next topic »
Display posts from previous:  Sort by  
Go to page Previous  1 ... 35, 36, 37, 38, 39, 40, 41  Next  [ 816 posts ]  Reply to topicPost new topic 


Who is online

Users browsing this topic: No registered users and 1 guest


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
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group