Ergebnis 1 bis 13 von 13

Thema: Tutorialidee: "RGSS games from scratch"

Hybrid-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #1
    Der zweite Link ist derselbe wie der erste.

  2. #2
    Ups, geändert (Man hätte sich aber auch anhand des Dateinamens denken können, wie der andere Link lautet)

  3. #3

    Doktor von Stein Gast
    Die Idee, allein über die "Sprache" RGSS Spiele zu schreiben, hat mich auch schon sehr oft beschäftigt. Das dabei natürlich Dinge wie Plattformunabhängigkeit flöten gehen, damit muss man umgehen. Aber es hilft ungemein, die Sprache von Grund auf zu lernen. Ich habe da auch direkt mal ein Beispiel dabei: Eine sehr einfache Snake-Variante.

    Download: Snake.rar

    Code:
    Code:
    class Game
      
      def main
        @direction = 0
        @tick = 0
        @tick_max = 10
        @parts = []
        @parts[0] = Sprite.new
        @parts[0].bitmap = Bitmap.new(16, 16)
        @parts[0].bitmap.fill_rect(Rect.new(0, 0, 16, 16), Color.new(200, 200, 200))
        @parts[0].x = 320
        @parts[0].y = 240
        @block = Sprite.new
        @block.bitmap = Bitmap.new(16, 16)
        @block.bitmap.fill_rect(Rect.new(0, 0, 16, 16), Color.new(255, 255, 255))
        @block.x = rand(39)*16
        @block.y = rand(29)*16
        Graphics.transition
        loop do
          Graphics.update
          Input.update
          update
          break if $scene != self
        end
      end
      
      def update
        @tick += 1
        if @tick >= @tick_max
          @tick = 0
          case @direction
          when 0
            @parts[-1].y -= 16
            reset if @parts[-1].y <= -16
          when 1
            @parts[-1].x += 16
            reset if @parts[-1].x >= 640
          when 2
            @parts[-1].y += 16
            reset if @parts[-1].y >= 480
          when 3
            @parts[-1].x -= 16
            reset if @parts[-1].x <= -16
          end
          follow if @parts.length > 1
        end
        if Input.trigger?(Input::UP)
          @direction = 0
        elsif Input.trigger?(Input::RIGHT)
          @direction = 1
        elsif Input.trigger?(Input::DOWN)
          @direction = 2
        elsif Input.trigger?(Input::LEFT)
          @direction = 3
        end
        if @parts[-1].x == @block.x && @parts[-1].y == @block.y
          new_part
          @block.x, @block.y = rand(39)*16, rand(29)*16
        end
        reset if crushing?
      end
      
      def reset
        @parts.each{|p| p.dispose}
        @parts = []
        @parts[0] = Sprite.new
        @parts[0].bitmap = Bitmap.new(16, 16)
        @parts[0].bitmap.fill_rect(Rect.new(0, 0, 16, 16), Color.new(200, 200, 200))
        @parts[0].x = 320
        @parts[0].y = 240
        @direction, @tick, @tick_max = 0, 0, 10
        @block.x, @block.y = rand(39)*16, rand(29)*16
      end
    
      def new_part
        @parts.unshift(Sprite.new)
        @parts[0].bitmap = Bitmap.new(16, 16)
        @parts[0].bitmap.fill_rect(Rect.new(0, 0, 16, 16), Color.new(255, 255, 255))
        @parts[0].x = -16
        @parts[0].y = -16
        @tick_max -= 1 if (@parts.length % 5 == 0) && @tick_max > 2
      end
        
      def follow
        for i in 0..@parts.length-3
          @parts[i].x = @parts[i+1].x
          @parts[i].y = @parts[i+1].y
        end
        case @direction
        when 0
          x = @parts[-1].x
          y = @parts[-1].y + 16
        when 1
          x = @parts[-1].x - 16
          y = @parts[-1].y
        when 2
          x = @parts[-1].x
          y = @parts[-1].y - 16
        when 3
          x = @parts[-1].x + 16
          y = @parts[-1].y
        end
        @parts[-2].x = x
        @parts[-2].y = y
      end
      
      def crushing?
        x = @parts[-1].x
        y = @parts[-1].y
        for i in 0..@parts.length-2
          if @parts[i].x == x && @parts[i].y == y
            return true
          end
        end
        return false
      end
    
    end
    (Bitte keine Kommentare zu meinem schlechten Schreibstil - Ist schon relativ alt.)

    Wenn Interesse da ist, kann ich das sehr gerne näher erläutern.

  4. #4
    Ich habe noch ein oder zwei Projekte mit dem RPG-Maker XP für welche ich komplette (oder fast komplette) eigene Engines geschrieben habe.
    Auch relativ alte Arbeiten, aber vielleicht kann der ein oder andere Gefallen an den Subsystemen finden.

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •