Jump to content


Killpill

Member Since 22 Jul 2005
Offline Last Active Sep 09 2012 08:58 PM

Topics I've Started

Generating terrain objects as needed

11 May 2012 - 03:42 AM

I came here the other day and posted this topic:
http://gmc.yoyogames.com/index.php?showtopic=539230&st=0#entry3953653

I must say, my first method was stupid. As you read the topic you'll see I went towards using an array. Now I'm using a trigger that checks the array for collisions then I create the block (sometimes a few, depending on the nature of the object) at the right place on the grid and trigger the collision event that is meant to happen when that block is hit. The block will check every second for a collision and, if there is none, it destroys itself.

I don't mess with the slopes or any other terrain, just the squares. Adding slopes may be easy and I will try is a bit, but I wanted to post this and see what others thought of what I'm doing.

I am doing this so I can have the benefit of a reduced object count (before: 1849, after: 346) without completely rewriting my physics system. The game has gone too far and I don't want that setback. Hopefully such a system as this may help others as well, but I am not going to make an engine out of it. So here is my code. If anyone is helped or inspired by it, awesome.
Code

Generating the array/cleaning up the blocks:
//Get the width and height of the array
_width = ceil(room_width/32);
_height = ceil(room_height/32);

//Loop through the array and set the default value to false
for (_i = 0; _i < _width; _i+=1){
  for (_ii = 0; _ii < _height; _ii+=1){
    global.map[_i,_ii] = false;
  }
}

//Loop through the terrain objects and delete all the ones on the 32x32 grid
with objBlock {
  if (x mod 32 = 0 && y mod 32 = 0){ //if there is a remainder the object is not on the grid
    global.map[x/32,y/32] = object_index; //write position to the array
    instance_destroy();
  }
}

Trigger: It checks for the global variable just in case the map was NOT optimized. The game should run no differently if the above code is not run.
if (variable_global_exists("map"))
{
  _l = sprite_get_bbox_left(mask_index) - sprite_get_xoffset(mask_index);
  _t = sprite_get_bbox_top(mask_index) - sprite_get_yoffset(mask_index);
  _r = sprite_get_bbox_right(mask_index) - sprite_get_xoffset(mask_index);
  _b = sprite_get_bbox_bottom(mask_index) - sprite_get_yoffset(mask_index);
  //checks every side of the sprite for a collision.
  return global.map[floor((x+_l)/32),floor((y)/32)] || global.map[floor((x+_r)/32),floor((y)/32)] || global.map[floor((x)/32),floor((y + _b)/32)] || global.map[floor((x)/32),floor((y + _t)/32)];
}

Example collisions:
In Event Trigger Collide Map (the above code) in objGrenade
_x = floor(x/32);
_y = floor(y/32);
if (global.map[_x - 1, _y] && !instance_position((_x - 1) * 32, _y*32, objBlock)) instance_create((_x - 1) * 32, _y*32, objBlock);
if (global.map[_x, _y] && !instance_position(_x * 32, _y*32, objBlock)) instance_create(_x * 32, _y*32, objBlock);
if (global.map[_x + 1, _y] && !instance_position((_x + 1) * 32, _y*32, objBlock)) instance_create((_x + 1) * 32, _y*32, objBlock);
  
if (global.map[_x, _y - 1 ] && !instance_position(_x*32, (_y-1)*32, objBlock)) instance_create(_x*32, (_y-1)*32, objBlock);
if (global.map[_x, _y + 1 ] && !instance_position(_x*32, (_y+1)*32, objBlock)) instance_create(_x*32, (_y+1)*32, objBlock);

event_perform(ev_collision, objCollision);

Note for the above: This object is a grenade. If I don't pad the area around the collision block with other blocks it will bounce off the side of the block. The code checks to see if the map should have block in places before trying to place one and creates one if there is not one there already.

In Event Trigger Collide Map (the above code) in objShell_casing
if (!instance_position(floor(x/32)*32, floor(y/32)*32, objBlock)){
  instance_create(floor(x/32)*32, floor(y/32)*32, objBlock);
}
event_perform(ev_collision, objSolid);

Note for above: This is a very small object that just does a small bounce. Like before, I check if there is a block there before creating one. This time I don't need to check the map array at all because by triggering this event we know the object is at a place where a block is.

objBlock:
In Event Create
if ((variable_global_exists("map")) && (x mod 32 = 0) && (y mod 32 = 0))
alarm[0] = 30;
In Event Alarm 0
if (place_free(x,y)){
  instance_destroy();
}

alarm[0] = 30;

Note for above: The creation code checks if the map has been created and, if so, if the block is on the grid. This is so the blocks will not delete themselves if the optimization init was not run or they were skipped by it.

I would use instance_activate and such but until Game Maker has instance_activate_region_object and instance_deactivate_region_object that method is not an option for my type of game.

Here is a video showing the difference and some code that I had shown here. I forgot to show the trigger.
http://www.youtube.com/watch?v=lY4giL1lGFA

The dark spots on the map are the blocks I seek to reduce. I've only done the squares so far because the rest were only a minor concern. The second time I run the game I've enabled the map optimization and those blocks are gone, only being created when needed. I programmed the player to not require those blocks anymore, same with bullets. They use the array data directly so that is why they don't create blocks when they hit walls. I may take this back, it depends. Either way, I'm happy with the results of this code so far.

I hope you can read the instance count but the numbers are:
Before: 1849
After: 346

If I missed anything or something needs explaining be sure to ask. :)

Edit: Fixed some logic errors and changed the collision checking for when a block will delete itself.

Dealing with hundreds of terrain objects

08 May 2012 - 05:05 AM

My project's other programmer started having lag issues after tiling a map he made. He quickly jumped to blaming Game Maker's tile system, saying it can't handle a large amount of tiles and such. That struck me as silly because we have had larger maps with more tiles in the past.

Anyways, in looking for a solution to his lag (I can't even get the game to lag on my machine), I saw this map has around 1,500 32x32 terrain block objects. In our engine, like many engines, these blocks are not visible and have no events. We've always had a large number of objects like this so I figured I should try, again, to fix it.

I decided this time to compress all the blocks into two objects: a block and a slope.

This is my code:
//Create surfaces
_blocks = surface_create(room_width, room_height);
_slopes = surface_create(room_width, room_height);

//Go through the terrain objects
with objSolid{

  if (object_index = objBlock){ //normal 32x32 block
    surface_set_target(other._blocks); //set drawing target to the block surface
    draw_sprite(sprite_index, 0, x, y); //draw 32x32 block
    instance_destroy(); //destroy unneeded block object
  }
  
  if (object_index = objSlope_left || object_index = objSlope_right){  //slopes
    surface_set_target(other._slopes);
    draw_sprite(sprite_index, 0, x, y);
    instance_destroy();
  }
}

surface_reset_target(); //set normal drawing mode

//create a sprite for the new block object
_spr = sprite_create_from_surface(_blocks, 0, 0, room_width, room_height, 0, 0, 0, 0);
//create the block and set the sprite
(instance_create(0, 0, objBlock)).sprite_index = _spr;

//same for slopes
_spr = sprite_create_from_surface(_slopes, 0, 0, room_width, room_height, 0, 0, 0, 0);
(instance_create(0, 0, objSlope)).sprite_index = _spr;


//free the unneeded surfaces
surface_free(_blocks);
surface_free(_slopes);

Which reduces the object count by around 1,500 with a memory impact (two 5000x5000 sprites). I know I can trim a few thousand pixels from the sprites but I'll wait for the other coder to see how his PC handles this script before I go into it further.

Memory*:
18.993152mb, before
19.857408mb, after

*Note: cleanmem dll is run after this script

So, this reduces the object count by 1,500 but I don't know how well this code will run on other computers. Any thoughts on the method I'm using?

Out With A Whimper|a Platform Shooter With Feeling

21 December 2009 - 11:17 PM

Posted Image

A 2D Halo side-scroller from TriBlox Game Studios, featuring the level "Bysis", a prologue setting the stage for the events of H:OWaW. Play as Red Team's squad leader, Dustin B11, accompanied by scout sniper Allison B36 in a race against time to find the ONI AI, Bysis. Newly added online integration allows the player to login and track their kills and badges online.

>> NEWS


- February 08, 2010: Feburary News Update
- January 11, 2010: January News Update
- December 21, 2009: Newest demo from SAGE 2009 has been added. Download it now!

>> DEMO DOWNLOADS
- NEW SAGE 2009 Demo | TriBlox.org
- 2008 Demo | Mediafire | YoYo Games

>> FEATURES

- Custom content: Tons of all-original content, including all new weapons and enemies.
- Forge: A realtime map editor.
- Customization: Fully customizable characters, with tons of color, armor, and emblem combination.
- TriOnline: Track your kills and badges online
- And as always, much, much more...

>> SCREENSHOTS

Posted Image

Screenshot 1 / Screenshot 2 / Screenshot 3 / Screenshot 4 / Screenshot 5 / Screenshot 6

>> TRAILERS

- NEW SAGE Trailer
- 2008 Trailer

>> THE H:OWAW TEAM

- 117 - Coding, Sprite artwork, Graphic art, Plot
- Killpill - Coding, MP Coding, Plot, Website
- Makar - Sprite artwork, Plot
- Klaykid - Concept artwork, Graphic art
- Legacy - Additional coding
- NewGuy - Graphic art
- Torrent, Misfit - Sprite artwork
- Full credit list

>> LINKS

- H:OWaW Page
- TriBlox.org
- TriBlox Forums

>> SUPPORT

Signature Generator

Example:

Posted Image


Posted Image

[url="http://gmc.yoyogames.com/index.php?showtopic=457995"][img]http://www.majhost.com/gallery/TriBlox/Mock-Ups/owawsupport.gif[/img][/url]


>> CONTROLS

Spartan/Elite
A,D - Move left or right
W - Jump
S - Crouch
E - Pickup weapon, enter/exit vehicle
Q - Dual wield,
Space - Melee
Shift - Sprint
Left mouse button - Fire
Right mouse button - Throw grenade
Control - Switch weapons
G - Switch grenades
X - Use equipment
Z/MMB - Zoom (Scoped weapons only)

Monitor
Enter - Change into monitor/Player
W - Move
Space - Bring up forge pallets
Arrow keys - Switch through pallets
Delete - Delete

Vehicles
E - Enter/Exit
A,D - Move left or right
Left Mouse button - Fire

Halo: Out With a Whimper was created under Microsoft's Game Content Usage Rules, using assets from Halo: CE, Halo2, and Halo3, copyright Microsoft Corporation.

Saving Sounds From The Exe To The Computer.

26 July 2009 - 09:06 PM

I have a bit of a problem, and the answer is alluding me. I can see it being something simple.

The game I am working on has ran into a loading time issue, it takes way too long.

So I am going to load the sound files externally.

However, there are...198 sounds. Being as I am, someone who will spend more time making something easier than it would have taken to the actual hard work, I want to save the sound files with code.

I have everything worked out. I went to show resource names and got every sound's name.

I will create a giant string and have the game read each line then save that file.

I.E:

sound=string_replace("snd","",sndDeath)

Returning Death, which is then used to save the file as Death.wav.


There is the problem. Saving that sound. I haven't had much luck searching.

I've learned of MCI commands, but have not seen how to make it save a sound from the game, and my attempts
have failed.

MCI_command("open " + string(sndActive_camo) + " type waveaudio alias Activecamo")
MCI_command("save Activecamo" + string("sndActive_camo.wav"));
MCI_command("close Activecamo");

This is my latest try, using just one sound right now till the code works. It saves a blank "sndActive_camo.wav" file.

All I need is to get the command to load that sound or for someone to tell me another way, again, this could be a simple thing I've just overlooked.

Thank you for reading, I hope you can help,

Killpill

Halo Creator 1 --- 1000+ Downloads

11 December 2008 - 03:55 AM

Hey guys, I hosted Halo Creator to Yoyo Games a while ago, please play and rate.  :P

A tutorial can be found here:
http://uk.youtube.co...feature=related

Link:(Screenshots on Yoyo Page)

http://www.yoyogames...mes/show/62911#

A make-a-battle type of game.

Create and destroy, play as a unit yourself.


Unit list:
---------------
Humans:

Marines:
Assault rifle
Rocket launcher
Sniper rifle
SMG
Magnum

ODST:
Dual SMG
Battle Rifle

Spartans:
Assault rifle
Shotgun
Spartan Cannon
---------------
Covs:

Grunts:
Plasma pistol
Fuel rod
Needler

Jackles:
Sniper rifle
Shield and plasma pistol

Elites:
Duel plasma rifles
Carbine

Brutes:
Brute Shot
Spiker Rifle

Hunters:
Fuel rod arm attachment.

Object list:
---------------
Covs:
Shield
Spectra
---------------
Humans:
Shield
Warthog

Level list:
---------------
Grassland
Arctic
Desert

Have funXD

Please tell glitches, give comments!