Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Forum
1 2 3 Previous Next  
Search
Topic Changing the level in a game By kyonides Date 2019-08-27 03:51
Since jlnr suggested you should redistribute your game data, here's a small example of how to extrapolate all that stuff to different scenes.

#!/usr/bin/env ruby
#   Scripter : Kyonides-Arkanthes
#   Last Update : 2019-08-25
begin
  puts 'Using custom Gosu gem'
  require './gosu.so'
  require './lib/require_custom'
  Game.custom_gem = true
rescue
  puts 'Retry - Now using default Gosu gem'
  require 'gosu'
  require './lib/require_default'
  Game.custom_gem = nil
end
require './tileset'
require './lib/map'
class MainWindow < Gosu::Window
  attr_accessor :scene
  def initialize
    super(800, 608, false, 40) # Custom Gosu Gem
    Game.current_dimensions(self.width, self.height)
    self.show_cursor = true rescue nil
    self.caption = 'KScenario Gosu'
    puts 'Using Gosu version ' + Gosu::VERSION
    Game.setup_title
  end
  def button_down(bid) Game.scene.button_down(bid) end
  def button_up(bid) Game.scene.button_up(bid) end
  def update() Game.update end
  def draw() Game.scene.draw rescue nil end
  #def needs_cursor?() true end # Not needed in my custom Gosu gem!
end

begin
  Game.start_loop(MainWindow)
rescue
  Load.clear
  puts "Rescue!"
  puts m = $!.message
  puts b = $!.backtrace.reverse
  File.open('log.txt','w') do |file|
    puts "Opened file!"
    file.puts Time.now
    file.puts m
    file.puts b
  end
end
Topic Changing the level in a game By kyonides Date 2019-08-23 21:05
First it'd be helpful if you tell us what are the "changes" you're talking about. What kind of stuff do you need to save before the scene changes? HP HUD? Level? Difficulty? Angle? Zoom? X Y coordinates? O_o?

Even so you might keep in mind you can use more instance variables to store other stuff as well. :)
Topic Changing the level in a game By kyonides Date 2019-08-23 06:54
You know, that would relatively soon become a LARGE number so it wouldn't help you to store it at all. You'd better divide it by the update interval. Plus why do you wanna save any data in the draw method? You got an input and a general update method to do that! I'd recommend saving stuff inside any of those two methods. Since you're using an instance variable to determine the scene, that won't be a problem. :)
Topic SCROLLABLE Items list selection By kyonides Date 2019-08-15 21:45
How curious... You didn't pick clipping and updating y coordinate.
Topic KScenario Gosu By kyonides Date 2019-07-08 07:43
Yeah, I've been working on a project where I'd offer a menu scene where the player can choose a hero and a destination where to send him and let his story unfold. Of course he will get a few things right while exiting the scene to help him somehow. I was first busy with a version for another engine but now I have ported my script to a "full fledged" Gosu project. Well, so far it's working smoothly and let's you hear BGM's just as expected. :P

Here's the download link just in case you will download the demo some day...

Get KScenario

So far as I know, it works on Linux distros like Ubuntu or Kubuntu because I added a custom table gem or library file.

You can also take a look at the GUI. Oh well, it seems I can't resize the image... OK, I'm using a thumbnail then.

[https://i.postimg.cc/hhzL2TV5/kscenariogosu02.jpg]
Topic Installing chipmunk in Ruby 2.4.3 failed! By kyonides Date 2018-04-18 01:00
Since my linux distro has not updated Ruby since it had reached version 2.3.x chipmunk runs on it :P Windos had to be the same old rascal... =_=
Topic Issues with Ruby Gosu Image#subimage By kyonides Date 2018-04-17 00:01
Well, I also use mega, but I know, github might help. The thing is I never got used to github :P

The issue was that it subimage does not let you create composite images, like tiles that have different sizes. If you try to use it to draw them during gameplay, it fails to show you anything...
Topic Installing chipmunk in Ruby 2.4.3 failed! By kyonides Date 2018-04-14 20:30
This is the error message that I get if using Ruby 2.4.3 (but not on 2.3.3)...

Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions.  This could take a while...
ERROR:  Error installing chipmunk:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby/lib/ruby/gems/2.4.0/gems/chipmunk-6.1.3.4/ext/chipmunk
C:/Ruby/bin/ruby.exe -r ./siteconf20180414-4972-yr7qn9.rb extconf.rb creating Makefile

current directory: C:/Ruby/lib/ruby/gems/2.4.0/gems/chipmunk-6.1.3.4/ext/chipmunk
make "DESTDIR=" clean
"make" no se reconoce como un comando interno o externo, programa o archivo por lotes ejecutable.

current directory: C:/Ruby/lib/ruby/gems/2.4.0/gems/chipmunk-6.1.3.4/ext/chipmunk
make "DESTDIR="
"make" no se reconoce como un comando interno o externo, programa o archivo por lotes ejecutable.

make failed, exit code 1

Gem files will remain installed in C:/Ruby/lib/ruby/gems/2.4.0/gems/chipmunk-6.1.3.4 for inspection.
Results logged to C:/Ruby/lib/ruby/gems/2.4.0/extensions/x64-mingw32/2.4.0/chipmunk-6.1.3.4/gem_make.out
Topic Issues with Ruby Gosu Image#subimage By kyonides Date 2018-04-12 03:23
I was using two images as gauge components, that did not work at all. Using a single image seems to work fine, but there is no good reason why neither subimage nor dup would work as expected.
Topic Early Version of KUnits Gosu By kyonides Date 2018-04-11 18:25
Just edit the Audio.state variable by setting its value to false or nil. :P
Topic Early Version of KUnits Gosu By kyonides Date 2018-04-10 22:50
I think you had download an outdated version from mediafire, the other day I only had uploaded RAR files to mega :P

Anyway this time I have uploaded new demos to both websites, plus I do think I have come up with a sprite script that might not be affected by subimage method the way CompositePictureSprite does. I even dared to call the new class the Gauge Sprite.
Topic Issues with Ruby Gosu Image#subimage By kyonides Date 2018-04-08 19:13
O.o but it does exist, it's the same as gauge1 and gauge2... Let me check the resources compressed file I uploaded, but you can use any other image as a gauge and go through the same nasty situation as I did :/
Topic Early Version of KUnits Gosu By kyonides Date 2018-04-08 02:09
Well, I have updated my KUnits scripts and resources, but I faced a weird issue while working with the Image#subimage method... :S Nope, it won't make the game project crash at all. :P
Topic Issues with Ruby Gosu Image#subimage By kyonides Date 2018-04-07 17:22
You can easily fix that yourself, in lib/setup folder you'll find all the modules that are used to configure my scenes or states scripts. There they usually begin with a BGM constant... but if you wanna test it with the multiple gauges on screen (OK, just one being displayed while the others are missing), you better wait till I upload the most recent version of my project.

I know, it looks more like a concept than an actual game, even if it exceeded 8000 lines of code already... :S

By the way, you gotta talk to the dark elf lady on the first map to open the pseudo battle screen. :P
Topic Issues with Ruby Gosu Image#subimage By kyonides Date 2018-04-07 01:35
So far I was glad with the option of reusing pictures by caching them. The only thing I disliked was the very same need to cache them :P

Sadly that has changed since I tried to make a new composite sprite class that kept an image that looks like a gauge, some sort of bar. As a single bar in a menu it worked quite fine, but that was not the case when I tried to use more than one of the same kind. While trying to draw three of them, only the first one got drawn as expected. I thought they shared the same x coordinate but they didn't!! What did I use to tile it? The Image#subimage method because the tiles have different dimensions. I suspected I should not cache that picture since you cannot dup Gosu::Images, so I preferred to skip the caching part and load it from file every single time I need to update it... to no avail, guys!! Gosu keeps ignoring them,even after I confirmed they do so exist! Honestly, I don't think it could be my fault and I do need some serious help here... :S

You can find the CompositePictureSprite or SpriteCompositePicture class in my KUnits Gosu demo on the corresponding subforum.
Topic How do I enforce the vsync in my project? By kyonides Date 2018-04-02 22:48
Thanks for replying, jlnr. Sadly I cannot use the default update_interval value, it would update stuff too fast on both OS's. :(
Topic Gosu::Window closes itself By kyonides Date 2018-03-31 22:19
I have noticed two things. The first thing would be the two loops you create at the end of the main script. You only need call one of them! The latter would be the strange condition you set in the update method that should close the game window. Why don't you try solving the issue by removing it?
Topic How do I enforce the vsync in my project? By kyonides Date 2018-03-30 22:30
So does your silence mean no Ruby Gosu project can't be vsync'ed at all? O_o
Topic Survey about Gems and Rubyversion By kyonides Date 2018-03-17 00:26
Ruby 2.3.x or 2.4.x depending on what OS I am working on. Actually I installed it on both Windows and Ubuntu. I have tried opengl but I did not know if it was the latest version because it failed during tests. I also installed chipmunk. I did not know about Ashton but I would definitely like to get shaders in gosu. Personally I would prefer all input stuff in ruby gosu to be located in a specific module other than mere Gosu. Just a humble suggestion :)
Topic How do I enforce the vsync in my project? By kyonides Date 2018-03-12 21:36
In my case I am running it on Ubuntu Linux and Windows 8.1, as far as I have seen on Windows it runs slower than on Linux. Jnlr suspected it might not have been vsync'ed there. So how do I ensure it gets sync'ed as expected?
Topic Gosu 0.13.3 released By kyonides Date 2018-03-11 16:51
By the way, I have noticed that using a specific milliseconds delay for the input update on Linux, makes it run quite slow on Windows. I reduced it by 10 milliseconds because it isn't a high value nor a large number at all, and still it ran slowly. On Linux some 1200 water drops fall fast enough to simulate rain, but they fall slower than leaves in autumn while on Windows. Is this a feature we all gotta deal with? Or is there any previous report concerning this issue? O_o
Topic SpaceRace - USSR vs USA By kyonides Date 2018-03-08 19:06
Well, I could tell you that it is possible to make a ruby game without a single global variable. My KUnits project is a proof of it. I am not implying you should do the same, but you can reduce the number of global variables even more than you already stated above. Check which global variables aren't called often enough and transform them into module's functions like $audio.ok_se getter becoming Audio.ok_se after creating the Audio module :P
Topic Early Version of KUnits Gosu By kyonides Date 2018-03-03 00:20
Well, I finally implemented a system to let my map events include more player interaction than just automatically opening a new scene. Now it lets the player read a conversation before switching scenes. :) I know, other people have achieved such a simple thing with ease, but I just could not make up my mind to come up with my own implementation :P
Attachment: kunitsgosulinux10.png (67k)
Attachment: kunitsgosulinux09.png (64k)
Attachment: kunitsgosulinux08.png (62k)
Topic Early Version of KUnits Gosu By kyonides Date 2018-02-12 02:47
It was a mess, caching Text or Font the way you suggested provoked weird just as I had foreseen, either the color did not match or the height... The main reason why I hate Font the way it is would be the impissibility to change the font height. That was the motivation I had to implement Text without caching it at all. Now I need to modify Gosu::Font to become similar to text without the recreate method. The window Ruby file is quite old indeed, the original file was written when Gosu had reached version 0.7 or so... :P
Topic Early Version of KUnits Gosu By kyonides Date 2018-02-11 04:59
I know what you said earlier about fonts, but I wonder if it really lets you update a font's contents when you change stuff like its dimensions or the text itself. Won't I find weird stuff on my screen after caching those fonts? O.o?

By the way I could not make waterdrops fall adequately. After a few cycles you may notice there is a large gap that keeps growing and growing...
Topic Early Version of KUnits Gosu By kyonides Date 2018-02-09 01:17
I have posted an updated version of KUnits Gosu, including a lot more cache stuff I had been coding in the last few months. I guess it is faster than usual, but I am unsure if that's good enough :(
Topic Early Version of KUnits Gosu By kyonides Date 2018-02-08 04:57
Actually a version I modified later on does include a Cache module that should work like your $_img global variable by creating a specific map or sprite cache of sorts. Perhaps if you could test it including the five script files I included on the support topic you could tell me if I could not solve the issue because I had overlooked it somehow :(
Topic Early Version of KUnits Gosu By kyonides Date 2018-02-07 01:58
This topic is linked to the following Slowdown during state switching step because it really suffers from strange delays... I'm posting this comment just to let you know, guys.
Topic Slowdown during state switching step By kyonides Date 2018-01-25 04:59
The game have been uploaded months ago, it was named KUnits Gosu...
Topic Slowdown during state switching step By kyonides Date 2018-01-17 04:53
Since it is evident that this topic does not catch people's attention, I request a moderator to close it. I do not think it should be deleted so closing sounds like a better choice, or it could be moved to some forgotten or old topics hidden subforum.
Topic bullets are not created right in the middle of the ship By kyonides Date 2018-01-05 22:40
Did you know that you no longer need to pass a window as an argument? Or are you working with multiple windows in your game project?
Topic Slowdown during state switching step By kyonides Date 2018-01-05 22:33
Well, this time I will attach a few Ruby files in case anybody can point out what's the actual root cause for my project's slowdown.
Attachment: additions.rb - Addditions (5k)
Attachment: gamemodule.rb - Game module (6k)
Attachment: input.rb - Input mods (4k)
Attachment: mapmodule.rb - Map module (1k)
Attachment: scenes.rb - Scenes scripts (63k)
Topic Slowdown during state switching step By kyonides Date 2017-11-21 04:09
Well, this time I'll show you the code concerning the logic update stuff, the most basic part, just in case you may found out why it's been so head-breaking lately...

* Removed the code to help readers find my latest post here *
Topic Slowdown during state switching step By kyonides Date 2017-10-10 14:02
I tried to cache sprites by creating hashes to store them in order to avoid loading them every single time I needed them so I thought it would help improve my game's response but... My map aren't really large, one is only a bit larger than a 800x600 window, 960 pixels wide at most... It only sports 4 events on map plus the player's sprite and its four companions...
Topic Slowdown during state switching step By kyonides Date 2017-10-07 18:14
I have been using my own state switching solution in my game project, the thing is that switching between two menus is fast, I rarely find and issue. The story gets a horrible twist whenever the map spriteset is involved, it freezes for a few seconds and then continues loading the new map or menu depending on the case. My transition state draws simple rectangles and waterdrops on screen, plus setups the new state then. It first displays the previous state and then lets it get replaced by the second state. At some point all black rectangles and waterdrops freeze abruptly for over 15 seconds before finishing and letting the player walk all around the current map or navigate through the current menu. I thought I had to make the setup and drawing run in a parallel process... so I used a new Thread only to find out that concurrence was a wacky idea after all.

What should I do then?
Topic Including temporary Screenshots in Gosu By kyonides Date 2017-10-07 18:00
Yeah, I could foresee such a situation, but I had to let you know we wouldn't give up at all XD plus I really need it...
Topic Including temporary Screenshots in Gosu By kyonides Date 2017-09-28 03:21
Could it be possible to include the take a snapshot of current state feature in all versions of Gosu? (I'm especially interested in such Gosu for Ruby's improvement XD)
Topic Input update interval By kyonides Date 2017-09-25 21:29
The lpaste.net link XD

I couldn't make it work with just fake images, the ones recorded by window.record feature, so I had to create black rectangles to simulate a transition. Now my issue is that it gets stuck for a few seconds especially while transitioning between maps...
Topic Early Version of KUnits Gosu By kyonides Date 2017-09-23 03:35
KUnits Gosu

This is a project I originally started on another game making software but later moved to Ruby Gosu once I felt comfortable enough with it. Below you can find my original script namely Gem Roulette where you can make that wheel spin like crazy and get some prize if any. It's a demo filled with features like working traditional or creative menus, map scrolling, teleporting, event collisions, buying items at a local shop, etc.

[https://s6.postimg.org/y2b26cwzl/kunitsgosulinux07.png]
[https://s6.postimg.org/dtwvc4cg1/gemroulettegosu01.png]

DOWNLOAD SECTION

MEDIAFIRE

MEGA
Topic Input update interval By kyonides Date 2017-09-23 03:25
Thanks for your assistance, lol_o2, I'll be checking it out once I get some spare time, storms kept me busy lately, but why do you call yourself an anonymous coward on the first link you posted? O.o
Topic Input update interval By kyonides Date 2017-09-19 18:49
What I was thinking had to do more with black and white graphics (or grayish gradients) that could let you perform the transitions in many ways. Let's say I've got a graphic for a box transition, meaning there is a box inside another box and even another inside the last one and so on, then you'd see that half of the boxes make parts of the previous screen disappear and the next scene shows up slowly...
Topic Map scrolling nightmare... By kyonides Date 2017-09-09 17:13
Guess what? I solved it, not thanks to you, guys -_- (Yeah, I'd say I'm a bit disappointed here... but the truth is that I ended up not needing your help at all! (Tongue sticking out XP))

I'm posting this as a second part of my "sorrowful scripting" story, you'll see it does make sense after all!

As I told some guy better known as DerVVulfman last night a solution we both had found long time ago for map scrolling would NOT work on KUnits Gosu, that truth hasn't changed, BUT some creativity was needed to solve this mystery. I had partially found a way to solve it.

# Pressing Down Arrow
@offset_y = [-@screen_y + 608 / 1.08, 0].min# Works but only if you hit the lower edge of the game window then you'd make it scroll

# Pressing Right Arrow
@offset_x = [-@screen_x + 800 / 1.042, 0].min# Works but only if you hit the right edge of the game window then you'd make it scroll

Don't ask me why they had to be those values or else the minimum command wouldn't ever work! (I tried replacing the screen coordinate plus the dimension divided by a weird value with an 8, it automatically chose 0 as result, changing it to max became a new nightmare! The map either got scrolled to the left hand side almost EXPONENTIALLY or a sign change in reverted it by pushing the map to the right hand side making it arrive in Japan!)

But there's always a catch...

What if in some case like when the offset is decreasing (by adding 8 to its actual value) or the remainder (2px?) was possible in one situation? I started trying to make it work and it didn't take me long to noticed it was perfect... almost.

# Pressing Left Arrow
@offset_x += [8, -@offset_x].min if @offset_x < 0 and @screen_x - @offset_x < Map.width * 32

Yes, every single tile is 32 pixels wide and high as well. Multiplying the corresponding dimension sounds quite logical... but not to our dear Ruby Gosu engine! It made the player vanish unless IT, not the player's sprite character, got close to the left edge of the game window. Then I thought I had to define it as Map.width * 16 so it would only do it if the offset was less than half the current map's width... It messed it up as well.

After several attempts I found out the perfect value HAD to be 23.5 and it would work on ANY map that was larger than the minimum width (25 tiles * 32 pixels). Minimum sized maps wouldn't complain at all. (Shocked)

I still had a serious issue to solve, how could I make it stop waiting for the sprite to hit the opposite edge before it scrolled right? (Or to the right hand side?) I wasn't slow at all, I quickly thought a conditional statement would take care of that important job! I was WRONG! (Ticked off) I messed up once again!

Then I had a clever idea, what if the solution I applied to it's opposite direction had a clue on what to do to fix the latter?

@offset_x -= [-8, @offset_x].min if @offset_x < 0 and @screen_x - @offset_x > Map.width * 26 # Yeah I first tried with 26 for a reason I've forgotten...

How weird! It didn't help me, the screen jumped suddenly without warning! How crappy! (Happy with a sweat)

Nope, 0 would make the jump look even more extreme, as much as to beat any X-Gamer while trying to break his bones while flying briefly in the air before dropping onto the floor hitting his legs or arms hard against it...

There was a revelation finally! (Very happy + Tongue sticking out) I had to modify it slightly so it would actually help me there solving my issue.

@offset_x = [@offset_x - 8, @offset_x-@offset_x].min if @offset_x < 0 and @screen_x - @offset_x > Map.width * 26

Got close... but not enough to what people would actually expect, something was missing... (Confused)

Gotcha! I had to include a calculation included in XP, that's all I had to do!

@offset_x = [[@offset_x - 8, @offset_x-@offset_x].min, (Map.width - 25) * 32].max if @offset_x < 0 and @screen_x - @offset_x > Map.width * 26

It should work fine now for sure, I took into account that Gosu has no such real_x coordinates so I had to multiply it by the actual tile width. Wait a minute! (Ticked off) Where did my stupid map go? It looked like it did break through to the other side, whatever that was! (Feeling sick)

After a while I had found an "imperfect solution", but it WAS a solution after all!

@offset_x = [[@offset_x - 8, @offset_x-@offset_x].min, -(Map.width - 25) * 32].max if @offset_x < 0 and @screen_x - @offset_x > Map.width * 26

Say what? (Happy with a sweat) "How's that gonna help you at all?" you may ask me now. Well, it sure did! Yeah, I DO mean it! It took it a few more pixels to react than expected but no signs of oblivion was ever seen!

But how could I make it react soon enough as if I had gone through an invisible trigger right in the middle of the game window? That was the moment when I started fiddling with the map width value by increasing or decreasing it over and over again...

@offset_x = [[@offset_x - 8, @offset_x-@offset_x].min, -(Map.width - 25) * 32].max if @offset_x < 0 and @screen_x - @offset_x > Map.width * 12.75

Yeah! I DID IT! (Winks) I still don't know what the best value was 12.75, but it sure works fine! (Laughing + Tongue sticking out)

And for a while this early morning (like till 2 o'clock) I was happy with the result until I found out something was missing there... Indifferent

No, wait a second! (Shocked) My second scripting epiphany had arrived! Laughing A missing part was not the ACTUAL issue here, but an extra part was indeed! (Happy with a sweat)

@offset_x = [@offset_x - 8, -(Map.width - 25) * 32].max if @offset_x < 0 and @screen_x - @offset_x > Map.width * 12.75

Yeah, guys, the part inbetween was completely useless at that point... (Happy with a sweat)

Hold on! I clearly stated earlier that such basic solution we scripters knew all about didn't help me there at all, didn't I? And you know what, I wasn't lying, I just ignored why it didn't and never would. My solution was completely customized and that's how it should have been from the very beginning! Shocked

But what did I do? (Sarcasm)

First of all it's not that similar, I don't call the map to get any scrolling variable, and I skipped any unnecessary calculations and I never ADD the current distance, which is easily determined in my project, it's always 8 (most of the time (Laughing + Tongue sticking out) ). Oh and I substract the extra tiles width as well!

MYSTERY SOLVED! Ruby Gosu does never add distance to move everything on screen, it substract all values in a flip! (Shocked)

Solving the issue with the map's height was no problem at all! A real piece of cake! (Very happy + Tongue sticking out)

Was it? (Confused)

Take a look at the actual scrolling code and see by yourself if that was an accurate statement or not.

class Player
  def update
   return if @halt
   @last_x = @screen_x
   @last_y = @screen_y
   return if moved?
   if Gosu.button_down?(Gosu::KbDown)
     @dir = @other_way ? 8 : 2
     return unless pass?
     @y += 0.5
     @screen_y = @y * 16
     @offset_y = [@offset_y - 8, -(Map.height - 19) * 32].max if @screen_y > Map.height * 8
     update_steps
   elsif Gosu.button_down?(Gosu::KbUp)
     @dir = @other_way ? 2 : 8
     return unless pass?
     @y -= 0.5
     @screen_y = @y * 16
     @offset_y += [8, -@offset_y].min if @offset_y < 0 and @screen_y - @offset_y < Map.height * 32
     update_steps
   elsif Gosu.button_down?(Gosu::KbLeft)
     @dir = @other_way ? 6 : 4
     return unless pass?
     @x -= 0.5
     @screen_x = @x * 16
     @offset_x += [8, -@offset_x].min if @offset_x < 0 and @screen_x - @offset_x < Map.width * 23.5
     update_steps
   elsif Gosu.button_down?(Gosu::KbRight)
     @dir = @other_way ? 4 : 6
     return unless pass?
     @x += 0.5
     @screen_x = @x * 16
     @offset_x = [@offset_x - 8, -(Map.width - 25) * 32].max if @screen_x > Map.width * 12.75
     update_steps
   end
   if button_down?(:enter) or button_down?(:return)
     Map.events.each do |event|
     blocked = block_pass?(event)
     next unless blocked
     event.react_now if event.react
     if event.button?
       event.activate
       @halt = true
       return
     end
   end
  end
end

class SceneMap
  def update_scene
    if @map_ticks > 0
      @map_ticks -= 1
      @map_texts.clear if @map_ticks == 0
    end
    @player.update
    @offset_x = @player.offset_x
    @offset_y = @player.offset_y
    Map.events.each {|e| e.update }
    @spriteset.update
    if press_quit?
      Game.cancel_se.play
      Game.setup(SceneKUnitsMenu)
      return
    elsif button_down?(:left_ctrl)
      Game.ok_se.play
      Game.setup(SceneKUnitsAchieve)
    elsif button_down?(:caps_lock)
      Game.ok_se.play
      Game.setup(SceneKUnitsFoes)
    elsif button_down?(:left_shift)
      Game.ok_se.play
      Game.setup(SceneKBookPages, id: 1)
    end
  end

  def draw
    @window.clip_to(0,0,@window_width,@window_height) do
      @window.translate(@offset_x,@offset_y) do
        @spriteset.draw
      end
    end
    @map_texts.each {|text| text.draw }
  end
end
Topic Map scrolling nightmare... By kyonides Date 2017-09-09 17:03
I was trying to implement a map scrolling system thanks to Gosu's translate method that semiautomatically handles tiles and events offsets making it easier for game developers to handle more ordinary stuff than usual while drawing a map. Sadly you end up watching how my player and his not so heroic team makes the map look larger and darker than expected. I'm not really used dealing with scrolling issues so I thought somebody here could tell me what I'm doing wrong here hopefully... For now solving the issue with the horizontal map scroll should suffice. I only commented those lines that somehow affect map scrolling.

This happens when I go left... (Those two lonely tiles denote the actual end of the map on the righthand side.) (Check out the first image I attached.)

And this is the disaster that takes place if I go right... (Take a look at the second screenshot if you ever dare...)

class Player
  def update
    return if @halt
    @last_x = @screen_x
    @last_y = @screen_y
    return if moved?
    if Gosu.button_down?(Gosu::KbDown)
      @dir = @other_way ? 8 : 2
      return unless pass?
      @y += 0.5#actual_speed
      @screen_y = @y * 16
      update_steps
    elsif Gosu.button_down?(Gosu::KbUp)
      @dir = @other_way ? 2 : 8
      return unless pass?
      @y -= 0.5#actual_speed
      @screen_y = @y * 16
      update_steps
    elsif Gosu.button_down?(Gosu::KbLeft)
      @dir = @other_way ? 6 : 4
      return unless pass?
      @x -= 0.5#actual_speed
      @screen_x = @x * 16
      ### Calculating the horizontal offset, Current direction: Left (4)
      @offset_x = [0, -@screen_x].min if @screen_x < Map.width * 16
      update_steps
    elsif Gosu.button_down?(Gosu::KbRight)
      @dir = @other_way ? 4 : 6
      return unless pass?
      @x += 0.5#actual_speed
      @screen_x = @x * 16
      ### Calculating the horizontal offset, Current direction: Right (6)
      @offset_x = [[-@screen_x + @last_x, -Map.width * 16].max, 0].min if @screen_x > Map.width * 16
      update_steps
    end
    if button_down?(:enter) or button_down?(:return)
      Map.events.each do |event|
        blocked = block_pass?(event)
        next unless blocked
        event.react_now if event.react
        if event.button?
          event.activate
          @halt = true
          return
        end
      end
    end
  end
end

class SceneMap
  def update_scene
    @offset_x = @player.offset_x # saving last horizontal offset
    @offset_y = [-@player.screen_y + @window_height / 1.08, 0].min
    if @map_ticks > 0
      @map_ticks -= 1
      @map_texts.clear if @map_ticks == 0
    end
    @player.update # Calling Player's Update Method and setting a new horizontal offset value
    Map.events.each {|e| e.update }
    @spriteset.update
    if press_quit?
      Game.cancel_se.play
      Game.setup(SceneKUnitsMenu)
      return
    elsif button_down?(:left_ctrl)
      Game.ok_se.play
      Game.setup(SceneKUnitsAchieve)
    elsif button_down?(:caps_lock)
      Game.ok_se.play
      Game.setup(SceneKUnitsFoes)
    elsif button_down?(:left_shift)
      Game.ok_se.play
      Game.setup(SceneKBookPages, id: 1)
    end
  end

  def draw
    @window.clip_to(0,0,@window_width,@window_height) do # Some sort of Viewport singleton command
      @window.translate(@offset_x,@offset_y) do # Scroll loop
        @spriteset.draw
      end
    end
    @map_texts.each {|text| text.draw }
  end
end
Attachment: kunitsgosumaperror01.png - RIGHT! It's a true mess indeed! (33k)
Attachment: kunitsgosumaperror02.png - A sorrowful blank space Left alone! (27k)
Topic KBookPages By kyonides Date 2017-09-05 02:29
This is my very own implementation of a book page flipping effect I've been finding everywhere, even on my cellphone's sfx... Thanks to Gosu's draw_as_quad feature it's possible to easily implement a readable book with Ruby Gosu.

Download Link: Click here!

I know the example images look kind of lame when I added some comments or labels, but it was a humble test anyway...
Attachment: kbookpages01.png - Opening Book (492k)
Attachment: kbookpages02.png (737k)
Attachment: kbookpages03.png (743k)
Topic Input update interval By kyonides Date 2017-09-05 02:24
OK, it seems to be something I need to carefully analyze in hopes of finding a not so heavy solution to make it happen... Perhaps I could use a Module to avoid using global variables...
Topic Input update interval By kyonides Date 2017-09-02 17:06
Sounds bad... What can you tell me about the transitions? What should I learn to implement them in my Ruby Gosu projects? (Don't tell me I can only do that via C extensions... -_-)
Topic How to compile or compress Ruby files By kyonides Date 2017-09-02 16:45
Well, in my KUnits Gosu project I've been implementing many features that require separate binary data files. I know in Windows there's a gem to pack everything into a single package, but is there anything I can do in Linux that could pack all those data files in a single one? (Not including ruby script files...)
Topic Input update interval By kyonides Date 2017-09-02 16:34
I see, but I HATE to implement such counters, they look weird and I can't place it in button_down? method that's the one that gets updated often. Isn't there any other alternative? It had become a nuisance to update the counter info every time I had to change the update interval... Besides I have already noticed that even the counter blocks some attempts to press a different button that should trigger different methods...
Topic what happens when you call draw? By kyonides Date 2017-08-31 17:40
Why don't you try using Benchmark? It will tell you what is the fastest solution, make an example script, making sure you placed some require '.benchmark' on top of it and later call both kind of methods, perhaps one first and later the other one using Benchmark.real_time method. It will tell you how many seconds or milliseconds it took to make gosu draw them.
Topic Input update interval By kyonides Date 2017-08-30 02:26
So far I've seen and read Gosu (for Ruby) usually updates its contents or its input info every 16.6 milliseconds unless you change that right at the beginning. I've been having an issue with the input update stuff because I need the game to update images every 40 milliseconds or less to make them run smoothly or decently at least, but then I see that handling input becomes a pain you know where. It updates the button_down? method too often for my needs and the only thing I could do was to make my game ignore a button that has not released so far, forcing the player to keep pushing the button once and again. Most of the time it might work if I'm working with menus but not when walking on a map with my playable characters. How can I alter the input update frequency while keeping the refresh update frequency intact? I need it to ignore a pressed button that is not released for a few extra milliseconds...

I'd also be grateful if you could share some ideas on how to implement graphical transitions on Gosu (for Ruby).

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill